Thread: how to set a background as a image?

  1. #1
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214

    how to set a background as a image?

    hi is there some one out there who would know how to a set a background image in win32 api.thanks

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Code:
    SystemParametersInfo( SPI_SETDESKWALLPAPER, 0, "C:\\wallpaper.jpg", 0 );
    http://msdn.microsoft.com/library/de...metersinfo.asp
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214
    sorry
    i ment for the actual program like a bitmap file , not the desktop

  4. #4
    Easiest way is to do it in the registering of the window class

    wncl.hbrBackground = CreatePatternBrush( LoadBitmap( hInstance, MAKEINTRESOURCE( your_bitmap ) ) );

  5. #5
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214
    Code:
      wincl.hbrBackground = CreatePatternBrush( LoadBitmap( hThisInstance, MAKEINTRESOURCE(BACKGROUND) ) );
    this did not work

  6. #6
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Bear in mind that under Win9x, CreatePatternBrush will only use a max 8x8 bitmap for a pattern brush. If compatibility with this platform is required, then modification of the window's WM_PAINT message will be necessary (Some BitBlting required).

  7. #7
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Bear in mind that under Win9x, CreatePatternBrush will only use a max 8x8 bitmap for a pattern brush
    CreatePatternBrush is ok for win98; it's only win95 that limits the size to 8x8.
    this did not work
    This doesn't help us to help you. If you got an error what error was reported?
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  8. #8
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214
    i didnt get a error and im on XP
    its just not showing the picture
    and yes its all setup right in the resource file

  9. #9
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    There are two likely problems then:

    1. hThisInstance is not valid. Try using GetModuleHandle(0) instead.

    2. You're passing a string resource identifier to MAKEINTRESOURCE rather than a short int resource identifier (check value of 'BACKGROUND' - substitute in the numerical value in place of MAKEINTRESOURCE(...) in your LoadBitmap call.

    If that fails to identify the source of the problem then it might be a good idea to break the bitmap and brush creation line into separate parts, checking the return values from LoadBitmap and CreatePatternBrush to check for non-NULL values. If either is NULL then use GetLastError to give you some better idea of why.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  10. #10
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214
    Code:
    wincl.hbrBackground = CreatePatternBrush( LoadBitmap( GetModuleHandle(0), MAKEINTRESOURCE(700) ) );
    did not work it compiled and still nothing

  11. #11
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Quote Originally Posted by Ken Fitlike
    If that fails to identify the source of the problem then it might be a good idea to break the bitmap and brush creation line into separate parts, checking the return values from LoadBitmap and CreatePatternBrush to check for non-NULL values. If either is NULL then use GetLastError to give you some better idea of why.
    ...and the result of trying that is...?
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  12. #12
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214
    well i dont get a background or color it just paints wat window was over it say if explorer was over it then it will paint what was over it.
    sorry on the late reply

  13. #13
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214
    Code:
    #include <windows.h>
    #include "manifest.h"
    
    MANIFEST_RESOURCE_ID  MANIFEST "client.exe.manifest"
    
    500 ICON "main.ico"
    600 ICON "app.ico"
    800 ICON "tray.ico"
    700 BACKGROUND BITMAP "background.bmp"
    i have it defined as
    Code:
    #define BACKGROUND 700
    up the top
    when i open it it paints the current window that was above the app
    say if i have msn messenger over it.it will paint that to it.please help.thanks

  14. #14
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    700 BACKGROUND BITMAP "background.bmp"
    should be:
    Code:
    700 BITMAP "background.bmp"
    or
    Code:
    BACKGROUND BITMAP "background.bmp"
    --
    Typically, we create a header file "resource.h" with:
    Code:
    #define IDI_APPICON 1001
    #define IDI_TRAYICON 1002
    #define IDB_BACKGROUND 2001
    and then we #include that file in both the resource file and the project:
    Code:
    #include <windows.h>
    #include "resource.h"
    
    IDI_APPICON ICON "app.ico"
    IDI_TRAYICON ICON "tray.ico"
    IDB_BACKGROUND BITMAP "background.bmp"
    The numbers are only used once, in the header file.

  15. #15
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214
    ah thanks so much it works!!
    much apreciated

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM
  2. LISP (DrScheme) any one?
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-31-2004, 12:52 PM
  3. Changing background color of irregular image
    By Tesita in forum C++ Programming
    Replies: 5
    Last Post: 11-03-2003, 08:17 PM
  4. Replies: 4
    Last Post: 03-02-2003, 09:12 AM
  5. How to change a mouse cursor in console mode
    By GaPe in forum Windows Programming
    Replies: 10
    Last Post: 07-03-2002, 07:42 AM