Results 1 to 4 of 4

Thread: beginner

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    203

    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 ?

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    VB Code:
    1. Public Declare Function GetDesktopWindow Lib "user32" () As Long
    2. Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    3. Dim hWndDesk As Long, hDCDesk As Long
    4. hWndDesk = GetDesktopWindow()
    5. 'Get the desktop window's device context
    6. hDCDesk = GetDC(hWndDesk)
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    203
    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

  4. #4
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    I doubt this is what's doing it, but it could be it. You've got this:
    VB Code:
    1. Dim abc, xdim, ydim As Long
    2. 'but it should be this
    3. 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:
    1. Public Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long
    2. Public Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
    3.  
    4. Private Sub Command1_Click()
    5.    Dim xdim As Long, ydim As Long
    6.    Dim hWndDesk As Long, hDCDesk As Long
    7.    Dim str As String
    8.    hWndDesk = GetDesktopWindow
    9.    'get the entire desktop window DC
    10.    hDCDesk = GetWindowDC(hWndDesk)
    11.    xdim = Val(Text1.Text )
    12.    ydim = Val(Text2.Text)
    13.    str = "yyyyyyy..."
    14.    'the return isn't really important, unless you may want to check it for a possible error return
    15.    TextOut hDCDesk, xdim, ydim, str, Len(str)
    16.    'release the DC
    17.    ReleaseDC hWndDesk, hDCDesk
    18. 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
  •  



Click Here to Expand Forum to Full Width