一、位圖
1、三大函數(shù)
從源寫到目標(biāo)
BOOL BitBlt(HDC hdcDest,int nXDest,int nYDest,int nWidth,int nHeight,HDC hdcSrc,int nXSrc,int nYSrc,DWORD dwRop);
從源寫到目標(biāo) ,可以拉伸
BOOL StretchBlt(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeighDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, DWORD dwRop);
選定刷子。
函數(shù)原型:BOOL PatBlt(HDC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, DWORD dwRop);
2、加載位圖資源:
(1)、加載 hBitmap=LoadBitmap(hinst,MAKEINTRESOURCE(IDB_BITMAP2));
(2)、得到對象 GetObject(hBitmap,sizeof(BITMAP),&bitmap);
(3)創(chuàng)建內(nèi)存DC hdcMem=CreateCompatibleDC(hdc); //創(chuàng)建內(nèi)存dc
(4)把位圖對象選中到內(nèi)存dc上 SelectObject(hdcMem,hBitmap);
(5)用 BitBlt、StretchBlt、PatBlt畫圖:
注意要刪除DC,和對象
DeleteDC(hdcMem);
DeleteObject(hBitmap);
3、填充bitmap創(chuàng)建單色小位圖。
先用數(shù)據(jù)填充bitmap。然后調(diào)用CreateBitmap(&bitmap);
4、用位圖做畫刷 HBRUSH CreatePatternBrush(HBITMAP hbmp);
該函數(shù)可以創(chuàng)建具有指定位圖模式的邏輯刷子,該位圖不能是DIB類型的位圖,DIB位圖是由CreateDIBSection函數(shù)創(chuàng)建的。
二、透明位圖/透明窗口
//改變擴(kuò)展風(fēng)格
DWORD dwStyle=GetWindowLong(hwnd,GWL_EXSTYLE);
SetWindowLong(hwnd,GWL_EXSTYLE,dwStyle^0x80000);
//動態(tài)鏈接庫
hinst=LoadLibrary("User32.DLL");
if(hinst)
{
typedef BOOL (WINAPI *MYFUNC)(HWND ,COLORREF,BYTE,DWORD);
MYFUNC fun=NULL;
//獲得指針
fun=(MYFUNC)GetProcAddress(hinst,"SetLayeredWindowAttributes");
if (fun)
{
fun(hwnd,0,180,2); //設(shè)置
}
}
//擴(kuò)展風(fēng)格WS_EX_LAYERED
三、元文件
一、創(chuàng)建:
CreateMetaFile(); NULL表示存儲在內(nèi)存中
CloseMetaFile //返回元文件句柄
PlayMetaFile //在指定的設(shè)備場景中回放一個(gè)圖元文件。與原元文件的坐標(biāo)有關(guān),故要定義原點(diǎn)在哪里。。。
DeleteMetaFile //刪除
hmf=GetMetaFile(szFileName); //獲得句柄
CopyMetaFile //為元文件制定一個(gè)副本
EnumMetaFile //為一個(gè)標(biāo)準(zhǔn)的windows圖元文件枚舉單獨(dú)的圖元文件記錄
PlayMetaFileRecord //回放來自圖元文件的單條記錄(每條記錄都包含了單個(gè)GDI繪圖命令)
//EnumMetaFileProc
int CALLBACK EnumMetaFileProc(
HDC hDC, // handle to device context
HANDLETABLE FAR *lpHTable, // pointer to metafile handle table
METARECORD FAR *lpMFR, // pointer to metafile record
int nObj, // count of objects
LPARAM lpClientData // pointer to optional data
);
GetMetaFileBitsEx
SetMetaFileBitsEx
//增強(qiáng)型元文件
CreateEnhMetaFile //創(chuàng)建增強(qiáng)型元文件
CloseEnhMetaFile //返回元文件句柄。
PlayEnhMetaFile //顯示元文件
GetEnhMetaFileHeader(hemf,cbsize,&emh); //獲得ENHMETAHEADER信息。
GetEnhMetaFile //取得磁盤文件中包含的一個(gè)增強(qiáng)型圖元文件的圖元文件句柄
EnumEnhMetaFile
PlayEnhMetaFileRecord // 回放單獨(dú)一條增強(qiáng)型圖元文件記錄
//
CopyEnhMetaFile
DeleteEnhMetaFile
EnhMetaFileProc
GdiComment
GetEnhMetaFileBits
GetEnhMetaFileDescription
GetEnhMetaFilePaletteEntries
GetWinMetaFileBits
SetEnhMetaFileBits
SetWinMetaFileBits
記錄數(shù)據(jù)的元文件:
ENHMETAHEADER
typedef struct tagENHMETAHEADER { // enmh
DWORD iType; //類型
DWORD nSize; //大小
RECTL rclBounds; //指出圖像大小
RECTL rclFrame; //
DWORD dSignature; //字符串“EMF”
DWORD nVersion; //0X00010000
DWORD nBytes; //總字節(jié)數(shù)
DWORD nRecords; //指出記錄數(shù)。(頭記錄,GDI函數(shù)調(diào)用等記錄)
WORD nHandles; //指出元文件使用圖形對象的非默認(rèn)句柄數(shù)量。
WORD sReserved;
DWORD nDescription; //描述串的大小
DWORD offDescription; //描述串在文件中的偏移量
DWORD nPalEntries; //調(diào)試板中條目的個(gè)數(shù)
SIZEL szlDevice; //指出以像素為單位的輸出設(shè)備大小
SIZEL szlMillimeters; //以mm為單位輸出的設(shè)備大小
DWORD cbPixelFormat; //描述串
DWORD offPixelFormat;
DWORD bOpenGL;
} ENHMETAHEADER;
四、字體
一、用于文本輸出的函數(shù):
1、TextOut (hdc, xStart, yStart, pString, iCount) ;
2、TabbedTextOut ( hdc, xStart, yStart, pString, iCount,iNumTabs, piTabStops, xTabOrigin) ;iNumTabs制表位數(shù),piTabStops以像素為單位的制表位數(shù)。xTabOrigin平均字符寬度設(shè)置。
3、BOOL ExtTextOut(HDC hdc, int X, int Y, UINT fuOptions, CONST RECT *lprc, LPCTSTR lpString, UINT cbCount, CONST INT *lpDx);lpDx指定字符串中連續(xù)字符的間隔、NULL為默認(rèn)。
4、int DrawText(HDC hDC, LPCTSTR lpString,int nCount, LPRECT lpRect, UINT uFormat );
5、int DrawTextEx(HDC, hdc, LPTSTR lpchText, int cchText, LPRECT lprc, UINT dwDTFormat, LPDRAWTEXTPARAMS lpDTParams);
二、邏輯字體
1、CreateFont 或CreateFontIndirect建立邏輯字體
2、GetTextFace (hdc, sizeof (szFaceName) / sizeof (TCHAR), szFaceName) ;獲得字體名
3、GetTextMetrics (hdc, &textmetric) ;獲得字體信息
三、
該函數(shù)為指定的設(shè)備環(huán)境設(shè)置圖形模式。int SetGraphicsMode(HDC hdc, int iMode);
該函數(shù)用指定的方式修改與設(shè)備環(huán)境有關(guān)的全局轉(zhuǎn)換。BOOL ModifyWorldTransform(HDc hdc, CONST XFORM *lpXform, DWORD iMode);
四、hPen = ExtCreatePen (iStyle, iWidth, &lBrush, 0, NULL) ;使用該函數(shù)正常地繪制線段。
五:軌跡
BeginPath {路徑開始}
EndPath {路徑結(jié)束}
StrokePath {繪制路徑}
FillPath {填充路徑}
StrokeAndFillPath {繪制并填充路徑}
SelectClipPath 路徑的運(yùn)算
//在路徑中可以使用的圖形命令有:
AngleArc
Arc
ArcTo
Chord
CloseFigure
Ellipse
ExtTextOut
LineTo
MoveToEx
Pie
PolyBezier
PolyBezierTo
PolyDraw
Polygon
Polyline
PolylineTo
PolyPolygon
PolyPolyline
Rectangle
RoundRect
TextOut
六、字體效果
一、設(shè)置字體大小
LOGFONT lf;
ZeroMemory(&lf,sizeof(lf));
lf.lfCharSet=DEFAULT_CHARSET;
lf.lfHeight=m_iMineLength;
lf.lfWidth=m_iMineLength;
lf.lfWeight=1000;
HFONT hFont=CreateFontIndirect(&lf);
HFONT hOldFont=(HFONT)SelectObject(m_hMemDC,hFont);
DeleteObject(hFont);
二、輸出透明底色字體
SetBkMode(hMemDc,TRANSPARENT);
TextOut(hMemDc,0,0,sNum,strlen(sNum));
三、居中輸出
DrawText(hdc,str,&rt,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
//注意要同時(shí)DT_VCENTER|DT_SINGLELINE才能居中
posted on 2011-09-13 16:16
Yu_ 閱讀(728)
評論(0) 編輯 收藏 引用 所屬分類:
Windows程序設(shè)計(jì)