From: Jeffrey Walton on
Hi All,

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
From: Seetharam on
use FromHandlePermanent().

-Seetharam
From: Jeffrey Walton on
Hi Seethharam,

Thank you very much.

Jeff

On Jun 18, 10:19 am, Seetharam <smi...(a)gmail.com> wrote:
> use FromHandlePermanent().
>
> -Seetharam

From: Joseph M. Newcomer on
Why does it take an HWND from the app and not a CWnd*?

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

On Fri, 18 Jun 2010 06:46:56 -0700 (PDT), Jeffrey Walton <noloader(a)gmail.com> wrote:

>Hi All,
>
>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
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Goran on
On Jun 18, 3:46 pm, Jeffrey Walton <noloa...(a)gmail.com> wrote:
> Hi All,
>
> 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?

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?
 | 
Pages: 1
Prev: MSFlexGrid Question
Next: I love MFC!