Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

win32 c++ set window location to the right-down corner

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
        );

1 Answers

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.

like image 51
Rita Han Avatar answered Sep 20 '25 19:09

Rita Han