Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to get a window handle in MFC?

Posted on 1997-07-23
2
Medium Priority
?
801 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
[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 Comments
 
LVL 3

Accepted Solution

by:
jaba earned 150 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

618 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