Problem Creating Window

Reply

Join Date: Apr 2005
Posts: 71
Reputation: AhmedHan is an unknown quantity at this point 
Solved Threads: 1
AhmedHan's Avatar
AhmedHan AhmedHan is offline Offline
Junior Poster in Training

Problem Creating Window

 
1
  #1
Feb 25th, 2006
First, I prepared the class blow :
  1. class UserDefinedWindow
  2. {
  3. public:
  4. WNDCLASSEX WindowClass;
  5.  
  6. DWORD dwExStyle;
  7. LPCTSTR lpClassName;
  8. LPCTSTR lpWindowName;
  9. DWORD dwStyle;
  10. int x;
  11. int y;
  12. int nWidth;
  13. int nHeight;
  14. HWND hWndParent;
  15. HMENU hMenu;
  16. HINSTANCE hProgInst;
  17. LPVOID lpParam;
  18. char ClassName[MAX_LOADSTRING];
  19. char Caption[MAX_LOADSTRING];
  20. HWND hWnd;
  21.  
  22. UserDefinedWindow()
  23. {
  24. dwExStyle = 0; //These are default parameters for CreateWindowEx()
  25. lpClassName = "ClassName";
  26. lpWindowName = "Caption";
  27. dwStyle = WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE;
  28. x = 100;
  29. y = 100;
  30. nWidth = 100;
  31. nHeight = 100;
  32. hWndParent = HWND_DESKTOP;
  33. hMenu = NULL;
  34. hProgInst = hInstance;
  35. lpParam = NULL;
  36.  
  37. WindowClass.cbSize = (UINT) sizeof(WNDCLASSEX); //Defaults for WNDCLASSEX
  38. WindowClass.style = (UINT) CS_DBLCLKS;
  39. WindowClass.lpfnWndProc = (WNDPROC) WindowProcedure;
  40. WindowClass.cbClsExtra = (INT) 0;
  41. WindowClass.cbWndExtra = (INT) 0;
  42. WindowClass.hInstance = (HINSTANCE) hProgInst;
  43. WindowClass.hIcon = (HICON) LoadIcon (NULL, IDI_APPLICATION);
  44. WindowClass.hCursor = (HCURSOR) LoadCursor (NULL, IDC_ARROW);
  45. WindowClass.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  46. WindowClass.lpszMenuName = (LPCTSTR) NULL;
  47. WindowClass.lpszClassName = (LPCTSTR) ClassName;
  48. WindowClass.hIconSm = (HICON) LoadIcon (NULL, IDI_APPLICATION);
  49. }
  50. void Create(void)
  51. {
  52. if (!RegisterClassEx(&WindowClass)) MessageBox(NULL, "Error registering.", "Error", MB_OK);
  53. hWnd = CreateWindowEx( (DWORD) dwExStyle,
  54. (LPCTSTR) lpClassName,
  55. (LPCTSTR) lpWindowName,
  56. (DWORD) dwStyle,
  57. (int) x,
  58. (int) y,
  59. (int) nWidth,
  60. (int) nHeight,
  61. (HWND) hWndParent,
  62. (HMENU) hMenu,
  63. (HINSTANCE) hProgInst,
  64. (LPVOID) lpParam);
  65. }
  66. };

And the main() block of the program is...
  1. int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
  2. {
  3. hInstance = hInst;
  4. UserDefinedWindow MainWnd;
  5. MainWnd.Create();
  6.  
  7. while (GetMessage(&Msg, NULL, 0, 0))
  8. {
  9. TranslateMessage(&Msg);
  10. DispatchMessage(&Msg);
  11. }
  12. return (INT) Msg.wParam;
  13. }

And finally the problem is, nothing appears. Program seems to be running, but no window appears on the screen. There is no errors or even warnings given.

Can you give an idea why the window doesn't pop up?

Notes
-----
-Compiler is Visual Studio 2005.
-I didn't use ShowWindow(), because WS_VISIBLE already exists in dwStyle.
-hInstance is global defined variable.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Problem Creating Window

 
0
  #2
