Author |
Message |
Jeff Perr #1 / 8
|
 user32 API's not working
I have a set of calls I want to make but the return values from the windows API calls are incorrect. What am I doing wrong? Public Structure RECT Dim Left As Long Dim Top As Long Dim Right As Long Dim Bottom As Long End Structure Public Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Public Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Declare Auto Function GetClientRect Lib "user32" (ByVal hwnd As Long, ByVal lpRect As RECT) As Long Public Sub ClearSystemTray() Dim hTaskbar As Long Dim hTray As Long Dim rcTray As RECT Dim X As Long hTaskbar = FindWindowEx(0, 0, "Shell_TrayWnd", vbNullString) If hTaskbar Then hTray = FindWindowEx(hTaskbar, 0, "TrayNotifyWnd", vbNullString) If hTray Then GetClientRect(hTray, rcTray) For X = 0 To rcTray.Right Step 8 SendMessage(hTray, WM_MOUSEMOVE, 0, &H80000 + X) Next End If End If End Sub hTaskbar comes back as -5060775650092252192 not 0 as it should if it fails. Thanks Jeff
|
Sat, 25 Dec 2004 00:05:31 GMT |
|
 |
Corrado Cavall #2 / 8
|
 user32 API's not working
API defines are incorrect, try changing Long to Int32 and String to stringbuilder (if they need to me modified by the API) look at MSDN about interopServices... HTH Corrado
Quote: > I have a set of calls I want to make but the return values from the > windows API calls are incorrect. What am I doing wrong? > Public Structure RECT > Dim Left As Long > Dim Top As Long > Dim Right As Long > Dim Bottom As Long > End Structure > Public Declare Auto Function FindWindowEx Lib "user32" (ByVal > hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 > As String) As Long > Public Declare Auto Function SendMessage Lib "user32" (ByVal hwnd > As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As > Long) As Long > Public Declare Auto Function GetClientRect Lib "user32" (ByVal > hwnd As Long, ByVal lpRect As RECT) As Long > Public Sub ClearSystemTray() > Dim hTaskbar As Long > Dim hTray As Long > Dim rcTray As RECT > Dim X As Long > hTaskbar = FindWindowEx(0, 0, "Shell_TrayWnd", vbNullString) > If hTaskbar Then > hTray = FindWindowEx(hTaskbar, 0, "TrayNotifyWnd", > vbNullString) > If hTray Then > GetClientRect(hTray, rcTray) > For X = 0 To rcTray.Right Step 8 > SendMessage(hTray, WM_MOUSEMOVE, 0, &H80000 + X) > Next > End If > End If > End Sub > hTaskbar comes back as -5060775650092252192 not 0 as it should if it > fails. > Thanks > Jeff
|
Sat, 25 Dec 2004 01:09:58 GMT |
|
 |
