Question on HWND hDlg Parameter in ::SetDlgItemText(HWND hDlg, int nIDDlgItem, LPTSTR lpString, int nMaxCount)
Author |
Message |
Jeff Partc #1 / 10
|
 Question on HWND hDlg Parameter in ::SetDlgItemText(HWND hDlg, int nIDDlgItem, LPTSTR lpString, int nMaxCount)
Hi! If this is MFC code and CTempView is your CDialog(IDD_DIALOG1) class then use the CWnd::SetDlgItemText member function instead. For the record though, It calls the API version like this... ::SetDlgItemText(m_hWnd, nID, lpszString); If this is an SDK app -- which I doubt, then the HWND hDlg parameter is the HWND hwndDlg passed into the DialogProc for this dialog. INT_PTR CALLBACK DialogProc( HWND hwndDlg, // handle to dialog box UINT uMsg, // message WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ); HTH, Jeff... -- Please post all follow-ups to the newsgroup only.
|
Sat, 28 Jun 2003 20:14:37 GMT |
|
 |
Unknown Use #2 / 10
|
 Question on HWND hDlg Parameter in ::SetDlgItemText(HWND hDlg, int nIDDlgItem, LPTSTR lpString, int nMaxCount)
Jeff, Thank you for your reply. Unfortunately, your explanation is CIPU (Clear If Previously Understood). The code below compiled but failed to placed the text "HELLO" in the IDC_EDIT1 box. void CTempView::OnButton1() { TRACE("Button1 Clicked \n"); CString s_Text = "HELLO"; ::SetDlgItemText(m_hWnd, IDC_EDIT1, s_Text); Quote: }
An example code which compiles and places a string in the IDC_EDIT1 would clearly illustrate your explanation below. I am unsure if the code above is the correct method and any corrections would be most appreciative. On Tue, 9 Jan 2001 06:14:37 -0600, "Jeff Partch" Quote:
>Hi! >If this is MFC code and CTempView is your CDialog(IDD_DIALOG1) class then use the >CWnd::SetDlgItemText member function instead. For the record though, It calls the API version like >this... > ::SetDlgItemText(m_hWnd, nID, lpszString); >If this is an SDK app -- which I doubt, then the HWND hDlg parameter is the HWND hwndDlg passed into >the DialogProc for this dialog. > INT_PTR CALLBACK DialogProc( > HWND hwndDlg, // handle to dialog box > UINT uMsg, // message > WPARAM wParam, // first message parameter > LPARAM lParam // second message parameter > ); >HTH, >Jeff...
|
Sun, 29 Jun 2003 04:14:56 GMT |
|
 |
Jeff Partc #3 / 10
|
 Question on HWND hDlg Parameter in ::SetDlgItemText(HWND hDlg, int nIDDlgItem, LPTSTR lpString, int nMaxCount)
Hi! Sorry for stating the obvious, but I really did think that's what you were asking. Anyway, I just created a dialog resource with these controls on it... IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 215, 151 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Test" FONT 8, "MS Sans Serif" BEGIN DEFPUSHBUTTON "OK",IDOK,158,7,50,14 PUSHBUTTON "Cancel",IDCANCEL,158,24,50,14 PUSHBUTTON "&Text",IDC_BUTTON1,158,124,50,14 EDITTEXT IDC_EDIT1,10,123,141,14,ES_AUTOHSCROLL END I then used ClassWizard to create a CDialog derived class called CTempView using the IDD_DIALOG1... class CTempView : public CDialog { // Construction public: CTempView(CWnd* pParent = NULL); // standard constructor // Dialog Data //{{AFX_DATA(CTempView) enum { IDD = IDD_DIALOG1 }; // NOTE: the ClassWizard will add data members here //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CTempView) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: // Generated message map functions //{{AFX_MSG(CTempView) afx_msg void OnButton1(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; And then I used ClassWizard to add a BN_CLICKED message handler for the IDC_BUTTON1 control to the CTempView class... BEGIN_MESSAGE_MAP(CTempView, CDialog) //{{AFX_MSG_MAP(CTempView) ON_BN_CLICKED(IDC_BUTTON1, OnButton1) //}}AFX_MSG_MAP END_MESSAGE_MAP() void CTempView::OnButton1() { TRACE("Button1 Clicked \n"); CString s_Text = "HELLO"; ::SetDlgItemText(m_hWnd, IDC_EDIT1, s_Text); } Which is how I understand your situation. And it just works for me. Do you have any idea where my implementation differs from yours? Jeff... -- Please post all follow-ups to the newsgroup only.
|
Sun, 29 Jun 2003 05:48:32 GMT |
|
 |
#4 / 10
|
 Question on HWND hDlg Parameter in ::SetDlgItemText(HWND hDlg, int nIDDlgItem, LPTSTR lpString, int nMaxCount)
|
Fri, 19 Jun 1992 00:00:00 GMT |
|
 |
Unknown Use #5 / 10
|
 Question on HWND hDlg Parameter in ::SetDlgItemText(HWND hDlg, int nIDDlgItem, LPTSTR lpString, int nMaxCount)
Jeff, Thank you again for your response. It is most appreciated. Your example is almost identical with one exception. I am using class CTempView : public CView What am I trying to do? I have a dialog IDD_DIALOG1 with the following controls. Please see attached bitmaps before.bmp and after.bmp. IDC_BUTTON1, IDC_EDIT1 IDC_BUTTON2, IDC_EDIT2 Intent is to set text in the IDC_EDIT1 by clicking on IDC_BUTTON1 and IDC_EDIT2 by clicking on IDC_BUTTON2. For IDC_EDIT2 and IDC_BUTTON2, I am using class CDlg : public CDialog void CDlg::OnButton2() // Button2 works as shown by after.bmp { TRACE("Button2 Clicked\n"); SetDlgItemText(IDC_BUTTON2, "Sample Text"); SetDlgItemText(IDC_EDIT2, "Sample Text"); Quote: }
FOR IDC_EDIT1 and IDC_BUTTON1, I am using class CTempView : public CView void CTempView::OnButton1() { TRACE("Button1 Clicked \n"); // Works upto here CString s_Text = "HELLO"; ::SetDlgItemText(m_hWnd, IDC_EDIT1, s_Text); Quote: }
For IDC_BUTTON1 to send a command message, I've set the COMMAND ID as 0x9000. The view has a handler for the button's command and responds with the TRACE("Button1 Clicked \n") in the output window. Question now is how to ::SetDlgItemText(m_hWnd, IDC_EDIT1, s_Text); Forgive me for my ignorance but the Tutorial Book I am reading covers how to do button2/edit2 but does not cover button1/edit1. Thanks. On Tue, 9 Jan 2001 15:48:32 -0600, "Jeff Partch" Quote:
>Hi! >Sorry for stating the obvious, but I really did think that's what you were asking. >Anyway, I just created a dialog resource with these controls on it... > IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 215, 151 > STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU > CAPTION "Test" > FONT 8, "MS Sans Serif" > BEGIN > DEFPUSHBUTTON "OK",IDOK,158,7,50,14 > PUSHBUTTON "Cancel",IDCANCEL,158,24,50,14 > PUSHBUTTON "&Text",IDC_BUTTON1,158,124,50,14 > EDITTEXT IDC_EDIT1,10,123,141,14,ES_AUTOHSCROLL > END >I then used ClassWizard to create a CDialog derived class called CTempView using the IDD_DIALOG1... > class CTempView : public CDialog > { > // Construction > public: > CTempView(CWnd* pParent = NULL); // standard constructor > // Dialog Data > //{{AFX_DATA(CTempView) > enum { IDD = IDD_DIALOG1 }; > // NOTE: the ClassWizard will add data members here > //}}AFX_DATA > // Overrides > // ClassWizard generated virtual function overrides > //{{AFX_VIRTUAL(CTempView) > protected: > virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support > //}}AFX_VIRTUAL > // Implementation > protected: > // Generated message map functions > //{{AFX_MSG(CTempView) > afx_msg void OnButton1(); > //}}AFX_MSG > DECLARE_MESSAGE_MAP() > }; >And then I used ClassWizard to add a BN_CLICKED message handler for the IDC_BUTTON1 control to the >CTempView class... > BEGIN_MESSAGE_MAP(CTempView, CDialog) > //{{AFX_MSG_MAP(CTempView) > ON_BN_CLICKED(IDC_BUTTON1, OnButton1) > //}}AFX_MSG_MAP > END_MESSAGE_MAP() > void CTempView::OnButton1() > { > TRACE("Button1 Clicked \n"); > CString s_Text = "HELLO"; > ::SetDlgItemText(m_hWnd, IDC_EDIT1, s_Text); > } >Which is how I understand your situation. And it just works for me. Do you have any idea where my >implementation differs from yours? >Jeff...
|
Sun, 29 Jun 2003 06:57:41 GMT |
|
 |
#6 / 10
|
 Question on HWND hDlg Parameter in ::SetDlgItemText(HWND hDlg, int nIDDlgItem, LPTSTR lpString, int nMaxCount)
|
Fri, 19 Jun 1992 00:00:00 GMT |
|
 |
Jeff Partc #7 / 10
|
 Question on HWND hDlg Parameter in ::SetDlgItemText(HWND hDlg, int nIDDlgItem, LPTSTR lpString, int nMaxCount)
Hi! Three things and then an answer that may just work... 1. 465k attachments are frowned upon in non-binary newsgroups. 2. I have no idea why you are doing this in this way. 3. I'm skating on thin ice with this one, but here goes... void CTempView::OnButton1() { TRACE("Button1 Clicked \n"); // Works upto here CString s_Text = "HELLO"; ::SetDlgItemText(GetCurrentMessage()->hwnd, IDC_EDIT1, s_Text); } HTH, Jeff... -- Please post all follow-ups to the newsgroup only.
|
Sun, 29 Jun 2003 08:02:55 GMT |
|
 |
Unknown Use #8 / 10
|
 Question on HWND hDlg Parameter in ::SetDlgItemText(HWND hDlg, int nIDDlgItem, LPTSTR lpString, int nMaxCount)
Jeff, Thank you very much. It worked finally. :-) Quote: >1. 465k attachments are frowned upon in non-binary newsgroups.
Without knowing the proper terminology, I thought it best to show the picture to communicate my intent. I will refrain from posting large bitmaps in the future. Quote: >2. I have no idea why you are doing this in this way.
The tutorial I am reading covers ActiveX for Internet Explorer and I am modifying the code to allow entering the URL. Here is the snippet that has not worked until now. void CEx08bView::OnGoLeft() { char char_leftURL[] = "http://www.msnbc.com/"; ::GetDlgItemText(GetCurrentMessage()->hwnd, IDC_URL_LEFT, char_leftURL, 100); m_target.Navigate(char_leftURL, NULL, NULL, NULL, NULL); Quote: }
I searched the VC++ Documentation for GetCurrentMessage() and found 2 entries. ------------------------------------------------------------------- CContainedWindow::GetCurrentMessage const MSG* GetCurrentMessage( ); Return Value The current message, packaged in the MSG structure. Remarks Returns the current message (m_pCurrentMsg). ------------------------------------------------------------------- CWnd::GetCurrentMessage static const MSG* Pascal GetCurrentMessage( ); Return Value Returns a pointer to the MSG structure that contains the message the window is currently processing. Should only be called when in an OnMessage handler. Example See the example for CMDIFrameWnd::MDICascade. -------------------------------------------------------------------- Without reiterating the above, could you tell me how this process works in simple English? Thank you. On Tue, 9 Jan 2001 18:02:55 -0600, "Jeff Partch" Quote:
>Hi! >Three things and then an answer that may just work... >1. 465k attachments are frowned upon in non-binary newsgroups. >2. I have no idea why you are doing this in this way. >3. I'm skating on thin ice with this one, but here goes... > void CTempView::OnButton1() > { > TRACE("Button1 Clicked \n"); // Works upto here > CString s_Text = "HELLO"; > ::SetDlgItemText(GetCurrentMessage()->hwnd, IDC_EDIT1, s_Text); > } >HTH, >Jeff...
|
Sun, 29 Jun 2003 18:00:10 GMT |
|
 |
Jeff Partc #9 / 10
|
 Question on HWND hDlg Parameter in ::SetDlgItemText(HWND hDlg, int nIDDlgItem, LPTSTR lpString, int nMaxCount)
Hi!
Quote: > Jeff, > Thank you very much. It worked finally. :-) > Without reiterating the above, could you tell me how this process > works in simple English? Thank you.
Well I'm glad of that, and I'll try to explain it... In Windows messages are (basically) sent from one HWND to another HWND. The button HWND sends the BN_CLICKED notification as part of a WM_COMMAND message to its parent HWND which in this case is the dialogbox it lives on. Something like this... HWND hwndParent = GetParent(); SendMessage(hwndParent, WM_COMMAND, MAKEWPARAM(myid, 0), (LPARAM)(DWORD)myhwnd); So then MFC, having subclassed the dialogbox intercepts the message... AfxWndProcBase AfxWndProc AfxCallWndProc // Saves the message here AfxCallWndProc saves the message in the MSG m_lastSentMsg member of a CThreadLocal structure... LRESULT AFXAPI AfxCallWndProc(CWnd* pWnd, HWND hWnd, UINT nMsg, WPARAM wParam = 0, LPARAM lParam = 0) { _AFX_THREAD_STATE* pThreadState = _afxThreadState.GetData(); MSG oldState = pThreadState->m_lastSentMsg; // save for nesting pThreadState->m_lastSentMsg.hwnd = hWnd; pThreadState->m_lastSentMsg.message = nMsg; pThreadState->m_lastSentMsg.wParam = wParam; pThreadState->m_lastSentMsg.lParam = lParam; And then begins its message map routing... CWnd::WindowProc CWnd::OnWndMsg // Looks for WM_COMMAND here OnCmdMsg // Does its WM_COMMAND routing here _AfxDispatchCmdMsg // Call the found CCmdTarget handler here Which gets to your handler where GetCurrentMessage returns a pointer the m_lastSentMsg that was filled in above (it sets the time and pt members too), and where m_lastSentMsg.hwnd is still the HWND of the window that the button sent the message to in the first place -- its parent, or the dialog box it lives on. Which is the same dialog box that the IDC_EDIT1 edit control lives on. Which is what you need for the call to... ::SetDlgItemText(hdlg, IDC_EDIT1, strPath); Does that make sense? Is that what you were asking this time? Jeff... -- Please post all follow-ups to the newsgroup only.
|
Sun, 29 Jun 2003 20:07:53 GMT |
|
 |
Unknown Use #10 / 10
|
 Question on HWND hDlg Parameter in ::SetDlgItemText(HWND hDlg, int nIDDlgItem, LPTSTR lpString, int nMaxCount)
Jeff, Your explanation is elegant and most informative. I absorbed the general concept and will review the technical details as I continue my study. Thank you again for your assistance. On Wed, 10 Jan 2001 06:07:53 -0600, "Jeff Partch" Quote:
>Hi!
>> Jeff, >> Thank you very much. It worked finally. :-) >> Without reiterating the above, could you tell me how this process >> works in simple English? Thank you. >Well I'm glad of that, and I'll try to explain it... >In Windows messages are (basically) sent from one HWND to another HWND. The button HWND sends the >BN_CLICKED notification as part of a WM_COMMAND message to its parent HWND which in this case is the >dialogbox it lives on. Something like this... > HWND hwndParent = GetParent(); > SendMessage(hwndParent, WM_COMMAND, MAKEWPARAM(myid, 0), (LPARAM)(DWORD)myhwnd); >So then MFC, having subclassed the dialogbox intercepts the message... > AfxWndProcBase > AfxWndProc > AfxCallWndProc // Saves the message here >AfxCallWndProc saves the message in the MSG m_lastSentMsg member of a CThreadLocal structure... > LRESULT AFXAPI AfxCallWndProc(CWnd* pWnd, HWND hWnd, UINT nMsg, > WPARAM wParam = 0, LPARAM lParam = 0) > { > _AFX_THREAD_STATE* pThreadState = _afxThreadState.GetData(); > MSG oldState = pThreadState->m_lastSentMsg; // save for nesting > pThreadState->m_lastSentMsg.hwnd = hWnd; > pThreadState->m_lastSentMsg.message = nMsg; > pThreadState->m_lastSentMsg.wParam = wParam; > pThreadState->m_lastSentMsg.lParam = lParam; >And then begins its message map routing... > CWnd::WindowProc > CWnd::OnWndMsg // Looks for WM_COMMAND here > OnCmdMsg // Does its WM_COMMAND routing here > _AfxDispatchCmdMsg // Call the found CCmdTarget handler here >Which gets to your handler where GetCurrentMessage returns a pointer the m_lastSentMsg that was >filled in above (it sets the time and pt members too), and where m_lastSentMsg.hwnd is still the >HWND of the window that the button sent the message to in the first place -- its parent, or the >dialog box it lives on. Which is the same dialog box that the IDC_EDIT1 edit control lives on. Which >is what you need for the call to... > ::SetDlgItemText(hdlg, IDC_EDIT1, strPath); >Does that make sense? Is that what you were asking this time? >Jeff...
|
Sun, 29 Jun 2003 21:42:51 GMT |
|
|
|