CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2003
    Posts
    3

    Unhappy Handle to AfxMessageBox

    How do i get the handle to an active AfxMessageBox.?
    I need to close it on timer..

  2. #2
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Create your own... CreateDialog(...) or call GetForegroundWindow(...) or findwindow(...)

    It's best to create your own dialog box function though.

  3. #3
    Join Date
    Jun 2003
    Posts
    3
    Thanks for the reply..
    But I need to use AfxMessageBox since my own created dialog box will not pickup the display settings from the system.

  4. #4
    Join Date
    Apr 2003
    Posts
    1,755

    Smile

    You don't need to get the handle of the messagebox on order to close it. Just call PostQuitMessage(0) in your TimerProc
    Code:
    VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
    {
       PostQuitMessage(0);
    }
    
    
    ...
    ...
    
       UINT idTimer = ::SetTimer(NULL, 0, 3000, (TIMERPROC)TimerProc);
       AfxMessageBox("HELLO");
       KillTimer(NULL, idTimer);
    Hope this will help you

  5. #5
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by LetsCVC
    Thanks for the reply..
    But I need to use AfxMessageBox since my own created dialog box will not pickup the display settings from the system.
    Well I'm not sure what you are talking about, so perhaps you should explain that statement more, it could be someone will be able to solve your underlying problem and you won't have the need to use AfxMessageBox....

    any way...kill the afxmessagebox and use ::MessageBox(...)

    You can set modal with it (MB_SYSTEMMODAL) to almost guarentee you'll be the topmost window, for a call to GetForeground window, I still advise against it, as nothing is sure you'll acutally get the window you want when you kill timer and close the window. I've been there Wouldn't it be nice if they simply put another parameter (timer) to kill the window, since you're most likely coding something that has a auto user logoff feature...

  6. #6
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by rxbagain
    You don't need to get the handle of the messagebox on order to close it. Just call PostQuitMessage(0) in your TimerProc
    Code:
    VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
    {
       PostQuitMessage(0);
    }
    
    
    ...
    ...
    
       UINT idTimer = ::SetTimer(NULL, 0, 3000, (TIMERPROC)TimerProc);
       AfxMessageBox("HELLO");
       KillTimer(NULL, idTimer);
    Hope this will help you
    Can't see a reason why that shouln't work...
    EDIT: but I'll add creating your own dialog, and having the HWND is the preferred solution.

  7. #7
    Join Date
    Jun 2003
    Posts
    3

    Question

    The code which is suggested causes the entire application to shut down. I just want the AfxMessageBox to shut down.

  8. #8
    Join Date
    Apr 2003
    Posts
    1,755

    Smile

    hey guys try this, I tested it in my PC
    Code:
    void CMainFrame::ShowMessageBox() 
    {
       UINT idTimer = SetTimer(0, 3000, NULL);
       AfxMessageBox("HELLO");
    }
    
    void CMainFrame::OnTimer(UINT nIDEvent) 
    {
       KillTimer(nIDEvent);
       CWnd *wnd = GetLastActivePopup();
       if (wnd) ::EndDialog(wnd->m_hWnd, 0);
       CFrameWnd::OnTimer(nIDEvent);
    }
    Hope this will work for you

  9. #9
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by rxbagain
    hey guys try this, I tested it in my PC
    Code:
    void CMainFrame::ShowMessageBox() 
    {
       UINT idTimer = SetTimer(0, 3000, NULL);
       AfxMessageBox("HELLO");
    }
    
    void CMainFrame::OnTimer(UINT nIDEvent) 
    {
       KillTimer(nIDEvent);
       CWnd *wnd = GetLastActivePopup();
       if (wnd) ::EndDialog(wnd->m_hWnd, 0);
       CFrameWnd::OnTimer(nIDEvent);
    }
    Hope this will work for you

    Uhh isn't that what I said in the fist place? And I'll go back to what I said, CreateDialog(...) please post yiour problem with creating your own dialog as you said, GetLastActivePopup(...) should be very clear that it is not the best way to solve the problem...

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured