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.
Printable View
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.
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.
Code:hdc = GetDC(hwnd)
MoveToEx hdc,x1, y1, 0
LineTo hdc, x2, y2
ReleaseDC hwnd, hdc
It says it's missing GetDC not declared.
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
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
or windows SDK ;)
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?
what doesn't work, what does it say, what do you have?
That code will only work in a module...if you're trying to declare it from a form then add Private before each line.Quote:
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?
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.netQuote:
Originally posted by abdul
or windows SDK ;)
regards,