-
June 17th, 2007, 06:45 AM
#1
Start menu related question
hello there,
i wrote a Start menu replacement for xp in vb2005. It works fine, the only thing i need to know how to detect when a user clicks on xp's start button and instead of the built in menu show mine.
i got this code from here and it finds me the start button:
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
On Error Resume Next
Dim tWnd As Integer = 0
Dim bWnd As Integer = 0
tWnd = FindWindow("Shell_TrayWnd", vbNullString)
bWnd = FindWindowEx(tWnd, bWnd, "BUTTON", vbNullString)
end sub
How can i catch mouse clicks of start button and act on them?
thnx a lot for helping me out
-
June 18th, 2007, 07:08 AM
#2
Re: Start menu related question
I think you'll need to have a global mouse hook, in order to achieve this
Just a comment about your code.
These API declarations :
FindWindow
FindWindowEx
ShowWindow
Should be declared like this in .NET :
Code:
Imports System.Runtime.InteropServices 'Add this import
<DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="FindWindowEx", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _
ByVal childAfter As IntPtr, _
ByVal lclassName As String, _
ByVal windowTitle As String) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="ShowWindow", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Int32) As Boolean
End Function
And you should rather make use of Try & Catch blocks instead of On Error Resume Next in .NET
-
June 20th, 2007, 10:53 AM
#3
Re: Start menu related question
the declaration is ok as i wrote it... and i got a hooking class so everything is fine now...
just one more tiny problem. whenever my form gets opened it doesn't get activated, too. So whenever i click on the desktop or on an other window my form won't disappear calling its deactivate sub. Why's that? how can i activate it (and give focus to it)? me.activate() doesn't work...
Last edited by geeq; June 20th, 2007 at 11:03 AM.
-
June 20th, 2007, 11:18 AM
#4
Re: Start menu related question
Originally Posted by geeq
the declaration is ok as i wrote it...
In VB 6 yes
Originally Posted by geeq
whenever my form gets opened it doesn't get activated, too. So whenever i click on the desktop or on an other window my form won't disappear calling its deactivate sub. Why's that? how can i activate it (and give focus to it)? me.activate() doesn't work...
I think the SetActiveWindow API might work here. here is the declaration :
Code:
<DllImport("user32.dll", EntryPoint:="SetActiveWindow", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SetActiveWindow(ByVal hwnd As Int32) As Int32
End Function
-
June 20th, 2007, 01:20 PM
#5
Re: Start menu related question
i used it in vb2005 and have no problem with it - works fine...
and how should i call this api in the code?
now i call the form like this:
Code:
If sender = bWnd Then
If Me.visibility = False Then
menufrm.Show()
Me.visibility = True
menufrm.Activate()
Else
menufrm.Hide()
Me.visibility = False
End If
End If
never mind, i got it: (currently testing the code)
Code:
me.SetActiveWindow(Me.Handle)
Last edited by geeq; June 20th, 2007 at 01:33 PM.
-
June 20th, 2007, 02:00 PM
#6
Re: Start menu related question
it doesn't work... maybe the problem is that i call the hook from an other form that is invisible. and maybe when it hooks the Start button it gets the focus...
how could i cut off the first form (which hooks the button of start button)? I want my form not to appear at the start of my application...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|