How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS) before dlg.DoModal() 
Author Message
 How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS) before dlg.DoModal()

I have a dialog with List Box ID_SECTIONS.  I want to place text and
need to get the HWND as the first argument.  How do you get the HWND?
Thanks for your help.

void CSQLView::OnIndexDlg()
{
IndexDlg dlg;

CListBox* pLB = (CListBox*) ::GetDlgItem(HWND hDlg,ID_SECTIONS);
pLB->ResetContent();
pLB->AddString("Hello, Again!");

dlg.DoModal();  

Quote:
}



Sun, 17 Aug 2003 14:21:39 GMT  
 How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS) before dlg.DoModal()
Hello,

Quote:
> need to get the HWND as the first argument.  How do you get the HWND?

The right place for doing that is IndexDlg::OnInitDialog method - use
ClassWizard to create WM_INITDIALOG handler.

HTH
--
ChainsaW



Sun, 17 Aug 2003 14:55:33 GMT  
 How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS) before dlg.DoModal()

Thank you for your reply.  I am aware that WM_INITDIALOG handler is
the place to set initial values into the ListBox.  

What I am trying to do is to "UPDATE" the listbox after DoModal() from
within the View class (where I have the function I need).

Quote:
>Hello,

>> need to get the HWND as the first argument.  How do you get the HWND?

>The right place for doing that is IndexDlg::OnInitDialog method - use
>ClassWizard to create WM_INITDIALOG handler.

>HTH



Sun, 17 Aug 2003 16:19:24 GMT  
 How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS) before dlg.DoModal()
Greets,

    It is important to note that any controls on your dialog do not have
valid HWND values until after your WM_INITDIALOG message is received and
should not be assumed to be valid after you've received and handled the
WM_DESTROY message.  When DoModal() has returned, you can no longer get
information from your controls.  Your best course of action is to create a
member variable (such as a vector or list) that you can fill with data
before your OnInitDialog() handler is called and retrieve data from after
DoModal() has returned.  While your variable is still in scope, you will
have access to member variables, but you won't have access to the HWNDs of
the child windows, they are gone.  Also, instead of using GetDlgItem(), you
can make your life a little easier by using the ClassWizard to add member
variables of type "Control" to your dialog class.  That way, you can refer
to the controls your dialog hosts through a simple variable as opposed to
getting an HWND by control ID each time you wish to perform some operation
on the control.

Regards,

Joe


Quote:

> Thank you for your reply.  I am aware that WM_INITDIALOG handler is
> the place to set initial values into the ListBox.

> What I am trying to do is to "UPDATE" the listbox after DoModal() from
> within the View class (where I have the function I need).

> >Hello,

> >> need to get the HWND as the first argument.  How do you get the HWND?

> >The right place for doing that is IndexDlg::OnInitDialog method - use
> >ClassWizard to create WM_INITDIALOG handler.

> >HTH



Sun, 17 Aug 2003 22:25:36 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS) before dlg.DoModal()

2. Question on HWND hDlg Parameter in ::SetDlgItemText(HWND hDlg, int nIDDlgItem, LPTSTR lpString, int nMaxCount)

3. Question on HWND hDlg Parameter in ::SetDlgItemText(HWND hDlg, int nIDDlgItem, LPTSTR lpString, int nMaxCount)

4. HWND hWnd

5. DestroyWindow( HWND hWnd ) doesnt kill window

6. Losing HWND when using Modeless Dlg

7. retrieving a HWND hWnd from a UINT wParam

8. Ever seen debug build HWND != release HWND

9. Getting hWnd of word docs

10. Getting IUnknown from HWND

11. Getting IWebBrowser2 from an HWND?

12. Getting the HWND of Owner draw MENU

 

 
Powered by phpBB® Forum Software