Board index » Visual Studio » verify that a dialog box exists
|
coldplayshiverhotmailcom
|
|
coldplayshiverhotmailcom
|
verify that a dialog box exists
Visual Studio361
I want to verify that a dialog box exists before I send it some message. I have a pointer to its object. Can someone remind me please? Thanks George - |
| Ajay
Registered User |
Thu Aug 31 12:18:45 CDT 2006
Re:verify that a dialog box existsQuoteI want to verify that a dialog box exists before I send it some message. I { ... } --- Ajay - |
| Ajay
Registered User |
Thu Aug 31 12:20:44 CDT 2006
Re:verify that a dialog box existsQuoteI want to verify that a dialog box exists before I send it some message. I great use. Something like: ASSERT_VALID(pDlg); if(pDlg) { } --- Ajay - |
| Tom
Registered User |
Thu Aug 31 13:27:03 CDT 2006
Re:verify that a dialog box exists
You can use GetSafeHwnd() to check it out if you have the pointer:
msdn2.microsoft.com/en-us/library/d64ehwhz.aspx">msdn2.microsoft.com/en-us/library/d64ehwhz.aspx Unfortuantely if the pointer is not really for a dialog you may get an exception. You could set the pointer to NULL when it is deleteted just so you could check that first. Tom "abi" <Abi@john.com>wrote in message QuoteI want to verify that a dialog box exists before I send it some message. I - |
| Joseph
Registered User |
Fri Sep 01 14:33:53 CDT 2006
Re:verify that a dialog box exists
I presume you are talking here about a modeless dialog. If the modeless dialog has a
pointer, then you should assume it exists. If it can be destroyed, then it must undertake to notify its parent that it has been destroyed, so the parent can set that pointer back to NULL. Otherwise, you will be relying on a variety of undocumented and unsupported kinds of behavior, so it is not recommended. joe On Thu, 31 Aug 2006 20:07:16 -0700, "abi" <Abi@john.com>wrote: QuoteI want to verify that a dialog box exists before I send it some message. I Web: www.flounder.com">www.flounder.com MVP Tips: www.flounder.com/mvp_tips.htm">www.flounder.com/mvp_tips.htm - |
| Joseph
Registered User |
Fri Sep 01 14:32:29 CDT 2006
Re:verify that a dialog box exists
Or
if(pDlg->GetSafeHwnd() != NULL) joe On 31 Aug 2006 10:18:45 -0700, "Ajay Kalra" <ajaykalra@yahoo.com>wrote: Quote>I want to verify that a dialog box exists before I send it some message. I Web: www.flounder.com">www.flounder.com MVP Tips: www.flounder.com/mvp_tips.htm">www.flounder.com/mvp_tips.htm - |
| Ajay
Registered User |
Fri Sep 01 22:41:21 CDT 2006
Re:verify that a dialog box exists"Joseph M. Newcomer" <newcomer@flounder.com>wrote in message QuoteOr -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo.com - |
| David
Registered User |
Fri Sep 01 23:02:18 CDT 2006
Re:verify that a dialog box exists
"Ajay Kalra" <ajaykalra@yahoo.com>wrote in message
Quote
a window or if it is used with a NULL CWnd pointer. (from MSDN) -- David - |
| Ajay
Registered User |
Fri Sep 01 23:14:59 CDT 2006
Re:verify that a dialog box exists
"David Ching" <dc@remove-this.dcsoft.com>wrote in message
Quote"Ajay Kalra" <ajaykalra@yahoo.com>wrote in message This will blow up: CWnd* pDlg = NULL; if(pDlg->whateverFunction() ) { } -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo.com - |
| David
Registered User |
Fri Sep 01 23:27:38 CDT 2006
Re:verify that a dialog box exists
"Ajay Kalra" <ajaykalra@yahoo.com>wrote in message
QuoteThis will blow up: a) is not virtual b) does not reference member data -- David - |
| Joseph
Registered User |
Sat Sep 02 12:48:18 CDT 2006
Re:verify that a dialog box exists
Actually, it can't, and that's why it's called GetSafeHwnd(), with emphasis on the "Safe";
read the code. From afxwin2.inl: _AFXWIN_INLINE HWND CWnd::GetSafeHwnd() const { return this == NULL ? NULL : m_hWnd; } joe On Fri, 1 Sep 2006 23:41:21 -0400, "Ajay Kalra" <ajaykalra@yahoo.com>wrote: Quote
Web: www.flounder.com">www.flounder.com MVP Tips: www.flounder.com/mvp_tips.htm">www.flounder.com/mvp_tips.htm - |
| Joseph
Registered User |
Sat Sep 02 12:52:07 CDT 2006
Re:verify that a dialog box exists
No. In fact, there was a question earlier in some thread where someone was asking why his
code didn't blow up. It turns out that whateverFunction() did not actually do anything involving 'this'. All that happens is that 'this' is NULL. The blowup happens not at the call, but at the access to the 'this' pointer (except for virtual methods, that will die instantly when you try to access their vtable pointer via the NULL pointer). Example: void whateverFunction() { if(this == NULL) return; ... do something } would actually work robustly, although I think something like this is a little marginal with respect to the actual C++ standard. joe On Sat, 2 Sep 2006 00:14:59 -0400, "Ajay Kalra" <ajaykalra@yahoo.com>wrote: Quote"David Ching" <dc@remove-this.dcsoft.com>wrote in message Web: www.flounder.com">www.flounder.com MVP Tips: www.flounder.com/mvp_tips.htm">www.flounder.com/mvp_tips.htm - |
| Ajay
Registered User |
Sat Sep 02 15:14:20 CDT 2006
Re:verify that a dialog box exists
"David Ching" <dc@remove-this.dcsoft.com>wrote in message
Quote"Ajay Kalra" <ajaykalra@yahoo.com>wrote in message --- Ajay - |
| Ajay
Registered User |
Sat Sep 02 15:16:30 CDT 2006
Re:verify that a dialog box exists"Joseph M. Newcomer" <newcomer@flounder.com>wrote in message QuoteNo. In fact, there was a question earlier in some thread where someone to try this out. -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo.com - |
| David
Registered User |
Sat Sep 02 15:30:39 CDT 2006
Re:verify that a dialog box exists
"Ajay Kalra" <ajaykalra@yahoo.com>wrote in message
QuoteWould you put this code in production? yourself from what happens if the implementation of whateverFunction() were changed to use "this". But, in this PARTICULAR example, I would use either: if ( pDlg && pDlg->m_hWnd ) Or if ( pDlg->GetSafeHwnd() ) because GetSafeHwnd() was invented exactly for the purpose of not having to check for NULL pDlg. What you did: if ( pDlg && pDlg->GetSafeHwnd() ) is not optimal. Not that all this means much. We have too much time on our hands, and on a Saturday to boot! ;) -- David - |
| Joseph
Registered User |
Tue Sep 05 09:19:06 CDT 2006
Re:verify that a dialog box exists
GetSafeHwnd() already does that...
joe On Sat, 2 Sep 2006 16:16:30 -0400, "Ajay Kalra" <ajaykalra@yahoo.com>wrote: Quote
Web: www.flounder.com">www.flounder.com MVP Tips: www.flounder.com/mvp_tips.htm">www.flounder.com/mvp_tips.htm - |
