Solved

How to get a window handle in MFC?

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASCII Non-Printable characters/codes and their HTML equivalents 6 130
MaxSpan challenge 9 105
wordcount challenge 11 132
how to split multiple lines delimiter : 8 109
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. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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