Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Windows class not created error?

Windows class not created error?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheDelChop
    wrote on last edited by
    #1

    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

    CPalliniC M 3 Replies Last reply
    0
    • T TheDelChop

      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

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Can you post the code of the DlgProc? Please use pre 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.

      In testa che avete, signor di Ceprano?

      T 1 Reply Last reply
      0
      • CPalliniC CPallini

        Can you post the code of the DlgProc? Please use pre 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.

        T Offline
        T Offline
        TheDelChop
        wrote on last edited by
        #3

        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

        CPalliniC 1 Reply Last reply
        0
        • T TheDelChop

          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

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          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.

          In testa che avete, signor di Ceprano?

          T 1 Reply Last reply
          0
          • CPalliniC CPallini

            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.

            T Offline
            T Offline
            TheDelChop
            wrote on last edited by
            #5

            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?

            CPalliniC 1 Reply Last reply
            0
            • T TheDelChop

              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?

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              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.

              In testa che avete, signor di Ceprano?

              T 1 Reply Last reply
              0
              • CPalliniC CPallini

                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.

                T Offline
                T Offline
                TheDelChop
                wrote on last edited by
                #7

                JDelCioppio@astromed.com Thank you so much, Joe

                1 Reply Last reply
                0
                • T TheDelChop

                  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

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #8

                  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));

                  1 Reply Last reply
                  0
                  • T TheDelChop

                    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

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups