I have a MFC DLL that takes a HWND from applications. The Dialog's
wizard generated constructor is boilerplate. But I also needed one for
HWNDs
CMyDialog: public CDialog
{
// MFC callers
explicit CMyDialog(CWnd* pParent = NULL);
// Win32 callers
explicit CMyDialog(HWND hOwner = NULL);
};
CMyDialog::CMyDialog(HWND hOwner = NULL)
: CDialog(CMyDialog::IDD, (hOwner ? CWnd::FromHandle(hOwner) : NULL)
{
}
Unfortunately, the docs state the mapping is temporary [1]. How do I
get a mapping of an HWND -> CWnd for the lifetime of the dialog?
Thanks,
Jeff
[1] http://msdn.microsoft.com/en-us/library/e547yfza(VS.80).aspx
-Seetharam
Thank you very much.
Jeff
On Jun 18, 10:19 am, Seetharam <smi...@gmail.com> wrote:
> use FromHandlePermanent().
>
> -Seetharam
Note the constructor below is pretty useless. The "owner" of a dialog is not the window
you pass in, but the main window of the app. Therefore, no matter what you put in the
constructor, the parent of the dialog will be the main window of the app. So get rid of
all that code entirely, it is doing nothing useful.
A bit of experimentation with Spy++ will show you that the code you wrote below has no
effect.
joe
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
FromHandlePermanent(). However, I think that you should reconsider
that question. Why do you care about that CWnd? You can always get it
when you need it, just call FromHandle "locally".
On top of that, since it's a HWND, you don't gain much by getting a
CWnd, do you? What are you planning to do with it? Send/post it some
messages, most likely. If so,
CWnd* p = CWnd::FromHandle(...)
BOOL b = pWnd->SendMessage(...)
is more work than
BOOL b = ::SendMessage(hWnd, ...);
Goran.
P.S. By the way, you seem to be mixing "parent" (1st ctor) and
"owner" (2nd ctor) windows?