win32 - 创建带有标准阴影的无边框窗口
这个框框好像删不掉,就先放这边吧。。。
#define WIN32_LEAN_AND_MEAN
#include <unknwn.h>
#include <windows.h>
#include <dwmapi.h>
#include <gdiplus.h>
#include <objidl.h> using namespace Gdiplus; #pragma comment(lib, "dwmapi.lib")
#pragma comment(lib, "gdiplus.lib") INT_PTR CALLBACK MyDialogProc(HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam); int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine,
_In_ int nCmdShow) {
// Initialize GDI+
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdipToken = 0;
Gdiplus::GdiplusStartup(&gdipToken, &gdiplusStartupInput, nullptr); struct MyDialog : DLGTEMPLATE {
WORD dummy[3] = {0}; // unused menu, class and title
} dlg;
dlg.style = WS_POPUP | WS_CAPTION | DS_CENTER;
dlg.dwExtendedStyle = 0;
dlg.cdit = 0; // no controls in template
dlg.x = 0;
dlg.y = 0;
dlg.cx = 300; // width in dialog units
dlg.cy = 200; // height in dialog units DialogBoxIndirectW(hInstance, &dlg, nullptr, MyDialogProc); Gdiplus::GdiplusShutdown(gdipToken); return 0;
} INT_PTR CALLBACK MyDialogProc(HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam) {
switch (message) {
case WM_INITDIALOG: {
SetWindowTextW(hDlg, L"Borderless Window with Shadow"); // This plays together with WM_NCALCSIZE.
MARGINS m{0, 0, 0, 1};
DwmExtendFrameIntoClientArea(hDlg, &m); // Force the system to recalculate NC area (making it send WM_NCCALCSIZE).
SetWindowPos(hDlg, nullptr, 0, 0, 0, 0,
SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE |
SWP_FRAMECHANGED);
return TRUE;
}
case WM_NCCALCSIZE: {
// Returning 0 from the message when wParam is TRUE removes the standard
// frame, but keeps the window shadow.
if (wParam == TRUE) {
SetWindowLong(hDlg, DWL_MSGRESULT, 0);
return TRUE;
}
return FALSE;
}
case WM_PAINT: {
PAINTSTRUCT ps{0};
HDC hdc = BeginPaint(hDlg, &ps); // Draw with GDI+ to make sure the alpha channel is opaque.
Gdiplus::Graphics gfx{hdc};
Gdiplus::SolidBrush brush{Gdiplus::Color{255, 255, 255}};
int x = ps.rcPaint.left;
int y = ps.rcPaint.top;
int width = ps.rcPaint.right - ps.rcPaint.left;
int height = ps.rcPaint.bottom - ps.rcPaint.top;
gfx.FillRectangle(&brush, x, y, width, height); EndPaint(hDlg, &ps);
return TRUE;
}
case WM_NCHITTEST: {
// Returning HTCAPTION allows the user to move the window around by
// clicking anywhere. Depending on the mouse coordinates passed in LPARAM,
// you may return other values to enable resizing.
SetWindowLong(hDlg, DWL_MSGRESULT, HTCAPTION);
return TRUE;
}
case WM_COMMAND: {
WORD id = LOWORD(wParam);
if (id == IDOK || id == IDCANCEL) {
EndDialog(hDlg, id);
return TRUE;
}
return FALSE;
}
}
return FALSE; // return FALSE to let DefDialogProc handle the message
}
结果:

相关文章: Borderless Window with Drop Shadow
github上另外一篇教程:https://github.com/melak47/BorderlessWindow#borderlesswindow
拓展:
如果想要启用drop shadow效果,可以使用CS_DROPSHADOW样式,子窗口不可用。
ULONG_PTR cNewStyle = GetClassLongPtr(hWnd, GCL_STYLE) | CS_DROPSHADOW;
SetClassLongPtr(hWnd, GCL_STYLE, cNewStyle);
win32 - 创建带有标准阴影的无边框窗口的更多相关文章
- 让Qt的无边框窗口支持拖拽、Aero Snap、窗口阴影等特性
环境:Desktop Qt 5.4.1 MSVC2013 32bit 需要的库:dwmapi.lib .user32.lib 需要头文件:<dwmapi.h> .<windowsx. ...
- 如何在pyqt中给无边框窗口添加DWM环绕阴影
前言 在之前的博客<如何在pyqt中通过调用SetWindowCompositionAttribute实现Win10亚克力效果>中,我们实现了窗口的亚克力效果,同时也用SetWindowC ...
- 如何在pyqt中在实现无边框窗口的同时保留Windows窗口动画效果(一)
无边框窗体的实现思路 在pyqt中只要 self.setWindowFlags(Qt.FramelessWindowHint) 就可以实现边框的去除,但是没了标题栏也意味着窗口大小无法改变.窗口无法拖 ...
- 【转】MFC 无边框窗口的拖动
MFC中无边框窗口的拖动 void CXXXXDialog::OnLButtonDown(UINT nFlags, CPoint point) { PostMessage(WM_NCLBUTTONDO ...
- electron关于无边框窗口无法拖拽移动以及点击事件失效的问题
为了使窗口无边框,使得在某些时候让项目看起来更美观,所以在创建窗口的时候通过设置 frame 属性的值为 false 来创建无边框窗口.但是无边框窗口会产生无法移动的问题,对于这个问题我们可以在渲染进 ...
- pyqt5设计无边框窗口(一)
import sys from PyQt5 import QtGui,QtCore from PyQt5 import QtCore, QtGui, QtWidgets ############### ...
- 如何在pyqt中自定义无边框窗口
前言 之前写过很多关于无边框窗口并给窗口添加特效的博客,按照时间线罗列如下: 如何在pyqt中实现窗口磨砂效果 如何在pyqt中实现win10亚克力效果 如何在pyqt中通过调用SetWindowCo ...
- WPF系列:无边框窗口
<Window x:Class="Ares.Animations.Window3" xmlns="http://schemas.microsoft.com/winf ...
- Qt5:无边框窗口拖动
在窗口程序中,无边框窗口程序一般需要特殊处理才能拖动 Qt中,要实现无边框窗口的拖动,需要重新实现 mousePressEvent 和 mouseMoveEvent 俩虚函数 void Widget: ...
- 【Qt编程】基于Qt的词典开发系列<五>--无边框窗口的拖动
在上一篇文章中,我们讲述了如何进行无边框窗口的缩放与拖动,而在一些情况下,我们的窗口只需要进行拖动也不需要改变其大小,比如:QQ的登录窗口.本来在上一篇文章中已经讲述了如何进行窗口的拖动,但是却与窗口 ...
随机推荐
- [转帖]Linux终端:用cat命令查看不可见字符
https://developer.aliyun.com/article/80607 printf 'testing\012\011\011testing\014\010\012more testin ...
- 【转帖】数据库篇-MySql架构介绍
https://zhuanlan.zhihu.com/p/147161770 公众号-坚持原创,码字不易.加微信 : touzinv 关注分享,手有余香~ 本篇咱们也来聊聊mysql物理和逻辑架构,还 ...
- 【转帖】3.JVM内存结构概述
目录 1.JVM内存结构 1.JVM内存结构 在JVM系列的第一篇文章中已经给出了JVM内存结构的简图,下面是JVM内存结构更加详细的图. 同样,JVM的内存结构可以分为上中下3层. 上层主要是类加载 ...
- [转帖]Docker、containerd的关系
Docker.containerd的关系 containerd囊括了单机运行一个容器时所需要的一切: 为了能够支持多种OCI Runtime,containerd 内部使用containerd-shi ...
- [转帖]FT-2000+/64 - Phytium
https://en.wikichip.org/wiki/phytium/feiteng/ft-2000%2B-64 Edit Values FT-2000+/64 General Info De ...
- Linux时间戳转换成易读格式的方法
背景 最近一直在学习Redis相关的知识. 其中遇到了一个redis monitor的命令 但是这里有一个问题是: 原生命令查询出来的时间是Unix时间戳格式的. 不太好发现查看与进行对照. 所以今天 ...
- ESXi6.5 登录后出现错误 必须 退出的解决办法
- KD-Tree 小记🐤
KD-Tree,是用来维护一个空间(其实一般是平面)中的信息的数据结构. 以下就 2D-Tree 进行讨论.(盲猜并不会考 3D 及以上) 思想:将一个大矩形以一种方式划分成若干个小矩形,然后询问时只 ...
- React中函数组件与类组件的两种使用
React 创建组件的两种方式 函数组件:使用js函数创建的组件 约定1:函数名称必须以大写字母开头 约定2:函数组件必须要有返回值. 如果返回值为null.表示不渲染任何内容. return nul ...
- Go 泛型之明确使用时机与泛型实现原理
目录 一.引入 二.何时适合使用泛型? 场景一:编写通用数据结构时 场景二:函数操作的是 Go 原生的容器类型时 场景三:不同类型实现一些方法的逻辑相同时 三.Go 泛型实现原理 Stenciling ...