Thread: Bmp background in C++

  1. #1
    Registered User
    Join Date
    Aug 2008

    Bmp background in C++

    I made a program and would like to know how to put a wallpaper behind.
    with this code put an orange with a yellow line!

    #include "stdafx.h"
    #include "Painter.h"
    BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
    	return true;
    class BackgroundPainter : public Painter
    	HBRUSH brush;
    	HPEN pen;
    	HFONT font;
    	virtual void Paint(HDC hdc, int horizonOffsetY, int viewOffsetX, int viewOffsetY, int viewWidth, int viewHeight, int x, int y, int width, int height)
    		SelectObject(hdc, pen);
    		SelectObject(hdc, font);
    		SetTextColor(hdc, RGB(0, 0, 0));
    		SetBkMode(hdc, TRANSPARENT);
    		RECT rc = { x, y, x + width, y + height };
    		FillRect(hdc, &rc, brush);
    		//como não tem nenhum tratamento especial, apenas soma os dois
    		viewOffsetY += horizonOffsetY;
    		MoveToEx(hdc, viewOffsetX, viewHeight + viewOffsetY, 0);
    		LineTo(hdc, viewOffsetX + 300, viewHeight + viewOffsetY - 300);
    		LineTo(hdc, viewOffsetX + 600, viewHeight + viewOffsetY);
    		LineTo(hdc, viewOffsetX + 900, viewHeight + viewOffsetY - 300);
    		LineTo(hdc, viewOffsetX + 1200, viewHeight + viewOffsetY);
    		SetTextAlign(hdc, TA_LEFT);
    		TextOut(hdc, 0, 0, TEXT("Eu sou o topo!"), 14);
    		TextOut(hdc, viewOffsetX, viewHeight + viewOffsetY - 20, TEXT("Eu sou o baseline!"), 18);
    		SetTextAlign(hdc, TA_RIGHT);
    		TextOut(hdc, viewWidth, viewHeight + viewOffsetY - 20, TEXT("Eu sou o baseline no canto!"), 27);
    	virtual BOOL Initialize()
    		brush = CreateSolidBrush(RGB(255, 117, 24));
    		pen = CreatePen(PS_SOLID, 2, RGB(255, 201, 14));
    		font = (HFONT)GetStockObject(ANSI_VAR_FONT);
    		return true;
    	virtual void Terminate()
    		delete this;
    __declspec(dllexport) Painter* __stdcall CreateBackgroundPainter()
    	return new BackgroundPainter();

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Liverpool UK
    This is for windows programming innit?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Search for examples (on MSDN or elsewhere) that demonstrate the LoadBitmap() or the LoadImage() function. (Apparently the latter is preferred over the former.)

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    train spotter
    Join Date
    Aug 2001
    near a computer
    I suggest you read about GDI leaks and how a Device Contex works (as your code is leaking 2 GDI objects each time it paints).
    Under .NET you may not notice this leak or it may crash the whole computer.

    I have posted code to do this or similar many time before.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. running in background
    By krishnapollu in forum C Programming
    Replies: 24
    Last Post: 03-01-2011, 08:21 AM
  2. Background
    By hdragon in forum Game Programming
    Replies: 11
    Last Post: 04-01-2006, 12:14 AM
  3. background color
    By DavidP in forum Tech Board
    Replies: 3
    Last Post: 07-21-2004, 01:36 AM
  4. Run in background
    By smog890 in forum C Programming
    Replies: 4
    Last Post: 06-09-2002, 02:22 PM
  5. Background
    By drdroid in forum C++ Programming
    Replies: 2
    Last Post: 06-04-2002, 09:43 PM