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
jpw1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexFMCommented:
grassG is instance of CWnd-derived class ( CGrassGame -> CDialog -> CWnd ). You can apply any CWnd function to it.
0
jpw1Author Commented:
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 ????)
0
AlexFMCommented:
grassG.Create(IDD_DIALOG_GRASS_FIELD, this);
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

jpw1Author Commented:
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...


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

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

0
jpw1Author Commented:
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);

0
jpw1Author Commented:
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?
0
AlexFMCommented:
You need to define the dialog parent. CVirtualBadmintonDoc is not a window, it is specific to your project to find a window for this dialog. For example, you can use main frame:

grassG->Create(IDD_DIALOG_GRASS_FIELD, AfxGetMainWnd());

The difference between this and your version (NULL) is that dialog with parent is always placed above it's parent window in Z-order.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlexFMCommented:
To find document's view use GetFirstViewPosition.
0
jpw1Author Commented:
Great !!

Is there a way to get the windows handle (HWND) of this dialog box inside it?
0
AlexFMCommented:
Every CWnd-derived class has member m_hWnd which is this window handle.
0
jpw1Author Commented:
Thanks ...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.