Thread: Button positioning

  1. #31
    Registered User
    Join Date
    May 2005
    Posts
    207
    Yeah I managed to figure that out (after cursing Charles Petzold and describing what he can do with his book in gory detail).

    Full screen looks different than maximized. Is maximized not too hard to do?

    mw
    Blucast Corporation

  2. #32
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Is maximized not too hard to do?
    In CreateWindow? Add the WS_MAXIMIZE flag.

    Outside CreateWindow?

    Code:
    ShowWindow( hwndMain, SW_MAXIMIZE );
    Anyway Charlez Petzold's books only teach the basics, and some slightly advanced things, but once you know in general how Windows programming works, you'll have to refer to MSDN's Windows API reference constantly.

  3. #33
    Registered User
    Join Date
    May 2005
    Posts
    207
    I added WS_MAXIMIZE like this:

    WS_OVERLAPPED | WS_MAXIMIZE,

    And I changed the width/height back to CW_USEDEFAULT as well.

    But it doesn't maximize it...

    Is that where I'm supposed to put it?

    mw
    Blucast Corporation

  4. #34
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Yes. It seems to work for me.

    Code:
      hwndMain = CreateWindow( wc.lpszClassName,TEXT("Basic Windows API Program"),
                               WS_OVERLAPPEDWINDOW|WS_VISIBLE|WS_MAXIMIZE,
                               0,0,300,200,0,0,hInst,0);
    That creates a maximized window (not a fullscreen one).

  5. #35
    Registered User
    Join Date
    May 2005
    Posts
    207
    Why does everything in WinAPI have to be such a f***ing fight to get working?

    I still can't get it to work... Does this effect it:

    ShowWindow (hwndMain, iCmndShow);

    mw
    Blucast Corporation

  6. #36
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Try commenting that line and see.

    It may be a good idea to post your whole code, or zip it up and upload it somewhere. Or replicate the problem with a smaller piece of code, then post it.

  7. #37
    Registered User
    Join Date
    May 2005
    Posts
    207
    Here's my WinMain:

    Code:
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE, hPrevInstance, PSTR szCmdline, int iCmdShow)
    {
        MSG msg;
        WNDCLASS wc;
    
        wc.style = CD_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc = WndProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hInstance;
        wc.hIcon = LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE (IDI_BOOTICON));
        wc.hbrBackground = (HBRUSH) GetSTockObject (BLACK_BRUSH);
        wc.lpszMenuName = NULL
        wc.lpszClassName = szAppName;
    
        if (!RegisterClass (&wc))
        {
            MessageBox (NULL, TEXT ("ERROR! Window registration failed!", szAppName, MB_ICONERROR);
            return (0);
        }
    
        hwndMain = CreateWindow (szAppName, TEXT ("Game!"), WS_MAXIMIZE | WS_VISIBLE | WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
    
        if (!hwndMain)
        {
            MessageBox (NULL, TEXT ("ERROR! Window creation failed!", szAppName, MB_ICONERROR);
    
            return (0);
        }
    
    /* Button creation here*/
    
        ShowWindow (hwndMain, iCmdShow);
        UpdateWindow (hwndMain);
    
        while (GetMessage (&msg, NULL, 0, 0))
        {
            TranslateMessage (&msg);
            DispatchMessage (&msg);
        }
    
        return msg.wParam;
    }
    Blucast Corporation

  8. #38
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Ah, your one makes it go fullscreen. I think the difference is that you use WS_OVERLAPPED, while I use WS_OVERLAPPEDWINDOW.

  9. #39
    Registered User
    Join Date
    May 2005
    Posts
    207
    My window doesn't even go fullscreen. It displays my window as if I had left out the WS_MAXIMIZE entirely (ie: default size).

    WS_OVERLAPPED doesn't display the minimize/maximize/close buttons at the very top right of the window. As far as I can tell, it doesn't effect the window size.

    Anyway, even if I enter WS_OVERLAPPEDWINDOW instead it has the same effect on the window size (ie: none).

    mw
    Blucast Corporation

  10. #40
    Registered User
    Join Date
    May 2005
    Posts
    207
    Would my window procedure effect the window size? I can't figure this out... :-(

    The only things I do in my winproc is:
    01) draw a bitmap on the background (WM_CREATE)
    02) resize the bitmap to fill the background (WM_PAINT)

    And that's about it. I haven't tried the WM_SIZE yet because I wanted to get the damn window to work properly... :-(

    mw
    Blucast Corporation

  11. #41
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Hmm, if it's not too much trouble, could you post your whole code for your main source file? I want to try running and compiling it to see if the same problem occurs here.

  12. #42
    Registered User
    Join Date
    May 2005
    Posts
    207
    I include my own icon and bitmap as resources.

    Even when I change ShowWindow to:

    ShowWindow (hwndMain, WS_MAXIMIZE)

    It *still* shows the window in default size.

    mw

    Code:
    #include <windows.h>
    #include "resource.h"
    
    //prototypes:
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    
    //global variables:
    static TCHAR szAppName[] = TEXT ("GAME!");
    static RECT rect;
    static HBITMAP hBitmapMain;
    HWND hwndMain, hwndNew, hwndLoad, hwndOptions, hwndQuit;
    HDC hdc, hdcBitmapMem;
    MSG msg;
    WNDCLASS wc;
    BITMAP bitmap;
    PAINTSTRUCT ps;
    int btnHeight = 30;
    int btnWidth = 110;
    int cxScreen;
    int cyScreen;
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE, hPrevInstance, PSTR szCmdline, int iCmdShow)
    {
        wc.style = CD_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc = WndProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hInstance;
        wc.hIcon = LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE (IDI_BOOTICON));
        wc.hbrBackground = (HBRUSH) GetSTockObject (BLACK_BRUSH);
        wc.lpszMenuName = NULL
        wc.lpszClassName = szAppName;
    
        if (!RegisterClass (&wc))
        {
            MessageBox (NULL, TEXT ("ERROR! Window registration failed!", szAppName, MB_ICONERROR);
            return (0);
        }
    
        hwndMain = CreateWindow (szAppName, TEXT ("Game!"), WS_MAXIMIZE | WS_VISIBLE | WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
    
        if (!hwndMain)
        {
            MessageBox (NULL, TEXT ("ERROR! Window creation failed!", szAppName, MB_ICONERROR);
    
            return (0);
        }
    
        GetClientRect (hwndMain, &rect);
    
        hwndNew = CreateWindow (TEXT ("button"), TEXT ("New Game"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, (rect.right - (2 * btnWidth)) / 3, 500 btnWidth, btnHeight, hwndMain, (HMENU) IDB_NEWGAMEBUTTON, GetModuleHandle (NULL), NULL);
    
        hwndLoad = CreateWindow (TEXT ("button"), TEXT ("Load Game"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, ((rect.right - (2 * btnWidth)) / 3) - btnWidth, 500, btnWidth, btnHeight, hwndMain, (HMENU) IDB_LOADGAMEBUTTON, GetModuleHandle (NULL), NULL);
    
        hwndNew = CreateWindow (TEXT ("button"), TEXT ("Options"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, (rect.right - (2 * btnWidth)) / 3, 600, btnWidth, btnHeight, hwndMain, (HMENU) IDB_OPTIONSBUTTON, GetModuleHandle (NULL), NULL);
    
        hwndNew = CreateWindow (TEXT ("button"), TEXT ("Quit"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, ((rect.right - (2 * btnWidth)) / 3) - btnWidth, 600, btnWidth, btnHeight, hwndMain, (HMENU) IDB_QUITBUTTON, GetModuleHandle (NULL), NULL);
    
        ShowWindow (hwndMain, iCmdShow);
        UpdateWindow (hwndMain);
    
        while (GetMessage (&msg, NULL, 0, 0))
        {
            TranslateMessage (&msg);
            DispatchMessage (&msg);
        }
    
        return msg.wParam;
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)
        {
            case WM_CREATE:
                cxScreen = GetSystemMetrics (SM_CXSCREEN);
                cyScreen = GetSystemMetrics (SM_CYSCREEN);
    
                hBitmapMain = (HBITMAP) LoadImage (GetModuleHandle (NULL), MAKEINTRESOURCE (IDB_BITMAP), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
    
                if (!hBitmapMain)
                {
                    MessageBox (hwnd, TEXT ("ERROR! Could not load window background!"),  szAppName, MB_ICONERROR);
                }
    
                return (0);
    
            case WM_SIZE:
                return (0);
    
            case WM_COMMAND:
                switch (wParam)
                {
                    case IDB_NEWGAMEBUTTON:
                        return (0);
    
                    case IDB_LOADGAMEBUTTON:
                        return (0);
    
                    case IDB_OPTIONSBUTTON:
                        return (0);
    
                    case IDB_QUITBUTTON:
                        PostQuitMessage (0);
    
                        return (0);
                }
    
                return (0);
    
            case WM_PAINT:
                hdcBitmapMem = CreateCompatibleDC (NULL);
                SelectObject (hdcBitmapMem, hBitmapMain);
                GetObject (hBitmapMain, sizeof (BITMAP), &bitmap);
    
                hdc = BeginPaint (hwnd, &rect);
    
                StretchBlt (hdc, 0, 0, rect.right, rect.bottom, hdcBitmapMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, MERGECOPY);
    
                DeleteDC (hdcBitmapMem);
    
                EndPaint (hwnd, &ps);
    
                return (0);
    
            case WM_DESTROY:
                PostQuitMessage (0);
    
                return (0);
        }
    
        return DefWindowProc (hwnd, message, wParam, lParam);
    }
    Last edited by Lionmane; 10-13-2005 at 09:48 PM.
    Blucast Corporation

  13. #43
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    You use the iCmdShow from the WinMain(). What value is in it?

    Maximise is 3
    Check Winuser.h for other values.

    Try adding a

    ShowWindow(hwnd,SW_SHOWMAXIMIZED);

    to your WM_CREATE

    I have found that when a window is first created, it will be created a default size.

    During the create/init it will send a size msg to maximise the window.
    "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

  14. #44
    Registered User
    Join Date
    May 2005
    Posts
    207
    Ok, just for fun I did this:

    Code:
        hwndMain = CreateWindow (szAppName, TEXT ("Game!"), WS_MAXIMIZE | WS_VISIBLE | WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
    This:

    Code:
        ShowWindow (hwndMain, WS_MAXIMIZE);
        UpdateWindow (hwndMain);
    And this:

    Code:
            case WM_CREATE:
            ShowWindow (hwndMain, WS_MAXIMIZE);
    And it *STILL* shows the window in the default size.

    So something is wrong here...

    mw
    Last edited by Lionmane; 10-14-2005 at 09:37 AM.
    Blucast Corporation

  15. #45
    Registered User
    Join Date
    May 2005
    Posts
    207
    Is there something wrong with my hwnd references? They don't look right, but when I try to change them I get errors...

    mw
    Blucast Corporation

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-28-2008, 08:30 PM
  2. elliptical button
    By geek@02 in forum Windows Programming
    Replies: 0
    Last Post: 11-21-2006, 02:15 AM
  3. Remove dialog button border
    By RedZone in forum Windows Programming
    Replies: 4
    Last Post: 08-21-2006, 01:20 PM
  4. writing text over a deleted button
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-02-2005, 11:32 AM
  5. Window won't display on button command!?
    By psychopath in forum Windows Programming
    Replies: 6
    Last Post: 06-22-2004, 08:12 PM