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. Button with Icon not showing tooltip

Button with Icon not showing tooltip

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsstutorial
5 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.
  • _ Offline
    _ Offline
    _AnsHUMAN_
    wrote on last edited by
    #1

    I have a CButton on which I load an Icon. I set the Icon property of the button to true and load the icon using the LoadImage() function as follows: HANDLE hIconHandle = ::LoadImage( AfxGetResourceHandle(), MAKEINTRESOURCE( IDI_MYICON), IMAGE_ICON, 0, 0, LR_LOADTRANSPARENT ); ::SendMessage( m_button.m_hWnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) (DWORD) hU ); The tool tips show only if the mouse is on the border of the button and not on the image. The button is placed on a mode less dialog. Any ideas on how can I get the tool tip to show when the mouse is over the button? P.S: I don't want to add a new class to implement this functionality...

    Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

    H 1 Reply Last reply
    0
    • _ _AnsHUMAN_

      I have a CButton on which I load an Icon. I set the Icon property of the button to true and load the icon using the LoadImage() function as follows: HANDLE hIconHandle = ::LoadImage( AfxGetResourceHandle(), MAKEINTRESOURCE( IDI_MYICON), IMAGE_ICON, 0, 0, LR_LOADTRANSPARENT ); ::SendMessage( m_button.m_hWnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) (DWORD) hU ); The tool tips show only if the mouse is on the border of the button and not on the image. The button is placed on a mode less dialog. Any ideas on how can I get the tool tip to show when the mouse is over the button? P.S: I don't want to add a new class to implement this functionality...

      Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      When you run this code what happen?

      void CDialogDlg::SetToolTip(LPCTSTR Text,HWND hwnd)
      {
      TOOLINFO ti;
      ti.cbSize = sizeof(TOOLINFO);
      ti.lpszText = (LPTSTR)Text;
      ti.hinst = AfxGetInstanceHandle();
      ti.hwnd = hwnd;
      ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
      ti.uId = (UINT) hwnd;
      m_tooltip.SendMessage(TTM_ADDTOOL, 0, (LPARAM) &ti);

      }

      void CDialogDlg::OnBnClickedCancel()
      {
      m_tooltip.Create(this);

      m\_Button.ModifyStyle(BS\_BITMAP,BS\_ICON);
      

      //HANDLE hIconHandle = ::LoadImage( AfxGetResourceHandle(),
      //MAKEINTRESOURCE( IDI_UP), IMAGE_ICON, 0, 0, LR_LOADTRANSPARENT );
      //m_Button.SetIcon((HICON)hIconHandle );
      m_Button.SetIcon(LoadIcon(AfxGetApp()->m_hInstance,(LPCTSTR)IDI_UP));
      SetToolTip("Test",m_Button.m_hWnd);
      }


      WhiteSky


      _ 2 Replies Last reply
      0
      • H Hamid Taebi

        When you run this code what happen?

        void CDialogDlg::SetToolTip(LPCTSTR Text,HWND hwnd)
        {
        TOOLINFO ti;
        ti.cbSize = sizeof(TOOLINFO);
        ti.lpszText = (LPTSTR)Text;
        ti.hinst = AfxGetInstanceHandle();
        ti.hwnd = hwnd;
        ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
        ti.uId = (UINT) hwnd;
        m_tooltip.SendMessage(TTM_ADDTOOL, 0, (LPARAM) &ti);

        }

        void CDialogDlg::OnBnClickedCancel()
        {
        m_tooltip.Create(this);

        m\_Button.ModifyStyle(BS\_BITMAP,BS\_ICON);
        

        //HANDLE hIconHandle = ::LoadImage( AfxGetResourceHandle(),
        //MAKEINTRESOURCE( IDI_UP), IMAGE_ICON, 0, 0, LR_LOADTRANSPARENT );
        //m_Button.SetIcon((HICON)hIconHandle );
        m_Button.SetIcon(LoadIcon(AfxGetApp()->m_hInstance,(LPCTSTR)IDI_UP));
        SetToolTip("Test",m_Button.m_hWnd);
        }


        WhiteSky


        _ Offline
        _ Offline
        _AnsHUMAN_
        wrote on last edited by
        #3

        The image on the button disappears when I click on the Cancel button for the first time and is not displayed again. The application crashes when I click on Cancel button for the second time (but this can be handled)

        Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

        H 1 Reply Last reply
        0
        • H Hamid Taebi

          When you run this code what happen?

          void CDialogDlg::SetToolTip(LPCTSTR Text,HWND hwnd)
          {
          TOOLINFO ti;
          ti.cbSize = sizeof(TOOLINFO);
          ti.lpszText = (LPTSTR)Text;
          ti.hinst = AfxGetInstanceHandle();
          ti.hwnd = hwnd;
          ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
          ti.uId = (UINT) hwnd;
          m_tooltip.SendMessage(TTM_ADDTOOL, 0, (LPARAM) &ti);

          }

          void CDialogDlg::OnBnClickedCancel()
          {
          m_tooltip.Create(this);

          m\_Button.ModifyStyle(BS\_BITMAP,BS\_ICON);
          

          //HANDLE hIconHandle = ::LoadImage( AfxGetResourceHandle(),
          //MAKEINTRESOURCE( IDI_UP), IMAGE_ICON, 0, 0, LR_LOADTRANSPARENT );
          //m_Button.SetIcon((HICON)hIconHandle );
          m_Button.SetIcon(LoadIcon(AfxGetApp()->m_hInstance,(LPCTSTR)IDI_UP));
          SetToolTip("Test",m_Button.m_hWnd);
          }


          WhiteSky


          _ Offline
          _ Offline
          _AnsHUMAN_
          wrote on last edited by
          #4

          Do we have a substitute for PreTranslateMessage in Modeless dialog. I guess I have figured the problem and now I need a substitute...

          Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

          1 Reply Last reply
          0
          • _ _AnsHUMAN_

            The image on the button disappears when I click on the Cancel button for the first time and is not displayed again. The application crashes when I click on Cancel button for the second time (but this can be handled)

            Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #5

            Yeah you got an error because you have this function on the cancel m_tooltip.Create(this); you must remove this function of Oncancel I tried to work with this code and it worked and I could see image on the button before and after click.


            WhiteSky


            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