Fixed window size

This is a discussion on Fixed window size within the Windows Programming forums, part of the Platform Specific Boards category; Searched MSDN for WS and CS styles.. did google search for window styles.. did a board search... I can't seem ...

  1. #1
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    Fixed window size

    Searched MSDN for WS and CS styles.. did google search for window styles.. did a board search...

    I can't seem to find a style that will create a window that cannot be resized..

    I would like to create a window of fixed length and width for a calculator program.. this is how my parent window is initialized:

    Code:
     /* 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 Windows's default color as the background of the window */
        wincl.hbrBackground = (HBRUSH)(COLOR_MENU);
    
        /* Register the window class, and if it fails 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 */
               "calculator",       /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               207,                 /* The programs width */
               333,                 /* 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 */
               );

    I would like to add a style with one of the blue highlighted portions of the code that would disable resizing of the parent window if this is possible.

    any suggestions..?
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    I think that there's no style for that. you should check the WM_SIZE message and use the 'SetWindowPos' with the handler of the main window to resize, reposition, visibility, etc (search for that funciotn for more). just set a global window_width and height (207 and 333) and use them to create the window and then for reset it when size change.
    Niara

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>I would like to add a style ...that would disable resizing of the parent window<<

    Make sure your window doesn't have the WS_THICKFRAME window style (WS_OVERLAPPEDWINDOW includes that style).

    If you still want all of the other styles associated with WS_OVERLAPPEDWINDOW then replace that parameter of your CreateWindowEx call with:
    Code:
    WS_OVERLAPPEDWINDOW&~WS_THICKFRAME
    - or just OR the styles as you see fit.

    If you need to control window dimensions at runtime then handle WM_GETMINMAXINFO messages; search this board for examples of its use.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    135
    There's many ways to do what you want. The following is one of the ways I usually did it:

    Code:
    	case WM_GETMINMAXINFO :
    		((MINMAXINFO*)lParam)->ptMinTrackSize.x = XSIZE_WANTED;
    		((MINMAXINFO*)lParam)->ptMinTrackSize.y = YSIZE_WANTED;
    		return 0;
    You now have a fixed constant size and you didn't need to change the windows border look [smile].

    xeddiex.

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    69
    When I want to disable resizing I usually start with WS_DLGFRAME instead of WS_OVERLAPPEDWINDOW and build it up from there.

    For example: WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX

    Now that might not be quite the 'look' you want for your calculator but you can swap other style options in or out and it gives you one more possible approach to the problem.

    Regards,
    Brian

  6. #6
    Registered User
    Join Date
    Oct 2005
    Posts
    10
    Hellow;

    Code:
        hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "calculator",       /* Title Text */
               WS_CAPTION|WS_SYSMENU|WS_VISIBLE|WS_MINIMIZEBOX, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               207,                 /* The programs width */
               333,                 /* 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 */
               );
    Bye

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 05:05 AM
  2. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 11:50 AM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  4. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 02: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