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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to change background at run time?

How to change background at run time?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
3 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.
  • P Offline
    P Offline
    pavelcyu
    wrote on last edited by
    #1

    i put a picture control onto a form,& i wanna change it's content in a button click event.i've tried with function (CStatic)SetBitMap ,but it seems doesn't work! it puzzled me for two days ,somebody help me!;P;P

    B 1 Reply Last reply
    0
    • P pavelcyu

      i put a picture control onto a form,& i wanna change it's content in a button click event.i've tried with function (CStatic)SetBitMap ,but it seems doesn't work! it puzzled me for two days ,somebody help me!;P;P

      B Offline
      B Offline
      Beer
      wrote on last edited by
      #2

      first, go to classwizard from by right clicking on your dialog class click the member variables tab and add a variable for your picture CStatic as a CStatic CONTROL, and call it m_picture. Now left click on your CStatic in the resource editor and make sure it's set to type: bitmap Now double click on the button you want to control the picture change in the resource editor and let it add the mapped function for you by hitting "ok". Now you should be in your dialog with the new button pressed mapped function now add this code like so void Cdlg::OnButtonClick() {HBITMAP hBitmap = (HBITMAP) ::LoadImage(NULL, _T("C:\\some\\image\\location.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); m_picture.SetBitmap(hBitmap); } now compile and watch as the code works. PS- that obviously works just as well using a resource bitmap, and if it's not a dialog you would obviously create the CStatic naming it m_picture(class member) and initialize it and show it before using it.

      A 1 Reply Last reply
      0
      • B Beer

        first, go to classwizard from by right clicking on your dialog class click the member variables tab and add a variable for your picture CStatic as a CStatic CONTROL, and call it m_picture. Now left click on your CStatic in the resource editor and make sure it's set to type: bitmap Now double click on the button you want to control the picture change in the resource editor and let it add the mapped function for you by hitting "ok". Now you should be in your dialog with the new button pressed mapped function now add this code like so void Cdlg::OnButtonClick() {HBITMAP hBitmap = (HBITMAP) ::LoadImage(NULL, _T("C:\\some\\image\\location.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); m_picture.SetBitmap(hBitmap); } now compile and watch as the code works. PS- that obviously works just as well using a resource bitmap, and if it's not a dialog you would obviously create the CStatic naming it m_picture(class member) and initialize it and show it before using it.

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        THANK U!!!!!!!! IT WORKS!:):wtf:

        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