这个框框好像删不掉,就先放这边吧。。。
 
#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 - 创建带有标准阴影的无边框窗口的更多相关文章

  1. 让Qt的无边框窗口支持拖拽、Aero Snap、窗口阴影等特性

    环境:Desktop Qt 5.4.1 MSVC2013 32bit 需要的库:dwmapi.lib .user32.lib 需要头文件:<dwmapi.h> .<windowsx. ...

  2. 如何在pyqt中给无边框窗口添加DWM环绕阴影

    前言 在之前的博客<如何在pyqt中通过调用SetWindowCompositionAttribute实现Win10亚克力效果>中,我们实现了窗口的亚克力效果,同时也用SetWindowC ...

  3. 如何在pyqt中在实现无边框窗口的同时保留Windows窗口动画效果(一)

    无边框窗体的实现思路 在pyqt中只要 self.setWindowFlags(Qt.FramelessWindowHint) 就可以实现边框的去除,但是没了标题栏也意味着窗口大小无法改变.窗口无法拖 ...

  4. 【转】MFC 无边框窗口的拖动

    MFC中无边框窗口的拖动 void CXXXXDialog::OnLButtonDown(UINT nFlags, CPoint point) { PostMessage(WM_NCLBUTTONDO ...

  5. electron关于无边框窗口无法拖拽移动以及点击事件失效的问题

    为了使窗口无边框,使得在某些时候让项目看起来更美观,所以在创建窗口的时候通过设置 frame 属性的值为 false 来创建无边框窗口.但是无边框窗口会产生无法移动的问题,对于这个问题我们可以在渲染进 ...

  6. pyqt5设计无边框窗口(一)

    import sys from PyQt5 import QtGui,QtCore from PyQt5 import QtCore, QtGui, QtWidgets ############### ...

  7. 如何在pyqt中自定义无边框窗口

    前言 之前写过很多关于无边框窗口并给窗口添加特效的博客,按照时间线罗列如下: 如何在pyqt中实现窗口磨砂效果 如何在pyqt中实现win10亚克力效果 如何在pyqt中通过调用SetWindowCo ...

  8. WPF系列:无边框窗口

    <Window x:Class="Ares.Animations.Window3" xmlns="http://schemas.microsoft.com/winf ...

  9. Qt5:无边框窗口拖动

    在窗口程序中,无边框窗口程序一般需要特殊处理才能拖动 Qt中,要实现无边框窗口的拖动,需要重新实现 mousePressEvent 和 mouseMoveEvent 俩虚函数 void Widget: ...

  10. 【Qt编程】基于Qt的词典开发系列<五>--无边框窗口的拖动

    在上一篇文章中,我们讲述了如何进行无边框窗口的缩放与拖动,而在一些情况下,我们的窗口只需要进行拖动也不需要改变其大小,比如:QQ的登录窗口.本来在上一篇文章中已经讲述了如何进行窗口的拖动,但是却与窗口 ...

随机推荐

  1. [转帖]Nginx四层负载均衡详解

    https://developer.aliyun.com/article/885599?spm=a2c6h.24874632.expert-profile.315.7c46cfe9h5DxWK 202 ...

  2. [转帖]CKA 真题

    https://segmentfault.com/a/1190000021380185   1.列出pod并排序 kubectl get pod --sort-by .metadata.name 题目 ...

  3. ESXi 虚拟机性能情况简单验证

    1.虚拟化的CPU超售问题. 经过查找资料, 发现 ESXi 5.5 的版本 一个 物理CPU的Core 可以虚拟出 25个vCPU, 升级到ESXi6.0 之后可以虚拟化32个vCPU. 所以虚拟化 ...

  4. 查看 Oracle 数据库内 没有Primary key 类型主键的表信息

    查看 Oracle 数据库内 没有Primary key 类型主键的表信息 SELECT * FROM user_tables A WHERE NOT EXISTS ( SELECT * FROM u ...

  5. Oracle 建立数据库dblink 然后同步部分表内容的总结

    同步处理部分数据 背景 最近在项目上发现两个分库进行数据同步时部分内容同步存在问题. 最简单的方法是导表,但是害怕有其他关联信息异常, 所以同事想到了dblink的方式. 这里简单整理一下 同事用到的 ...

  6. 文盘Rust -- 如何把配置文件打包到二进制文件里

    ​在实际开发中,经常会遇到各种不同的配置文件.通常,程序运行的各种配置从外部读取,以增强应用配置的灵活性.java 生态中的 springboot 提供了这种设计的典范.springboot 的应用程 ...

  7. export default 和 export 这两种方式导出的区别

    参考地址 https://blog.csdn.net/sleepwalker_1992/article/details/81461543 使用export向外暴露的成员,只能使用{ }的形式来接收,这 ...

  8. svn把文件日期设置为最后提交的时间

    在使用svn进行checkout或update时,我想让文件的日期为提交那时的日期,这要怎样做? 说明:我是在windows下使用TortoiseSVN进行操作的 方法1.修改config [misc ...

  9. 【四】多智能体强化学习(MARL)近年研究概览 {Learning cooperation(协作学习)、Agents modeling agents(智能体建模)}

    相关文章: [一]最新多智能体强化学习方法[总结] [二]最新多智能体强化学习文章如何查阅{顶会:AAAI. ICML } [三]多智能体强化学习(MARL)近年研究概览 {Analysis of e ...

  10. window hadoop yarn任务执行失败:ExitCodeException exitCode=-1073741515

    环境 window server 2019 单机版hadoop3.3.1 和 winutils.exe 异常 winutils.exe task create -m -1 -c -1 continer ...