<b>Help!! How to access Static control from other class</B>
-
HI I am new to MFC VC++. I want to creat a Button control in VC++. I created cMyButton class derived from CButton. I want that if i move the cursor on the button, it should display some text in one of the static controls on my Dlg. is there a way to pass the pointer of the static control to the cMyButton class. I added some code like this: CStatic m_static; cMyButton::SetStaticCtrl(CStatic &cstatic) { m_static = cstatic; } void cMyButton::OnMouseMove(UINT nFlags, CPoint point) { m_static->SetWindowText("This is test! OK"); CButton::OnMouseMove(nFlags, point); } :confused:But above code gives errors. Pl. :(:((help me solving this. Tell me how to access controls on Dialog from CButton derived classes.:omg:
-
HI I am new to MFC VC++. I want to creat a Button control in VC++. I created cMyButton class derived from CButton. I want that if i move the cursor on the button, it should display some text in one of the static controls on my Dlg. is there a way to pass the pointer of the static control to the cMyButton class. I added some code like this: CStatic m_static; cMyButton::SetStaticCtrl(CStatic &cstatic) { m_static = cstatic; } void cMyButton::OnMouseMove(UINT nFlags, CPoint point) { m_static->SetWindowText("This is test! OK"); CButton::OnMouseMove(nFlags, point); } :confused:But above code gives errors. Pl. :(:((help me solving this. Tell me how to access controls on Dialog from CButton derived classes.:omg:
as you said you want to pass the pointer, however you pass the static control by reference and then copy it... make your m_static member of CMyButton a pointer like: CStatic *m_pStatCtrl; make your SetStaticCtrl like: void CMyButton::SetStaticCtrl(CStatic* pStatCtrl) { m_pStatCtrl = pStatCtrl; } and finally you onmousemove should look like if( NULL != m_pStatCtrl ) m_pStatCtrl->SetWindowText(... ); //and here the rest of the func... It would be good to set you m_pStatCtrl pointer to NULL in the constructor of CMyButton just as a precaution.. hope this helps you... Greetings, Davy
-
as you said you want to pass the pointer, however you pass the static control by reference and then copy it... make your m_static member of CMyButton a pointer like: CStatic *m_pStatCtrl; make your SetStaticCtrl like: void CMyButton::SetStaticCtrl(CStatic* pStatCtrl) { m_pStatCtrl = pStatCtrl; } and finally you onmousemove should look like if( NULL != m_pStatCtrl ) m_pStatCtrl->SetWindowText(... ); //and here the rest of the func... It would be good to set you m_pStatCtrl pointer to NULL in the constructor of CMyButton just as a precaution.. hope this helps you... Greetings, Davy
Hi Thanks a lot for your help. Its working for me. :):-D