?
Solved

How do I get the CWnd from a dialog box?

Posted on 2004-11-04
12
Medium Priority
?
2,457 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:jpw1
  • 6
  • 6
12 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 12492272
grassG is instance of CWnd-derived class ( CGrassGame -> CDialog -> CWnd ). You can apply any CWnd function to it.
0
 

Author Comment

by:jpw1
ID: 12492404
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 12492480
grassG.Create(IDD_DIALOG_GRASS_FIELD, this);
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jpw1
ID: 12492571
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 12492635
Strange, such code fragment is always compiled in my projects. Try this:

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

0
 

Author Comment

by:jpw1
ID: 12492687
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
 

Author Comment

by:jpw1
ID: 12492762
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
 
LVL 48

Accepted Solution

by:
AlexFM earned 200 total points
ID: 12492776
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 12492787
To find document's view use GetFirstViewPosition.
0
 

Author Comment

by:jpw1
ID: 12492822
Great !!

Is there a way to get the windows handle (HWND) of this dialog box inside it?
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 12492867
Every CWnd-derived class has member m_hWnd which is this window handle.
0
 

Author Comment

by:jpw1
ID: 12492887
Thanks ...
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question