loading bitmaps

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2009
Posts: 104
Reputation: goody11 is an unknown quantity at this point 
Solved Threads: 1
goody11 goody11 is offline Offline
Junior Poster

loading bitmaps

 
0
  #1
Aug 9th, 2009
I'm trying to load a bit map but the picture won't come up. It compiles just fine. I'm not sure if this makes a difference either but I am trying to load a bitmap into a dialog box. Here's the code:

The .cpp file:
  1. #include "windows.h"
  2. #include "resource.h"
  3.  
  4. HBITMAP g_hbmHang = NULL;
  5.  
  6. BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
  7. {
  8. switch(Message)
  9. {
  10. case WM_CREATE:
  11. g_hbmHang = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_HANG));
  12. if(g_hbmHang == NULL)
  13. MessageBox(hwnd, "Could not load IDB_HANG!", "Error", MB_OK |MB_ICONEXCLAMATION);
  14. break;
  15. case WM_CLOSE:
  16. DestroyWindow(hwnd);
  17. break;
  18. case WM_PAINT:
  19. {
  20.  
  21. BITMAP bm;
  22. PAINTSTRUCT ps;
  23.  
  24. HDC hdc = BeginPaint(hwnd, &ps);
  25.  
  26. HDC hdcMem = CreateCompatibleDC(hdc);
  27. HBITMAP hbmOld = (HBITMAP)SelectObject (hdcMem, g_hbmHang);
  28.  
  29. GetObject(g_hbmHang, sizeof(bm), &bm);
  30.  
  31. BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
  32.  
  33. SelectObject(hdcMem, hbmOld);
  34. DeleteDC(hdcMem);
  35.  
  36. EndPaint(hwnd, &ps);
  37. }
  38. break;
  39. case WM_DESTROY:
  40. DeleteObject(g_hbmHang);
  41. PostQuitMessage(0);
  42. break;
  43. default:
  44. return FALSE;
  45. }
  46. return TRUE;
  47. }
  48.  
  49. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  50. {
  51. return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
  52. }
The resource file:
  1. //Microsoft Developer Studio generated resource script.
  2. //
  3. #include "resource.h"
  4.  
  5. #define APSTUDIO_READONLY_SYMBOLS
  6. /////////////////////////////////////////////////////////////////////////////
  7. //
  8. // Generated from the TEXTINCLUDE 2 resource.
  9. //
  10. #ifndef __BORLANDC__
  11. #include "winres.h"
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. #undef APSTUDIO_READONLY_SYMBOLS
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // English (Canada) resources
  19.  
  20. #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENC)
  21. #ifdef _WIN32
  22. LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_CAN
  23. #pragma code_page(1252)
  24. #endif //_WIN32
  25.  
  26. #ifdef APSTUDIO_INVOKED
  27. /////////////////////////////////////////////////////////////////////////////
  28. //
  29. // TEXTINCLUDE
  30. //
  31.  
  32. 1 TEXTINCLUDE DISCARDABLE
  33. BEGIN
  34. "resource.h\0"
  35. END
  36.  
  37. 2 TEXTINCLUDE DISCARDABLE
  38. BEGIN
  39. "#ifndef __BORLANDC__\r\n"
  40. "#include ""winres.h""\r\n"
  41. "#endif\r\n"
  42. "\0"
  43. END
  44.  
  45. 3 TEXTINCLUDE DISCARDABLE
  46. BEGIN
  47. "\r\n"
  48. "\0"
  49. END
  50.  
  51. #endif // APSTUDIO_INVOKED
  52.  
  53.  
  54.  
  55. IDD_MAIN DIALOG DISCARDABLE 0, 0, 207, 156
  56. STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
  57. CAPTION "Controls One"
  58. FONT 8, "MS Sans Serif"
  59. BEGIN
  60. LTEXT "Add",IDC_STATIC,7,10,14,8
  61. END
  62.  
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. //
  66. // Bitmap
  67. //
  68.  
  69. IDB_HANG BITMAP DISCARDABLE "hang.bmp"
  70. #endif // English (Canada) resources
  71. /////////////////////////////////////////////////////////////////////////////
  72.  
  73.  
  74.  
  75. #ifndef APSTUDIO_INVOKED
  76. /////////////////////////////////////////////////////////////////////////////
  77. //
  78. // Generated from the TEXTINCLUDE 3 resource.
  79. //
  80.  
  81.  
  82. /////////////////////////////////////////////////////////////////////////////
  83. #endif // not APSTUDIO_INVOKED
The resource.h file:
#define IDD_MAIN 100
#define IDB_HANG 101
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
[/code]
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,600
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 460
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: loading bitmaps

 
0
  #2
Aug 10th, 2009
Download code from http://winprog.org/tutorial/ and compare it with your code.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 147
Reputation: Laiq Ahmed will become famous soon enough Laiq Ahmed will become famous soon enough 
Solved Threads: 20
Laiq Ahmed Laiq Ahmed is offline Offline
Junior Poster

Re: loading bitmaps

 
0
  #3
Aug 10th, 2009
Hi,
why you've called LoadBitmap(...) in WM_CREATE message? I am sure your problem will be resolved if you change WM_CREATE to WM_INITDIALOG.
further you should learn and understand the difference between WM_CREATE & WM_INITDIALOG.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 104
Reputation: goody11 is an unknown quantity at this point 
Solved Threads: 1
goody11 goody11 is offline Offline
Junior Poster

Re: loading bitmaps

 
0
  #4
Aug 10th, 2009
Thanks that worked perfect.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 8
Reputation: amarucla is an unknown quantity at this point 
Solved Threads: 0
amarucla amarucla is offline Offline
Newbie Poster

Re: loading bitmaps

 
0
  #5
Aug 18th, 2009
Hi goody11,

I'm trying to write a similar program where I can display an image in a dialogbox. I've posted a thread on how to do it....but no response from anyone.
http://www.daniweb.com/forums/thread210539.html


Now i'm trying to use your program, to see if I can extend it for my purpose. I'm getting a compile error "cannot open include file winres.h" Where does this file come from?

Thanks,
Amar
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 104
Reputation: goody11 is an unknown quantity at this point 
Solved Threads: 1
goody11 goody11 is offline Offline
Junior Poster

Re: loading bitmaps

 
0
  #6
Aug 18th, 2009
I downloaded winres.h. If you look in the resource file, and see where I include it, you can replace it with afxres.h instead.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC