Link to home
Start Free TrialLog in
Avatar of jpw1
jpw1

asked on

How do I get the CWnd from a dialog box?

I use VC++.
I want to crate a Model less dialog box from another dialog box

I use following code inside a dialog box.

CGrassGame grassG = new CGrassGame();
grassG.Create(IDD_DIALOG_GRASS_FIELD, ????);
grassG.ShowWindow(SW_SHOW);

How do I get the CWnd from a dialog box?


Janaka
Avatar of AlexFM
AlexFM

grassG is instance of CWnd-derived class ( CGrassGame -> CDialog -> CWnd ). You can apply any CWnd function to it.
Avatar of jpw1

ASKER

To create and show the dialog box as model I must pass the CWnd to it.

grassG.Create(IDD_DIALOG_GRASS_FIELD, ????);

since I am inside another dialog how do I get it?
(what should I put for ????)
grassG.Create(IDD_DIALOG_GRASS_FIELD, this);
Avatar of jpw1

ASKER

it gives this error when i try it ...

(3221) : error C2664: 'int __thiscall CDialog::Create(const char *,class CWnd *)' : cannot convert parameter 1 from 'const int' to 'const char *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
Creating browse info file...


Strange, such code fragment is always compiled in my projects. Try this:

grassG.Create(MAKEINTRESOURCE(IDD_DIALOG_GRASS_FIELD), this);

Avatar of jpw1

ASKER

No luck

VirtualBadmintonDoc.cpp
F:\Game Development\My Work\3D\14-Grass Field\VirtualBadminton\VirtualBadmintonDoc.cpp(3228) : error C2664: 'int __thiscall CDialog::Create(const char *,class CWnd *)' : cannot convert parameter 2 from 'class CVirtualBadmintonDoc *const ' to 'class
CWnd *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
Creating browse info file...

but if i use this it works ...

      CGrassGame *grassG = new CGrassGame();
      
      grassG->Create(IDD_DIALOG_GRASS_FIELD, NULL);
      grassG->ShowWindow(SW_SHOW);

Avatar of jpw1

ASKER

Ok I found the problem …


I am calling this from document class so I can not pass <b>this</b>
What should I use instead of this?
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To find document's view use GetFirstViewPosition.
Avatar of jpw1

ASKER

Great !!

Is there a way to get the windows handle (HWND) of this dialog box inside it?
Every CWnd-derived class has member m_hWnd which is this window handle.
Avatar of jpw1

ASKER

Thanks ...