Article View: borland.public.cppbuilder.nativeapi
Article #3576Re: Handle of MessageBox
From: Remy Lebeau (TeamB)
Date: Wed, 31 May 2006 02:02
Date: Wed, 31 May 2006 02:02
66 lines
2816 bytes
2816 bytes
"Dennis Jones" <nospam@nospam.com> wrote in message
news:447cf4e6$1@newsgroups.borland.com...
> Right. In my case, the process is kicked off by a TTimer::OnTimer event
> handler on the application's main form and uses PostMessage calls to close
> the windows in question.
One thing to try is to have each form that shows a MessageBox grab the HWND,
like I mentioned earlier, and store it in a member of itself. Then your
TTimer can close the active MessageBox of any form it wants. For example
(untested):
class TForm1 : public TForm
{
private:
HWND hMsgBoxWnd;
HHOOK hMsgBoxHook;
static LRESULT CALLBACK MsgBoxCBTProc(int nCode, WPARAM wParam,
LPARAM lParam);
public:
int __fastcall ShowMsgBox(const AnsiString &Msg, const AnsiString
&Title, int Flags);
void __fastcall CloseMsgBox();
};
LRESULT CALLBACK TForm1::MsgBoxCBTProc(int nCode, WPARAM wParam, LPARAM
lParam)
{
if( nCode == HCBT_ACTIVATE )
Form1->hMsgBoxWnd = reinterpret_cast<HWND>(wParam);
return ::CallNextHookEx(Form1->hMsgBoxHook);
}
int __fastcall TForm1::ShowMsgBox(const AnsiString &Msg, const
AnsiString &Title, int Flags)
{
hMsgBoxHook = ::SetWindowsHookEx(WH_CBT, (HOOKPROC) MsgBoxCBTProc,
NULL, GetCurrentThreadId());
if( !hMsgBoxHook )
return 0;
int iRet = ::MessageBox(NULL, Msg.c_str(), Title.c_str(), Flags);
hMsgBoxWnd = NULL;
::UnhookWindowsHookEx(hMsgBoxHook);
hMsgBoxHook = NULL;
return iRet;
}
void __fastcall TForm1::CloseMsgBox()
{
if( hMsgBoxWnd )
::EndDialog(hMsgBoxWnd, IDABORT);
}
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Form1->CloseMsgBox();
}
Gambit
Technical Details
Message-ID:
<447cf9be$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<447ce85d$1@newsgroups.borland.com> <447cee05$1@newsgroups.borland.com> <447cf4e6$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,21899a732622f4b0 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <447ce85d$1@newsgroups.borland.com> <447cee05$1@newsgroups.borland.com> <447cf4e6$1@newsgroups.borland.com> Subject: Re: Handle of MessageBox Date: Tue, 30 May 2006 19:02:03 -0700 Lines: 68 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <447cf9be$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1149041086 68.69.17.41 (30 May 2006 19:04:46 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail