1

I have a university assignment for my programming class to set up a C++/Win32API script which would use tiny windows to show an analog clock.

All fine and dandy but I cannot figure out how to resize a window to less than ~17 px.

I tried to handle the

case WM_GETMINMAXINFO:
{
    MINMAXINFO* mmi = (MINMAXINFO*)lParam;
    mmi->ptMinTrackSize.x = 1; // doesn't do anything below 18-20
    mmi->ptMinTrackSize.y = 1; // same as above
    return 0;
}

yet the window doesn't want to resize below around 17 pixels in width or height.

I use the following code to create the windows

   hWnd = CreateWindowEx(
        WS_EX_TOOLWINDOW,
        szWindowClass,
        _T( "tool" ),
        WS_EX_TOOLWINDOW,
        300 + ( 20 * i ), // x
        150, // y
        1, // width
        1, // height
        NULL, 
        NULL, 
        hInstance, 
        NULL
    );
   SetWindowLong(hWnd, GWL_STYLE, 0); // remove borders

the orange boxes are 18 little windows that I tried to create: the orange boxes are 18 little windows that I tried to create

Asmodiel
  • 1,002
  • 1
  • 12
  • 21
  • 4
    I think that this size is for the client area. You will also need to remove the non-client area to get smaller sizes. – RedX Mar 10 '14 at 15:15
  • The `WS_EX_TOOLWINDOW` adds a title bar to the window. You must remove that. You're window must not have non-client areas. – Marius Bancila Mar 10 '14 at 15:16
  • 3
    Why are you creating little boxes as windows? Wouldn't custom paint handling in the parent window do the job? – Skizz Mar 10 '14 at 15:26
  • Skizz: I'm creating them as windows because the task says so :/ RedX: How do I do that? Marius Bancila: The WS_EX_TOOLWINDOW just makes it not appear in the taskbar – Asmodiel Mar 11 '14 at 11:17
  • I've just noticed that you're passing an extended style value for the standard style parameter. That's going to produce unusual effects. Just pass WS_OVERLAPPED (which is 0) as the fourth parameter to CreateWindowEx and you won't need the SetWindowLong that comes after it. – Skizz Mar 14 '14 at 15:36
  • If the task requires 1x1 sized windows, then it's a really bad task and teaching some bad techniques. A window has overheads, both in terms of resources and processing. – Skizz Mar 14 '14 at 15:45
  • not necessarily. in Windows, many lightweight controls are windows (and have a hWnd). – Cee McSharpface Jul 13 '21 at 07:37

1 Answers1

0

The correct combination of window style flags to achieve this, is the following:

WS_POPUP | WS_BORDER | WS_VISIBLE

The call to SetWindowLong is not needed. If you really want no border, you can omit the WS_BORDER flag. What WS_POPUP does, is to suppress the non-client area of the window entirely. Therefore, no minimums apply and you can make the window as small as 1 x 1 px.

hWnd = CreateWindow(
    szWindowClass,
    0,
    WS_POPUP | WS_BORDER | WS_VISIBLE,
    300 + (20 * i),
    150,
    1,
    1,
    nullptr,
    nullptr,
    hInstance,
    this
);

See also:
How can I remove a window's non-client area completely?
https://stackoverflow.com/a/43819334/1132334

Tested on a Windows 10 Version 2004.

Cee McSharpface
  • 8,493
  • 3
  • 36
  • 77