Solved

How to get a window handle in MFC?

Posted on 1997-07-23
2
759 Views
Last Modified: 2013-11-20
 I'm using VC40 to develope a application about audio compression. Some of the ACM functions need to be provided a user defined application instance as parameter. I guess it is something like a window handle. Currently I'm using a dialog box as the main window. How can I get the handle of this dialog. There is also a list box in the dialog box. Does this listbox have handle? if so, how can i get it?

Thanks in advance!
Ryan
0
Comment
Question by:eatfish
  • 2
2 Comments
 
LVL 3

Accepted Solution

by:
jaba earned 50 total points
ID: 1302772
If ACM functions want applications instance you need to call AfxGetInstanceHandle() to get HINSTANCE of you applications. How handle of window.

P.S. to get handle of any window object in MFC , use GEtSafeHwnd() method. All CWnd derived classes have it

0
 
LVL 3

Expert Comment

by:jaba
ID: 1302773
Forgot somthing.
About dialog. You can add member variable of ( as control) in ClassWizard and use m_cListbox.GetSafeHWnd()
Or , inside dialog functions , you can call GetDlgItem(IDC_LIST)->GetSafeHwnd();
Really , you can call SDK functions:
void CMyDialog::OnOK ()
{
HWND hDlg = GetSafeHwnd();
HWND hListBox = ::GetDlgItem(hDlg, IDC_LIST) ;
// IDC_LIST - recource ID of lisbox
}

about getting handle of dialog. If you using modeless dialog :
CMyDlg dlg(this);
dlg.Create();
HWND hDialog = dlg.GetSafeHWnd();
If you using modal dialog you can access to his window handle only inside dialog class function ( because modal dialog starting and destroying while working one function - DoModal) :

CMyDlg dlg(this);
dlg.DoModal(); //  dialog processed
How to get handle of dialog inside dialog function - see OnOK method above
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 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