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的登录窗口.本来在上一篇文章中已经讲述了如何进行窗口的拖动,但是却与窗口 ...
随机推荐
- [转帖]无需 zookeeper 安装 kafka 集群 (kakfa3.0 版本)
https://xie.infoq.cn/article/7769ef4576a165f7bdf142aa3 一.kafka 集群实例角色规划 在 kafka3.0 中已经可以将 zookeeper ...
- [转帖]Redis压力测试——redis-benchmark
liunx 安装 redis & redis benchmark 1.下载安装包 点击官网,下载stable版本 wget http://download.redis.io/releases/ ...
- ContextSwitch 学习与使用
ContextSwitch 学习与使用 说明 github上面有一个简单的测试系统调用以及上下文切换的工具. contextswitch. 下载之后直接make就可以进行简单的测试 需要注意的是 部分 ...
- ESXi6.7安装Win11的方法
背景 公司里面要进行新的操作系统验证了. 之前Win10 Win7 Win8 都比较简单. 就是现在Win11有了TPM非常繁琐. 今天必须得搞一把了,就简单搜索了下. 发现还是可以解决的. 然后记录 ...
- IIS 实现autoindex的简单方法 能够下载文件等.
之前使用nginx 的autoindex on 的参数 能够实现了 nginx的 目录浏览查看文件 但是那是linux上面的 windows 上面很多 使用的 其实是 iis的居多 然后看了下 其实也 ...
- ESXi重置密码以及修改网络IP地址的方法
Study From https://www.cnblogs.com/mk21/p/15784082.html 前期公司有部分虚拟化的服务器因为只通过vCenter进行管理. 导致密码遗失. 最近因为 ...
- JRC Flink流作业调优指南
# 作者:京东物流 康琪 本文综合Apache Flink原理与京东实时计算平台(JRC)的背景,详细讲述了大规模Flink流作业的调优方法.通过阅读本文,读者可了解Flink流作业的通用调优措施,并 ...
- es6新增的运算符-链判断运算符的诞生[?.]和null的判断运算符??
指数运算符 ** console.log(2 ** 2 ) //4 console.log(2 ** 3 ) //8 console.log(2 ** 4) //16 链判断运算符的诞生(?.) 在实 ...
- 【代码片段】fasthttp 中的输出使用 gzip 压缩
作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢! cnblogs博客 zhihu Github 公众号:一本正经的瞎扯 直接上代码: import ( "github. ...
- 【K哥爬虫普法】老铁需要车牌靓号吗?判刑的那种
我国目前并未出台专门针对网络爬虫技术的法律规范,但在司法实践中,相关判决已屡见不鲜,K 哥特设了"K哥爬虫普法"专栏,本栏目通过对真实案例的分析,旨在提高广大爬虫工程师的法律意识, ...