Results 1 to 4 of 4
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Fake System Menu/Title Bar (2000+)

    Maybe later I'll go into why Word application events are poorly implemented -- I guess
    I'll have to making a statement like that. But for now, suffice it to say, no technique in all
    of Googledom or MSDN-land or EVEN the Lounge has produced a satisfactory way to
    intercept all of Word's docClose, exit and save paths consistently and reliably. My explanation
    would bore most readers and enlighten a few.

    But I digress. The solution to the app event deficiency boils down to disabling the app (Word)
    system menu Close button so that a user cannot exit Word by clicking the Big X. I lieu of that time-honored and
    previously respectible way to say adios to your app, I have placed a faux Big X button on my
    custom app toolbar (which is posititioned upper right on most Word desktops). What I'd really
    like is a Faux System Menu Close item or a fake Big X button. Anybody ever seen some code that would
    do that?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Fake System Menu/Title Bar (2000+)

    In Excel, this code disables the close box and removes the close option from the sytem menu:

    <pre>Option Explicit

    Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
    Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long _
    , ByVal wFlags As Long) As Long
    Declare Function FindWindow32 Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String _
    , ByVal lpWindowName As String) As Long
    Const MF_BYPOSITION = &H400&
    Const MF_REMOVE = &H1000&
    Private Sub Form_Load()
    Dim hSysMenu As Long, nCnt As Long
    Dim hWndXL As Long
    ' Get handle to our form's system menu
    ' (Restore, Maximize, Move, close etc.)
    hWndXL = FindWindow32("XLMAIN", Application.Caption)
    hSysMenu = GetSystemMenu(hWndXL, False)
    If hSysMenu Then
    ' Get System menu's menu count
    nCnt = GetMenuItemCount(hSysMenu)
    If nCnt Then
    ' Menu count is based on 0 (0, 1, 2, 3...), this removes the last entry
    RemoveMenu hSysMenu, nCnt - 1, MF_BYPOSITION Or MF_REMOVE
    DrawMenuBar hWndXL
    End If
    End If
    End Sub

    </pre>

    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Fake System Menu/Title Bar (2000+)

    And this is the code for Word (2000):
    <pre>Option Explicit

    Private Declare Function GetSystemMenu Lib "user32" _
    (ByVal hwnd As Long, ByVal bRevert As Long) As Long

    Private Declare Function GetMenuItemCount Lib "user32" _
    (ByVal hMenu As Long) As Long

    Private Declare Function DrawMenuBar Lib "user32" _
    (ByVal hwnd As Long) As Long

    Private Declare Function RemoveMenu Lib "user32" _
    (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long

    Declare Function FindWindow32 Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    Const MF_BYPOSITION = &H400&
    Const MF_REMOVE = &H1000&
    Private Sub Form_Load()
    Dim hSysMenu As Long, nCnt As Long
    Dim hWndWD As Long
    ' Get handle to our form's system menu
    ' (Restore, Maximize, Move, close etc.)
    hWndWD = FindWindow32("OpusApp", vbNullString)
    hSysMenu = GetSystemMenu(hWndWD, False)
    If hSysMenu Then
    ' Get System menu's menu count
    nCnt = GetMenuItemCount(hSysMenu)
    If nCnt Then
    ' Menu count is based on 0 (0, 1, 2, 3...)
    RemoveMenu hSysMenu, nCnt - 1, MF_BYPOSITION Or MF_REMOVE
    ' RemoveMenu hSysMenu, nCnt - 2, MF_BYPOSITION Or MF_REMOVE ' Remove the seperator
    DrawMenuBar hWndWD
    End If
    End If
    End Sub
    </pre>

    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Fake System Menu/Title Bar (2000+)

    Jan,

    Thanks for posting, but I was too verbose for my own good. I know all about said posted disable code and
    am using something similar.

    What I want is the ability to put up a "fake" close button -- that sits on top of the real (disabled) one -- which when clicked will run
    code of my choosing. I have seen some API work that allows you to add items to the
    system menu, but that's not quite what I need.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •