-
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!
Code:
#include "stdafx.h"
#include "Painter.h"
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
DisableThreadLibraryCalls(hModule);
return true;
}
class BackgroundPainter : public Painter
{
private:
HBRUSH brush;
HPEN pen;
HFONT font;
public:
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()
{
DeleteObject((HGDIOBJ)brush);
DeleteObject((HGDIOBJ)pen);
delete this;
}
};
__declspec(dllexport) Painter* __stdcall CreateBackgroundPainter()
{
return new BackgroundPainter();
}
-
This is for windows programming innit?
-
Search for examples (on MSDN or elsewhere) that demonstrate the LoadBitmap() or the LoadImage() function. (Apparently the latter is preferred over the former.)
-
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.