Modal Form In Taskbar.
-
Heres one for you. How do you force a modal form to show up in the taskbar. E.g. You have a bog basic VB Form named Form1 and a Sub Main which looks like this. Public Sub Main Form1.Show vbModal End Sub The fact that the form is modal means that it doesn;t show up on the taskbar. I need it to show up on the task bar. Any ideas? API Welcome! Cheers Pete
-
Heres one for you. How do you force a modal form to show up in the taskbar. E.g. You have a bog basic VB Form named Form1 and a Sub Main which looks like this. Public Sub Main Form1.Show vbModal End Sub The fact that the form is modal means that it doesn;t show up on the taskbar. I need it to show up on the task bar. Any ideas? API Welcome! Cheers Pete
If its the first form you are showing, then you dont need to make it modal. Just remove "vbModal" from your line. :) -- David Wengier
-
If its the first form you are showing, then you dont need to make it modal. Just remove "vbModal" from your line. :) -- David Wengier
This is obviously just a piece of test code. You dont think I'd leave a form named "Form1" in a real project do you? Think of it as a puzzel. You have this information and need this result. What do you do? Thanks for your answer. Pete
-
This is obviously just a piece of test code. You dont think I'd leave a form named "Form1" in a real project do you? Think of it as a puzzel. You have this information and need this result. What do you do? Thanks for your answer. Pete
Pete Bassett wrote: You dont think I'd leave a form named "Form1" in a real project do you? I've seen worse, and I dont like to assume anything about the knowledge people on forums have. But, the question you asked, I answered correctly. For the answer to the question you should have asked, and meant, I shall post in a reply to this, as it is rather long. There are probably other ways of doing this, but I use this method as it means I can just drop the module into my apps, and call the HookAttach method as necessary, whenever I want to give something a taskbar button -- David Wengier Sonork ID: 100.14177 - Ch00k
-
Pete Bassett wrote: You dont think I'd leave a form named "Form1" in a real project do you? I've seen worse, and I dont like to assume anything about the knowledge people on forums have. But, the question you asked, I answered correctly. For the answer to the question you should have asked, and meant, I shall post in a reply to this, as it is rather long. There are probably other ways of doing this, but I use this method as it means I can just drop the module into my apps, and call the HookAttach method as necessary, whenever I want to give something a taskbar button -- David Wengier Sonork ID: 100.14177 - Ch00k
Okay, long code: Firstly, usage. Call the HookAttach function before loading and showing your form, as it catches the WM_CREATE message. Call HookDetach when you want to stop it catching forms. A good place for this is in the child form. Now, the code. Put this in a standard module:
Option Explicit
Private Type CWPSTRUCT
lParam As Long
wParam As Long
message As Long
hwnd As Long
End TypePrivate Type CREATESTRUCT
lpCreateParams As Long
hInstance As Long
hMenu As Long
hWndParent As Long
cy As Long
cx As Long
y As Long
x As Long
style As Long
lpszName As Long ' String
lpszClass As Long ' String
ExStyle As Long
End TypePrivate Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As LongPrivate Const WH_CALLWNDPROC = 4
Private Const WS_EX_APPWINDOW = &H40000
Private Const WS_EX_TOOLWINDOW = &H80&' VB5 & VB6 class names:
Private Const C_MDIFORMCLASS_IDE = "ThunderMDIForm"
Private Const C_MDIFORMCLASS_EXE = "ThunderRT6MDIForm"
Private Const C_MDIFORMCLASS5_IDE = "ThunderMDIForm"
Private Const C_MDIFORMCLASS5_EXE = "ThunderRT5MDIForm"Private Const C_FORMCLASS_IDE_DC = "ThunderFormDC"
Private Const C_FORMCLASS_EXE_DC = "ThunderRT6FormDC"
Private Const C_FORMCLASS_IDE = "ThunderForm"
Private Const C_FORMCLASS_EXE = "ThunderRT6Form"
Private Const C_FORMCLASS5_IDE = "ThunderForm"
Private Const C_FORMCLASS5_EXE = "ThunderRT5Form"Private m_hHook As Long
Private m_lHookWndProc As LongPrivate Function Form_WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lSetStyleEX As Long
' SPM - specific wnd proc for a form. Only called once for the WM_CREATE message.
Select Case Msg
Case WM_CREATE
Dim tCS As CREATESTRUCT
CopyMemory tCS, ByVal lParam, Len(tCS)
lSetStyleEX = GetWindowLong(hwnd, GWL_EXSTYLE)
lSetStyleEX = lSetStyleEX Or WS_EX_APPWINDOW
lSetStyleEX = lSetStyleEX And (Not WS_EX_TOOLWINDOW)
tCS.ExStyle = lSetStyleEX
CopyMemory ByVal lParam, tCS, Len(tCS)
SetWindowLong hwnd, GWL_WNDPROC, m_lHookWndProc
SetWindowLong hwn -
Pete Bassett wrote: You dont think I'd leave a form named "Form1" in a real project do you? I've seen worse, and I dont like to assume anything about the knowledge people on forums have. But, the question you asked, I answered correctly. For the answer to the question you should have asked, and meant, I shall post in a reply to this, as it is rather long. There are probably other ways of doing this, but I use this method as it means I can just drop the module into my apps, and call the HookAttach method as necessary, whenever I want to give something a taskbar button -- David Wengier Sonork ID: 100.14177 - Ch00k
Nice looking code there David. Unfortunatly it crashes pretty bad. Takes VB down with it. I put the Hook call before the Form1.Show vbmodal and the unhook call after. It just shuts down vb. Any other ideas? Maybe you could email me your working example? Thanks again. Pete
-
Nice looking code there David. Unfortunatly it crashes pretty bad. Takes VB down with it. I put the Hook call before the Form1.Show vbmodal and the unhook call after. It just shuts down vb. Any other ideas? Maybe you could email me your working example? Thanks again. Pete
Interesting. Aside from adding the few API declerations I forgot :-O (I am too used to win.tlb these days) it worked fine. Email is on its way :) -- David Wengier Sonork ID: 100.14177 - Ch00k
-
Okay, long code: Firstly, usage. Call the HookAttach function before loading and showing your form, as it catches the WM_CREATE message. Call HookDetach when you want to stop it catching forms. A good place for this is in the child form. Now, the code. Put this in a standard module:
Option Explicit
Private Type CWPSTRUCT
lParam As Long
wParam As Long
message As Long
hwnd As Long
End TypePrivate Type CREATESTRUCT
lpCreateParams As Long
hInstance As Long
hMenu As Long
hWndParent As Long
cy As Long
cx As Long
y As Long
x As Long
style As Long
lpszName As Long ' String
lpszClass As Long ' String
ExStyle As Long
End TypePrivate Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As LongPrivate Const WH_CALLWNDPROC = 4
Private Const WS_EX_APPWINDOW = &H40000
Private Const WS_EX_TOOLWINDOW = &H80&' VB5 & VB6 class names:
Private Const C_MDIFORMCLASS_IDE = "ThunderMDIForm"
Private Const C_MDIFORMCLASS_EXE = "ThunderRT6MDIForm"
Private Const C_MDIFORMCLASS5_IDE = "ThunderMDIForm"
Private Const C_MDIFORMCLASS5_EXE = "ThunderRT5MDIForm"Private Const C_FORMCLASS_IDE_DC = "ThunderFormDC"
Private Const C_FORMCLASS_EXE_DC = "ThunderRT6FormDC"
Private Const C_FORMCLASS_IDE = "ThunderForm"
Private Const C_FORMCLASS_EXE = "ThunderRT6Form"
Private Const C_FORMCLASS5_IDE = "ThunderForm"
Private Const C_FORMCLASS5_EXE = "ThunderRT5Form"Private m_hHook As Long
Private m_lHookWndProc As LongPrivate Function Form_WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lSetStyleEX As Long
' SPM - specific wnd proc for a form. Only called once for the WM_CREATE message.
Select Case Msg
Case WM_CREATE
Dim tCS As CREATESTRUCT
CopyMemory tCS, ByVal lParam, Len(tCS)
lSetStyleEX = GetWindowLong(hwnd, GWL_EXSTYLE)
lSetStyleEX = lSetStyleEX Or WS_EX_APPWINDOW
lSetStyleEX = lSetStyleEX And (Not WS_EX_TOOLWINDOW)
tCS.ExStyle = lSetStyleEX
CopyMemory ByVal lParam, tCS, Len(tCS)
SetWindowLong hwnd, GWL_WNDPROC, m_lHookWndProc
SetWindowLong hwnGosh! Instead of all this VB code, can't you just use something easier like C++? Nish My most recent CP article :- A newbie's elementary guide to spawning processes www.busterboy.org