C++ 用win32打开一个没有标题栏的窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7442939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 16:56:30  来源:igfitidea点击:

opening a window that has no title bar with win32

c++windowswinformswin32gui

提问by blejzz

I'm developing a c++ application for windows. I'm using win32 API. I have a very simple question, which i couldn't find an answer to. How can i open a window without a title bar (without controls, icon and title) and that can not be resized.

我正在为 Windows 开发一个 C++ 应用程序。我正在使用 win32 API。我有一个非常简单的问题,我找不到答案。如何打开没有标题栏(没有控件、图标和标题)且无法调整大小的窗口。

Piece of code that i am using for the application to create a window:

我用于应用程序创建窗口的一段代码:

      hWnd = CreateWindow(szWindowClass, 0, (WS_BORDER ),
             0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL);

UPDATE:

更新:

To do this in c#, you just define this code:

要在 c# 中执行此操作,您只需定义以下代码:

 FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
 ControlBox = false;

回答by Mike

hWnd = CreateWindow(szWindowClass, 0, (WS_BORDER ), 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL); 

SetWindowLong(hWnd, GWL_STYLE, 0); //remove all window styles, check MSDN for details

ShowWindow(hWnd, SW_SHOW); //display window

回答by mohammad bagher kenari

HWND hWnd ;
hWnd = CreateWindow(szWindowClass, 0, (WS_BORDER ), 0, 0, 100, 100, NULL, NULL, Instance, NULL); 
SetWindowLong(hwnd, GWL_STYLE, WS_BORDER );  // With 1 point border
//OR
SetWindowLong(hwnd, GWL_STYLE, 0 );  // Without 1 point border = white rectangle 
SetWindowPos(hwnd, 0, 150, 100, 250, 250, SWP_FRAMECHANGED); 

if (!hWnd)
 return FALSE ;
else
ShowWindow(hwnd, SW_SHOW);

回答by Dede Kusuma

CreateWindowEx(0, szWindowClass, 0, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL);

using SetWindowLongwill change the size and post. use the WS_POPUPstyle

使用SetWindowLong将改变大小和帖子。使用WS_POPUP样式

回答by Talim

SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW);