News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

GDI-lineto question(MASM&C++)

Started by poetbox, March 04, 2007, 12:35:40 PM

Previous topic - Next topic

poetbox

In C++ or OTHER Langs we always draw lines by 5 steps such as this:
  HDC   hdc;   
  lpDDSBuffer->GetDC(&hdc);   
  HPEN   hpen   =   CreatePen   (PS_SOLID,   5,   RGB(0,   0,   0));   
  SelectObject   (hdc,   hpen);   
  MoveToEx   (hdc,   100,   100,   NULL);   
  LineTo   (hdc,   200,   100);   
  lpDDSBuffer->ReleaseDC(hdc);   

While in MASM,we draw lines without the first line "GETDC",why?
      invoke   CreatePen,_dwPen,_dwPenWidth,_dwColor
      invoke   SelectObject,_hDC,eax
      invoke   DeleteObject,eax
      invoke   MoveToEx,_hDC,_dwStartX,_dwY,NULL
      invoke   LineTo,_hDC,_dwEndX,_dwY
      ret

I'm a newbie in MASM,I wrote such programs by VB6.When I learn to write a simple program of drawing a line onto the current window,I read many similar sources and then have no idea.
Can anyone help me with it?Or provide a simple source file which can only draw a line onto the current window and auto-refresh itself.
Thanks for any idea.

TNick

Welcome, poetbox!

The rules for using the API are the same in whatever language.
In this particular case:
1) if you are drawing as a response to WM_PAINT, you should use
INVOKE BeginPaint, ...
;draw goes here
INVOKE EndPaint,...
and you should use the DC from PAINTSTRUCT
2) if you are drawing somwhere else
INVOKE GetDC,...
;draw goes here
INVOKE ReleaseDC,...
and you should use the hDC returned by GetDC in eax register.

HTH,
Nick

poetbox

thank you very much,You're so excellent!