Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Loading image
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Sat Apr 11, 2009 5:11 pm    Post subject: [C++] Loading image Reply with quote

I want to load an image from a resource so I did this:

Resource.rc:
Code:
#include "Resource.h"

IDB_HP_BAR BITMAP "HP_Bar.bmp"

And Resource.h:
Code:
#define IDB_HP_BAR 201

and to load it I did this:
Code:
CreateWindowEx(0, WC_STATIC, 0, WS_VISIBLE | WS_CHILD | SS_BITMAP, 0, 0, 0, 0, hWnd, (HMENU)ID_HP, hInstance, NULL);
SendDlgItemMessage(hWnd, ID_HP, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)LoadImage(hInstance, MAKEINTRESOURCE(IDB_HP_BAR), IMAGE_BITMAP, 0, 0, 0));

But the image won't show. It works if I use LR_LOADFROMFILE and put it in C:\ drive, but I want to load it from a resource so is there anything I've done wrong?
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Apr 11, 2009 5:24 pm    Post subject: Reply with quote

Don't you have to give the width/height of the static control a value?
_________________
Back to top
View user's profile Send private message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Sat Apr 11, 2009 5:49 pm    Post subject: Reply with quote

Nope.
MSDN wrote:
The style ignores the nWidth and nHeight parameters; the control automatically sizes itself to accommodate the bitmap.
But I tried just in case but the results was the same.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Apr 11, 2009 6:07 pm    Post subject: Reply with quote

Try this:

Code:
BOOL CreateStaticImage(__in HINSTANCE hInstance, __in HWND hWnd)
{
   BOOL   bRET = FALSE;
   HWND   hStatic;
   HANDLE   hBitmap;
   
   hStatic = CreateWindowEx(0, WC_STATIC, 0, WS_VISIBLE | WS_CHILD | SS_BITMAP, 0, 0, 0, 0, hWnd, (HMENU)ID_HP, hInstance, 0);
   if (hStatic != NULL)
   {
      MessageBox(hWnd, _T("CreateWindowEx success."), _T("Step 1"), MB_OK);
      hBitmap = LoadImage(hInstance, MAKEINTRESOURCE(IDB_HP_BAR), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADTRANSPARENT);
      if (hBitmap != NULL)
      {
         MessageBox(hWnd, _T("LoadImage success."), _T("Step 2"), MB_OK);
         if (SendMessage(hStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap) != NULL)
         {
            MessageBox(hWnd, _T("SendMessage success."), _T("Step 3"), MB_OK);
            bRET = TRUE;
         }
      }
   }
   return bRET;
}


See where the Message Box's stop.
If you do not get all 3 then use GetLastError to find out what's going on.

_________________
Back to top
View user's profile Send private message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Sat Apr 11, 2009 6:46 pm    Post subject: Reply with quote

I get an error at LoadImage()
Error wrote:
Can not find the specified resource type in the memory image file.
What does that mean? I have the bitmap in the same folder as the source :O.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Apr 11, 2009 6:50 pm    Post subject: Reply with quote

What does GetLastError return?
_________________
Back to top
View user's profile Send private message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Sat Apr 11, 2009 6:57 pm    Post subject: Reply with quote

the eror was that in the quote. MSDN doesn't show what errors that might be returned so I had to use an alternative function I found on the internet to show the last error.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Apr 11, 2009 7:49 pm    Post subject: Reply with quote

TraxMate wrote:
the eror was that in the quote. MSDN doesn't show what errors that might be returned so I had to use an alternative function I found on the internet to show the last error.


it does...
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Apr 11, 2009 8:00 pm    Post subject: Reply with quote

Are you sure you added the bitmap correctly...?
_________________
Back to top
View user's profile Send private message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Sat Apr 11, 2009 8:20 pm    Post subject: Reply with quote

@slovach: Didn't find it when I looked. Will look again then..

@lurc: I think so cuz I've done it before. But this time I'm doing it in a dll, does it matter if it's in a dll or not?
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Apr 11, 2009 9:19 pm    Post subject: Reply with quote

If it's in a different dll other then the module itself then you must LoadLibrary that dll before you are able to use its resources.
_________________
Back to top
View user's profile Send private message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Sat Apr 11, 2009 9:30 pm    Post subject: Reply with quote

It is in the same module. I have embedded a GUI into a dll file.
Back to top
View user's profile Send private message
Bizarro
I post too much
Reputation: 0

Joined: 01 May 2007
Posts: 2648

PostPosted: Sat Apr 11, 2009 10:59 pm    Post subject: Reply with quote

use GetModuleHandle(NULL) instead of hInstance when u loadimage
_________________

w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils


Last edited by Bizarro on Sat Apr 11, 2009 11:00 pm; edited 1 time in total
Back to top
View user's profile Send private message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Sat Apr 11, 2009 11:06 pm    Post subject: Reply with quote

@Bizarro: Tried that same thing, no image.

@Moose: w00t? o.O Edit: Searched on that and found a link to msdn. I'm going to look at that.

This works perfectly when it's a normal win32 application...


Last edited by TraxMate on Sat Apr 11, 2009 11:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
Bizarro
I post too much
Reputation: 0

Joined: 01 May 2007
Posts: 2648

PostPosted: Sat Apr 11, 2009 11:18 pm    Post subject: Reply with quote

o just read u are doing it in a dll.

in the case of injecting dll, ur hInstance is messed up and returns the main app not the dll

so instead of GetModuleHandle(NULL)/hInstance , use GetModuleHandle("project name"). replace it with your project/dll name

_________________

w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites