setting text on dialog from a subclass
-
i subclassed CButton class and have a onmousemove in it and i need to set text on my dialog i know it can be done ive done it before but i cant remember now to save my life
void CMyButton::OnMouseMove(UINT nFlags, CPoint point) { if (!m_bOverControl) { TRACE0("Entering control\n"); m_bOverControl = TRUE; Invalidate(); if (GetDlgCtrlID() == IDC_STATUS_BUTTON) { //IDC_DISPLAY_TEXT is the control i need to set text to } if (GetDlgCtrlID() == IDC_SEARCH_BUTTON) { MessageBox("hi"); } if (GetDlgCtrlID() == IDC_OPTIONS_BUTTON) { MessageBox("low"); } SetTimer(m_nTimerID, 100, NULL); } CButton::OnMouseMove(nFlags, point); }
the messagebox works. -
i subclassed CButton class and have a onmousemove in it and i need to set text on my dialog i know it can be done ive done it before but i cant remember now to save my life
void CMyButton::OnMouseMove(UINT nFlags, CPoint point) { if (!m_bOverControl) { TRACE0("Entering control\n"); m_bOverControl = TRUE; Invalidate(); if (GetDlgCtrlID() == IDC_STATUS_BUTTON) { //IDC_DISPLAY_TEXT is the control i need to set text to } if (GetDlgCtrlID() == IDC_SEARCH_BUTTON) { MessageBox("hi"); } if (GetDlgCtrlID() == IDC_OPTIONS_BUTTON) { MessageBox("low"); } SetTimer(m_nTimerID, 100, NULL); } CButton::OnMouseMove(nFlags, point); }
the messagebox works.Usually it's preferable to send/post a message to the parent and let the parent set the text. This eliminates the need for the child to have intimate knowledge of its parent. Regardless of how you choose to implement this, eventually you'll probably want to use SetWindowText() to set the IDC_DISPLAY_TEXT control's text. Also, what sets your m_bOverControl to FALSE? Is that what the timer is for? If so, you may want to look into TrackMouseEvent() and WM_MOUSELEAVE for a more elegant solution to tracking when the cursor leaves a window. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Usually it's preferable to send/post a message to the parent and let the parent set the text. This eliminates the need for the child to have intimate knowledge of its parent. Regardless of how you choose to implement this, eventually you'll probably want to use SetWindowText() to set the IDC_DISPLAY_TEXT control's text. Also, what sets your m_bOverControl to FALSE? Is that what the timer is for? If so, you may want to look into TrackMouseEvent() and WM_MOUSELEAVE for a more elegant solution to tracking when the cursor leaves a window. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
ive tryed SetWindowtext()but nothing happens ive tryed ::SetWindowText() to but for some reason i cant get a HWND to my control till after its to late
What type of control is it? What window is the parent of the control? Is it the same parent as the button's parent? If you're using MFC then you should be using an MFC object to wrap the control - CStatic, CEdit, etc. If you don't use an MFC control object, there's GetDlgItem() to get a control's HWND given its ID. You need to know the controls parent to use it, that's it. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: