943,697 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1699
  • C++ RSS
Sep 15th, 2008
0

Creating a window with CreateWindowA(...)

Expand Post »
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:


****************************************************************************
C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dinomike1000 is offline Offline
16 posts
since Sep 2008
Sep 15th, 2008
0

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

1407 is ERROR_CANNOT_FIND_WND_CLASS (see http://msdn.microsoft.com/en-us/libr...85(VS.85).aspx)
Reputation Points: 395
Solved Threads: 71
Posting Whiz
jencas is offline Offline
362 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Huffman coding Issue
Next Thread in C++ Forum Timeline: need help in operator overloading...?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC