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:15 GMT  
 How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS) before dlg.DoModal()
About every Window derived from CWnd has a public Member variable
m_hWnd

Use this : )

Hope this helps
Thilo



Quote:
>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();      
>}



Sun, 17 Aug 2003 16:09:50 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:18:54 GMT  
 How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS) before dlg.DoModal()
Read my essays on my MVP Tips site on avoiding GetDlgItem and avoiding
UpdateData. They will tell all. You don't need the HWND at all, except
in rare circumstances or for legacy interfaces.
                        joe



Quote:
>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();      
>}

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Mon, 18 Aug 2003 11:12:26 GMT  
 How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS) before dlg.DoModal()
You can't. After the DoModal, the list box does not exist. In fact, if
you could get the HWND, the HWND would become illegal. The listbox has
exists from the OnInitDialog to the OnDestroy of the dialog. It does
not exist before or after.
                        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

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Mon, 18 Aug 2003 11:13:49 GMT  
 How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS) before dlg.DoModal()
You can use a member function of CWnd Class, which is named as GetDlgItem
too. Here is the prototype of the function.

          CWnd* GetDlgItem( int nID ) const;

Please refer to the following code.

CListBox* pLB = (CListBox*) dlg.GetDlgItem(ID_SECTIONS);

Regards,

-Frank



Mon, 18 Aug 2003 13:47:41 GMT  
 How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS) before dlg.DoModal()
It's true you cannot update the content of ListBox after the DoModal
function call finish. Instead, you may record the information about ListBox
to some memebr variables of the dialog class before the DoModal is
returned. Then, you can retrieve or modify the information from these
variable.

Regards,

-Frank

--------------------

| Newsgroups: microsoft.public.vc.mfc
| Subject: Re: How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS)
before dlg.DoModal()
| Date: Wed, 28 Feb 2001 22:13:49 -0500
| Organization: Posted via Supernews, http://www.supernews.com



| X-Newsreader: Forte Agent 1.8/32.548
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit

| Lines: 30
| Path:
cppssbbsa01.microsoft.com!tkmsftngp01!newsfeed00.sul.t-online.de!t-online.de
!newsfeed.icl.net!dispose.news.demon.net!demon!grolier!sn-xit-01!sn-post-01!
supernews.com!corp.supernews.com!not-for-mail
| Xref: cppssbbsa01.microsoft.com microsoft.public.vc.mfc:259612
| X-Tomcat-NG: microsoft.public.vc.mfc
|
| You can't. After the DoModal, the list box does not exist. In fact, if
| you could get the HWND, the HWND would become illegal. The listbox has
| exists from the OnInitDialog to the OnDestroy of the dialog. It does
| not exist before or after.
|                       joe
|

|
| >
| >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
|
| Joseph M. Newcomer [MVP]

| Web: http://www3.pgh.net/~newcomer
| MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm
|



Mon, 18 Aug 2003 14:05:37 GMT  
 How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS) before dlg.DoModal()
Yes, but the question dealt with getting an HWND after DoModal...
                        joe



Quote:
>It's true you cannot update the content of ListBox after the DoModal
>function call finish. Instead, you may record the information about ListBox
>to some memebr variables of the dialog class before the DoModal is
>returned. Then, you can retrieve or modify the information from these
>variable.

>Regards,

>-Frank

>--------------------

>| Newsgroups: microsoft.public.vc.mfc
>| Subject: Re: How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS)
>before dlg.DoModal()
>| Date: Wed, 28 Feb 2001 22:13:49 -0500
>| Organization: Posted via Supernews, http://www.supernews.com



>| X-Newsreader: Forte Agent 1.8/32.548
>| MIME-Version: 1.0
>| Content-Type: text/plain; charset=us-ascii
>| Content-Transfer-Encoding: 7bit

>| Lines: 30
>| Path:
>cppssbbsa01.microsoft.com!tkmsftngp01!newsfeed00.sul.t-online.de!t-online.de
>!newsfeed.icl.net!dispose.news.demon.net!demon!grolier!sn-xit-01!sn-post-01!
>supernews.com!corp.supernews.com!not-for-mail
>| Xref: cppssbbsa01.microsoft.com microsoft.public.vc.mfc:259612
>| X-Tomcat-NG: microsoft.public.vc.mfc
>|
>| You can't. After the DoModal, the list box does not exist. In fact, if
>| you could get the HWND, the HWND would become illegal. The listbox has
>| exists from the OnInitDialog to the OnDestroy of the dialog. It does
>| not exist before or after.
>|                   joe
>|


>|
>| >
>| >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
>|
>| Joseph M. Newcomer [MVP]

>| Web: http://www3.pgh.net/~newcomer
>| MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm
>|

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Tue, 19 Aug 2003 02:32:01 GMT  
 How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS) before dlg.DoModal()
But why bother with all that effort when you can avoid it entirely by
using control member variables. See the essay on my MVP Tips site on
avoiding GetDlgItem.
                        joe



Quote:
>You can use a member function of CWnd Class, which is named as GetDlgItem
>too. Here is the prototype of the function.

>          CWnd* GetDlgItem( int nID ) const;

>Please refer to the following code.

>CListBox* pLB = (CListBox*) dlg.GetDlgItem(ID_SECTIONS);

>Regards,

>-Frank

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Tue, 19 Aug 2003 02:33:52 GMT  
 How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS) before dlg.DoModal()
Yes, I agreed with you. The idea of getting an HWND after DoModal doesn't
make sense.

Regards,

Frank

|
| Yes, but the question dealt with getting an HWND after DoModal...
|                       joe
|

|
| >It's true you cannot update the content of ListBox after the DoModal
| >function call finish. Instead, you may record the information about
ListBox
| >to some memebr variables of the dialog class before the DoModal is
| >returned. Then, you can retrieve or modify the information from these
| >variable.
| >
| >Regards,
| >
| >-Frank
| >
| >
| >
| >--------------------

| >| Newsgroups: microsoft.public.vc.mfc
| >| Subject: Re: How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS)
| >before dlg.DoModal()
| >| Date: Wed, 28 Feb 2001 22:13:49 -0500
| >| Organization: Posted via Supernews, http://www.supernews.com




| >| X-Newsreader: Forte Agent 1.8/32.548
| >| MIME-Version: 1.0
| >| Content-Type: text/plain; charset=us-ascii
| >| Content-Transfer-Encoding: 7bit

| >| Lines: 30
| >| Path:
|

Quote:
>cppssbbsa01.microsoft.com!tkmsftngp01!newsfeed00.sul.t-online.de!t-online.d

e
|
Quote:
>!newsfeed.icl.net!dispose.news.demon.net!demon!grolier!sn-xit-01!sn-post-01

!
| >supernews.com!corp.supernews.com!not-for-mail
| >| Xref: cppssbbsa01.microsoft.com microsoft.public.vc.mfc:259612
| >| X-Tomcat-NG: microsoft.public.vc.mfc
| >|
| >| You can't. After the DoModal, the list box does not exist. In fact, if
| >| you could get the HWND, the HWND would become illegal. The listbox has
| >| exists from the OnInitDialog to the OnDestroy of the dialog. It does
| >| not exist before or after.
| >|                         joe
| >|

| >|
| >| >
| >| >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
| >|
| >| Joseph M. Newcomer [MVP]

| >| Web: http://www3.pgh.net/~newcomer
| >| MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm
| >|
|
| Joseph M. Newcomer [MVP]

| Web: http://www3.pgh.net/~newcomer
| MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm
|


Tue, 19 Aug 2003 10:17:11 GMT  
 
 [ 10 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