Problems with RegisterClassEx() function... why does it return 0?

This is a discussion on Problems with RegisterClassEx() function... why does it return 0? within the Windows Programming forums, part of the Platform Specific Boards category; Hi guys, I'm first time working with win32 api, with C I dont know why, but my function RegisterClassEx(&submenuWStruct) is ...

  1. #1
    Registered User
    Join Date
    Jun 2013
    Posts
    5

    Problems with RegisterClassEx() function... why does it return 0?

    Hi guys, I'm first time working with win32 api, with C


    I dont know why, but my function RegisterClassEx(&submenuWStruct) is returning FALSE. Could you please tell me why?


    Here's the code:






    Code:
            int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
    {
        static char mainW_class[ ] = "MainWindow";
        static char toolsW_class[ ] = "ToolsWindow";
        static char submenuW_class[ ] = "SubmenuWindow";
    
    
        HWND hwnd, tools, submenu; //handle
        MSG messages;            
    
    
        WNDCLASSEX mainWStruct, toolsWStruct, submenuWStruct;
    
    
        /*         generates main window    */
        mainWStruct.hInstance = hThisInstance;
        mainWStruct.lpszClassName = mainW_class;
        mainWStruct.lpfnWndProc = WindowProcedure; 
        mainWStruct.style = CS_DBLCLKS;
        mainWStruct.cbSize = sizeof(WNDCLASSEX);
        mainWStruct.hIcon = LoadIcon (NULL, IDI_APPLICATION); 
        mainWStruct.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        mainWStruct.hCursor = LoadCursor (NULL, IDC_ARROW);
        mainWStruct.lpszMenuName = NULL;        
        mainWStruct.cbClsExtra = 0;                    
        mainWStruct.cbWndExtra = 0;                     
        mainWStruct.hbrBackground = GetSysColorBrush(10);
    
    
        if (!RegisterClassEx (&mainWStruct))
            return 0;                              //<-----REGISTERED OK!
    
    
        hwnd = CreateWindowEx (
               0,
               mainW_class,
               "project title",
               WS_SYSMENU | WS_BOXES,
               0, 0,
               GetSystemMetrics(SM_CXSCREEN),
               GetSystemMetrics(SM_CYSCREEN)-1,
               HWND_DESKTOP,
               NULL, //menu
               hThisInstance,
               NULL);
    
    
    
    
        toolsWStruct.hInstance = hThisInstance;
        toolsWStruct.lpszClassName = toolsW_class;
        toolsWStruct.lpfnWndProc = WindowProcedure;
        toolsWStruct.style = CS_DBLCLKS;
        toolsWStruct.cbSize = sizeof(WNDCLASSEX);
        toolsWStruct.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        toolsWStruct.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
        toolsWStruct.hCursor = LoadCursor (NULL, IDC_HAND);
        toolsWStruct.lpszMenuName = NULL;
        toolsWStruct.cbClsExtra = 0;
        toolsWStruct.cbWndExtra = 0;
        toolsWStruct.hbrBackground = GetSysColorBrush(0);
    
    
        if (!RegisterClassEx (&toolsWStruct))
            return 0;                           //<-------------REGISTERED OK!
    
    
       tools = CreateWindowEx(
              0,
              toolsW_class,
              "Ferramentas",
              WS_CHILD | WS_DLGFRAME | WS_EX_PALETTEWINDOW,
              -SM_CXBORDER,
              -SM_CYBORDER,
              GetSystemMetrics(SM_CXFULLSCREEN) / 4,
              GetSystemMetrics(SM_CYFULLSCREEN),
              hwnd,
              NULL,
              hThisInstance,
              NULL);
    
    
    
    
         submenuWStruct.hInstance = hThisInstance;
         submenuWStruct.lpszClassName = submenuW_class;
         submenuWStruct.lpfnWndProc = WindowProcedure;
         submenuWStruct.style = WS_BORDER;
         submenuWStruct.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
         submenuWStruct.cbSize = sizeof(WNDCLASSEX);
         submenuWStruct.hIcon = LoadIcon(NULL, IDI_APPLICATION);
         submenuWStruct.hCursor = LoadCursor(NULL, IDC_ARROW);
         submenuWStruct.lpszMenuName = NULL;
         submenuWStruct.cbClsExtra = 0;
         submenuWStruct.cbWndExtra = 0;
         submenuWStruct.hbrBackground = GetSysColorBrush(4);
    
    
        **if (!RegisterClassEx(&submenuWStruct))
            return 0;**                                  //<------IT RETURNS 0.. It is not REGISTERING... WHY?
             
         submenu = CreateWindowEx(
                           0,
                           submenuW_class,
                           "add",
                           WS_VISIBLE | WS_CHILD,
                           0,
                           0,
                           GetSystemMetrics(SM_CXFULLSCREEN),
                           GetSystemMetrics(SM_CYFULLSCREEN) / 5,
                           hwnd,
                           (HMENU) NULL,
                           hThisInstance,
                           NULL);
              /*
              CreateWindow(TEXT("button"), TEXT("EDIT"), WS_VISIBLE | WS_CHILD, 60, 20, 40, 20, tools, (HMENU) NULL, NULL, NULL);
              CreateWindow(TEXT("button"), TEXT("DEL"), WS_VISIBLE | WS_CHILD, 130, 20, 40, 20, tools, (HMENU) NULL, NULL, NULL);
              */
    
    
        ShowWindow (hwnd, nFunsterStil);
        ShowWindow (tools, nFunsterStil);
        ShowWindow (submenu, nFunsterStil);
    
    
        /* Run the message loop. It will run until GetMessage() returns 0 */
        while (GetMessage (&messages, NULL, 0, 0))
        {
            /* Translate virtual-key messages into character messages */
            TranslateMessage(&messages);
            /* Send message to WindowProcedure */
            DispatchMessage(&messages);
        }
    
    
        /* The program return-value is 0 - The value that PostQuitMessage() gave */
        return messages.wParam;
    }

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    What does GetLastError() return?

    BTW, you should always zero the STRUCT. (set all elements to zero) Either in the init or with something like ZeroMemory()

    This is to ensure all elements you do not explicitly set are empty (in case the OS tries to use a random value in an element you forgot to set.)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 08-22-2011, 02:44 PM
  2. Replies: 6
    Last Post: 04-09-2006, 04:32 PM
  3. Error 87 from RegisterClassEx()
    By The Wazaa in forum Windows Programming
    Replies: 2
    Last Post: 02-20-2006, 12:15 AM
  4. RegisterClassEx fails on Win95
    By knutso in forum Windows Programming
    Replies: 5
    Last Post: 01-20-2003, 07:38 AM
  5. union problems return
    By nextus in forum C++ Programming
    Replies: 2
    Last Post: 01-14-2003, 01:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21