How can I get the handle of the dialog ?
-
I have the following code in my applications InitInstance. CLoginNConfigDlg is the class of a dialog.
CLoginNConfigDlg clncdLoginNConfig;
m_pMainWnd = &clncdLoginNConfig;
HWND hand = clncdLoginNConfig.m_hWnd;
I am not able to get the value of handle in 'hand'. What am I doing wrong ? Thanks in advance
-
I have the following code in my applications InitInstance. CLoginNConfigDlg is the class of a dialog.
CLoginNConfigDlg clncdLoginNConfig;
m_pMainWnd = &clncdLoginNConfig;
HWND hand = clncdLoginNConfig.m_hWnd;
I am not able to get the value of handle in 'hand'. What am I doing wrong ? Thanks in advance
That is because there is no window created yet. A Dialog is created only when you call DoModal (for a modal dialog ofcourse). Try calling this in OnInitDialog member of the dialog class. -Saurabh
-
I have the following code in my applications InitInstance. CLoginNConfigDlg is the class of a dialog.
CLoginNConfigDlg clncdLoginNConfig;
m_pMainWnd = &clncdLoginNConfig;
HWND hand = clncdLoginNConfig.m_hWnd;
I am not able to get the value of handle in 'hand'. What am I doing wrong ? Thanks in advance
HANDLE p_Dialog= GetDlgItem(/*handle of dialogbox*/,IDDIALOG); The GetDlgItem function retrieves a handle to a control in the specified dialog box. Syntax
HWND GetDlgItem( HWND hDlg,
int nIDDlgItem
);Parameters hDlg [in] Handle to the dialog box that contains the control. nIDDlgItem [in] Specifies the identifier of the control to be retrieved. Return Value If the function succeeds, the return value is the window handle of the specified control. If the function fails, the return value is NULL, indicating an invalid dialog box handle or a nonexistent control. To get extended error information, call GetLastError.
-
HANDLE p_Dialog= GetDlgItem(/*handle of dialogbox*/,IDDIALOG); The GetDlgItem function retrieves a handle to a control in the specified dialog box. Syntax
HWND GetDlgItem( HWND hDlg,
int nIDDlgItem
);Parameters hDlg [in] Handle to the dialog box that contains the control. nIDDlgItem [in] Specifies the identifier of the control to be retrieved. Return Value If the function succeeds, the return value is the window handle of the specified control. If the function fails, the return value is NULL, indicating an invalid dialog box handle or a nonexistent control. To get extended error information, call GetLastError.
Nope this doesnt work. GetDlgItem either works in the CDialog derived classes, in that case you can simply use m_hWnd, or it expectes two parameters and first is HWND of the the dialog. -Saurabh
-
Nope this doesnt work. GetDlgItem either works in the CDialog derived classes, in that case you can simply use m_hWnd, or it expectes two parameters and first is HWND of the the dialog. -Saurabh
-
Hi, But if u give the HWND as NULL by default as first parameter it will take the default Dialog handel. And once the function executes u will get the Dialog handel, as it returns the handel of the window.
pallaka wrote:
But if u give the HWND as NULL by default as first parameter it will take the default Dialog handel.
What is the 'default dialog handle'?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
pallaka wrote:
But if u give the HWND as NULL by default as first parameter it will take the default Dialog handel.
What is the 'default dialog handle'?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi, But if u give the HWND as NULL by default as first parameter it will take the default Dialog handel. And once the function executes u will get the Dialog handel, as it returns the handel of the window.
I just tried this and I get NULL pointer on return. I also checked MSDN and it doesn't say anything about first parameter being NULL. In fact it specifically says: "If the function fails, the return value is NULL, indicating an invalid dialog box handle or a nonexistent control." I take that as input dialog boc handle must be valid. Can you share you source of information? -Saurabh Edit1: I checked GetLastError after calling GetDlgItem(NULL, IDD_MYDIALOG) and it says Invalid Window Handle. Edit2: Okay just saw that you modified your original post to include MSDN documentation.
-
I have the following code in my applications InitInstance. CLoginNConfigDlg is the class of a dialog.
CLoginNConfigDlg clncdLoginNConfig;
m_pMainWnd = &clncdLoginNConfig;
HWND hand = clncdLoginNConfig.m_hWnd;
I am not able to get the value of handle in 'hand'. What am I doing wrong ? Thanks in advance
an important concept to know in MFC is that window creation and destruction are TWO STEP PROCESSES.... 1) the C++ object - a CWnd or derived object 2) the operating system object - an HWND You have only created item 1 :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: