Creating a window with CreateWindowA(...)

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

Join Date: Sep 2008
Posts: 16
Reputation: Dinomike1000 is an unknown quantity at this point 
Solved Threads: 0
Dinomike1000 Dinomike1000 is offline Offline
Newbie Poster

Creating a window with CreateWindowA(...)

 
0
  #1
Sep 15th, 2008
Hello,

I'm trying to create a window with a C++ win32 app project. I am using creating the HWND object, setting its properties, and then registering the object. Also, there is a WindowProc function.

What seems to happen is that the object registers but when I call CreateWindowA(...), this function call fails and no window is created.

Also, it seems that Error 1407 is generated on the CreateWindowA call.

Here is the code, any help is appreciated:


****************************************************************************
  1. // INCLUDES
  2. #define WIN32_LEAN_AND_MEAN
  3. #include <windows.h>
  4. #include <windowsx.h>
  5. #include <stdio.h>
  6. #include <math.h>
  7. #include <iostream>
  8.  
  9. // DEFINES
  10. #define WINDOW_CLASS_NAME "WINCLASS1"
  11.  
  12. // GLOBALS
  13. HWND main_window_handle = NULL; // declares the window handle
  14.  
  15. // FUNCTIONS
  16. LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam,
  17. LPARAM lparam)
  18. {
  19.  
  20. PAINTSTRUCT ps;
  21. HDC hdc;
  22.  
  23. switch(msg)
  24. {
  25. case WM_CREATE:
  26. {
  27. return(0);
  28. } break;
  29.  
  30. case WM_PAINT:
  31. {
  32. hdc = BeginPaint(hwnd, &ps);
  33. EndPaint(hwnd, &ps);
  34. return(0);
  35. } break;
  36.  
  37. case WM_DESTROY:
  38. {
  39. PostQuitMessage(0);
  40. return(0);
  41. } break;
  42.  
  43. default: break;
  44.  
  45. }
  46.  
  47. return (DefWindowProc(hwnd, msg, wparam, lparam));
  48. }
  49.  
  50. // WINMAIN
  51. int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance,
  52. LPSTR lpcmdline, int ncmdshow)
  53. {
  54. WNDCLASS winclass;
  55. HWND hwnd;
  56. MSG msg;
  57.  
  58. winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
  59. winclass.lpfnWndProc = WindowProc;
  60. winclass.cbClsExtra = 0;
  61. winclass.cbWndExtra = 0;
  62. winclass.hInstance = hinstance;
  63. winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  64. winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  65. winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  66. winclass.lpszMenuName = NULL;
  67. winclass.lpszClassName = (LPCWSTR)WINDOW_CLASS_NAME;
  68.  
  69. if(!RegisterClass(&winclass))
  70. return(0);
  71.  
  72. hwnd = CreateWindowA( WINDOW_CLASS_NAME,
  73. "Hello Dave",
  74. WS_OVERLAPPEDWINDOW | WS_VISIBLE,
  75. 0, 0,
  76. 320, 200,
  77. NULL,
  78. NULL,
  79. hinstance,
  80. NULL);
  81.  
  82. if(hwnd == NULL)
  83. {
  84. return(0);
  85. }
  86.  
  87. main_window_handle = hwnd;
  88.  
  89. while(1)
  90. {
  91. if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  92. {
  93. if(msg.message = WM_QUIT) break;
  94.  
  95. TranslateMessage(&msg);
  96. DispatchMessage(&msg);
  97. }
  98. }
  99.  
  100. return (msg.wParam);
  101. }
Last edited by cscgal; Sep 15th, 2008 at 11:24 am. Reason: forgot to add some info / Added code tags
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 360
Reputation: jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice 
Solved Threads: 69
jencas jencas is offline Offline
Posting Whiz

Re: Creating a window with CreateWindowA(...)

 
0
  #2
Sep 15th, 2008
1407 is ERROR_CANNOT_FIND_WND_CLASS (see http://msdn.microsoft.com/en-us/libr...85(VS.85).aspx)
If you are forced to reinvent the wheel at least try to invent a better one!

Please use code tags - Please mark solved threads as solved
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum


Views: 829 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC