I am sick and tired of giving out my windows applications with bitmap files that are required. Does anyone know how to use a resource bitmap? Thanks in advance.
I am sick and tired of giving out my windows applications with bitmap files that are required. Does anyone know how to use a resource bitmap? Thanks in advance.
I know of some things you need:
in your resource file, put:
402 BITMAP "Bmp location"
Then, in your main code:
HBITMAP hBmp;
case WM_CREATE:
hBmp=LoadBitmap(Program's Instance, MAKEINTRESOURCE(402));
break;
The only thing I don't know how to do is use WM_PAINT to draw the Bitmap. This is as far as I've gotten. I hope I helped some.
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
thanks! now all need to know how to do is draw the bitmap.
WM_CREATE:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
hBitmap = LoadBitmap (hInstance, TEXT ("BITMAP")) ;
GetObject (hBitmap, sizeof (BITMAP), &bitmap) ;
cxSource = bitmap.bmWidth ;
cySource = bitmap.bmHeight ;
WM_PAINT:
hdcMem = CreateCompatibleDC (hdc) ;
SelectObject (hdcMem, hBitmap) ;
BitBlt (hdc, 1, 1, 50, 50, hdcMem, 0, 0, SRCCOPY)
wm_destroy
DeleteObject (hBitmap) ;
wm_size
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
i think that will work.
arrh, i got nothing good to say.
http://www.praxis1.vic.edu.au/home/dcola/
thanks, but that doesn't work.
i chucked this code up in a hurry so i just went and check it to see if it works. and it worked fine for me. There is a few reasons i can guess why it wont be working. if it compiled okay then im guession when you named your bitmap you didnt name it "mybitmap" or "thepic" or whatever, but include it inside "" marks in the resource script. also when you call hBitmap = LoadBitmap (hInstance, TEXT ("BITMAP")) ; make sure you call
TEXT ("mypic or whatever you called it"))
arrh, i got nothing good to say.
http://www.praxis1.vic.edu.au/home/dcola/
no, I don't think that's it. My compiler doesn't like anything in WM_SIZE or some stuff in wm_create
here are my errors:
help please? thanks.Code:Compiling... main.cpp C:\Tom\GameWIN\EDUWIN\main.cpp(14) : error C2065: 'hInstance' : undeclared identifier C:\Tom\GameWIN\EDUWIN\main.cpp(14) : error C2065: 'lParam' : undeclared identifier C:\Tom\GameWIN\EDUWIN\main.cpp(14) : error C2440: '=' : cannot convert from 'struct HINSTANCE__ *' to 'int' This conversion requires a reinterpret_cast, a C-style cast or function-style cast C:\Tom\GameWIN\EDUWIN\main.cpp(15) : error C2065: 'hBitmap' : undeclared identifier C:\Tom\GameWIN\EDUWIN\main.cpp(16) : error C2065: 'bitmap' : undeclared identifier C:\Tom\GameWIN\EDUWIN\main.cpp(17) : error C2065: 'cxSource' : undeclared identifier C:\Tom\GameWIN\EDUWIN\main.cpp(17) : error C2228: left of '.bmWidth' must have class/struct/union type C:\Tom\GameWIN\EDUWIN\main.cpp(18) : error C2065: 'cySource' : undeclared identifier C:\Tom\GameWIN\EDUWIN\main.cpp(18) : error C2228: left of '.bmHeight' must have class/struct/union type C:\Tom\GameWIN\EDUWIN\main.cpp(25) : error C2065: 'hdcMem' : undeclared identifier C:\Tom\GameWIN\EDUWIN\main.cpp(25) : error C2440: '=' : cannot convert from 'struct HDC__ *' to 'int' This conversion requires a reinterpret_cast, a C-style cast or function-style cast C:\Tom\GameWIN\EDUWIN\main.cpp(28) : error C2146: syntax error : missing ';' before identifier 'EndPaint' C:\Tom\GameWIN\EDUWIN\main.cpp(40) : error C2065: 'cxClient' : undeclared identifier C:\Tom\GameWIN\EDUWIN\main.cpp(41) : error C2065: 'cyClient' : undeclared identifier
omg... *BASIC* programming rules, any varable used must be declared first...
static HBITMAP hBitmap ;
static int cxClient, cyClient, cxSource, cySource;
BITMAP bitmap ;
HDC hdc, hdcMem ;
HINSTANCE hInstance ;
PAINTSTRUCT ps;
i think that is all of them, if not just declare them.
arrh, i got nothing good to say.
http://www.praxis1.vic.edu.au/home/dcola/
Sorry, I just figured that out, but it still won't show! It compiles, though.
I DID IT!!!!!!!!!!!!!! yaaaahoooooooooooooo! Sept i didn't use TEXT(), I used MAKEINTRESOURCE(). Thanks for showing me how to draw!