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. setting text on dialog from a subclass

setting text on dialog from a subclass

Scheduled Pinned Locked Moved C / C++ / MFC
4 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.
  • L Offline
    L Offline
    locoone
    wrote on last edited by
    #1

    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.

    M 1 Reply Last reply
    0
    • L locoone

      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.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      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:

      L 1 Reply Last reply
      0
      • M Mark Salsbery

        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:

        L Offline
        L Offline
        locoone
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • L locoone

          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

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          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:

          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