Solved

Attached HWND

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sum28 challenge 31 112
no14 challenge 14 67
sumHeights2  challenge 7 105
Capture logon name 13 73
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

778 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