Solved

HWND of a CDialog...

Posted on 1998-06-11
5
1,702 Views
Last Modified: 2012-08-14
Hey,
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)
{
      //{{AFX_DATA_INIT(COpen_dlg)
            // NOTE: the ClassWizard will add member initialization here
      //}}AFX_DATA_INIT
  Timer = ::SetTimer( "CDialog HWND",0,1000,(TIMERPROC)Timer_Proc);

}


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

}


BEGIN_MESSAGE_MAP(COpen_dlg, CDialog)
      //{{AFX_MSG_MAP(COpen_dlg)
      ON_BN_CLICKED(IDC_BUTTON1, On_OpenButton)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
0
Comment
Question by:wwalschaerts
[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
  • 2
5 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1165642
Th handle should be in the m_hWnd member.
0
 
LVL 3

Accepted Solution

by:
stefanr earned 100 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.
0
 
LVL 22

Expert Comment

by:nietod
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.
0
 
LVL 3

Expert Comment

by:stefanr
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.
0
 

Author Comment

by:wwalschaerts
ID: 1165646
Great ! it's working !
Thanks.
0

Featured Post

Technology Partners: 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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

726 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