Solved

How to get a window handle in MFC?

Posted on 1997-07-23
2
752 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET how to use the Vertical ScrollBar 5 90
Expand macro to ask for filename column 8 37
maxBlock challenge 30 111
only14 challenge 19 68
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 …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now