PDA

Click to See Complete Forum and Search --> : Cute little app


Dejvi
Feb 25th, 2001, 08:42 AM
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.

Feb 25th, 2001, 12:14 PM
Try the following 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

parksie
Feb 27th, 2001, 12:31 PM
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.

Feb 27th, 2001, 02:33 PM
Either way works well. I prefer to use ByVal in the statement (bad habit).