I am trying to read a calc window and copy it into my window using bitblt, but the program just crashes. Can anyone advise if this should work or should I have a look elsewhere.

Posted on 2008-08-14 09:40:14 by sidey1234
How do you read it? Are you sure you are getting something? Post some code if you'd like.
Posted on 2008-08-14 10:46:39 by JimmyClif
You will have to bear with me for the mismash of calling conventions, I am only a week old on win32 assembler and have been been reading iczelions tuts :D

My basic outline for the code is to.

1 Create a window (working)
2 test if calculator is running and update the window to say wether it is or not (working)
3 if the window is found then copy the window into my window

There is no real reason for this, just learning, here is the code snippet, as i say please bear with if the code is horrible inefficent or just damn right smoking crack :D

push offset windownamefw
push 0
call FindWindowA
mov fwreturn, eax
call GetDC, Hwnd
mov hDC, eax
                .if fwreturn != 0
                call TextOutA, hDC, 1, 22, offset searchfor, 21
                call TextOutA, hDC, 1, 40, offset fwstringtrue, 14
call TextOutA, hDC, 1, 58, offset windownamefwc, 3
                call ReleaseDC, Hwnd, hDC
                call TextOutA, hDC, 1, 2, offset searchfor, 21     
                call TextOutA, hDC, 1, 22, offset windownamefw, 10
                call TextOutA, hDC, 1, 40, offset fwstringfalse, 15
                call ReleaseDC, Hwnd, hDC

call GetDC, Hwnd
mov hDC, eax
call GetDC, fwreturn
mov hDC2, eax

push 2
push 2
push hDC
push 2
push 2
push 20
push 20
push hDC2
call BitBlt
call EndPaint, Hwnd, 0
Push Hwnd
call UpdateWindow
call ReleaseDC, Hwnd, hDC
call ReleaseDC, fwreturn, hDC2
Posted on 2008-08-14 11:32:19 by sidey1234
Start by checking the return values from the api calls better.
For example, you're checking result of FindWindowA and using it as a switch for the two TextOut logic blocks, but then you go ahead and pass the result to GetDC without a second thought - what happens if the result is NULL? GetDC will fail, and you'll be handing a bad DC to BitBlt.
If you need a quick way to show a debug message, why not use MessageBox?
It's good practise to check for and handle bad return values properly, even if you're pretty sure of the result.
Posted on 2008-08-15 02:36:46 by Homer
Excellent advice thank you.

I did run this through ollydbg and I can see the hDC generated from the clac window being passed to bitblt. Wether this is the correct window or not I don't know, is there a way of checking this?

Also I tried just passing the result of getdc to textout to display in my window and the i get a few ||| and random ascii chars. I'll re-read my code and pass some error checking in :D and see it how I go
Posted on 2008-08-15 03:25:44 by sidey1234
Are you trying to copy the graphical content of the window, or do you just want to read text from the window?
If you only want the text, you can send the window a WM_GETTEXT message.

Note that the EDIT control which contains the text isn't the main window.
Controls such as edit and listbox and combobox etc are 'children' of their parent window, and are considered windows in their own right.
You'll need to enumerate the child windows of the main window in order to obtain the handle of the textbox you want (yes theres other ways).

Posted on 2008-08-15 06:27:16 by Homer
I would just like to copy the graphical view that is displayed in the window. But that WM_GETTEXT tip is also useful, thanks homer I appreciate your time and input
Posted on 2008-08-15 09:20:58 by sidey1234
OK Its solved and now working. instead of having rectangles at the size of 2 and 1 i increased the size to 150 etc. Its not work 100% but i can work it out from here.

Thanks for all the advise, no doubt i'll be back :D
Posted on 2008-08-15 10:12:27 by sidey1234
OK The actual problem was with the SRCCOPY variable in win32.inc, i had it as 00cc020h instead of 00cc0020h :(
Posted on 2008-08-15 16:23:09 by sidey1234
For any future reference:

#define SRCCOPY             (DWORD)0x00CC0020 /* dest = source                   */
#define SRCPAINT            (DWORD)0x00EE0086 /* dest = source OR dest          */
#define SRCAND              (DWORD)0x008800C6 /* dest = source AND dest          */
#define SRCINVERT          (DWORD)0x00660046 /* dest = source XOR dest          */
#define SRCERASE            (DWORD)0x00440328 /* dest = source AND (NOT dest )  */
#define NOTSRCCOPY          (DWORD)0x00330008 /* dest = (NOT source)            */
#define NOTSRCERASE        (DWORD)0x001100A6 /* dest = (NOT src) AND (NOT dest) */
#define MERGECOPY          (DWORD)0x00C000CA /* dest = (source AND pattern)    */
#define MERGEPAINT          (DWORD)0x00BB0226 /* dest = (NOT source) OR dest    */
#define PATCOPY            (DWORD)0x00F00021 /* dest = pattern                  */
#define PATPAINT            (DWORD)0x00FB0A09 /* dest = DPSnoo                  */
#define PATINVERT          (DWORD)0x005A0049 /* dest = pattern XOR dest        */
#define DSTINVERT          (DWORD)0x00550009 /* dest = (NOT dest)              */
#define BLACKNESS          (DWORD)0x00000042 /* dest = BLACK                    */
#define WHITENESS          (DWORD)0x00FF0062 /* dest = WHITE                    */
Posted on 2008-08-15 20:05:05 by ti_mo_n