Results 1 to 4 of 4

Thread: Cute little app

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    Yugoslavia
    Posts
    16

    Exclamation

    If I understood properly GetWindowText call returns the caption property of a control. Is that true?
    I have one problem: I'm trying to make an app that will change the caption of every control mouse moves over.
    I use the GetCursorPos call to get the cursors position, then I use WindowFromPointXY call with the position I got from the previous call to get the handle of the object my mouse is on, then I use the SetWindow call to set the caption, but there seems to be a problem here. It changes the caption of a window at once, but the caption of a label stays the same and only when the parent window refreshes the caption changes. I've tried to use the UpdateWindow but I had no results. The strange thing is that when I don't use a variable to store the objects handle, but I write the handle myself it changes without having to refresh the window.
    Anybody knows what the heck is the matter whit this.

  2. #2
    Guest
    Try the following code.
    Code:
    Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const WM_SETTEXT = &HC
    Private Type POINTAPI
        x As Long
        y As Long
    End Type
    
    Private Sub Form_Load()
        Timer1.Interval = 1
    End Sub
    
    Private Sub Timer1_Timer()
        Dim hWnd_Window As Long
        Dim PT As POINTAPI
        
        GetCursorPos PT
        hWnd_Window = WindowFromPoint(PT.x, PT.y)
        SendMessage hWnd_Window, WM_SETTEXT, 0, ByVal "TheText"
    End Sub

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Type safety goes pretty much out of the window with VB However, it's usually best just to keep your ByVal lParam As Long definition and when passing a string use VarPtr(sMyString).

    It helps you not to forget where the pointers are going. Just because VB doesn't support them doesn't mean you can ignore them, especially when using the API.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Guest
    Either way works well. I prefer to use ByVal in the statement (bad habit).

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