Solved

Attached HWND

Posted on 1998-10-06
2
262 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 antispam), the admini…

749 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