|
-
Jun 12th, 2007, 01:15 AM
#1
Thread Starter
Addicted Member
Draw line on windows
Draw Line On Windows
Does anyone know how to make it so that something draws a line on windows using the variables x1,x2,y1 and y2. e.g
Code:
drawLineWindows(x1,x2,y1,y2,color)
Picture below for example.

Thanks, Nuclear112
Last edited by nuclear112; Jun 12th, 2007 at 01:27 AM.
-
Jun 12th, 2007, 04:02 AM
#2
Thread Starter
Addicted Member
Re: Draw line on windows
Can someone please give me a hand
-
Jun 12th, 2007, 04:08 AM
#3
Re: Draw line on windows
I believe you will need to use SetPixels or some other API i will see what i cna come up with
-
Jun 12th, 2007, 07:25 AM
#4
Re: Draw line on windows
you want to do this on the desktop (or form), or on an image or form within your program?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jun 12th, 2007, 07:41 AM
#5
Re: Draw line on windows
Here is a wonderfully messy method to draw non persistent lines on your desktop... This method is safe but by no means great, the only way to delete what you draw is to force a desktop refresh.
Code:
Option Explicit
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, lpPoint As Any) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Sub Command1_Click()
DrawLineOnDesktop 100, 100, 400, 400, vbRed, 5
End Sub
Private Sub DrawLineOnDesktop(ByVal X1 As Long, Y1 As Long, X2 As Long, Y2 As Long, Optional ByVal Colour As Long = -1, Optional ByVal Wdth As Long = 0)
Dim Wnd As Long, DC As Long
Dim hPen As Long, hOld As Long
Wnd = GetDesktopWindow
DC = GetWindowDC(Wnd)
If Colour <> -1 Then
hPen = CreatePen(0, Wdth, Colour) 'create a new pen
hOld = SelectObject(DC, hPen) 'our new pen is selected, hOld is the old object handle
End If
MoveToEx DC, X1, Y1, ByVal &H0
LineTo DC, X2, Y2
If Colour <> -1 Then DeleteObject SelectObject(DC, hOld) 'delete new pen and reselect the old one
ReleaseDC Wnd, DC
End Sub
An alternative and perhaps much better way would be to create a large borderless form and have that form pretend to be the desktop either by copying the desktop DC onto it or by creating a transparent form (SetWindowLayerAttributes win2k+)
-
Jun 12th, 2007, 02:17 PM
#6
Thread Starter
Addicted Member
Re: Draw line on windows
Greats thanks for the code... Can someone edit this code so that the line can be deleted?
-
Jun 13th, 2007, 12:18 AM
#7
Thread Starter
Addicted Member
Re: Draw line on windows
Can someone please help me?
-
Jun 13th, 2007, 12:26 AM
#8
Re: Draw line on windows
As Milk already stated
the only way to delete what you draw is to force a desktop refresh.
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Jun 13th, 2007, 12:31 AM
#9
Thread Starter
Addicted Member
Re: Draw line on windows
But isn't there way to rescript it so that it can turn it on and off?
Have have seen it done before...
-
Jun 13th, 2007, 12:37 AM
#10
Re: Draw line on windows
If have seen a line or something similar, drawn onto the desktop, which could be switched on and off, it was either not on the desktop (maybe an tranparent form) or the swichting-off was just the refreshing of the desktop!
The code presented by milk just drwas a line onto something (the dektop), it's not an control which has a .visible property!
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Jun 13th, 2007, 12:58 AM
#11
Thread Starter
Addicted Member
Re: Draw line on windows
Oh... Cause what im trying to achieve is... In my program I want the user to click and select a window and when they select the window a box will flash around the windows handle(hwnd).
-
Jun 13th, 2007, 01:29 AM
#12
Re: Draw line on windows
 Originally Posted by nuclear112
In my program I want the user to click and select a window and when they select the window a box will flash around the windows handle(hwnd).
I take it, you don't want to activate that window (in other words, your applications window is activated but the selected is "highlighted").
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Jun 13th, 2007, 01:31 AM
#13
Thread Starter
Addicted Member
Re: Draw line on windows
Na its ok if the other window gets activated
-
Jun 13th, 2007, 01:40 AM
#14
Re: Draw line on windows
OK, but why invent something new, windows does highlight the activated window, if you don't like the color of the the activated windowtitle just change the color-setting for that.
Or am I missing a point?
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Jun 13th, 2007, 01:55 AM
#15
Thread Starter
Addicted Member
Re: Draw line on windows
mmm, I think we are thinking about 2 different things
-
Jun 14th, 2007, 07:11 AM
#16
Fanatic Member
Re: Draw line on windows
Hi,
I am not sure this is the thread that I was trying to remember in my post -
http://www.vbforums.com/showthread.p...73#post2910573
But I will post a link to my text solution -
http://www.planet-source-code.com/vb...53509&lngWid=1
It may help, as it appears to be using similar API's
If someone can provide the tweak I mention in the top link (write over a form that was Topmost) , I would appreciate it.
Last edited by RobCrombie; Jun 14th, 2007 at 07:15 AM.
Rob C
-
Jun 14th, 2007, 02:21 PM
#17
Thread Starter
Addicted Member
Re: Draw line on windows
Thanks you are heading on the right track... But can you make it so that it draws a line instead of text?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|