 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Heartless I post too much
Reputation: 0
Joined: 03 Dec 2006 Posts: 2436
|
Posted: Wed Feb 11, 2009 2:22 pm Post subject: [C++]Image not showing up |
|
|
| Code: | #include <windows.h>
#include "resource.h"
LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
INT WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT);
HBITMAP bitMainBackground;
HWND hwndMain;
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS WC;
MSG Message;
POINT ptsPolygon[4];
HRGN hrgnPolygon;
WC.style = CS_HREDRAW | CS_VREDRAW;
WC.lpfnWndProc = WindowProc;
WC.cbClsExtra = 0;
WC.cbWndExtra = 0;
WC.hInstance = hInstance;
WC.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
WC.hCursor = LoadCursor(NULL, IDC_ARROW);
WC.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
WC.lpszMenuName = NULL;
WC.lpszClassName = "Class";
if (RegisterClass(&WC) == 0)
return false;
bitMainBackground = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_BACKGROUND_1), GetSystemMetrics(IDB_BACKGROUND_1), GetSystemMetrics(IDB_BACKGROUND_1), LR_DEFAULTSIZE, LR_DEFAULTCOLOR);
hwndMain = CreateWindow("Class", "Window", WS_POPUPWINDOW, 100, 100, 178, 272, NULL, NULL, hInstance, NULL);
ptsPolygon[0].x = 178; ptsPolygon[0].y = 0;
ptsPolygon[1].x = 178; ptsPolygon[1].y = 272;
ptsPolygon[3].x = 0; ptsPolygon[2].y = 272;
ptsPolygon[4].x = 0; ptsPolygon[3].y = 0;
hrgnPolygon = CreatePolygonRgn(&ptsPolygon[0], 4, WINDING);
SetWindowRgn(hwndMain, hrgnPolygon, true);
ShowWindow(hwndMain, SW_SHOW);
SetWindowLong(hwndMain, GWL_EXSTYLE, GetWindowLong(hwndMain, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(hwndMain, 0x00FF00FF, 0, LWA_COLORKEY);
UpdateWindow(hwndMain);
while(GetMessage(&Message, NULL, 0, 0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_PAINT:
PAINTSTRUCT psPicture;
HDC hdcKON, hdcPOM;
hdcKON = BeginPaint(hwndMain, &psPicture);
hdcPOM = CreateCompatibleDC(hdcKON);
SelectObject(hdcPOM, hwndMain);
BitBlt(hdcKON, 0, 0, 178, 272, hdcPOM, 0, 0, SRCCOPY);
DeleteDC(hdcPOM);
EndPaint(hwndMain, &psPicture);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return (DefWindowProc(hwnd, Message, wParam, lParam));
}
return 0;
}
|
I can get the window to be drawn with a grey background, but my image won't show.
_________________
What dosen't kill you, usually does the second time. |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Thu Feb 12, 2009 5:32 pm Post subject: |
|
|
First off, you don't have to typecast the return value of LoadImage. Also, you're not using SelectObject correctly.
| Code: |
HGDIOBJ SelectObject(
__in HDC hdc,
__in HGDIOBJ hgdiobj
);
|
| MSDN wrote: |
hgdiobj [in]
Handle to the object to be selected. The specified object must have been created by using one of the following functions.
Object Functions
Bitmap
CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBitmap, CreateDIBSection
(Bitmaps can be selected for memory DCs only, and for only one DC at a time.)
Brush
CreateBrushIndirect, CreateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush
Font
CreateFont, CreateFontIndirect
Pen
CreatePen, CreatePenIndirect
Region
CombineRgn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, CreateRectRgn, CreateRectRgnIndirect
|
hwndMain is none of those. Try something like this:
| Code: |
HBITMAP bitMainBackground = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BACKGROUND_1);
//code
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwndMain, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = SelectObject(hdcMem, bitMainBackground);
BitBlt(hdc, 0, 0, 178, 272, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
EndPaint(hwndMain, &ps);
}
break;
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Heartless I post too much
Reputation: 0
Joined: 03 Dec 2006 Posts: 2436
|
Posted: Thu Feb 12, 2009 5:35 pm Post subject: |
|
|
oh ok thank you.
_________________
What dosen't kill you, usually does the second time. |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Feb 12, 2009 8:40 pm Post subject: |
|
|
| When you load the image, you can (should?) use GetObject to fill out the bitmap structure, and you'll get all the information you need about it, from size to depth
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Thu Feb 12, 2009 9:03 pm Post subject: |
|
|
slovach you're right.
Revised code:
| Code: |
case WM_PAINT:
{
PAINTSTRUCT ps;
BITMAP bm;
HDC hdc = BeginPaint(hwndMain, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = SelectObject(hdcMem, bitMainBackground);
GetObject(bitMainBackground, sizeof(bm), &bm);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
EndPaint(hwndMain, &ps);
}
break;
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Feb 12, 2009 10:57 pm Post subject: |
|
|
| Also, if you are worried about speed, it's faster to just create your buffers / bitmaps once, and delete them only when not needed any more, or you're doing something like resizing the window rather than constantly creating / destroying them.
|
|
| Back to top |
|
 |
Heartless I post too much
Reputation: 0
Joined: 03 Dec 2006 Posts: 2436
|
Posted: Fri Feb 13, 2009 1:45 pm Post subject: |
|
|
I got the picture to show up, but there is a vertical line that shows up on the left that runs down the whole picture. Any way to get rid of that?
EDIT
Nevermind got it. Just chnaged WS_OVERLAPPEDWINDOW to WS_POPUP.
EDIT
How would I create a new image and put it over that one? Like in an animation?
_________________
What dosen't kill you, usually does the second time. |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|