buttons won't work when in child window!?

This is a discussion on buttons won't work when in child window!? within the Windows Programming forums, part of the Platform Specific Boards category; i'm creating an app, and so far i have the main window, and a child window wich will contain buttons, ...

  1. #1
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070

    buttons won't work when in child window!?

    i'm creating an app, and so far i have the main window, and a child window wich will contain buttons, tools, etc.....i have two buttons in the child window, and they don't seem to be recieving input......if i move them into the main window, they work fine (when i say work, i mean when you click on them, they 'push' in)

    heres the code if anyone needs to look at it:
    Code:
    // Includes
    
    #include <windows.h>
    #include "menu.h"
    
    // Function Declarations
    
    LRESULT CALLBACK 
    WndProc( HWND hWnd, UINT message,
    WPARAM wParam, LPARAM lParam );
    
    // WinMain
    
    int WINAPI 
    WinMain( HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int iCmdShow )
    {
    WNDCLASS wc;
    WNDCLASS tb;
    HWND hWnd;
    HDC hDC;
    MSG msg;
    BOOL bQuit = FALSE;
    
    // register window class
    wc.style = CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    wc.hCursor = LoadCursor( NULL, IDC_ARROW );
    wc.hbrBackground = (HBRUSH)GetStockObject( GRAY_BRUSH );
    wc.lpszMenuName = "MAIN";
    wc.lpszClassName = "Main";
    RegisterClass( &wc );
    
    //register tool box
    tb.style = CS_OWNDC;
    tb.lpfnWndProc = WndProc;
    tb.cbClsExtra = 0;
    tb.cbWndExtra = 0;
    tb.hInstance = hInstance;
    tb.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    tb.hCursor = LoadCursor( NULL, IDC_ARROW );
    tb.hbrBackground = (HBRUSH)GetStockObject( LTGRAY_BRUSH );
    tb.lpszMenuName = NULL;
    tb.lpszClassName = "ToolBox";
    RegisterClass( &tb );
    
    
    // create main window
    hWnd = CreateWindow( 
    "Main", "IGM | Insomniac Game Maker",
    WS_TILEDWINDOW | WS_POPUPWINDOW | WS_VISIBLE,
    0, 0, 800, 570,
    NULL, NULL, hInstance, NULL );
    
    //create tool box
    HWND tool_box;
    tool_box = CreateWindow(
    "ToolBox", "Tools",
    WS_CHILD | WS_BORDER | WS_VISIBLE,
    592, 0, 200, 516,
    hWnd, NULL, hInstance, NULL );
    
    //create buttons
    HWND button;
    button = CreateWindow("BUTTON", "Sprites", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 616, 40, 64, 24, hWnd,(HMENU) 10, (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
    button = CreateWindow("BUTTON", "Objects", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 706, 40, 64, 24, hWnd,(HMENU) 20, (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
    
    BOOL EnableWindow(HWND button, BOOL bEnable);
    
    // program main loop
    while ( !bQuit ) {
    
    // check for messages
    if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
    
    // handle or dispatch messages
    if ( msg.message == WM_QUIT ) {
    bQuit = TRUE;
    } else {
    TranslateMessage( &msg );
    DispatchMessage( &msg );
    }
    
    }
    
    }
    
    
    // destroy the window explicitly
    DestroyWindow( hWnd );
    
    return msg.wParam;
    
    }
    
    // Window Procedure
    
    LRESULT CALLBACK 
    WndProc( HWND hWnd, UINT message,
    WPARAM wParam, LPARAM lParam )
    {
    
    switch ( message ) {
    
    case WM_CREATE:
    return 0;
    
    case WM_CLOSE:
    PostQuitMessage( 0 );
    return 0;
    
    case WM_DESTROY:
    return 0;
    
    case WM_KEYDOWN:
    switch ( wParam ) {
    
    case VK_ESCAPE:
    PostQuitMessage( 0 );
    return 0;
    
    }
    return 0;
    
    default:
    return DefWindowProc( hWnd, 
    message, wParam, lParam );
    
    }
    
    }
    thanks ahead of time
    -psychopath

  2. #2
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    lol......ok seriously now...can anyone help?

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    OK, seriously, you need to post your code with some semblance of formatting! Surely, that is not how your code actually looks!?
    --
    If you want your buttons to be children of the tool box, you should specify their parent as tool_box rather that hWnd. At the moment tool_box and the buttons are all children of hWnd and that may cause problems as they overlap.
    --
    Unless you have a very good reason, you should not use a PeekMessage() message loop.
    --
    It is somewhat unusual to see a function re-prototyped in the middle of WinMain().
    Code:
    BOOL EnableWindow(HWND button, BOOL bEnable);

  4. #4
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    yupp.....that is how my code looks :P
    ---
    i replaced hWnd with tool_box and the buttons dissapeared!?
    ---
    that is there because it was there in the dev-c++ template
    ---
    entered that bit of code to see if prehaps the buttons wern't enabled

    -psychopath

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    When you create a window its coordinates must be relative to its parents.
    Code:
    616, 40, 64, 24,
    So, with these coordinates the buttons are being created off the edge of the toolbox as the toolbox is less than 616 wide.
    --
    Your message loop should look like:
    Code:
    while (GetMessage(&msg, NULL, 0, 0)) 
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    Last edited by anonytmouse; 06-17-2004 at 01:16 PM.

  6. #6
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    ok....got it workin now....THANX!

    -psychopath

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. The Invisible Child Window
    By SMurf in forum Windows Programming
    Replies: 0
    Last Post: 03-19-2006, 07:25 AM
  3. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 11:14 PM
  4. child windows
    By face_master in forum Windows Programming
    Replies: 14
    Last Post: 03-01-2002, 07:08 AM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM

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