資源簡介
使用updatelayeredwindow函數(shù)制作出漂亮的窗口,本窗口使用自繪加圖片實(shí)現(xiàn)。(我要設(shè)置成不要積分下載的,或者最低積分)

代碼片段和文件信息
#include?
#include?
//本代碼用于建立特殊形狀窗口
#pragma?comment?(lib?“GdiPlus.lib“)
using?namespace?Gdiplus;
LRESULT?CALLBACK?WndProc(HWND?hwnd?UINT?msg?WPARAM?wParam?LPARAM?lParam);
int?WINAPI?WinMain(HINSTANCE?hInstance?HINSTANCE?hPrevInstance?LPSTR?szCmdLine?int
nCmdShow)
{
TCHAR szAppName[]?=?TEXT(“Windows程序設(shè)計“);
WNDCLASSEX wndClass;
MSG msg;
HWND hwnd;
ULONG_PTR token;
GdiplusStartupInput gin;
wndClass.cbSize?=?sizeof(WNDCLASSEX);
wndClass.cbClsExtra?=?0;
wndClass.cbWndExtra?=?0;
wndClass.hbrBackground?=?(HBRUSH)GetStockobject(WHITE_BRUSH);
wndClass.hCursor?=?LoadCursor(NULL?IDC_ARROW);
wndClass.hIcon?=?LoadIcon(NULL?IDI_APPLICATION);
wndClass.hIconSm?=?NULL;
wndClass.hInstance?=?hInstance;
wndClass.lpszClassName?=?TEXT(“AppTest“);
wndClass.lpszMenuName?=?NULL;
wndClass.lpfnWndProc?=?WndProc;
wndClass.style?=?CS_HREDRAW?|?CS_VREDRAW?|?CS_IME?|?CS_DBLCLKS;
GdiplusStartup(&token?&gin?NULL);
RegisterClassEx(&wndClass);
hwnd?=?CreateWindowEx(WS_EX_layerED?TEXT(“AppTest“)?szAppName?WS_CLIPCHILDREN?|?WS_CLIPSIBLINGS?|?WS_POPUP/*無邊框風(fēng)格*/
?0?0?100?100
NULL?NULL?hInstance?NULL);
//設(shè)置本窗口為分層窗口支持透明
//分層窗口沒有WM_PAINT消息
ShowWindow(hwnd?SW_SHOW);
UpdateWindow(hwnd);
while?(GetMessage(&msg?NULL?0?0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GdiplusShutdown(token);
return?0;
}
void?CreateRoundRectangle(Rect?rc?int?Round?GraphicsPath?*?gp)
{
gp->AddArc(0?0?Round?Round?180?90);
gp->AddLine(Round?0?rc.Width?-?Round?0);
gp->AddArc(rc.Width?-?Round?0?Round?Round?270?90);
gp->AddLine(rc.Width?Round?rc.Width?rc.Height?-?Round);
gp->AddArc(rc.Width?-?Round?rc.Height?-?Round?Round?Round?0?90);
gp->AddLine(rc.Width?-?Round?rc.Height?Round?rc.Height);
gp->AddArc(0?rc.Height?-?Round?Round?Round?90?90);
}
LRESULT?CALLBACK?WndProc(HWND?hwnd?UINT?msg?WPARAM?wParam?LPARAM?lParam)
{
static?BOOL ldown;
static?POINT TheFirstPoint;
static?int cxClient?cyClient;
switch?(msg)
{
case?WM_SIZE:
cxClient?=?LOWORD(lParam);
cyClient?=?HIWORD(lParam);
break;
case?WM_LBUTTONDOWN:
ldown?=?TRUE;
SetCapture(hwnd);//這句代碼可以進(jìn)行容錯處理誰知道那次window響應(yīng)速度慢了你不信?‘-_-‘去掉這句代碼試一試
TheFirstPoint.x?=?LOWORD(lParam);
TheFirstPoint.y?=?HIWORD(lParam);
break;
case?WM_LBUTTONUP:
ldown?=?FALSE;
ReleaseCapture();
break;
case?WM_MOUSEMOVE:
if?(ldown)
{
POINT pt;
GetCursorPos(&pt);
pt.x?-=?TheFirstPoint.x;
pt.y?-=?TheFirstPoint.y;
SetWindowPos(hwnd?NULL?pt.x?pt.y?NULL?NULL?SWP_NOREDRAW?|
SWP_NOSIZE?|?SWP_NOZORDER);
}
break;
case?WM_LBUTTONDBLCLK:
DestroyWindow(hwnd);
case?WM_CREATE:
{
Image ?image(TEXT(“bianping-christmas-2014-12.png“));
//加載窗口圖形
int?iWidth?=?image.GetWidth();
int?iHeight?=?image.GetHeight();
HDC?hdcScreen?=?GetDC(NULL);
HDC?hdcMem?=?CreateCompatibleDC(hdcScreen);
HBITMAP?hBitma
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-06-16?17:59??分層窗口\
?????目錄???????????0??2015-06-15?16:43??分層窗口\Debug\
?????文件????????5420??2014-12-08?14:34??分層窗口\Debug\bianping-christmas-2014-01.png
?????文件???????44032??2015-06-15?16:45??分層窗口\Debug\窗口01.exe
?????文件??????381388??2015-06-15?16:45??分層窗口\Debug\窗口01.ilk
?????文件??????748544??2015-06-15?16:45??分層窗口\Debug\窗口01.pdb
?????目錄???????????0??2015-06-15?16:47??分層窗口\Release\
?????文件??????182272??2015-06-16?17:56??分層窗口\Release\窗口01.exe
?????文件?????2796544??2015-06-16?17:56??分層窗口\Release\窗口01.pdb
?????目錄???????????0??2015-06-16?17:59??分層窗口\窗口01\
?????文件?????????970??2015-06-15?07:32??分層窗口\窗口01.sln
?????文件???????22528??2015-06-16?17:59??分層窗口\窗口01.v12.suo
?????文件????????5420??2014-12-08?14:34??分層窗口\窗口01\a.png
?????文件????????6632??2014-12-08?14:34??分層窗口\窗口01\bianping-christmas-2014-02.png
?????文件????????5288??2014-12-08?14:34??分層窗口\窗口01\bianping-christmas-2014-03.png
?????文件????????2713??2014-12-08?14:35??分層窗口\窗口01\bianping-christmas-2014-04.png
?????文件????????6728??2014-12-08?14:35??分層窗口\窗口01\bianping-christmas-2014-05.png
?????文件????????4593??2014-12-08?14:35??分層窗口\窗口01\bianping-christmas-2014-06.png
?????文件????????5980??2014-12-08?14:35??分層窗口\窗口01\bianping-christmas-2014-07.png
?????文件????????5750??2014-12-08?14:35??分層窗口\窗口01\bianping-christmas-2014-08.png
?????文件????????7821??2014-12-08?14:35??分層窗口\窗口01\bianping-christmas-2014-09.png
?????文件????????3029??2014-12-08?14:35??分層窗口\窗口01\bianping-christmas-2014-10.png
?????文件????????4948??2014-12-08?14:35??分層窗口\窗口01\bianping-christmas-2014-11.png
?????文件????????8584??2014-12-08?14:35??分層窗口\窗口01\bianping-christmas-2014-12.png
?????目錄???????????0??2015-06-15?16:45??分層窗口\窗口01\Debug\
?????文件????????5420??2014-12-08?14:34??分層窗口\窗口01\Debug\bianping-christmas-2014-01.png
?????文件??????486400??2015-06-15?16:45??分層窗口\窗口01\Debug\vc120.idb
?????文件??????315392??2015-06-15?16:45??分層窗口\窗口01\Debug\vc120.pdb
?????文件???????57863??2015-06-15?16:45??分層窗口\窗口01\Debug\源.obj
?????文件????????2171??2015-06-15?16:45??分層窗口\窗口01\Debug\窗口01.log
?????目錄???????????0??2015-06-15?16:45??分層窗口\窗口01\Debug\窗口01.tlog\
............此處省略22個文件信息
評論
共有 條評論