话不多说,先验货:

(原始状态)

(最大化状态)

(对比图)

为自己鼓掌!!!

哈哈,捣鼓2天终于把这个搞出来了!虽然代码一团糟,但是不难理解!

要实现这个功能需要几个组件:DWM,GDI+

在实现这个代码中我认为最困难的就是chrome边框的阴影部分~

(这里的2个像素的阴影)

和本身客户区边框的1个黑色像素,这1个像素IE11没有处理,而CHROME却没有这个黑边:

最开始使用GDI,但是GDI不带有Alpha通道,导致在画阴影时画出来的是实线,所以换成GDI+,下面是实现效果(没有采用圆角矩形,因为GDI+没有直接绘制圆角矩形的接口):

好了,上代码:

 # include <windows.h>
#include <windowsx.h>
# include <stdio.h>
# include <stdlib.h>
#include "dwmapi.h"
#include "resource.h"
#include <gdiplus.h>
using namespace Gdiplus; const int TOPEXTENDWIDTH = ;
const int TOPEXTENDWIDTHMAX = ;
const int BOTTOMEXTENDWIDTH = ;
const int LEFTEXTENDWIDTH = ;
const int RIGHTEXTENDWIDTH = ; LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
LRESULT AppWinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CustomCaptionProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool* pfCallDWP); bool formstateMax=false; LRESULT HitTestNCA(HWND hWnd, WPARAM wParam, LPARAM lParam)
{ POINT ptMouse = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; RECT rcWindow;
GetWindowRect(hWnd, &rcWindow); RECT rcFrame = { };
AdjustWindowRectEx(&rcFrame, WS_OVERLAPPEDWINDOW & ~WS_CAPTION, FALSE, NULL); USHORT uRow = ;
USHORT uCol = ;
bool fOnResizeBorder = false; if (ptMouse.y >= rcWindow.top && ptMouse.y < rcWindow.top + (formstateMax?TOPEXTENDWIDTHMAX:TOPEXTENDWIDTH) )
{
fOnResizeBorder = (ptMouse.y < (rcWindow.top - rcFrame.top));
uRow = ;
}
else if (ptMouse.y < rcWindow.bottom && ptMouse.y >= rcWindow.bottom - BOTTOMEXTENDWIDTH)
{
uRow = ;
} if (ptMouse.x >= rcWindow.left && ptMouse.x < rcWindow.left + LEFTEXTENDWIDTH)
{
uCol = ;
}
else if (ptMouse.x < rcWindow.right && ptMouse.x >= rcWindow.right - RIGHTEXTENDWIDTH)
{
uCol = ;
} // Hit test (HTTOPLEFT, ... HTBOTTOMRIGHT)
LRESULT hitTests[][] =
{
{ HTTOPLEFT, fOnResizeBorder ? HTTOP : HTCAPTION, HTTOPRIGHT },
{ HTLEFT, HTNOWHERE, HTRIGHT },
{ HTBOTTOMLEFT, HTBOTTOM, HTBOTTOMRIGHT },
}; return hitTests[uRow][uCol];
} int RECTWIDTH(RECT trec)
{
int rWidth = ;
rWidth = trec.right - trec.left;
return rWidth;
} int RECTHEIGHT(RECT trec)
{
int rHeight = ;
rHeight = trec.bottom - trec.top;
return rHeight;
} void ReDrawExtendFrame(HWND hWnd)
{
MARGINS margins; margins.cxLeftWidth = LEFTEXTENDWIDTH;
margins.cxRightWidth = RIGHTEXTENDWIDTH;
margins.cyBottomHeight = BOTTOMEXTENDWIDTH;
if (formstateMax)
margins.cyTopHeight = TOPEXTENDWIDTHMAX;
else
margins.cyTopHeight = TOPEXTENDWIDTH; int hr = DwmExtendFrameIntoClientArea(hWnd, &margins); if (!SUCCEEDED(hr))
{ }
} int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
static TCHAR szAppName [] = TEXT("Pavkoo SChrome");
int address = (int)hInstance;
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken,&gdiplusStartupInput,NULL);
wndclass.style = CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = ;
wndclass.cbWndExtra = ;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szAppName;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("This program requires Windows NT!"),szAppName,MB_ICONERROR);
return ;
}
hwnd=CreateWindow(szAppName,TEXT("Schrome"),WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd); while(GetMessage(&msg,NULL,,))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GdiplusShutdown(gdiplusToken);
return msg.wParam;
} LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
bool fCallDWP = true; //是否需要将消息传递给默认的窗口处理程序,如果是重绘窗体框架就不用传递消息了!
BOOL fDwmEnabled = FALSE;
LRESULT lRet = ;
HRESULT hr = S_OK; // 判断Aero Glass是否开启
hr = DwmIsCompositionEnabled(&fDwmEnabled);
if (SUCCEEDED(hr))
{
lRet = CustomCaptionProc(hWnd, message, wParam, lParam, &fCallDWP);
} // 处理其他默认的消息
if (fCallDWP)
{
lRet = AppWinProc(hWnd, message, wParam, lParam);
}
return lRet;
} //
// 绘制自定义窗体框架的处理程序
//
LRESULT CustomCaptionProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool* pfCallDWP)
{
LRESULT lRet = ;
HRESULT hr = S_OK;
bool fCallDWP = true; // 传递给DefWindowProc //是否需要DWM绘制非客户区
fCallDWP = !DwmDefWindowProc(hWnd, message, wParam, lParam, &lRet); if (message == WM_CREATE)
{
RECT rcClient;
GetWindowRect(hWnd, &rcClient); SetWindowPos(hWnd,
NULL,
rcClient.left, rcClient.top,
RECTWIDTH(rcClient), RECTHEIGHT(rcClient),
SWP_FRAMECHANGED);//触发一条WM_NCCALCSIZE消息,通吃应用程序框架大小发生改变 fCallDWP = true;
lRet = ;
} // 窗口激活
if (message == WM_ACTIVATE)
{
ReDrawExtendFrame(hWnd);
fCallDWP = true;
lRet = ;
} if (message == WM_PAINT)
{
HDC hdc;
PAINTSTRUCT ps;
{
hdc = BeginPaint(hWnd, &ps); //使用gdi+绘制
Graphics graphicsInstance(hdc);
Rect rect = Rect(ps.rcPaint.left + LEFTEXTENDWIDTH,
ps.rcPaint.top + (formstateMax?TOPEXTENDWIDTHMAX:TOPEXTENDWIDTH),
ps.rcPaint.right - ps.rcPaint.left - RIGHTEXTENDWIDTH-LEFTEXTENDWIDTH ,
ps.rcPaint.bottom -ps.rcPaint.top -BOTTOMEXTENDWIDTH-(formstateMax?TOPEXTENDWIDTHMAX:TOPEXTENDWIDTH));
SolidBrush solidBrush(Color(,,,));
rect.Inflate(,);
graphicsInstance.FillRectangle(&solidBrush,rect);
Pen pen(Color(,,,));
graphicsInstance.DrawRectangle(&pen,rect);
rect.Inflate(,);
pen.SetColor(Color(,,,));
graphicsInstance.DrawRectangle(&pen,rect);
rect.Inflate(,);
pen.SetColor(Color(,,,));
graphicsInstance.DrawRectangle(&pen,rect); //画标签
Rect rectTab= Rect(,rect.Y-TOPEXTENDWIDTHMAX++,,TOPEXTENDWIDTHMAX-);
solidBrush.SetColor(Color(,,,));
graphicsInstance.FillRectangle(&solidBrush,rectTab);
pen.SetColor(Color(,,,));
graphicsInstance.DrawRectangle(&pen,rectTab);
pen.SetColor(Color(,,,));
graphicsInstance.DrawLine(&pen,rectTab.X,rectTab.Y+rectTab.Height,rectTab.X+rectTab.Width,rectTab.Y+rectTab.Height); Rect * add = rectTab.Clone();
add->Offset(add->Width +,);
add->Width = ;
add->Height = ;
add->Y = add->Y +;
solidBrush.SetColor(Color(,,,));
graphicsInstance.FillRectangle(&solidBrush,*add);
pen.SetColor(Color(,,,));
graphicsInstance.DrawRectangle(&pen,*add); SolidBrush brush(Color(, , , ));
FontFamily fontFamily(L"微软雅黑");
Font font(&fontFamily, , FontStyleRegular, UnitPixel);
PointF pointF(rectTab.X +,rectTab.Y+); graphicsInstance.DrawString(L"打开新的标签页", -, &font, pointF, &brush);
FontFamily fontFamily2(L"Gautami");
Font font2(&fontFamily2,, FontStyleBold, UnitPixel);
PointF pointF2(rectTab.X + rectTab.Width - - ,rectTab.Y+);
brush.SetColor(Color(, , , ));
graphicsInstance.DrawString(L"x", -, &font2, pointF2, &brush); Rect rectAddress = Rect(rect.X+,rectTab.Y+rectTab.Height,rect.Width-,TOPEXTENDWIDTHMAX);
LinearGradientBrush linGrBrush(
Point(rectAddress.X,rectAddress.Y),
Point(rectAddress.X, rectAddress.Y+rectAddress.Height-), //不包含边框
Color(, ,, ),
Color(, , , )
);
graphicsInstance.FillRectangle(&linGrBrush,rectAddress);
pen.SetColor(Color(,,,));
graphicsInstance.DrawLine(&pen,rectAddress.X,rectAddress.Y+rectAddress.Height-,rectAddress.X +rectAddress.Width,rectAddress.Y+rectAddress.Height-); Rect * left= rectAddress.Clone();
left->X = left->X +;
left->Y = left->Y + ;
left ->Width = ;
left->Height = ;
Image imageLeft(L"D:\\Code\\WINAPI\\chrome\\alpha\\Windowstyle\\RES\\left.png");
graphicsInstance.DrawImage(&imageLeft,left->X,left->Y,left->Width,left->Height); Image imageRight(L"D:\\Code\\WINAPI\\chrome\\alpha\\Windowstyle\\RES\\right.png");
graphicsInstance.DrawImage(&imageRight,left->X+left->Width+,left->Y,left->Width,left->Height); Image imageRefresh(L"D:\\Code\\WINAPI\\chrome\\alpha\\Windowstyle\\RES\\refresh.png");
graphicsInstance.DrawImage(&imageRefresh,left->X+left->Width++left->X+left->Width,left->Y,left->Width,left->Height);
int leftSparate = left->X+left->Width++left->X+left->Width+ + left->Width;
Rect rectSearch = Rect(leftSparate,rectAddress.Y +,rectAddress.Width-leftSparate,rectAddress.Height -);
solidBrush.SetColor(Color(,,,));
graphicsInstance.FillRectangle(&solidBrush,rectSearch.X,rectSearch.Y,rectSearch.Width,rectSearch.Height);
rectSearch.Inflate(,);
pen.SetColor(Color(,,,));
graphicsInstance.DrawRectangle(&pen,rectSearch);
rectSearch.Inflate(-,-);
pen.SetColor(Color(,,,));
graphicsInstance.DrawRectangle(&pen,rectSearch); Image image(L"D:\\Code\\WINAPI\\chrome\\alpha\\Windowstyle\\RES\\center.png");
PointF point3(((ps.rcPaint.right-ps.rcPaint.left) - image.GetWidth()) / ,((ps.rcPaint.bottom-ps.rcPaint.top) - image.GetHeight()) / );
graphicsInstance.DrawImage(&image,point3.X,point3.Y,image.GetWidth(),image.GetHeight()); EndPaint(hWnd, &ps);
} fCallDWP = true;
lRet = ;
} // 接受非客户区大小发生改变
if ((message == WM_NCCALCSIZE) && (wParam == TRUE))
{
// 计算新的NCCALCSIZE_PARAMS大小
NCCALCSIZE_PARAMS *pncsp = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam); pncsp->rgrc[].left = pncsp->rgrc[].left + ;
pncsp->rgrc[].top = pncsp->rgrc[].top + ;
pncsp->rgrc[].right = pncsp->rgrc[].right - ;
pncsp->rgrc[].bottom = pncsp->rgrc[].bottom - ; lRet = ; // 这个消息没有必要传递给Defwindowproc
fCallDWP = false;
} // 处理DwmDefWindowProc没有处理到的hit testing消息
if ((message == WM_NCHITTEST) && (lRet == ))
{
lRet = HitTestNCA(hWnd, wParam, lParam); if ((lRet != HTNOWHERE) )
{
fCallDWP = false;
}
}
*pfCallDWP = fCallDWP; return lRet;
} LRESULT AppWinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
HRESULT hr;
LRESULT result = ; switch (message)
{
case WM_CREATE:
{}
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
}
break;
case WM_SIZE:
{
if (wParam==SIZE_MAXIMIZED)
{
formstateMax = true;
}
else
{
formstateMax = false;
}
ReDrawExtendFrame(hWnd);
}
break;
case WM_DESTROY:
PostQuitMessage();
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return ;
}

