Hi all,
I have written a code which restores the application minimized in any
state either in system tray or just minimized.
But the main problem starts from here.After maximizing the application
it is not at all allowing me to use the menu's available for invoking
other functionality in the application.
Say suppose I right click on the treeview in my application then
it is giving me error as 'Context menu cannot be shown in an invisible
control' is it like all the menus are disabled or destroyed.
Here is the sample code I have written for restoring -
Public Declare Auto Function SetForegroundWindow Lib "user32" Alias
"SetForegroundWindow" (ByVal hwnd As IntPtr) As Boolean
Public Declare Auto Function ShowWindowAsync Lib "user32" Alias
"ShowWindowAsync" (ByVal hwnd As IntPtr, ByVal nCmdShow As Int32) As
Boolean
Public Declare Auto Function EnumWindows Lib "user32" Alias
"EnumWindows" (ByVal lpEnumProc As EnumWindowProcDelegate, ByVal lParam
As Int32) As Boolean
Public Declare Auto Function GetWindowThreadProcessId Lib "user32"
Alias "GetWindowThreadProcessId" (ByVal hwnd As IntPtr, ByRef
lpdwProcessId As Int32) As Integer
Public Declare Auto Function GetWindowText Lib "user32" Alias
"GetWindowText" (ByVal hWnd As IntPtr, ByVal lpString As StringBuilder,
ByVal nMaxCount As Int32) As Integer
Public Delegate Function EnumWindowProcDelegate(ByVal hWnd As
IntPtr, ByVal lParam As Int32) As Boolean
Private Const SW_SHOWNORMAL As Integer = 1
Public Function EnumWindowProc(ByVal hWnd As IntPtr, ByVal lParam
As Int32) As Boolean
Dim processID As Integer
processID = 0
GetWindowThreadProcessId(hWnd, processID)
Dim caption As New StringBuilder(1024)
GetWindowText(hWnd, caption, 1024)
If (processID = lParam And caption.ToString() = "Myform") Then
Dim h1 As IntPtr
h1 = New IntPtr(&H400FD6)
Dim h2 As IntPtr
h2 = hWnd
Dim h3 As Integer
h3 = h1.ToInt32()
ShowWindowAsync(h2, SW_SHOWNORMAL)
SetForegroundWindow(h2)
End If
Return True
End Function
Public Sub main()
Dim bRunning As Boolean
Dim processes() As Process
Dim proc As Process
bRunning = False
processes = Process.GetProcessesByName("mysystray") 'appname
For Each proc In processes
If (proc.Id <> Process.GetCurrentProcess().Id) Then
Dim enumProc As New EnumWindowProcDelegate (AddressOf
EnumWindowProc)
EnumWindows(enumProc, proc.Id)
bRunning = True
End If
Next
If (bRunning = False) Then
Application.Run(New Form1)
End If
end sub