您可以在Windows中创建无边界应用程序主窗口,无WS_POPUP风格? [英] Can you make a Borderless Application Main Window in Windows, without WS_POPUP style?

查看:206
本文介绍了您可以在Windows中创建无边界应用程序主窗口,无WS_POPUP风格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个窗口,这个窗口将成为主窗口,Windows将其视为主应用程序窗口。然而,当我使我的窗口无边界,没有任何非客户端区域,Windows不再认识到这个窗口是一个应用程序主窗口。这有几个副作用:

I want to create a window that will be the main window and that Windows itself recognizes as a main application window. However, when I make my window borderless, and without any non-client area at all, Windows no longer recognizes that this window is an application main window. This has several side effects:


  1. WindowsKey + M最大限度地减少了我应用程序主窗口以外的所有窗口。

  1. WindowsKey+M minimizes all windows except my application's main window.

在任务栏上单击一次(在win7中),然后再次应该在应用程序主窗口的状态/可见性之间切换正常和最小化状态。对于这样的窗口,这不起作用。

Clicking once on the taskbar (in win7) and then again, should toggle the application main window's state/visibility between normal and minimized state. This does not work for such a window.

在Win32编程术语中,我询问参数值 dwStyle ,当调用 CreateWindow (WS _...常量)或CreateWindowEx( WS_EX _...常量)。对于delphi用户,这些值将在CreateParams方法中设置,您将被覆盖,然后设置Params.Style:= WS_xxx;对于MFC / C ++用户和C用户,您的框架中的某些东西最终将以此dwStyle值调用CreateWindow。

In bare Win32 programming terms, I'm asking about parameter values for dwStyle as when calling CreateWindow (WS_... constants), or CreateWindowEx (WS_EX_... constants). For delphi users, these values would be set in the CreateParams method, which you would override, and then set Params.Style := WS_xxx; For MFC/C++ users and C users, something in your framework would eventually be calling CreateWindow, with this dwStyle value.

在delphi中,设置form.BorderStyle = bsNone ,导致dwStyle = WS_POPUP。但是我想要一个无边界的窗口,而不使用dwStyle = WS_POPUP。

In delphi terms, setting your form.BorderStyle=bsNone, results in dwStyle=WS_POPUP. However I want a borderless window without using dwStyle=WS_POPUP.

注意:以下所有答案都是好的,但是在生产场景中使用每个都是有问题的,我尝试做所以,已经遇到了很多毛刺,对于一个专业的质量应用,我仍然发现我无法解决。戴维斯的答案是一个伟大的纯Win32 API答案,但符合条例草案。看来,工业实力解决方案应该结合多种素质,包括我在上述问题上所有的素质。简而言之,使用BorderStyle = bsNone(dwStyle = WS_POPUP)的无边界形式阻止通常适用于应用程序主窗口的所有Windows功能,下面的所有解决方案都解决了其中的一部分。

Note: All the answers below are good, but using each in production scenarios is problematic, and my attempts to do so, have resulted in encountering many glitches, which for a professional quality application, I still find I can not work around. Davids answer is a great pure Win32 API answer though, and fits the bill. It seems that an industrial strength solution should combine multiple qualities, including all those I have in my question above. In short, borderless forms using BorderStyle=bsNone (dwStyle=WS_POPUP) block all Windows functionality that usually applies to main windows of applications, and all the solutions below solve part of it.

根据David的建议,我写了以下内容,这不起作用:
我想要一个没有边框的窗口,其行为方式如下一个Windows应用程序窗口,即系统,即可以通过单击任务栏中的窗口进行最小化/恢复,并将WindowsKey + M最小化。我开始认为,唯一的方法是添加非客户端的paint代码,并将顶层的非客户端区域的大小调整为零。这当然不是一个微不足道的想法。

Based on David's suggestions, I wrote the following, which doesn't work: I want a window without a border, that behaves in all ways, like a windows application window, to the system, that is, it can be minimized/restored by clicking on the window in the taskbar, and will be minimized by WindowsKey+M. I am beginning to think that the only way to do this is to add non-client paint code and to resize the top nonclient area bounds to zero. This is of course not a trivial idea.

事实证明,我在编码中犯了一个简单的错误(因此是上面的两段),实际上下面的代码现在按照我的愿望工作。这是一个pascal,但它应该很容易将其转换为C ++或其他任何东西。

It turns out that I made a simple mistake in my coding (hence the two paragraphs above) and in fact the code below does now work as I desire. This one is in pascal, but it should be easy to convert it to C++ or anything else.

program NoBorderProject;

uses
  Windows, Messages;
  {the Messages unit contains the windows
  Message constants like WM_COMMAND}

{$R *.RES}

var
  wClass: TWndClass;
  Msg: TMsg;
  win:HWND;
function WindowProc(hWnd,Msg,wParam,lParam:Integer):Integer; stdcall;
begin
 if Msg = WM_DESTROY then PostQuitMessage(0);
 Result := DefWindowProc(hWnd,Msg,wParam,lParam);
end;

begin
 wClass.lpszClassName:= 'CN';
 wClass.lpfnWndProc :=  @WindowProc;
 wClass.hInstance := hInstance;
 wClass.hbrBackground:= 1;
 RegisterClass(wClass);
 win := CreateWindow(wClass.lpszClassName,'Title Bar',
              WS_POPUP,//WS_OVERLAPPEDWINDOW or WS_VISIBLE,
              10,10,340,220,0,0,hInstance,nil);
 SetWindowLong(win, GWL_STYLE, WS_POPUP or WS_MINIMIZEBOX);
 SetWindowLong(win, GWL_EXSTYLE, 0 );
 ShowWindow(win,SW_SHOW);
 while GetMessage(Msg,0,0,0) do
   DispatchMessage(Msg);
end. 


推荐答案

以下功能完成:

hWnd = CreateWindow(...);
SetWindowLong(hWnd, GWL_STYLE, WS_POPUP | WS_MINIMIZEBOX);
SetWindowLong(hWnd, GWL_EXSTYLE, 0);
ShowWindow(hWnd, ...);

您可能缺少 WS_MINIMIZEBOX

这篇关于您可以在Windows中创建无边界应用程序主窗口,无WS_POPUP风格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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