| BLACK_BRUSH 黑色刷子 NULL_BRUSH 空刷子 WHITE_PEN 白色画笔 DEVICE_DEFAULT_FONT 默认字体 |
| OnDraw(CDC* pDC) { a) CPen pen1,pen2; b) pen1.CreatePen(PS_SOLID,2,RGB(128,128,128));//创建画笔对象一 c) pen2.CreatePen(PS_SOLID,2,RGB(128,128,0));//创建画笔对象二 d) CPen* pOldPen=(CPen*)pDC->SelectObject(&pen1);//选择对象进DC e) drawWithPen1... f) (CPen*)pDC->SelectObject(&pen2);//选择对象进DC g) drawWithPen2... h) pen1.DeleteObject();//再次创建前先销毁 i) pen1.CreatePen(PS_SOLID,2,RGB(0,0,0));//再次创建对象 j) (CPen*)pDC->SelectObject(&pen1);//选择对象进DC k) drawWithPen1... l) pDC->SelectObject(pOldPen);//恢复 } |
| long CImg::OutImgFromText(LPCTSTR vFileName, LPCTSTR lpText, LPCTSTR lpBgImg, long lCSet, LPCTSTR lpFont, long lWidth, long lHeight, long lLeft, long lTop, long llfHeight, long lWeight, long l3D) { i. m_nWidth = lWidth; ii. m_nHeight = lHeight; iii. if((m_nWidth % 8) != 0) 1. m_nWidth = ((int)(m_nWidth/8) + 1) * 8; iv. if(m_nWidth < 3 * lLeft) 1. m_nWidth = 3 * lLeft; v. if(m_nHeight < 3 * lTop) 1. m_nHeight = 3 * lTop; vi. int nFHeight = llfHeight; vii. if(0 == nFHeight) 1. nFHeight = 1; viii. int nRealClientWidth = (m_nWidth - 2 * lLeft); ix. HDC hDC; x. hDC = CreateCompatibleDC(NULL); xi. LOGFONT lf; xii. memset(&lf,0,sizeof(lf)); xiii. lf.lfCharSet = GB2312_CHARSET; xiv. lf.lfHeight = nFHeight; xv. lstrcpy(lf.lfFaceName, lpFont); xvi. lf.lfPitchAndFamily = 8; xvii. lf.lfWeight = lWeight; xviii. HFONT hFont = CreateFontIndirect(&lf); 1. HFONT hOldFont = (HFONT)SelectObject(hDC, hFont); //选入字体 xix. CComBSTR bstrText(lpText); xx. RECT rectClient = {lLeft, lTop, m_nWidth - lLeft, m_nHeight - lTop}; xxi. ::DrawText( 1. hDC, 2. bstrText.m_str, 3. bstrText.Length(), 4. &rectClient, 5. DT_WORDBREAK|DT_LEFT|DT_CALCRECT 6. ); //计算输出距形 xxii. int nRealHeight = rectClient.bottom + lTop; xxiii. if(m_nHeight < nRealHeight) 1. m_nHeight = nRealHeight; xxiv. else 1. rectClient.bottom = m_nHeight - lTop; xxv. HBITMAP hBitmap; xxvi. hBitmap = CreateDiscardableBitmap(hDC, m_nWidth, m_nHeight); xxvii. SelectObject(hDC, hBitmap); xxviii. //--------------------------------- xxix. HBRUSH hBBg = CreateSolidBrush(RGB(255,255,255)); xxx. RECT rectFull = {0, 0, m_nWidth, m_nHeight}; xxxi. FillRect(hDC, &rectFull, hBBg); xxxii. if(l3D > 0) xxxiii. { 1. //SetBkColor(hDC, RGB(200,193,193)); 2. SetTextColor(hDC, ::GetSysColor(COLOR_3DDKSHADOW)); 3. SetBkMode(hDC, OPAQUE); xxxiv. } xxxv. else xxxvi. { 1. SetBkColor(hDC, RGB(255,255,255)); 2. SetTextColor(hDC, RGB(0,0,0)); 3. SetBkMode(hDC, TRANSPARENT); xxxvii. } xxxviii. ::DrawText( 1. hDC, 2. bstrText.m_str, 3. bstrText.Length(), 4. &rectClient, 5. DT_WORDBREAK 6. ); //输出 xxxix. if(l3D > 0) xl. { 1. SetTextColor(hDC, ::GetSysColor(COLOR_3DHILIGHT)); 2. SetBkMode(hDC, TRANSPARENT); 3. rectClient.left = rectClient.left + l3D; 4. rectClient.top = rectClient.top - 1; 5. rectClient.right = rectClient.right + l3D; 6. rectClient.bottom = rectClient.bottom - 1; 7. ::DrawText( a) hDC, b) lpText, c) wcslen(lpText), d) &rectClient, e) DT_WORDBREAK); xli. } xlii. SelectObject(hDC, hOldFont); xliii. DeleteObject(hFont); xliv. DeleteObject(hBBg); xlv. SaveDCBmp(hDC, hBitmap, vFileName); xlvi. //SaveDCJPG(hDC, hBitmap, vFileName); xlvii. DeleteObject(hBitmap); xlviii. ::ReleaseDC(NULL, hDC); xlix. return 0; } |