Creating a window without caption and border

前端 未结 1 1820
被撕碎了的回忆
被撕碎了的回忆 2021-01-02 11:08

How can you create a window without caption and border using CreateWindowEx()? And I why do you use \'|\' OR operator to combine styles instead of \'&\' And?

相关标签:
1条回答
  • 2021-01-02 11:26
    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 a border, you can add WS_BORDER or WS_DLGFRAME (Not both). If you don't want to show the window in the taskbar, add the WS_EX_TOOLWINDOW extended style.

    As to why you need to bitwise OR the styles; OR will combine all the style values, AND is used (by windows) to check which styles are set. 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 info.

    0 讨论(0)
提交回复
热议问题