-
June 2nd, 2003, 08:17 AM
#1
Handle to AfxMessageBox
How do i get the handle to an active AfxMessageBox.?
I need to close it on timer..
-
June 2nd, 2003, 08:24 AM
#2
Create your own... CreateDialog(...) or call GetForegroundWindow(...) or findwindow(...)
It's best to create your own dialog box function though.
-
June 2nd, 2003, 08:29 AM
#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.
-
June 2nd, 2003, 08:33 AM
#4
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
-
June 2nd, 2003, 08:38 AM
#5
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...
-
June 2nd, 2003, 08:46 AM
#6
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.
-
June 2nd, 2003, 09:10 AM
#7
The code which is suggested causes the entire application to shut down. I just want the AfxMessageBox to shut down.
-
June 2nd, 2003, 09:37 AM
#8
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
-
June 2nd, 2003, 09:58 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|