Dale Roberson (Microso #3 / 8
|
 user32 API's not working
Jeff, Looks like Corrado has pointed you in the right direction. Let us know if you need anything further. Thank You, Dale Roberson Microsoft Developer Support This posting is provided "AS IS" with no warranties, and confers no rights. You assume all risk for your use. ? 2001 Microsoft Corporation. All rights reserved.
|
Sat, 25 Dec 2004 02:40:46 GMT |
|
 |
Jeff Perr #4 / 8
|
 user32 API's not working
Quote:
>Jeff, >Looks like Corrado has pointed you in the right direction. Let us know if >you need anything further. > Thank You, > Dale Roberson > Microsoft Developer Support > This posting is provided "AS IS" with no warranties, and confers no rights. > You assume all risk for your use. ? 2001 Microsoft Corporation. All rights >reserved.
I have the FindWindowEx, GetClientRect, and CopyMemory API calls to work. But I can't seem to find the proper syntax for SendMessage. This is what the API text viewer says. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long This is what I tried. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32 But no luck. I'm watching a process with Spy++ and trying to send a mouse move to it. Heres my call. For X = 0 To rcTray.right intMouseMove = MAKELONG(X, 10) intReturn = SendMessage(hTray, WM_MOUSEMOVE, 0, intMouseMove) Next Any help would be great. Thanks Jeff
|
Sun, 26 Dec 2004 19:42:16 GMT |
|
 |
Dale Roberson (Microso #5 / 8
|
 user32 API's not working
Looks like the declaration should work. Are you getting a return code of 0? Thank You, Dale Roberson Microsoft Developer Support This posting is provided "AS IS" with no warranties, and confers no rights. You assume all risk for your use. ? 2001 Microsoft Corporation. All rights reserved.
|
Mon, 27 Dec 2004 00:27:37 GMT |
|
 |
Jeff Perr #6 / 8
|
 user32 API's not working
Quote:
>Looks like the declaration should work. Are you getting a return code of 0? > Thank You, > Dale Roberson > Microsoft Developer Support > This posting is provided "AS IS" with no warranties, and confers no rights. > You assume all risk for your use. ? 2001 Microsoft Corporation. All rights >reserved.
Yes the return value is zero. But Spy++ shows no messages going to that process. But I get a return of 0 even if I change the declaration around some. I've tried experimenting with byref's and different types... All have given a return of 0 with no message going where it should. Jeff
|
Mon, 27 Dec 2004 00:37:54 GMT |
|
 |
Dale Roberson (Microso #7 / 8
|
 user32 API's not working
Be careful about spy++. I hooked the windows message processor to see if the message was being sent and it is. Here is what I wrote. Create a form with a button. Place the following code in the form. Dim catchmessage As Boolean = False Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim x As Integer Dim mousepoint As Integer mousepoint = &H1000 Or &H20000000 'this is a bogus number I just threw in for arguments sake. 'It evaluates to 536875008 which you can see in the locals window when you run the app catchmessage = True x = SendMessage(Me.Handle.ToInt32, WM_MOUSEMOVE, 0, mousepoint) catchmessage = False End Sub Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) If catchmessage = True Then If m.Msg = WM_MOUSEMOVE Then MessageBox.Show(m.Msg.ToString & vbCrLf & m.LParam.ToString) End If End If MyBase.WndProc(m) End Sub Create a module and add the following code. Public Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" (ByVal hwnd As Integer, _ ByVal wMsg As Integer, ByVal wParam As Integer, _ ByVal lParam As Integer) As Integer Public Const WM_MOUSEMOVE = &H200 The mouse doesn't actually move. I don't have it all set up correctly to handle this, I just want to see the message get to the window proc. Thank You, Dale Roberson Microsoft Developer Support This posting is provided "AS IS" with no warranties, and confers no rights. You assume all risk for your use. ? 2001 Microsoft Corporation. All rights reserved.
|
Mon, 27 Dec 2004 03:55:20 GMT |
|
 |
Jeff Perr #8 / 8
|
 user32 API's not working
I got it working... I found a sub window for the System Tray and updated my code to use that as a target. I now have code to clear any dead icons from the system tray. I wouldn't mind a critique of the code. Code Follows: <StructLayout(LayoutKind.Explicit)> Public Structure Rect <FieldOffset(0)> Public left As Integer <FieldOffset(4)> Public top As Integer <FieldOffset(8)> Public right As Integer <FieldOffset(12)> Public bottom As Integer End Structure Public Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32 Public Declare Auto Function GetClientRect Lib "user32" (ByVal hwnd As Int32, ByRef lpRect As Rect) As Int32 Public Declare Auto Function PostMessage Lib "user32" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32 Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef dest As Int16, ByRef src As Int32, ByVal length As Int32) Public Function LoWord(ByVal dwValue As Long) As Int16 CopyMemory(LoWord, dwValue, 2) End Function Public Function MAKELONG(ByVal wLow As Long, ByVal wHigh As Long) As Long MAKELONG = LoWord(wLow) Or (&H10000 * LoWord(wHigh)) End Function Public Sub ClearSystemTray() Dim hTaskbar As Long Dim hTray As Long Dim hToolBar As Long Dim rcTray As Rect Dim X As Long Dim Y As Long Dim intMouseMove As Int32 hTaskbar = FindWindowEx(0, 0, "Shell_TrayWnd", vbNullString) If hTaskbar Then hTray = FindWindowEx(hTaskbar, 0, "TrayNotifyWnd", vbNullString) If hTray Then hToolBar = FindWindowEx(hTray, 0, "ToolbarWindow32", vbNullString) If hToolBar Then GetClientRect(hToolBar, rcTray) For Y = 10 To rcTray.bottom Step 10 For X = 0 To rcTray.right Step 8 intMouseMove = MAKELONG(X, Y) PostMessage(hToolBar, WM_MOUSEMOVE, 0, intMouseMove) Next Next End If End If End If End Sub Thanks for the help Jeff Perrin
|
Mon, 27 Dec 2004 19:48:37 GMT |
|
|
|