Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Modal Form In Taskbar.

Modal Form In Taskbar.

Scheduled Pinned Locked Moved Visual Basic
jsonquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pete Bassett
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • P Pete Bassett

      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

      D Offline
      D Offline
      David Wengier
      wrote on last edited by
      #2

      If its the first form you are showing, then you dont need to make it modal. Just remove "vbModal" from your line. :) -- David Wengier

      P 1 Reply Last reply
      0
      • D 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

        P Offline
        P Offline
        Pete Bassett
        wrote on last edited by
        #3

        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

        D 1 Reply Last reply
        0
        • P Pete Bassett

          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

          D Offline
          D Offline
          David Wengier
          wrote on last edited by
          #4

          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

          D P 2 Replies Last reply
          0
          • D David Wengier

            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

            D Offline
            D Offline
            David Wengier
            wrote on last edited by
            #5

            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 Type

            Private 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 Type

            Private 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 Long

            Private 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 Long

            Private 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

            N 1 Reply Last reply
            0
            • D David Wengier

              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

              P Offline
              P Offline
              Pete Bassett
              wrote on last edited by
              #6

              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

              D 1 Reply Last reply
              0
              • P Pete Bassett

                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

                D Offline
                D Offline
                David Wengier
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • D David Wengier

                  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 Type

                  Private 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 Type

                  Private 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 Long

                  Private 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 Long

                  Private 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

                  N Offline
                  N Offline
                  Nish Nishant
                  wrote on last edited by
                  #8

                  Gosh! 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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups