| | |
Problem Creating Window
![]() |
First, I prepared the class blow :
And the main() block of the program is...
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.
C Syntax (Toggle Plain Text)
class UserDefinedWindow { public: WNDCLASSEX WindowClass; DWORD dwExStyle; LPCTSTR lpClassName; LPCTSTR lpWindowName; DWORD dwStyle; int x; int y; int nWidth; int nHeight; HWND hWndParent; HMENU hMenu; HINSTANCE hProgInst; LPVOID lpParam; char ClassName[MAX_LOADSTRING]; char Caption[MAX_LOADSTRING]; HWND hWnd; UserDefinedWindow() { dwExStyle = 0; //These are default parameters for CreateWindowEx() lpClassName = "ClassName"; lpWindowName = "Caption"; dwStyle = WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE; x = 100; y = 100; nWidth = 100; nHeight = 100; hWndParent = HWND_DESKTOP; hMenu = NULL; hProgInst = hInstance; lpParam = NULL; WindowClass.cbSize = (UINT) sizeof(WNDCLASSEX); //Defaults for WNDCLASSEX WindowClass.style = (UINT) CS_DBLCLKS; WindowClass.lpfnWndProc = (WNDPROC) WindowProcedure; WindowClass.cbClsExtra = (INT) 0; WindowClass.cbWndExtra = (INT) 0; WindowClass.hInstance = (HINSTANCE) hProgInst; WindowClass.hIcon = (HICON) LoadIcon (NULL, IDI_APPLICATION); WindowClass.hCursor = (HCURSOR) LoadCursor (NULL, IDC_ARROW); WindowClass.hbrBackground = (HBRUSH) COLOR_BACKGROUND; WindowClass.lpszMenuName = (LPCTSTR) NULL; WindowClass.lpszClassName = (LPCTSTR) ClassName; WindowClass.hIconSm = (HICON) LoadIcon (NULL, IDI_APPLICATION); } void Create(void) { if (!RegisterClassEx(&WindowClass)) MessageBox(NULL, "Error registering.", "Error", MB_OK); hWnd = CreateWindowEx( (DWORD) dwExStyle, (LPCTSTR) lpClassName, (LPCTSTR) lpWindowName, (DWORD) dwStyle, (int) x, (int) y, (int) nWidth, (int) nHeight, (HWND) hWndParent, (HMENU) hMenu, (HINSTANCE) hProgInst, (LPVOID) lpParam); } };
And the main() block of the program is...
C Syntax (Toggle Plain Text)
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { hInstance = hInst; UserDefinedWindow MainWnd; MainWnd.Create(); while (GetMessage(&Msg, NULL, 0, 0)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return (INT) Msg.wParam; }
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.
This part returns NULL.
C Syntax (Toggle Plain Text)
hWnd = CreateWindowEx( (DWORD) dwExStyle, (LPCTSTR) lpClassName, (LPCTSTR) lpWindowName, (DWORD) dwStyle, (int) x, (int) y, (int) nWidth, (int) nHeight, (HWND) hWndParent, (HMENU) hMenu, (HINSTANCE) hProgInst, (LPVOID) lpParam); if ( hWnd == NULL ) { MessageBox(NULL, "CreateWindow Returned NULL", "Error", MB_OK ); return; }
Thanks for your help.
It OK now!
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.
It OK now!
C Syntax (Toggle Plain Text)
VOID ErrorTest(LPSTR lpzsErrorText); VOID ErrorTest(INT nText); class UserDefinedWindow { public: WNDCLASSEX WindowClass; DWORD dwExStyle; //LPCTSTR lpClassName; //LPCTSTR lpWindowName; char lpClassName[MAX_LOADSTRING]; char lpWindowName[MAX_LOADSTRING]; DWORD dwStyle; int x; int y; int nWidth; int nHeight; HWND hWndParent; HMENU hMenu; HINSTANCE hProgInst; LPVOID lpParam; HWND hWnd; UserDefinedWindow() { dwExStyle = 0; //These are default parameters for CreateWindowEx() strcpy(lpClassName, "ClassName"); strcpy(lpWindowName, "Caption"); dwStyle = WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE; x = 100; y = 100; nWidth = 200; nHeight = 200; hWndParent = HWND_DESKTOP; hMenu = NULL; hProgInst = hInstance; lpParam = NULL; WindowClass.cbSize = (UINT) sizeof(WNDCLASSEX); //Defaults for WNDCLASSEX WindowClass.style = (UINT) CS_DBLCLKS; WindowClass.lpfnWndProc = (WNDPROC) WindowProcedure; WindowClass.cbClsExtra = (INT) 0; WindowClass.cbWndExtra = (INT) 0; WindowClass.hInstance = (HINSTANCE) hProgInst; WindowClass.hIcon = (HICON) LoadIcon (NULL, IDI_APPLICATION); WindowClass.hCursor = (HCURSOR) LoadCursor (NULL, IDC_ARROW); WindowClass.hbrBackground = (HBRUSH) COLOR_BACKGROUND; WindowClass.lpszMenuName = (LPCTSTR) NULL; WindowClass.lpszClassName = (LPCTSTR) lpClassName; WindowClass.hIconSm = (HICON) LoadIcon (NULL, IDI_APPLICATION); } void Create(void) { if (!RegisterClassEx(&WindowClass)) MessageBox(NULL, "Error registering.", "Error", MB_OK); hWnd = CreateWindowEx( (DWORD) dwExStyle, (LPCTSTR) lpClassName, (LPCTSTR) lpWindowName, (DWORD) dwStyle, (int) x, (int) y, (int) nWidth, (int) nHeight, (HWND) hWndParent, (HMENU) hMenu, (HINSTANCE) hProgInst, (LPVOID) lpParam); if (hWnd == NULL) { //1407 Cannot find window class. ERROR_CANNOT_FIND_WND_CLASS DWORD ErrCode = GetLastError(); MessageBox(NULL, "Error creating.", "Error", MB_OK); ErrorTest(ErrCode); } } }; VOID ErrorTest(LPSTR lpzsErrorText) { if (MessageBox(NULL, lpzsErrorText, "Error", MB_ICONERROR | MB_OKCANCEL)==IDCANCEL);//PostQuitMessage(0); } VOID ErrorTest(INT nText) { CHAR lpzsErrorText[32]; _itoa(nText, lpzsErrorText, 10); if (MessageBox(NULL, lpzsErrorText, "Error", MB_ICONERROR | MB_OKCANCEL)==IDCANCEL);//PostQuitMessage(0); }
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.
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.
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.
![]() |
Similar Threads
- creating a window in turbo c?? (C++)
- WIN32 GUI application - Problem popping up dialog box (C++)
- Small problem with web links? (Windows 95 / 98 / Me)
- can't open new browser window on aol (Web Browsers)
- Window XP start up lag... (Windows NT / 2000 / XP)
- Can't open more than one window at a time (Windows NT / 2000 / XP)
Other Threads in the C Forum
- Previous Thread: Algorithm for EBCDIC to ASCII Conversion
- Next Thread: hi
| Thread Tools | Search this Thread |
#include * ansi api array arrays asterisks binarysearch calculate centimeter changingto char character convert copyanyfile copyimagefile copypdffile creafecopyofanytypeoffileinc createcopyoffile createprocess() database dynamic execv fflush fgets file floatingpointvalidation fork forloop frequency function getlogicaldrivestrin givemetehcodez grade graphics gtkwinlinux histogram homework i/o inches include infiniteloop input interest intmain() iso keyboard km license linked linkedlist linux list looping loopinsideloop. lowest matrix microsoft mysql oddnumber open opendocumentformat openwebfoundation pdf pointer posix power program programming pyramidusingturboccodes radix read recursion recv recvblocked reversing scanf scheduling segmentationfault send sequential shape single socket socketprogramming stack standard strchr string suggestions test threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi






