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 Bitmap

Button Bitmap

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpquestion
7 Posts 3 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.
  • R Offline
    R Offline
    Ruca
    wrote on last edited by
    #1

    Hi everybody, I have a button on the status bar. The following code is included in mainframe::oncreate function: CButton * button = new CButton; button->Create(_T("SMS"), WS_CHILD | WS_VISIBLE | BS_FLAT | BS_BITMAP, CRect(0, 0, 0, 0), &m_wndStatusBar, IDC_BUTTON_STATUS_BAR); button->SetBitmap( ::LoadBitmap( NULL, MAKEINTRESOURCE(IDB_BITMAP5) ) ); I want to place a BItmap in the button, as can be seen. But the above code does not work. The button simply appears empty. button->SetIcon(::LoadIcon(NULL, MAKEINTRESOURCE( IDI_ICON1 )) ); An attempt at loading an icon does not work either. (with the BS_ICON set). Can anyone help? :confused: Thanks Rui

    J 1 Reply Last reply
    0
    • R Ruca

      Hi everybody, I have a button on the status bar. The following code is included in mainframe::oncreate function: CButton * button = new CButton; button->Create(_T("SMS"), WS_CHILD | WS_VISIBLE | BS_FLAT | BS_BITMAP, CRect(0, 0, 0, 0), &m_wndStatusBar, IDC_BUTTON_STATUS_BAR); button->SetBitmap( ::LoadBitmap( NULL, MAKEINTRESOURCE(IDB_BITMAP5) ) ); I want to place a BItmap in the button, as can be seen. But the above code does not work. The button simply appears empty. button->SetIcon(::LoadIcon(NULL, MAKEINTRESOURCE( IDI_ICON1 )) ); An attempt at loading an icon does not work either. (with the BS_ICON set). Can anyone help? :confused: Thanks Rui

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      I guess the problem lies in the CRect(0, 0, 0, 0) part. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      R 1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        I guess the problem lies in the CRect(0, 0, 0, 0) part. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        R Offline
        R Offline
        Ruca
        wrote on last edited by
        #3

        Hi Joaquín, thanks for the try, but the following works: CButton * button = new CButton; button->Create(_T("SMS"), WS_CHILD | WS_VISIBLE | BS_FLAT | BS_ICON, CRect(0, 0, 0, 0), &m_wndStatusBar, IDC_BUTTON_STATUS_BAR); button->SetIcon( AfxGetApp()->LoadIcon( IDI_ICON1 ) ); I cannot understand why, this works and not the previous code. Why must I use AfxGetApp to LoadIcon() and not just LoadIcon()? Any answers? Rui

        E 1 Reply Last reply
        0
        • R Ruca

          Hi Joaquín, thanks for the try, but the following works: CButton * button = new CButton; button->Create(_T("SMS"), WS_CHILD | WS_VISIBLE | BS_FLAT | BS_ICON, CRect(0, 0, 0, 0), &m_wndStatusBar, IDC_BUTTON_STATUS_BAR); button->SetIcon( AfxGetApp()->LoadIcon( IDI_ICON1 ) ); I cannot understand why, this works and not the previous code. Why must I use AfxGetApp to LoadIcon() and not just LoadIcon()? Any answers? Rui

          E Offline
          E Offline
          Ed Gadziemski
          wrote on last edited by
          #4

          Because you need an instance handle in order to find and load the icon. The NULL value you supplied as the first parameter to ::LoadIcon and ::LoadBitmap was insufficient.

          R 2 Replies Last reply
          0
          • E Ed Gadziemski

            Because you need an instance handle in order to find and load the icon. The NULL value you supplied as the first parameter to ::LoadIcon and ::LoadBitmap was insufficient.

            R Offline
            R Offline
            Ruca
            wrote on last edited by
            #5

            Thanks for the explanation. How do I get the hinst? Cheers Rui

            1 Reply Last reply
            0
            • E Ed Gadziemski

              Because you need an instance handle in order to find and load the icon. The NULL value you supplied as the first parameter to ::LoadIcon and ::LoadBitmap was insufficient.

              R Offline
              R Offline
              Ruca
              wrote on last edited by
              #6

              OK, I understand that, what is bothering me is, after reading the MSDN documentation, I don't understand how to get the "Handle to an instance of the module whose executable file contains the icon to be loaded"? Thanks for your time and excuse my ignorance. Cheers Rui

              E 1 Reply Last reply
              0
              • R Ruca

                OK, I understand that, what is bothering me is, after reading the MSDN documentation, I don't understand how to get the "Handle to an instance of the module whose executable file contains the icon to be loaded"? Thanks for your time and excuse my ignorance. Cheers Rui

                E Offline
                E Offline
                Ed Gadziemski
                wrote on last edited by
                #7

                The hInstance parameter is passed by Windows to WinMain when an application is started. Use AfxGetInstanceHandle() to get it. If that does not answer you, I don't understand your question. Try rephrasing it and posting again and perhaps someone can help.

                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