PDA

Click to See Complete Forum and Search --> : How to draw a Line.


prog_tom
Aug 4th, 2001, 03:49 AM
Hi I would like to know how to draw a Line in VB using GDi? I already know how to create a line... Just want to know how to create a line in Code.

kedaman
Aug 4th, 2001, 04:05 AM
Not so complicated, here's a sample that draws a line from x1,y1 to x2,y2, if you want to draw from 2 to another point you don't need to movetoex in between.

hdc = GetDC(hwnd)
MoveToEx hdc,x1, y1, 0
LineTo hdc, x2, y2
ReleaseDC hwnd, hdc

prog_tom
Aug 4th, 2001, 05:57 AM
It says it's missing GetDC not declared.

might
Aug 4th, 2001, 06:36 AM
You should declare GDI functions by adding the following code to the General Declerations part.

Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
Declare Function LineTo Lib "gdi32" Alias "LineTo" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Declare Function MoveToEx Lib "gdi32" Alias "MoveToEx" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Long, ByVal hdc As Long) As Long

kedaman
Aug 4th, 2001, 07:02 AM
You should be able to look up all GDI functions, types and constants in the windows api viewer, it should be in your addin list

abdul
Aug 4th, 2001, 09:59 PM
or windows SDK ;)

prog_tom
Aug 5th, 2001, 03:11 PM
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long


Doesn't work
Anyone?

kedaman
Aug 6th, 2001, 03:22 AM
what doesn't work, what does it say, what do you have?

nishantp
Aug 7th, 2001, 08:14 AM
Originally posted by prog_tom
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long


Doesn't work
Anyone?
That code will only work in a module...if you're trying to declare it from a form then add Private before each line.

Chris
Aug 7th, 2001, 10:41 AM
Originally posted by abdul
or windows SDK ;)

Platform SDK is mainly explain for VC++, as for VB, you still need the VB build in API Viewer or download the latest APIViewer from www.AllApi.net (http://allapi.net)

regards,