要是有兴趣下下来看看吧!

参考链接:

http://msdn.microsoft.com/en-us/library/bb688195(VS.85).aspx#appendixc

http://msdn.microsoft.com/en-us/library/ms632606(VS.85).aspx

http://blog.csdn.net/oldmtn/article/details/7258003

http://www.cnblogs.com/kekec/archive/2010/10/08/1845645.html

模拟Chrome皮肤的更多相关文章

  1. RobotFrameWork--selenium2模拟chrome的user agent

    ${options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver ${opt ...

  2. [HTML] IE=edge,chrome=1的META标签详解

    文件兼容性用于定义让IE如何编译你的网页.此文件解释文件兼容性,如何指定你网站的文件兼容性模式以及如何判断一个网页该使用的文件模式. meta信息中常有这么一句: <meta content=& ...

  3. IE=edge,chrome=1的META信息详解

    这几天在玩 HTML5 ★ Boilerplate,注意到meta信息中有这么一句: 复制代码 代码如下: <meta http-equiv="X-UA-Compatible" ...

  4. content = "IE=edge,chrome=1" 详解

    content = "IE=edge,chrome=1" 详解 < meta http-equiv = "X-UA-Compatible" content ...

  5. < meta http-equiv = "X-UA-Compatible" content = "IE=edge,chrome=1" />的作用

    < meta http-equiv = "X-UA-Compatible" content = "IE=edge,chrome=1" /> 介绍:这 ...

  6. < meta http-equiv = "X-UA-Compatible" content = "IE=edge,chrome=1" />

    目录(?)[-] 1 meta http-equiv  X-UA-Compatible content  chrome1 1 meta http-equiv  X-UA-Compatible cont ...

  7. 配置Nutch模拟浏览器以绕过反爬虫限制

    原文链接:http://yangshangchuan.iteye.com/blog/2030741 当我们配置Nutch抓取 http://yangshangchuan.iteye.com 的时候,抓 ...

  8. 详解< meta http-equiv = "X-UA-Compatible" content = "IE=edge,chrome=1" />

    < meta http-equiv = "X-UA-Compatible" content = "IE=edge,chrome=1" /> 这是个是 ...

  9. 写给对<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">迷惑不解的小伙伴

    1.X-UA-Compatible X-UA-Compatible是自从IE8新加的一个设置,对于IE8以下的浏览器是不识别的. 通过在meta中设置X-UA-Compatible的值,可以指定网页的 ...

随机推荐

  1. Kbuild、Kconfig、make menuconfig、.config、Makefile之间的关系

    今天突发奇想,想在这里分享下比喻分析Kbuild ---->去饭店吃饭的过程.   1.Kconfig --->饭店的菜单 2.条件编译选项--->菜单中的每一盘菜,可以选择这个菜的 ...

  2. 洛谷P3507 [POI2010]GRA-The Minima Game

    题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...

  3. Lack of free swap space on zabbix

    把监控项修改成 {Template OS Linux:system.swap.size[,pfree].last()}< and {Template OS Linux:system.swap.s ...

  4. json遍历,List<Map<String,Object>>遍历

    js怎样给input对象追加属性,如disabled $(":textbox").attr({"disabled":true}); List<Map< ...

  5. Js 向json对象中添加新元素

    即:var json={a:1,b:2} json.c=3  添加新元素直接使用赋值就行了

  6. TortoiseGit安装简单介绍和使用

    首先,你必须有会装软件的技能和一个看得懂英语的眼睛.然后保证Git也装好了 他提供了中文版的安装包哦 安装过程尽量选择默认就行,先装上面那个啊,语言包最后装. 语言配置 因为以前装过,所以...路径是 ...

  7. 隐藏win10中“此电脑”里的6个子文件夹

    删除点击此电脑后6个子文件夹 运行regedit: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Fold ...

  8. python 操作excel 的包 函数

    ###########sample 1 https://blog.csdn.net/chengxuyuanyonghu/article/details/54951399 python操作excel主要 ...

  9. 性能测试工具LoadRunner12-LR之Virtual User Generator 脚本编写验证步骤以及LR常见错误处理方法

    验证脚本比较好的流程: Generate:录制或开发脚本 SUSI(Single User Single Iteration,单用户单循环):运行录制生成的脚本,解决可能存在的关键问题 SUMI(Si ...

  10. object的equals方法与“==”的使用

    官方文档是这么说的: