 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Thu Jan 22, 2009 9:34 am Post subject: [C++] loading img |
|
|
how would i load an image to my form in c++?
i know that in C# there's a picture control, but C# != C++ so :\
if some1 can explain me here or link to any good tutorial i'd be grateful
|
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Thu Jan 22, 2009 9:35 am Post subject: Re: [C++] loading img |
|
|
| 1qaz wrote: | how would i load an image to my form in c++?
i know that in C# there's a picture control, but C# != C++ so :\
if some1 can explain me here or link to any good tutorial i'd be grateful |
err add the photo as a resource, and draw it onpaint....though its not the best way...
Edit: There just might be a picture control, but its in MFC
http://www.functionx.com/visualc/applications/displaybitmap.htm
_________________
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Thu Jan 22, 2009 9:38 am Post subject: |
|
|
like i said i have no experience at this whole process in C++
and i can't get what you're saying so if you could point me to some good tut?
@to your edit: MFC can't help me i never learned it :\ thx anyway
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Thu Jan 22, 2009 9:59 am Post subject: |
|
|
Well if you want to just make a static control with the style SS_BITMAP then sending the message STM_SETIMAGE. You can load the image using LoadImage. If you don't want to add it from resource you can use the LR_LOADFROMFILE flag.
_________________
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Thu Jan 22, 2009 10:36 am Post subject: |
|
|
lemme see if i got you straight
i defined a new control (but i wasn't sure about the class name so i put WC_BUTTON)
| Code: |
btmp = CreateWindowEx(0,WC_BUTTON,0,SS_BITMAP | WS_CHILD | WS_VISIBLE,15,15,200,200,hWnd,(HMENU)BITTT,GetModuleHandle(0),0);
|
then loaded an image using LoadImage to get the handle to the picture?
| Code: |
hPic = LoadImage(m_hInstance,"aaa.bmp",IMAGE_BITMAP,155,150,LR_LOADFROMFILE);
|
and then sent a message to the control to set the image to it
| Code: |
SendMessage(btmp,STM_SETIMAGE,(WPARAM)IMAGE_BITMAP,(LPARAM)hPic);
|
and all i get is an empty checkbox square that does nothing
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Thu Jan 22, 2009 10:51 am Post subject: |
|
|
Class is WC_STATIC. And you don't even have to store the variable. You can just call it in LPARAM and cast it.
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Jan 22, 2009 10:56 am Post subject: |
|
|
you can always just do this.
1. Get a handle to whatever you want to draw on. GetDC()
2. Create an offscreen buffer. CreateCompatibleDC()
3. Get a handle to your bitmap. LoadImage()
4. Select the bitmap into your memory DC. SelectObject()
5. Blit that shit. BitBlt()
easy as pie.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Thu Jan 22, 2009 11:00 am Post subject: |
|
|
| slovach wrote: | you can always just do this.
1. Get a handle to whatever you want to draw on. GetDC()
2. Create an offscreen buffer. CreateCompatibleDC()
3. Get a handle to your bitmap. LoadImage()
4. Select the bitmap into your memory DC. SelectObject()
5. Blit that shit. BitBlt()
easy as pie. |
how would i get a handle to the DC of my bitmap file?
@lurc
it failed again i guess the return value of LoadImage is NULL that's why it fail is something wrong with those parameters?
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Jan 22, 2009 11:13 am Post subject: |
|
|
| 1qaz wrote: | | slovach wrote: | you can always just do this.
1. Get a handle to whatever you want to draw on. GetDC()
2. Create an offscreen buffer. CreateCompatibleDC()
3. Get a handle to your bitmap. LoadImage()
4. Select the bitmap into your memory DC. SelectObject()
5. Blit that shit. BitBlt()
easy as pie. |
how would i get a handle to the DC of my bitmap file?
@lurc
it failed again i guess the return value of LoadImage is NULL that's why it fail is something wrong with those parameters? |
I should have said GetDC gets a handle to the DC of the window area.
LoadImage returns a handle of the loaded image.
if LoadImage is returning NULL, call GetLastError, and see what it has to say.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Thu Jan 22, 2009 12:09 pm Post subject: |
|
|
yea i thought about getlaserror but one other thing XD
how would i convert dword value to string so i'd present the error at messagebox?
|
|
| Back to top |
|
 |
FerrisBuellerYourMyHero Master Cheater
Reputation: 0
Joined: 14 Feb 2007 Posts: 401 Location: Inside your <kernel>
|
Posted: Thu Jan 22, 2009 12:35 pm Post subject: |
|
|
Ok I've known how to draw bitmaps, but they can be quite big. And it sucks including them embedded in your app, since it makes it larger.
How can you load a compressed image? such as PNG?
I imagine you have to decompress it and make it into a bitmap in memory. Probably something like that, but I could never figure it out...
Anyone know how to load a PNG image? If your using DirectX it will draw PNG images, so you don't even need to worry about decompressing it or anything, its all handled for you.
But if your not using DirectX, what do you use?
Anyway 1qaz, I made you an example application. The project was made in MSVC++ 2008, but the method will still work in whatever compiler you use...
It shows how to load a bitmap and draw it on your application (with the bitmap being in the same folder as your exe)
And also how to embed it as a resource, then load it from the resource and draw it that way...
Its not a bad way to do it, if your bitmap image is small, but for larger images it would be nice to be able to load PNG
The code is like this:
| Code: |
hImage = ez.image(hwnd, 1, 1, 200); //hwnd, x, y, id
//Loading bitmap from file in the same folder method
//hBitmap = LoadImageA(0, "GGkilla.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
//Loading bitmap from resource method
hBitmap = LoadImageW(hInstance, MAKEINTRESOURCE(102), IMAGE_BITMAP, 0, 0, 0);
SendMessage(hImage, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
|
ez.image just calls CreateWindowEx like this:
| Code: |
return CreateWindowExA(0, "STATIC", 0, WS_CHILD | WS_VISIBLE | SS_BITMAP, x, y, 0, 0, h, (HMENU)id, hInst, 0);
|
width and height don't matter, since your image width and height is what it will show once you set the image...
for the resource way, I just manually make a rsrc.rc and resource.h...
rsrc.rc
| Code: |
#include "resource.h"
IDI_BITMAP BITMAP "GGkilla.bmp"
|
resource.h
| Code: |
#define IDI_BITMAP 102
|
note: when your doing the resource way the image has to be in the same folder as where your source files are, for MSVC++ thats ProjectName\ProjectName
| 1qaz wrote: | yea i thought about getlaserror but one other thing XD
how would i convert dword value to string so i'd present the error at messagebox? |
| Code: |
char* dbg = new char[260];
sprintf(dbg, "dword value = %u", dwordvalue);
MessageBoxA(0, dbg, "DWORD VALUE:", 0);
delete[] dbg;
|
the %u should be different depending on how you want to display the value, %u is unsigned integer, %i is signed integer, %X or %x for hex, etc... look up sprintf for more help...
_________________
You know, life moves pretty fast. If you don't stop and look around once in a while, You could miss it!
 |
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Thu Jan 22, 2009 12:48 pm Post subject: |
|
|
wow looks grate thx a lot
i'll take a closer look at it tomorrow i gtg to sleep really tired |-]
|
|
| Back to top |
|
 |
crayzbeef Expert Cheater
Reputation: 0
Joined: 21 Jan 2007 Posts: 101
|
Posted: Thu Jan 22, 2009 4:38 pm Post subject: |
|
|
| Or just use a library like SDL to load images. Much easier and faster.
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Jan 22, 2009 9:52 pm Post subject: |
|
|
| Code: |
#include <Windows.h>
int main(){
BITMAP bm = { 0 };
HDC hdc = GetDC(NULL);
HDC hdcMem = CreateCompatibleDC(hdc);
HANDLE hbm = LoadImage(NULL, "C:\\Users\\Fake\\Desktop\\New Bitmap Image.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
SelectObject(hdcMem, (HGDIOBJ)hbm);
GetObject(hbm, sizeof(bm), &bm);
for(;;){
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
Sleep(10);
}
//fuck cleaning up resources, way too lazy right now.
return 0;
} |
GDI is rad.
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Fri Jan 23, 2009 5:58 am Post subject: |
|
|
| crayzbeef wrote: | | Or just use a library like SDL to load images. Much easier and faster. |
why would you load a whole library like SDL just for loading an image when you can do the same thing faster using win32? I dont get it, is it just easier? I dont see anyway it could be faster if you are using a raw method.
sure, it's great for portable games and direct graphics, but isn't it slightly overkill for just loading an image?
_________________
|
|
| 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
|
|