Solved

Attached HWND

Posted on 1998-10-06
2
267 Views
Last Modified: 2013-11-20


Hi, experts
Here a easy question to you, and a difficult one for me.

In the following code
why they say
the dialog has no attched HWND in the constructor



BOOL CDerEditDlg::OnInitDialog()
      // create children on InitDialog
      //  (not in CDerEditDlg constructor since the dialog has
      //    no attached HWND in the constructor)   <------------------here is the question
{
      // This is an example of the _incorrect_ way to create a dialog
      // The following code show you what you should _not_ do:
      //    1) do not use hard coded numbers for coordinates and sizes
      //     (these will break when the font sizes changes and are
      //     hard to edit and maintain).
      //    2) do not put strings in code, they should be in resources.
      //    3) as you can see below the programming steps required
      //     to create controls, pass the correct creation parameters,
      //     and set the appropriate font, is complicated and error prone.
      //    4) localization of the controls would require changes to the
      //     sources for the captions, font, coordinates, and sizes.

      const int yStart = 8;
      const int height = 30;

      CPoint whereLabel(10, yStart);
      CSize sizeLabel(80, 24);

      CPoint whereEdit(90, yStart);
      CSize sizeEdit(140, 24);

      m_static1.Create(_T("Letters:"), WS_VISIBLE | WS_CHILD | SS_LEFT,
            CRect(whereLabel, sizeLabel), this, (UINT)-1);
      m_static1.SetFont(m_pFont);
      whereLabel.y += height;
      [....]
      return FALSE;   // focus set
}
0
Comment
Question by:nightingale
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
mikeblas earned 50 total points
ID: 1323028
It's the way MFC works.

When you create a C++ object, such as an instance of your CDerEdit dialog, you're creating only the C++ object.  Some memory gets allocated, and the constructor runs.

That _doesn't_ create the actual Windows object. INstead, you need to take the separate step of calling the Create(), or DoModal() or CreateEx() members to get the Windows object associated with the C++ object created.

After you call one of those functions on a dialog box, Windows will send the dialog box window a WM_INITDIALOG message. So, the OnInitDialog() handler is the first place where a dialog object will have a valid m_hWnd after creation.

Similarly, when the dialog window is destroyed, it's destroyed before the C++ object.  The C++ object may realize the dialog is going away and delete itself, but it also may live on for a long time after the actual window is gone.

B ekiM

0
 

Author Comment

by:nightingale
ID: 1323029
Thank you so much,mikeblas
0

Featured Post

Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

623 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