I'm New to programming and can create a window but i can't seem to draw up a bitmap. I'm using dev c++ and just need some help please.
I'm New to programming and can create a window but i can't seem to draw up a bitmap. I'm using dev c++ and just need some help please.
Ok..if you have the window, then you have 90% of the code done....
If you just want the bitmap to appear on the window, then load a bitmap into your compiler's resource editor, save it as IDB_BITMAP1 and change your windows procedure like so
If you want a fool example go to Ken's site hereCode:LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { HDC hdc,//This is for the device context of your window memdc;//This DC will hold reference bitmap static HBITMAP hBit;//The actual bitmap PAINTSTRUCT ps;//For WS_PAINT HGDIOBJ hTemp;//Temp. Hold return of SelectObject static SIZE size;//Size of Bitmap switch(msg) { case WM_CREATE: size.cx = 50;//We want the bitmap to be 50x50 size.cy = 50; hBit = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1),IMAGE_BITMAP, size.cx,size.cy,0);//Load our bitmap if(!hBit)SendMessage(hWnd,WM_CLOSE,0,0);//Close if fail break; case WM_PAINT: hdc = BeginPaint(hWnd,&ps);//Do this at start of paint block memdc = CreateCompatibleDC(hdc);//copy the dc hTemp = SelectObject(memdc,hBit);//Select bitmap into dc BitBlt(hdc,0,0,size.cx,size.cy,memdc,0,0,SRCCOPY);//paint to screen SelectObject(memdc,hTemp);//restore the spare dc DeleteDC(memdc);//destroy the spare EndPaint(hWnd,&ps);//End Painting break; case WM_CLOSE: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, msg, wParam, lParam); } return 0; }
>>If you want a fool example go to Ken's site <<
Not sure what to make of this, but I love the use of the word 'fool'; I may incorporate it into future descriptions.
BTW, I like the use of HGDIOBJ in your example; looks like it sidesteps all that (c++) casting rather nicely.
ROFLMFAO!!!!!!Originally posted by Ken Fitlike
>>If you want a fool example go to Ken's site <<
Not sure what to make of this, but I love the use of the word 'fool'; I may incorporate it into future descriptions.
BTW, I like the use of HGDIOBJ in your example; looks like it sidesteps all that (c++) casting rather nicely.
Sorry Ken....I meant FULL but my pre-caffine mind had its own ideas......no Freudian slip I assure you ...I recommend your site most highly
And if you don't want to use resources...
Code:/*my first Windows hack, before learnig about GetObject()...:D*/ bool GetBitmapSize(char *filename, int *width, int *height) { FILE *image_file = fopen(filename, "rb"); if(image_file == NULL) { *width = 0, *height = 0; return false; } int read = 0; fseek(image_file, 18, SEEK_SET); read = fread( &(*width), sizeof(int), 1, image_file); if(!read) { fclose(image_file); *width = 0, *height = 0; return false; } fseek(image_file, 22, SEEK_SET); read = fread( &(*height), sizeof(int), 1, image_file ); if(!read) { fclose(image_file); *width = 0, *height = 0; return false; } fclose(image_file); return true; } HBITMAP LoadGraphic( char *file_name, int *width, int *height) { GetBitmapSize(file_name, width, height); return (HBITMAP)LoadImage(GetModuleHandle(NULL), file_name, IMAGE_BITMAP, *width, *height, LR_LOADFROMFILE ); }
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
I get these errors when compiling with Dev C. I also got an error about IDB_BITMAP1 being undefined, even though it was defined in the resource file. Can anyone explain what I am doing wrong?Code:d:\dev-c++\main.cpp: In function `LRESULT WndProc(HWND__ *, unsigned int, unsigned int, long int)': d:\dev-c++\main.cpp:164: redefinition of `LRESULT WndProc(HWND__ *, unsigned int, unsigned int, long int)' d:\dev-c++\main.cpp:16: `LRESULT WndProc(HWND__ *, unsigned int, unsigned int, long int)' previously defined here
Those error messages typically mean you did this:
Code:#define IDB_BITMAP1 1002 //..you forgot to put this line here. void foo() {} //..you probably did this. void foo(); //..when you meant to do this. //....rest of program... void foo() { int i; //..etc. }
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
Right on both counts. =) Much thanks indeed!