3

How to set a window to the right-down corner of the screen (not including the taskbar)? Can I accomplish it with CreateWindowEx? But I only saw CW_USEDEFAULT and there is no CW_ to set it to the corner.

HWND hwnd = CreateWindowEx(
            NULL,
            DUCKPROC_CLASS_NAME,
            DUCKPROC_WINDOW_TIP_NAME,
            WS_BORDER| WS_VISIBLE,
            CW_USEDEFAULT,
            CW_USEDEFAULT, 
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            NULL,
            NULL,
            GetModuleHandle(NULL),
            NULL
        );
  • 2
    You can provide required window coordinates instead of CW_USEDEFAULT values. – user7860670 Oct 10 '19 at 07:40
  • 1
    Also look at `SystemParametersInfo`: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa to retrieve the screen coordinate and taskbar size. You will have to use those data to calculate and set the position of your window – Asesh Oct 10 '19 at 07:44

1 Answers1

3

This is an example of placing the window to right bottom corner. (Here I set window's width and height are both 200.)

   RECT desktopRect;
   if (!GetWindowRect(GetDesktopWindow(), &desktopRect))
       return FALSE;

   int windowWidth = 200;
   int windowHeight = 200;
   int posX = desktopRect.right - windowWidth;
   int posY = desktopRect.bottom - windowHeight;
   HWND hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
       posX, posY, windowWidth, windowHeight, nullptr, nullptr, hInstance, nullptr);

You can use CreateWindowEx but you don't have to because:

Creates an overlapped, pop-up, or child window with an extended window style; otherwise, this function is identical to the CreateWindow function.

Rita Han
  • 9,574
  • 1
  • 11
  • 24