创建一个没有标题和边框的窗口 [英] Creating a window without caption and border

查看:43
本文介绍了创建一个没有标题和边框的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 CreateWindowEx() 创建一个没有标题和边框的窗口?我为什么你用'|'OR 运算符来组合样式而不是&"还有?

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?

推荐答案

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

如果需要边框,可以添加 WS_BORDER 或 WS_DLGFRAME(不能同时添加).如果不想在任务栏中显示窗口,请添加 WS_EX_TOOLWINDOW 扩展样式.

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.

至于为什么需要按位或样式;OR 将组合所有样式值,AND 用于(由 Windows)检查设置了哪些样式.假设我们有两种样式 (WS_FOO=1,WS_BAR=2):

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(二进制:01 AND 10 = 00)
  • 1 OR 2 = 3(二进制:01 OR 10 = 11)

有关详细信息,请参阅维基百科.

See wikipedia for more info.

这篇关于创建一个没有标题和边框的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