Button Won't Show!!

This is a discussion on Button Won't Show!! within the C++ Programming forums, part of the General Programming Boards category; Code: #include <windows.h> //Controls HWND Window1; HWND Button1; LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hThisInstance, ...

  1. #1
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542

    Angry Button Won't Show!!

    Code:
    #include <windows.h>
    //Controls
    HWND Window1;
    HWND Button1;
    
    
    
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI
    WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
    {
        MSG messages;            /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
    
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = "Window1";
        wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
        wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
        wincl.cbSize = sizeof (WNDCLASSEX);
    
        /* Use default icon and mouse-pointer */
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;                 /* No menu */
        wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
        wincl.cbWndExtra = 0;                      /* structure or the window instance */
        /* Use Windows's default color as the background of the window */
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    
        /* Register the window class, and if it fails quit the program */
        if (!RegisterClassEx (&wincl))
            return 0;
    
    
        //Window1
        Window1 = CreateWindowEx(
               0, "Window1", "Tic Tac Toe!", WS_OVERLAPPEDWINDOW, 300, 300, 300, 150,
               HWND_DESKTOP, NULL, hThisInstance, NULL);
        //Button1
        Button1 = CreateWindow(
                "Button1", "Exit", WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON, 10, 10, 50, 25, Window1,
                NULL, (HINSTANCE) GetWindowLong(Window1, GWL_HINSTANCE), NULL);
        ShowWindow (Window1, nFunsterStil);
        //Messages
    
    
        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;
    }
    
    
    /*  This function is called by the Windows function DispatchMessage()  */
    
    LRESULT CALLBACK
    WindowProcedure (HWND Window1, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  /* handle the messages */
        {
            case WM_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                break;
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (Window1, message, wParam, lParam);
        }
    
        return 0;
    }
    Please Help!!
    what does signature stand for?

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    I could be wrong but shouldn't you call ShowWindow for "Button" as well?

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    And shouldn't this be in the 'Windows Programming' forum as well?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    14
    Try:
    Code:
    Button1 = CreateWindow(
                "Button", "Exit", WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON, 10, 10, 50, 25, Window1,
                NULL, (HINSTANCE) GetWindowLong(Window1, GWL_HINSTANCE), NULL);

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    Put your CreateWindow function in the WndProc() under WM_CREATE:
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    polo found it! the name of the button class is "Button" not "Button1".

    As far as Okiesmokie's post goes, this is not necessary. WM_CREATE has returned already for the main window by the time he's making the call.

    Originally posted by Okiesmokie
    Put your CreateWindow function in the WndProc() under WM_CREATE:

  7. #7
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Thanks I got it
    what does signature stand for?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbee Q: reg. MFC dlg button & Vista UAC shield icon
    By colbyringeisen in forum Windows Programming
    Replies: 3
    Last Post: 12-29-2008, 04:16 PM
  2. elliptical button
    By geek@02 in forum Windows Programming
    Replies: 0
    Last Post: 11-21-2006, 01:15 AM
  3. writing text over a deleted button
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-02-2005, 11:32 AM
  4. Window won't display on button command!?
    By psychopath in forum Windows Programming
    Replies: 6
    Last Post: 06-22-2004, 08:12 PM
  5. Click button on dialog box to open window.
    By ooosawaddee3 in forum Windows Programming
    Replies: 1
    Last Post: 11-29-2002, 07:53 AM

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