The MASM Forum
General => The Campus => Topic started by: zedd151 on September 21, 2022, 01:48:18 AM
-
Yes I know I can search MSDN but need to hear from someone with practical experience drawing lines. :smiley:
If I understand correctly:
Call CreatePen to create pen object for the drawing of lines.
Then use MoveToEx for the start position of a line?
Then use LineTo for the end position?
For right angle, use that LineTo position as position for next MoveToEx call? Or does x/y have to be incremented?
Seems simple enough if not very verbose coding. I've used these functions a long time ago, but don't remember if their are any quirks with drawing lines. Iirc there were some oddities.
-
This is also vague memory, MoveToEx followed by more than one LineTo. All X Y coordinates.
-
Call CreatePen to create pen object for the drawing of lines.
Use invoke SelectObject, hDC, hPen
Then use MoveToEx for the start position of a line?
Then use LineTo for the end position?
For right angle, use that LineTo position as position for next MoveToEx call? Or does x/y have to be incremented?
For a right angle (and any other angle), you need to provide the next point.
If you have many lines, you might use a macro, used as _LineTo x, y:
_LineTo MACRO argX, argY
push argX
push argY
call _xLineTo
endm
_xLineTo:
invoke LineTo, hDC, [esp+12], [esp+4]
retn 8
Check also PolyLine
-
Okay. So, the end point of a line wouldn't be the exact starting point for next line at right angle then. (would be missing a pixel)
I think I'll just stick with drawing a rectangle for a black background then and let the drawing of the cells take care of making it look like a grid. Otherwise way to much code involved in drawing lines to create a grid. Would be a nice coding exercise, but too much code for the purpose that I had intended. Thanks.
This is also vague memory, MoveToEx followed by more than one LineTo. All X Y coordinates.
So for a right angle:
MoveToEx --> LineTo --> LineTo (after x, y adjustment)
for a box:
MoveToEx --> LineTo --> LineTo --> LineTo --> LineTo? (after x, y adjustment between each call)
x,y coordinates not shown, but inferred above. :tongue: I think I've got the basic gist of it.
-
It's easy to make grid with x and y in loops.
-
Hi swordfish,
The masm32 library provides a function to draw lines :
line proc hndl:DWORD,colr:DWORD,x1:DWORD,y1:DWORD,x2:DWORD,y2:DWORD
Description
line will display a line between the first X,Y co-ordinate and the second X,Y co-ordinate.
Parameters
1. hndl The handle of the window where the line will be displayed.
2. colr The RGB COLORREF value for the colour of the line.
3/4 x1, y1 The X, Y co-ordinates of the start of the line.
5/6 x2, y2 The X, Y co-ordinates of the end of the line.
A quick example :
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
.data
DlgBox db 1,0,255,255,0,0,0,0,0,0,0,0,64,0,207,16
db 0,0,6,0,6,0,147,0,136,0,0,0,0,0,71,0
db 114,0,97,0,112,0,104,0,0,0,8,0,0,0,0,0
db 77,0,83,0,32,0,83,0,65,0,78,0,83,0,32,0
db 83,0,69,0,82,0,73,0,70,0,0,0
.data?
hInstance dd ?
hDC dd ?
.code
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
xor ecx,ecx
invoke DialogBoxIndirectParam,hInstance,\
ADDR DlgBox,ecx,ADDR DlgProc,ecx
invoke ExitProcess,0
DlgProc PROC uses esi ebx hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL ps:PAINTSTRUCT
.IF uMsg==WM_CLOSE
invoke EndDialog,hWnd,NULL
.ELSEIF uMsg==WM_PAINT
lea eax,ps
invoke BeginPaint,hWnd,eax
mov hDC,eax
xor esi,esi
mov ebx,200
@@:
invoke line,hWnd,esi,\
esi,esi,ebx,200
sub ebx,2
jnz @b
invoke EndPaint,hWnd,ADDR ps
.ELSE
xor eax,eax
ret
.ENDIF
mov eax,TRUE
ret
DlgProc ENDP
END start
-
Okay. So, the end point of a line wouldn't be the exact starting point for next line at right angle then. (would be missing a pixel)
No, that's not correct: if you keep on doing LineTo()s, you'll draw a contiguous line with no breaks.
You might be thinking of the "fencepost problem" with RECTs and other objects which don't include the right and bottom borders (width-1/height-1). But LineTo() will always join up perfectly from the previous position.
Try it.
-
Ok guys, thanks for the replies. I'll keep these hints for future use, if it ever comes up.
-
Oh, it'll come up. Stuff always comes up. (Hopefully not your last meal ...)