Creating a window without a title and border

How to create a window without a title and frame using CreateWindowEx ()? And why do you use '|' OR to combine styles instead of '&' And?

+3
source share
1 answer
int WINAPI WinMain(....)
{
    MSG msg;
    WNDCLASS wc={0};
    wc.lpszClassName="MyClass";
    wc.lpfnWndProc=DefWindowProc;//You MUST use your own wndproc here
    wc.hInstance=hInstance;
    wc.hbrBackground=(HBRUSH)(COLOR_3DFACE+1);
    wc.hCursor=LoadCursor(NULL,IDC_ARROW);
    if (!RegisterClass(&wc)) {/*Handle Error*/}
    HWND hwnd;
    hwnd=CreateWindowEx(0,wc.lpszClassName,0,WS_POPUP|WS_VISIBLE|WS_SYSMENU,9,9,99,99,0,0,0,0);
    if (!hwnd) {/*Handle Error*/}
    while(GetMessage(&msg,0,0,0)>0)DispatchMessage(&msg);
    return 0;
}

If you want to get the border, you can add WS_BORDER or WS_DLGFRAME (not both). If you do not want to show the window on the taskbar, add the advanced style WS_EX_TOOLWINDOW.

What do you need for bitwise OR styles; OR will combine all the values โ€‹โ€‹of the style, and is used (by window) to check which styles are set. Let's say we had two styles (WS_FOO = 1, WS_BAR = 2):

  • 1 AND 2 = 0 (binary: 01 AND 10 = 00)
  • 1 OR 2 = 3 (binary: 01 OR 10 = 11)

See wikipedia for more details .

+5

Source: https://habr.com/ru/post/1760966/


All Articles