Thread: Putting stuff in my window...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212

    Question Putting stuff in my window...

    Yeah so anyway, I made this window, like this:
    Code:
    #include <windows.h>
    
    /* Declare Windows procedure */
    LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
    /* Make the class name into a global variable */
    char szClassName[ ] = "WindowsApp";
    int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
    
    {
        HWND hwnd;               /* This is the handle for our window */
        MSG messages;            /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
    
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        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 light-gray as the background of the window */
        wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
    
        /* Register the window class, if fail quit the program */
        if(!RegisterClassEx(&wincl)) return 0;
    
        /* The class is registered, let's create the program*/
        hwnd = CreateWindowEx(
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "Windows App",         /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               544,                 /* The programs width */
               375,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
    
        /* Make the window visible on the screen */
        ShowWindow(hwnd, 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;
    }
    
    /* This function is called by the Windows function DispatchMessage( ) */
    LRESULT CALLBACK WindowProcedure(HWND hwnd, 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(hwnd, message, wParam, lParam);
        }
        return 0;
    }
    Now how the hell do I put buttons, text boxes and whatnot in it?

    [i hate windows i hate windows i hate windows arrg]

  2. #2
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Talking You just...

    They are child windows. Just above the "case WM_DESTROY:" add "case WM_CREATE"(w/out the quotes). Then look up CreateWindow();/CreateWindowEx();
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: [email protected]

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  3. #3
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    Controls are merely child windows. Pass your hInstance to another Create function, but set the ClassName to the type of control you want to create.

    Then make sure to set the style to WS_CHILD | WS_VISIBLE and an optional control style (ex. | BS_PUSHBUTTON). Those are the minimum requirements for for a control, excluding dimensions.

    So here is your examlple of a control/child window:

    Code:
    CreateWindowEx( NULL, // extended style
                 "BUTTON", //constant that refers to the button class
                 "My Button", //the caption for your button
                 WS_CHILD | WS_VISIBLE | 
                 BS_PUSHBUTTON,  //child, visible, button style
                 10, 10, 40, 20,  //your button's dimensions
                 hwnd, //handle to the parent window
                 NULL, //no menu
                 hThisInstance, //the apps instance
                 NULL);
    No need to handle the WM_CREATE message. Just create the control directly under the parent window in your WinMain function. MSDN has lists of all the various control styles you canuse in your windows.
    [i hate windows i hate windows i hate windows arrg]
    Love it, or leave it
    Hope this helps.
    Last edited by Invincible; 03-04-2002 at 06:19 PM.
    "The mind, like a parachute, only functions when open."

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    363
    Have a look here, it explains all that sort of stuff:
    http://www.winprog.org/tutorial/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  2. how i create a window whith all it's elements
    By rasheed in forum Windows Programming
    Replies: 1
    Last Post: 05-31-2006, 06:53 PM
  3. Button positioning
    By Lionmane in forum Windows Programming
    Replies: 76
    Last Post: 10-21-2005, 05:22 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. dont want to use all params
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 02-18-2003, 08:10 AM