Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a window without caption and border

Tags:

winapi

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?

like image 974
cpx Avatar asked Aug 22 '10 07:08

cpx


1 Answers

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.

like image 76
Anders Avatar answered Nov 14 '22 19:11

Anders