Solved

How to get a window handle in MFC?

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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 remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

17 Experts available now in Live!

Get 1:1 Help Now