I am trying to understand GDI functions so I started to make some sample programs.However I cant grasp DC 'es.For example



.IF ax == IDM_About ;is this our about
mov eax,hInstance
invoke DialogBoxParam,hInstance,112,hWin,addr AboutDlg,0
.....


AboutDlg proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
LOCAL hdc:DWORD
LOCAL rect:RECT
LOCAL ps:PAINTSTRUCT

.IF uMsg==WM_INITDIALOG
invoke GetDC,hWin
mov hDC,eax
invoke CreateCompatibleDC,hDC
mov hScrollDC,eax
invoke GetClientRect,hWin, ADDR rect
invoke DrawText, hScrollDC,ADDR abouttxt,-1, ADDR rect, DT_CENTER or DT_VCENTER
...

However

if I draw at WM_PAINT it works

.ELSEIF uMsg==WM_PAINT
invoke BeginPaint,hWin, ADDR ps
mov hdc,eax ;this has different value than global hDC
invoke GetClientRect,hWin, ADDR rect
invoke DrawText, hdc,ADDR abouttxt,-1, ADDR rect, DT_CENTER or DT_VCENTER
invoke EndPaint,hWin, ADDR ps

I also tried to use BitBlt to copy hScrollDC to hdc at WM_PAINT and it didnt worked too.

What is different between these DC 'es.


Second at WM_DESTROY I use below code
.ELSEIF uMsg == WM_DESTROY
invoke DeleteDC,hScrollDC
invoke ReleaseDC,hWin,hDC

is this proper way of releasing & destroying DC.Thanks
Posted on 2003-02-24 17:01:43 by LaptoniC
You can only see the results of drawing if the window is opened up (maximized or restored). When you get WM_INITDIALOG, no window is being displayed yet. So drawing as a response to this message is wasted. (The system does not keep track of undisplayed portions of images.)
Posted on 2003-02-24 20:34:54 by tenkey
Thanks for the reply but I saw some examples which draw text at WM_CREATE which they create dialogboxes with createwindowex function.AFAIK, CreateCompatibleDC creates memory DC as I said in my post if I draw to that DC and bitblt on WM_PAINT it doesnt works too.
Posted on 2003-02-26 08:55:34 by LaptoniC