PDA

Click to See Complete Forum and Search --> : beginner


udit99
Sep 15th, 2001, 07:29 PM
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 ?

Vlatko
Sep 15th, 2001, 07:47 PM
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)

udit99
Sep 15th, 2001, 08:27 PM
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 = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy yyyyyyyyyyyyyy"
abc = TextOut(hDCDesk, xdim, ydim, str, Len(str))

End Sub

Kaverin
Sep 15th, 2001, 08:45 PM
I doubt this is what's doing it, but it could be it. You've got this:

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.

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