dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Stop the system menu Icon

  1. #1
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863

    Stop the system menu Icon

    For the system menu icon on a dialog box. When it is double clicked the window closes. This seems like a really stupid idea.

    Is this because the close option is specified as the default item for the popup menu? I can not seem to change this.

    Any Help?
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,207
    Handle both WM_SYSCOMMAND and WM_NCLBUTTONDBLCLK.
    Code:
    void CDlg::OnSysCommand( UINT nID, LPARAM lParam ) 
    {	
       if( ( SC_CLOSE == nID ) && ( 0 == lParam ) )
       {
          return;
       }
       CDialog::OnSysCommand( nID, lParam );
    }
    
    void CDlg::OnNcLButtonDblClk( UINT nHitTest, CPoint point ) 
    {
       if( HTSYSMENU == nHitTest )
       {
          return;
       }
       CDialog::OnNcLButtonDblClk( nHitTest, point );
    }
    Sorry for using MFC, but I think you can translate it
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: http://codexpert.ro/blog/author/ovidiu-cucu/

  3. #3
    Join Date
    Sep 2002
    Location
    14 39'19.65"N / 121 1'44.34"E
    Posts
    9,815

    Re: Stop the system menu Icon

    Originally posted by souldog
    For the system menu icon on a dialog box. When it is double clicked the window closes. This seems like a really stupid idea.
    But this is documented standard behaviour under windows, and the user expects it to work.

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,207
    Right!
    My answer was for "how can be done" not for "do it".
    Next similar posts will contain "don't try this home..."
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: http://codexpert.ro/blog/author/ovidiu-cucu/

  5. #5
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863
    Thanks Ovidiucucu, I had tried handling one or the other, but not both.

    I know this is standard windows behavior and that does give me pause, but I am not writing a program that is supposed to slip nicely into the windows environment. This program is the only reason the user will have the computer it is installed on. You have to admit that making an item that you click on once show a useful menu and double click on close the window (in my case destroy an object the user has been creating) is an annoyance at best. The user will at worst double click the menu icon and then go click the close box. Not a big problem.
    Last edited by souldog; March 28th, 2003 at 02:13 PM.
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  6. #6
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,207
    Hi,

    I'm also working on a similar kind of application.
    The most of people those use this application
    are not Windows Codegurus and an accidentally close of the application may have ugly effects.
    I think you know about the man of Oklahoma (not sure but doesn't matter)
    that used the CD unit as coffee cup support.
    There was a true story.

    My previous answer was not the best and the code is a little tricky.
    More, I think we must care about other user actions those
    could close the application.

    Here is a little sample in a dialog-based application:

    Code:
    void CDlg::OnOK() 
    {
       // disable closing on <OK> keystroke
       // CDialog::OnOK(); 
    }
    
    void CDlg::OnCancel() 
    {
       // disable closing on <Esc> keystroke
       // CDialog::OnCancel();
    }
    
    UINT CDlg::OnNcHitTest( CPoint point ) 
    {
       // assign to a member variable
       // to be used in OnClose message handler
       m_nHitTest = CDialog::OnNcHitTest( point );
       return m_nHitTest;
    }
    
    void CDlg::OnClose() 
    {
       // CDialog::OnClose(); // disable default
                              // behavior
       if( HTSYSMENU == m_nHitTest )
       {
          // No discuss on icon double-click
          return;
       }
       else
       {
          // ask for close in the remaining cases,
          // i.e. close button, close menu item,  
          // Alt+F4, and so on.
          if( IDYES == AfxMessageBox( IDS_ASKFORCLOSEAPP,
                                      MB_YESNO |
                                      MB_DEFBUTTON2 | 
                                      MB_ICONQUESTION ) )
    
          {
             EndDialog( IDOK );
          }
       }
    }
    Good luck,
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: http://codexpert.ro/blog/author/ovidiu-cucu/

  7. #7
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863
    Thanks alot!!
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  8. #8
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,917
    What about this:

    Handle WM_INITMENUPOPUP message. In the handler:

    Code:
    void CNoIconCloseDlg::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
    {
      CDialog::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
    
      if(bSysMenu)
      {
    
        pPopupMenu->ModifyMenu(SC_CLOSE, MF_BYCOMMAND, SC_CLOSE, (CBitmap*)NULL);
        pPopupMenu->ModifyMenu(SC_CLOSE, MF_BYCOMMAND, SC_CLOSE, "Close");
        pPopupMenu->SetDefaultItem(IDM_ABOUTBOX);
      }
    }
    This will show about dialog if icon is double clicked.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  9. #9
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,207

    Exclamation pPopupMenu->SetDefaultItem(IDM_ABOUTBOX);

    Every programmer may think: some things must never happen.
    Wrong!!!
    The users are as they are, but they are many.
    No offense, but that's it.
    All unexpected application behaviors will occur sooner or later.

    So let's see.
    We change the default system menu item on WM_INITMENUPOPUP handler.
    When first double-click on the system menu icon the About Dialog will appear.
    That's very good.
    But click once on the system menu icon, wait a second without moving the mouse,
    then double-click. A little nice WM_CLOSE will be sent to your window.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: http://codexpert.ro/blog/author/ovidiu-cucu/

  10. #10
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,917
    It is true.

    This is happening because popup-menu is already initialized and visible. When system gets nc double click it issues second menu (never shown) without calling OnInitMenuPopup and execute default command that is SC_CLOSE.
    I think it is a design flow. Tested on Windows 2K.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)