Feb 26th, 2006
This part returns NULL.
  1. hWnd = CreateWindowEx( (DWORD) dwExStyle,
  2. (LPCTSTR) lpClassName,
  3. (LPCTSTR) lpWindowName,
  4. (DWORD) dwStyle,
  5. (int) x,
  6. (int) y,
  7. (int) nWidth,
  8. (int) nHeight,
  9. (HWND) hWndParent,
  10. (HMENU) hMenu,
  11. (HINSTANCE) hProgInst,
  12. (LPVOID) lpParam);
  13. if ( hWnd == NULL )
  14. {
  15. MessageBox(NULL, "CreateWindow Returned NULL", "Error", MB_OK );
  16. return;
  17. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 71
Reputation: AhmedHan is an unknown quantity at this point 
Solved Threads: 1
AhmedHan's Avatar
AhmedHan AhmedHan is offline Offline
Junior Poster in Training

Re: Problem Creating Window

 
0
  #3
Feb 26th, 2006
Thanks for your help.
It OK now!

  1. VOID ErrorTest(LPSTR lpzsErrorText);
  2. VOID ErrorTest(INT nText);
  3. class UserDefinedWindow
  4. {
  5. public:
  6. WNDCLASSEX WindowClass;
  7.  
  8. DWORD dwExStyle;
  9. //LPCTSTR lpClassName;
  10. //LPCTSTR lpWindowName;
  11. char lpClassName[MAX_LOADSTRING];
  12. char lpWindowName[MAX_LOADSTRING];
  13. DWORD dwStyle;
  14. int x;
  15. int y;
  16. int nWidth;
  17. int nHeight;
  18. HWND hWndParent;
  19. HMENU hMenu;
  20. HINSTANCE hProgInst;
  21. LPVOID lpParam;
  22. HWND hWnd;
  23.  
  24. UserDefinedWindow()
  25. {
  26. dwExStyle = 0; //These are default parameters for CreateWindowEx()
  27. strcpy(lpClassName, "ClassName");
  28. strcpy(lpWindowName, "Caption");
  29. dwStyle = WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE;
  30. x = 100;
  31. y = 100;
  32. nWidth = 200;
  33. nHeight = 200;
  34. hWndParent = HWND_DESKTOP;
  35. hMenu = NULL;
  36. hProgInst = hInstance;
  37. lpParam = NULL;
  38.  
  39. WindowClass.cbSize = (UINT) sizeof(WNDCLASSEX); //Defaults for WNDCLASSEX
  40. WindowClass.style = (UINT) CS_DBLCLKS;
  41. WindowClass.lpfnWndProc = (WNDPROC) WindowProcedure;
  42. WindowClass.cbClsExtra = (INT) 0;
  43. WindowClass.cbWndExtra = (INT) 0;
  44. WindowClass.hInstance = (HINSTANCE) hProgInst;
  45. WindowClass.hIcon = (HICON) LoadIcon (NULL, IDI_APPLICATION);
  46. WindowClass.hCursor = (HCURSOR) LoadCursor (NULL, IDC_ARROW);
  47. WindowClass.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  48. WindowClass.lpszMenuName = (LPCTSTR) NULL;
  49. WindowClass.lpszClassName = (LPCTSTR) lpClassName;
  50. WindowClass.hIconSm = (HICON) LoadIcon (NULL, IDI_APPLICATION);
  51. }
  52. void Create(void)
  53. {
  54. if (!RegisterClassEx(&WindowClass)) MessageBox(NULL, "Error registering.", "Error", MB_OK);
  55. hWnd = CreateWindowEx( (DWORD) dwExStyle,
  56. (LPCTSTR) lpClassName,
  57. (LPCTSTR) lpWindowName,
  58. (DWORD) dwStyle,
  59. (int) x,
  60. (int) y,
  61. (int) nWidth,
  62. (int) nHeight,
  63. (HWND) hWndParent,
  64. (HMENU) hMenu,
  65. (HINSTANCE) hProgInst,
  66. (LPVOID) lpParam);
  67. if (hWnd == NULL)
  68. {
  69. //1407 Cannot find window class. ERROR_CANNOT_FIND_WND_CLASS
  70. DWORD ErrCode = GetLastError();
  71. MessageBox(NULL, "Error creating.", "Error", MB_OK);
  72. ErrorTest(ErrCode);
  73. }
  74. }
  75. };
  76. VOID ErrorTest(LPSTR lpzsErrorText)
  77. {
  78. if (MessageBox(NULL, lpzsErrorText, "Error", MB_ICONERROR | MB_OKCANCEL)==IDCANCEL);//PostQuitMessage(0);
  79. }
  80. VOID ErrorTest(INT nText)
  81. {
  82. CHAR lpzsErrorText[32];
  83. _itoa(nText, lpzsErrorText, 10);
  84. if (MessageBox(NULL, lpzsErrorText, "Error", MB_ICONERROR | MB_OKCANCEL)==IDCANCEL);//PostQuitMessage(0);
  85. }

ClassName was defined as the name of the class, but in the WNDCLASSEX structure, lpClassName was used.
So, because of not matching the class names in WNDCLASSEX and CreateWindowEx(), the system returned the error :
Error Code :1407
Meaning :Cannot find window class.
Constant :ERROR_CANNOT_FIND_WND_CLASS

Now the code is error-free.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 6
Reputation: EZO has a little shameless behaviour in the past 
Solved Threads: 0
EZO's Avatar
EZO EZO is offline Offline
Newbie Poster

Re: Problem Creating Window

 
0
  #4
Dec 28th, 2008
Peace...
Can anyone explain that more, step by step.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,030
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Problem Creating Window

 
0
  #5
Dec 28th, 2008
Originally Posted by EZO View Post
Peace...
Can anyone explain that more, step by step.
First, you read the date that conversation was initiated.
Second, you start a new thread, making sure you have done your part to follow the rules of posting.
Third, you link or point to the old conversation, if it is relevant to what you are going to ask.
Fourth, you ask in a clear and intelligent way, what your question is, and how you would like to obtain help.
Fifth, you wait patiently, for someone to be gracious enough to take the time to respond.
Sixth, you show gratitude, and mark the post solved if your problem has been resolved or question has been answered satisfactory.

[Disclaimer] Steps are only a guide to understanding, and not absolute
nor authoritative in nature. Differences in personality may or may not
lengthen or shorten the measure of the stride.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 6
Reputation: EZO has a little shameless behaviour in the past 
Solved Threads: 0
EZO's Avatar
EZO EZO is offline Offline
Newbie Poster

Re: Problem Creating Window

 
0
  #6
Dec 30th, 2008
Thaks for help, I'll fix that....
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