Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. <b>Help!! How to access Static control from other class</B>

<b>Help!! How to access Static control from other class</B>

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VikramDelhi i
    wrote on last edited by
    #1

    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:

    G 1 Reply Last reply
    0
    • V VikramDelhi i

      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:

      G Offline
      G Offline
      GDavy
      wrote on last edited by
      #2

      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

      V 1 Reply Last reply
      0
      • G GDavy

        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

        V Offline
        V Offline
        VikramDelhi i
        wrote on last edited by
        #3

        Hi Thanks a lot for your help. Its working for me. :):-D

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups