HWND of a CDialog...

Posted on 1998-06-11
Medium Priority
Last Modified: 2012-08-14
Continuing with my problem for having a CDialog automatically closed after a while, I need to pass the handle  window parameter of the CDialog I want to send the message WM_CLOSE.
I have spend plenty of hours searching for a way to have the HWND of that Dialog unsucessfully.
I have already have some help from WxW but it seems he use to develop with Borland. I am using Visual C++ v5. Someone has some more info ???
Here is a part of my CDialog definition :
// CLogin_Dlg message handlers

// COpen_dlg dialog

COpen_dlg::COpen_dlg(CWnd* pParent /*=NULL*/)
      : CDialog(COpen_dlg::IDD, pParent)
            // NOTE: the ClassWizard will add member initialization here
  Timer = ::SetTimer( "CDialog HWND",0,1000,(TIMERPROC)Timer_Proc);


void COpen_dlg::DoDataExchange(CDataExchange* pDX)
            // NOTE: the ClassWizard will add DDX and DDV calls here


      ON_BN_CLICKED(IDC_BUTTON1, On_OpenButton)

Question by:wwalschaerts
  • 2
  • 2
LVL 22

Expert Comment

ID: 1165642
Th handle should be in the m_hWnd member.

Accepted Solution

stefanr earned 400 total points
ID: 1165643
The HWND does not exist yet in the Constructor. You have to delay the creation of the timer to OnInitDialog. By that time the HWND exist. Alternatively you could do that in the OnCreate message function, after the default OnCreate have been called.
In any way, using the member function GetSafeHwnd (or using the member variable m_hWnd directly) returns the handle of the dialog at those times.

I would rather send a message WM_COMMAND simulating the OK/Cancel buttons to close the dialog, though, if it is a modal one.
LVL 22

Expert Comment

ID: 1165644
Note you need the dialog's handle only if you are using the ::SendMessage()  windows API.  You use the dialog object if you are using the MFC SendMessage() member procedure.

Expert Comment

ID: 1165645
BTW, since you are using a Timer procedure, you won't get a WM_TIMER event to the dialog (and hence no OnTimer will be called). The Timer procedure should be NULL if that is what you want.

Author Comment

ID: 1165646
Great ! it's working !

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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.

Join & Write a Comment

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

600 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