troubleshooting Question

CreateWindow Function

Avatar of shaun_hester
shaun_hester asked on
C++
3 Comments1 Solution1378 ViewsLast Modified:
Everytime i try to create the Sale Window in the main Window Procedure i get error 1407 can not find class name.
I must be missing something small but i can not seem to find the error.
I have the saleProc in a seperate file but at the minute it is just an empty window proc with a create paint and destroy message.

#include"main.h"

const TCHAR szAppName[] = TEXT ("EZE POS");
const TCHAR szSale[] = TEXT ("Sale");

HINSTANCE hInstance;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
      HWND hwnd;
      MSG msg;
      WNDCLASS wndclass;

      wndclass.style = CS_HREDRAW | CS_VREDRAW;
      wndclass.lpfnWndProc = WndProc;
      wndclass.cbClsExtra = 0;
      wndclass.cbWndExtra = 0;
      wndclass.hInstance = hInstance;
      wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
      wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
      wndclass.lpszMenuName = szAppName;
      wndclass.lpszClassName = szAppName;

      if(!RegisterClass (&wndclass)){
            MessageBox (NULL, TEXT ("This program requires Windows NT!"),szAppName, MB_ICONERROR);
            return 0;
      }

      wndclass.lpfnWndProc = SaleProc;
      wndclass.lpszClassName = szSale;
      if(!RegisterClass (&wndclass)){
            MessageBox (NULL, TEXT ("This program requires Windows NT!"),szAppName, MB_ICONERROR);
            return 0;
      }

      hwnd = CreateWindow(szAppName,
            szAppName,
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            NULL,
            NULL,
            hInstance,
            NULL);

      ShowWindow(hwnd, iCmdShow);
      UpdateWindow(hwnd);

      while(GetMessage(&msg, NULL, 0, 0)){
            TranslateMessage(&msg);
            DispatchMessage(&msg);
      }
      return msg.wParam;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
      HDC hdc;
      PAINTSTRUCT ps;
      RECT rect;
      static HWND hButtonArr[4];
      char szButtonArr[5][10] = {"Sale",
            "Delivery",
            "Admin",
            "Stock",
            "Deposits"
      };
      int i;
      DWORD dw;
      char temp[200];

      switch(message){
      case WM_CREATE:
            if(GetSystemMetrics(SM_CXSCREEN) < 800){
                  MessageBox (NULL, TEXT ("Mininum Resolution must be 800 x 600"),szAppName, MB_ICONERROR);
                  PostQuitMessage(0);
            }else if(GetSystemMetrics(SM_CYSCREEN) < 600){
                  MessageBox (NULL, TEXT ("Mininum Resolution must be 800 x 600"),szAppName, MB_ICONERROR);
                  PostQuitMessage(0);
            }

            hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
            
            for(i = 0; i < 5; i++){
                  hButtonArr[i] = CreateWindow("BUTTON", szButtonArr[i],
                  WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                  0, (0 + (i * 75)), 150, 50,
                  hwnd, (HMENU) i, hInstance, NULL);
            }
            return 0;
      case WM_PAINT:
            hdc = BeginPaint (hwnd, &ps);
            GetClientRect (hwnd, &rect);
            SetWindowPos(hwnd,
                  CWP_ALL,
                  0,
                  0,
                  800,
                  600,
                  SWP_SHOWWINDOW);
            EndPaint(hwnd,&ps);
            return 0;
      case WM_COMMAND:
            switch( LOWORD (wParam) ){
            case MAIN_BUTTON_SALE:
                  if( HIWORD (wParam) == BN_CLICKED ){
                        CreateWindow(szSale,
                              NULL,
                              WS_CHILDWINDOW | WS_VISIBLE,
                              150,
                              0,
                              650,
                              600,
                              hwnd,
                              (HMENU) MAIN_WINDOW_SALE,
                              hInstance,
                              NULL);
                        dw = GetLastError();
                        sprintf(temp, "%d", dw);
                        MessageBox(hwnd, temp, "ERROR", NULL);
                        for(i=0; i<5; i++){
                              EnableWindow(hButtonArr[i], FALSE);
                        }
                  }
                  return 0;
            }
            break;
      case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
      }

      return DefWindowProc(hwnd, message, wParam, lParam);
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros