|
-
Sep 15th, 2001, 07:29 PM
#1
Thread Starter
Addicted Member
beginner
Hi I'm a beginner to this API stuff and need sum help.
I need 2 write text on the desktop. Will this API do ?
Public Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
If yes, then how do I retreive the hdc of the dektop ?
-
Sep 15th, 2001, 07:47 PM
#2
Frenzied Member
VB Code:
Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Dim hWndDesk As Long, hDCDesk As Long
hWndDesk = GetDesktopWindow()
'Get the desktop window's device context
hDCDesk = GetDC(hWndDesk)
-
Sep 15th, 2001, 08:27 PM
#3
Thread Starter
Addicted Member
I'm using this code to try to write on the desktop, but whatever dimensions I specify, I can't get any text on the desktop.
Private Sub Command1_Click()
hWndDesk = GetDesktopWindow()
'Get the desktop window's device context
hDCDesk = GetDC(hWndDesk)
Dim abc, xdim, ydim As Long
Dim str As String
xdim = Text1.Text
ydim = Text2.Text
str = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy yyyyyyyyyyyyyyy"
abc = TextOut(hDCDesk, xdim, ydim, str, Len(str))
End Sub
-
Sep 15th, 2001, 08:45 PM
#4
Fanatic Member
I doubt this is what's doing it, but it could be it. You've got this:
VB Code:
Dim abc, xdim, ydim As Long
'but it should be this
Dim abc As Long, xdim As Long, ydim As Long
Without the As Long after each one, VB will make them type variant by default. That could be messing up the API. If GetDC() didn't work, you could try GetWindowDC() as well. You should be releasing that DC when you're done too since it's a common one to the system.
VB Code:
Public Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
Private Sub Command1_Click()
Dim xdim As Long, ydim As Long
Dim hWndDesk As Long, hDCDesk As Long
Dim str As String
hWndDesk = GetDesktopWindow
'get the entire desktop window DC
hDCDesk = GetWindowDC(hWndDesk)
xdim = Val(Text1.Text )
ydim = Val(Text2.Text)
str = "yyyyyyy..."
'the return isn't really important, unless you may want to check it for a possible error return
TextOut hDCDesk, xdim, ydim, str, Len(str)
'release the DC
ReleaseDC hWndDesk, hDCDesk
End Sub
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
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
|