Windows class not created error?
-
Hi, I am experiencing some real trouble with a simple windows program that I am trying to create. After running the CreateDialog() function, windows returns the error "Windows class not created". I am having trouble determing what this message is really telling me. The result of this error message is that after processing the WM_SETFONT message inside the DlgProc for the Dialog Box that it creates, Windows always processes the WM_DESTROY instead of the WM_INITDIALOG which is the next message that my other working windows programs processes which creates and displays the dialog box. I have posted my WinAPI function below: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int nCmdShow) { MSG msg; HWND mainWnd; hInst = hInstance; // Make instance available globally InitCommonControls(); // Create a dummy window so the dialog box can have a parent window, then // create the dialog box itself. mainWnd = CreateWindow("", "", 0, 0, 0, 0, 0, NULL,(HMENU)-1, hInstance, 0); MainDlgBox = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_AURACONNECT), mainWnd, (DLGPROC)DlgProc); DWORD Err = GetLastError(); SetClassLong(mainWnd,GCL_HICON,IDI_EXE); // Standard Windows message loop while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } I understand that I probably don't need to create a dummy window to create a dialog box. Also, I can't post my DlgProc because it is so large and long, but is this the most likely source of this error? Thank you for anyone who can offer any help. Joe
-
Hi, I am experiencing some real trouble with a simple windows program that I am trying to create. After running the CreateDialog() function, windows returns the error "Windows class not created". I am having trouble determing what this message is really telling me. The result of this error message is that after processing the WM_SETFONT message inside the DlgProc for the Dialog Box that it creates, Windows always processes the WM_DESTROY instead of the WM_INITDIALOG which is the next message that my other working windows programs processes which creates and displays the dialog box. I have posted my WinAPI function below: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int nCmdShow) { MSG msg; HWND mainWnd; hInst = hInstance; // Make instance available globally InitCommonControls(); // Create a dummy window so the dialog box can have a parent window, then // create the dialog box itself. mainWnd = CreateWindow("", "", 0, 0, 0, 0, 0, NULL,(HMENU)-1, hInstance, 0); MainDlgBox = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_AURACONNECT), mainWnd, (DLGPROC)DlgProc); DWORD Err = GetLastError(); SetClassLong(mainWnd,GCL_HICON,IDI_EXE); // Standard Windows message loop while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } I understand that I probably don't need to create a dummy window to create a dialog box. Also, I can't post my DlgProc because it is so large and long, but is this the most likely source of this error? Thank you for anyone who can offer any help. Joe
Can you post the code of the
DlgProc
? Please usepre
tags to post code: <pre> ...your code here... </pre> :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Can you post the code of the
DlgProc
? Please usepre
tags to post code: <pre> ...your code here... </pre> :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
Ok, its pretty long, but here you go.
LRESULT CALLBACK DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: switch(LOWORD(wParam)) { case IDCANCEL: DestroyWindow(MainDlgBox); PostQuitMessage(0); return TRUE; case IDC_SETIPADDR: // Adds fucntionality to the close button. SendDlgItemMessage(MainDlgBox, IDC_IPADDRESS, IPM_GETADDRESS, 0, (LPARAM)(LPDWORD)NewAddr); wsprintf(strAddr,"%d",NewAddr); SendCommand(&DataSocket, SET_IP_ADDRESS, sizeof(CommandStruct), messageFromHost); strAddr[cSetIP.length] = '\r'; SendCommand(&DataSocket, strAddr, strlen(strAddr), messageFromHost); MessageBox(NULL,"IP Address has been changed sucessfully","Address Changed",MB_OK); return TRUE; case IDC_SETIPMASK: SendDlgItemMessage(MainDlgBox, IDC_IPMASK, IPM_GETADDRESS, 0, (LPARAM)(LPDWORD)NewMask); wsprintf(strAddr,"%d",ConnectAddr); SendCommand(&DataSocket, SET_IP_MASK, sizeof(CommandStruct), messageFromHost); strAddr[cSetMask.length] = '\r'; SendCommand(&DataSocket, strAddr, strlen(strAddr), messageFromHost); MessageBox(NULL,"IP Mask has been changed sucessfully","Address Changed",MB_OK); return TRUE; case IDC_CONNECTBTN: WSAStartup(MAKEWORD(2, 0), &wsaData); SendDlgItemMessage(MainDlgBox, IDC_CONNECT, IPM_GETADDRESS,0, (LPARAM)(LPDWORD)ConnectAddr); wsprintf(strAddr,"%d",ConnectAddr); if(ConnectToSocket(MainDlgBox, &DataSocket, strAddr, DATA_PORT, WINSOCK_DATA_MESSAGE,FD_CONNECT|FD_CLOSE|FD_READ)) MessageBox(NULL,"Connection attempt with AuraNET Headbox was sucessfull!","Connected with AuraNET",NULL); else { if(MessageBox(NULL,"Connection attempt with AuraNET Headbox was unsucessfull!","Not Connected with AuraNET",MB_RETRYCANCEL) == IDRETRY) PostMessage(MainDlgBox,WM_COMMAND,(WPARAM)IDC_CONNECTBTN,0); else return TRUE; } EnableWindow(GetDlgItem(MainDlgBox,IDC_DISCONNECTBTN),TRUE); EnableWindow(GetDlgItem(MainDlgBox,IDC_SETIPADDR),TRUE); EnableWindow(GetDlgItem(MainDlgBox,IDC_SETIPMASK),TRUE); EnableWindow(GetDlgItem(MainDlgBox,IDC_GETSTATUS),TRUE); EnableWindow(GetDl
-
Ok, its pretty long, but here you go.
LRESULT CALLBACK DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: switch(LOWORD(wParam)) { case IDCANCEL: DestroyWindow(MainDlgBox); PostQuitMessage(0); return TRUE; case IDC_SETIPADDR: // Adds fucntionality to the close button. SendDlgItemMessage(MainDlgBox, IDC_IPADDRESS, IPM_GETADDRESS, 0, (LPARAM)(LPDWORD)NewAddr); wsprintf(strAddr,"%d",NewAddr); SendCommand(&DataSocket, SET_IP_ADDRESS, sizeof(CommandStruct), messageFromHost); strAddr[cSetIP.length] = '\r'; SendCommand(&DataSocket, strAddr, strlen(strAddr), messageFromHost); MessageBox(NULL,"IP Address has been changed sucessfully","Address Changed",MB_OK); return TRUE; case IDC_SETIPMASK: SendDlgItemMessage(MainDlgBox, IDC_IPMASK, IPM_GETADDRESS, 0, (LPARAM)(LPDWORD)NewMask); wsprintf(strAddr,"%d",ConnectAddr); SendCommand(&DataSocket, SET_IP_MASK, sizeof(CommandStruct), messageFromHost); strAddr[cSetMask.length] = '\r'; SendCommand(&DataSocket, strAddr, strlen(strAddr), messageFromHost); MessageBox(NULL,"IP Mask has been changed sucessfully","Address Changed",MB_OK); return TRUE; case IDC_CONNECTBTN: WSAStartup(MAKEWORD(2, 0), &wsaData); SendDlgItemMessage(MainDlgBox, IDC_CONNECT, IPM_GETADDRESS,0, (LPARAM)(LPDWORD)ConnectAddr); wsprintf(strAddr,"%d",ConnectAddr); if(ConnectToSocket(MainDlgBox, &DataSocket, strAddr, DATA_PORT, WINSOCK_DATA_MESSAGE,FD_CONNECT|FD_CLOSE|FD_READ)) MessageBox(NULL,"Connection attempt with AuraNET Headbox was sucessfull!","Connected with AuraNET",NULL); else { if(MessageBox(NULL,"Connection attempt with AuraNET Headbox was unsucessfull!","Not Connected with AuraNET",MB_RETRYCANCEL) == IDRETRY) PostMessage(MainDlgBox,WM_COMMAND,(WPARAM)IDC_CONNECTBTN,0); else return TRUE; } EnableWindow(GetDlgItem(MainDlgBox,IDC_DISCONNECTBTN),TRUE); EnableWindow(GetDlgItem(MainDlgBox,IDC_SETIPADDR),TRUE); EnableWindow(GetDlgItem(MainDlgBox,IDC_SETIPMASK),TRUE); EnableWindow(GetDlgItem(MainDlgBox,IDC_GETSTATUS),TRUE); EnableWindow(GetDl
Sorry for the delay, but rebuilding a project with that code took a bit of time. Anyway I don't get any error on my system, where
CreateDialog
works correctly. However, MSDN recommends, for modeless dialog, the following behaviour:while (GetMessage(&msg, NULL, NULL, NULL))
{
if (!IsWindow(hwndGoto) || !IsDialogMessage(hwndGoto, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}to avoid processing not-dialog messages (
hwndGoto
is the dialog HWND, in the above snippet). I don't know if that helps you.If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Sorry for the delay, but rebuilding a project with that code took a bit of time. Anyway I don't get any error on my system, where
CreateDialog
works correctly. However, MSDN recommends, for modeless dialog, the following behaviour:while (GetMessage(&msg, NULL, NULL, NULL))
{
if (!IsWindow(hwndGoto) || !IsDialogMessage(hwndGoto, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}to avoid processing not-dialog messages (
hwndGoto
is the dialog HWND, in the above snippet). I don't know if that helps you.If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
if you can build a project with no error on your system would you consider zipping it up and sending it to me/ posting it to see where we differ?
-
if you can build a project with no error on your system would you consider zipping it up and sending it to me/ posting it to see where we differ?
TheDelChop wrote:
would you consider zipping it up and sending it to me
Yes, of course (by the way I need you e-mail address)
TheDelChop wrote:
posting it
I don't know how if it is possible to post zip files via the forum.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
TheDelChop wrote:
would you consider zipping it up and sending it to me
Yes, of course (by the way I need you e-mail address)
TheDelChop wrote:
posting it
I don't know how if it is possible to post zip files via the forum.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
JDelCioppio@astromed.com Thank you so much, Joe
-
Hi, I am experiencing some real trouble with a simple windows program that I am trying to create. After running the CreateDialog() function, windows returns the error "Windows class not created". I am having trouble determing what this message is really telling me. The result of this error message is that after processing the WM_SETFONT message inside the DlgProc for the Dialog Box that it creates, Windows always processes the WM_DESTROY instead of the WM_INITDIALOG which is the next message that my other working windows programs processes which creates and displays the dialog box. I have posted my WinAPI function below: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int nCmdShow) { MSG msg; HWND mainWnd; hInst = hInstance; // Make instance available globally InitCommonControls(); // Create a dummy window so the dialog box can have a parent window, then // create the dialog box itself. mainWnd = CreateWindow("", "", 0, 0, 0, 0, 0, NULL,(HMENU)-1, hInstance, 0); MainDlgBox = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_AURACONNECT), mainWnd, (DLGPROC)DlgProc); DWORD Err = GetLastError(); SetClassLong(mainWnd,GCL_HICON,IDI_EXE); // Standard Windows message loop while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } I understand that I probably don't need to create a dummy window to create a dialog box. Also, I can't post my DlgProc because it is so large and long, but is this the most likely source of this error? Thank you for anyone who can offer any help. Joe
Did you try my suggestion in the reply to your other post? Try changing SetClassLong(mainWnd,GCL_HICON,IDI_EXE); to SetClassLong(mainWnd,GCL_HICON,LoadIcon(hInstance, MAKEINTRESOURCE(IDI_EXE));
-
Hi, I am experiencing some real trouble with a simple windows program that I am trying to create. After running the CreateDialog() function, windows returns the error "Windows class not created". I am having trouble determing what this message is really telling me. The result of this error message is that after processing the WM_SETFONT message inside the DlgProc for the Dialog Box that it creates, Windows always processes the WM_DESTROY instead of the WM_INITDIALOG which is the next message that my other working windows programs processes which creates and displays the dialog box. I have posted my WinAPI function below: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int nCmdShow) { MSG msg; HWND mainWnd; hInst = hInstance; // Make instance available globally InitCommonControls(); // Create a dummy window so the dialog box can have a parent window, then // create the dialog box itself. mainWnd = CreateWindow("", "", 0, 0, 0, 0, 0, NULL,(HMENU)-1, hInstance, 0); MainDlgBox = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_AURACONNECT), mainWnd, (DLGPROC)DlgProc); DWORD Err = GetLastError(); SetClassLong(mainWnd,GCL_HICON,IDI_EXE); // Standard Windows message loop while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } I understand that I probably don't need to create a dummy window to create a dialog box. Also, I can't post my DlgProc because it is so large and long, but is this the most likely source of this error? Thank you for anyone who can offer any help. Joe
Oops... Should be SetClassLongPtr(mainWnd, GCL_HICON, (LONG_PTR)LoadIcon(hInstance, MAKEINTRESOURCE(IDI_EXE))); And your parent window has no window class registered for it? Try making the dialog style overlapped and create it with parent HWND = NULL. Mark