Loading an image onto a Window

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2009
Posts: 2
Reputation: Drahmina is an unknown quantity at this point 
Solved Threads: 0
Drahmina Drahmina is offline Offline
Newbie Poster

Loading an image onto a Window

 
0
  #1
Mar 2nd, 2009
Im just trying to load a PNG file i created of a background for a game I plan to produce eventually. However im not sure how you go about adding that image to the window. Ive opened up a standard windows app template with the following code.
  1. #include <windows.h>
  2.  
  3.  
  4. /* Declare Windows procedure */
  5. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  6.  
  7. /* Make the class name into a global variable */
  8. char szClassName[ ] = "BKIV";
  9.  
  10. int WINAPI WinMain (HINSTANCE hThisInstance,
  11. HINSTANCE hPrevInstance,
  12. LPSTR lpszArgument,
  13. int nFunsterStil)
  14.  
  15. {
  16. HWND hwnd; /* This is the handle for our window */
  17. MSG messages; /* Here messages to the application are saved */
  18. WNDCLASSEX wincl; /* Data structure for the windowclass */
  19.  
  20. /* The Window structure */
  21. wincl.hInstance = hThisInstance;
  22. wincl.lpszClassName = szClassName;
  23. wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
  24. wincl.style = CS_DBLCLKS; /* Catch double-clicks */
  25. wincl.cbSize = sizeof (WNDCLASSEX);
  26.  
  27. /* Use default icon and mouse-pointer */
  28. wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  29. wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  30. wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  31. wincl.lpszMenuName = NULL; /* No menu */
  32. wincl.cbClsExtra = 0; /* No extra bytes after the window class */
  33. wincl.cbWndExtra = 0; /* structure or the window instance */
  34. /* Use Windows's default color as the background of the window */
  35. wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  36.  
  37. /* Register the window class, and if it fails quit the program */
  38. if (!RegisterClassEx (&wincl))
  39. return 0;
  40.  
  41. /* The class is registered, let's create the program*/
  42. hwnd = CreateWindowEx (
  43. 0, /* Extended possibilites for variation */
  44. szClassName, /* Classname */
  45. "Bare Knuckle IV", /* Title Text */
  46. WS_OVERLAPPEDWINDOW, /* default window */
  47. CW_USEDEFAULT, /* Windows decides the position */
  48. CW_USEDEFAULT, /* where the window ends up on the screen */
  49. 360, /* The programs width */
  50. 270, /* and height in pixels */
  51. HWND_DESKTOP, /* The window is a child-window to desktop */
  52. NULL, /* No menu */
  53. hThisInstance, /* Program Instance handler */
  54. NULL /* No Window Creation data */
  55. );
  56.  
  57. /* Make the window visible on the screen */
  58. ShowWindow (hwnd, nFunsterStil);
  59.  
  60. /* Run the message loop. It will run until GetMessage() returns 0 */
  61. while (GetMessage (&messages, NULL, 0, 0))
  62. {
  63. /* Translate virtual-key messages into character messages */
  64. TranslateMessage(&messages);
  65. /* Send message to WindowProcedure */
  66. DispatchMessage(&messages);
  67. }
  68.  
  69. /* The program return-value is 0 - The value that PostQuitMessage() gave */
  70. return messages.wParam;
  71. }
  72.  
  73.  
  74. /* This function is called by the Windows function DispatchMessage() */
  75.  
  76. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  77. {
  78. switch (message) /* handle the messages */
  79. {
  80. case WM_DESTROY:
  81. PostQuitMessage (0); /* send a WM_QUIT to the message queue */
  82. break;
  83. default: /* for messages that we don't deal with */
  84. return DefWindowProc (hwnd, message, wParam, lParam);
  85. }
  86.  
  87. return 0;
  88. }

How do I add an image onto the window? Many thanks for any help.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 353
Reputation: death_oclock will become famous soon enough death_oclock will become famous soon enough 
Solved Threads: 37
death_oclock's Avatar
death_oclock death_oclock is offline Offline
Posting Whiz

Re: Loading an image onto a Window

 
0
  #2
Mar 2nd, 2009
Since this is for a game (high performance required) I would recommend you look at DirectDraw. A decent tutorial I know is here: www.falloutsoftware.com
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
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