BOOL CTrayNotifyIcon::GetDynamicDCAndBitmap(CDC* pDC, CBitmap* pBitmap) { //Validate our parameters ASSERT(pDC != NULL); ASSERT(pBitmap != NULL); //Get the HWND for the desktop CWnd* pWndScreen = CWnd::GetDesktopWindow(); if (pWndScreen == NULL) return FALSE; //Get the desktop HDC to create a compatible bitmap from CDC* pDCScreen = pWndScreen->GetDC(); if (pDCScreen == NULL) return FALSE; //Get the width and height of a small icon int w = GetSystemMetrics(SM_CXSMICON); int h = GetSystemMetrics(SM_CYSMICON); //Create an off-screen bitmap that the dynamic tray icon //can be drawn into. (Compatible with the desktop DC). BOOL bSuccess = pBitmap->CreateCompatibleBitmap(pDCScreen, w, h); if (!bSuccess) { pWndScreen->ReleaseDC(pDCScreen); return FALSE; } //Get a HDC to the newly created off-screen bitmap bSuccess = pDC->CreateCompatibleDC(pDCScreen); if (!bSuccess) { //Release the Screen DC now that we are finished with it pWndScreen->ReleaseDC(pDCScreen); //Free up the bitmap now that we are finished with it pBitmap->DeleteObject(); return FALSE; } //Select the bitmap into the offscreen DC pDC->SelectObject(pBitmap); //Release the Screen DC now that we are finished with it pWndScreen->ReleaseDC(pDCScreen); return TRUE; }
void CNotification::LayerUpdate(CDIB *dib) { if(!dib) { dib = CNotification::dib; } if(!dib->Ready()) { return; } CRect rect; GetWindowRect(&rect); CWnd *wndDst = GetDesktopWindow(); CDC *hdcDst = wndDst->GetDC(); CDC *dc = new CDC(); dc->Attach(dib->dc); BLENDFUNCTION blend = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA}; CPoint zp(0, 0); CPoint pt(rect.left, rect.top); CSize size(rect.Width(), rect.Height()); UpdateLayeredWindow(hdcDst, &pt, &size, dc, &zp, NULL, &blend, ULW_ALPHA); dc->Detach(); delete dc; wndDst->ReleaseDC(hdcDst); }
BOOL CTransparentStatic2::OnEraseBkgnd(CDC* pDC) { if (m_Bmp.GetSafeHandle() == NULL) { CRect Rect; GetWindowRect(&Rect); CWnd *pParent = GetParent(); ASSERT(pParent); pParent->ScreenToClient(&Rect); //convert our corrdinates to our parents //copy what's on the parents at this point CDC *pDC = pParent->GetDC(); CDC MemDC; MemDC.CreateCompatibleDC(pDC); m_Bmp.CreateCompatibleBitmap(pDC,Rect.Width(),Rect.Height()); CBitmap *pOldBmp = MemDC.SelectObject(&m_Bmp); MemDC.BitBlt(0,0,Rect.Width(),Rect.Height(),pDC,Rect.left,Rect.top,SRCCOPY); MemDC.SelectObject(pOldBmp); pParent->ReleaseDC(pDC); } else //copy what we copied off the parent the first time back onto the parent { CRect Rect; GetClientRect(Rect); CDC MemDC; MemDC.CreateCompatibleDC(pDC); CBitmap *pOldBmp = MemDC.SelectObject(&m_Bmp); pDC->BitBlt(0,0,Rect.Width(),Rect.Height(),&MemDC,0,0,SRCCOPY); MemDC.SelectObject(pOldBmp); } return TRUE; }
void CLMenu::UpdateLayer(CDIB *dib) { if(!dib) { dib = CLMenu::dib; } CRect r; GetWindowRect(&r); CWnd *wndDst = GetDesktopWindow(); CDC *hdcDst = wndDst->GetDC(); CDC *dc = new CDC(); dc->Attach(dib->dc); BLENDFUNCTION bf = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA}; POINT zp = {0, 0}; POINT sp = {r.left, r.top}; SIZE sz = {r.Width(), r.Height()}; UpdateLayeredWindow(hdcDst, &sp, &sz, dc, &zp, NULL, &bf, ULW_ALPHA); dc->Detach(); delete dc; wndDst->ReleaseDC(hdcDst); }
void CHeaderCtrlExt::DrawDragDivider() { CWnd* pParent = GetParent(); CDC* pDC = pParent->GetDCEx(NULL, DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE); int nROP2 = pDC->SetROP2(R2_NOT); CPen pen; pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); CPen* pPenOld = pDC->SelectObject(&pen); CRect rc; pParent->GetWindowRect(&rc); ScreenToClient(&rc); CRect rcItem; GetItemRect(m_nDraggingItem, &rcItem); int dx = m_ptDragMove.x - m_ptDragStart.x; int x = max(rcItem.left, rcItem.right + dx); pDC->MoveTo(x, rc.top); pDC->LineTo(x, rc.bottom); pDC->SelectObject(pPenOld); pDC->SetROP2(nROP2); pParent->ReleaseDC(pDC); }
BOOL CXTThemeManagerStyle::TakeSnapShot(CWnd* pWndOwner) { CWnd *pWndParent = pWndOwner->GetParent(); if (::IsWindow(pWndParent->GetSafeHwnd())) { if (m_bmpSnapShot.GetSafeHandle() != NULL) m_bmpSnapShot.DeleteObject(); //convert our coordinates to our parent coordinates. CXTPWindowRect rc(pWndOwner); pWndParent->ScreenToClient(&rc); //copy what's on the parents background at this point CDC *pDC = pWndParent->GetDC(); CDC memDC; memDC.CreateCompatibleDC(pDC); m_bmpSnapShot.CreateCompatibleBitmap(pDC, rc.Width(), rc.Height()); CXTPBitmapDC bitmapDC(&memDC, &m_bmpSnapShot); memDC.BitBlt(0, 0, rc.Width(), rc.Height(), pDC, rc.left, rc.top, SRCCOPY); pWndParent->ReleaseDC(pDC); return TRUE; } return FALSE; }
HRGN CSkinWin::GetRegion(int w, int h) { CWnd *pWnd = CWnd::FromHandle(m_hWnd); CRect wr; pWnd->GetWindowRect(wr); //SKIN_SHANG 右边框 //wr.left+=m_BorderRightWidth; CRgn rgn; if ( m_bTrans ) { CDC *pDC = pWnd->GetDC(); CDC memDC; CMyBitmap bmp; CBitmap *obmp; memDC.CreateCompatibleDC(pDC); bmp.CreateCompatibleBitmap( pDC, w, m_TitleHeight ); obmp = memDC.SelectObject(&bmp); /* memDC.FillSolidRect( 0, 0, w, h, 0 ); DrawFrame( &memDC, 0, 0, w, h, 0 ); */ DrawTitle( &memDC, m_BorderLeftWidth , 0, wr.Width() - m_BorderRightWidth - m_BorderLeftWidth + 1, 0 ); DrawLeft( &memDC, 0, 0, m_bmpLeft.Height(), 0 ); //SKIN_SHANG 右边框 DrawRight( &memDC, wr.Width() - m_BorderRightWidth , 0, m_bmpRight.Height(), 0 ); memDC.SelectObject(obmp); //wyw memDC.DeleteDC(); pWnd->ReleaseDC( pDC ); rgn.CreateRectRgn( 0, m_TitleHeight, wr.Width(), wr.Height() ); HRGN hrgn = bmp.CreateRgnFromFile( m_colTrans ); CRgn newrgn; newrgn.CreateRectRgn( 0, m_TitleHeight, wr.Width(), wr.Height() ); newrgn.CombineRgn( &rgn, CRgn::FromHandle(hrgn), RGN_XOR ); //wyw bmp.DeleteObject(); DeleteObject(hrgn); rgn.DeleteObject(); return (HRGN)newrgn.Detach(); } else rgn.CreateRectRgn( 0, 0, wr.Width(), wr.Height() ); return (HRGN)rgn.Detach(); }
void CDockContext::CancelLoop() { DrawFocusRect(TRUE); // gets rid of focus rect ReleaseCapture(); CWnd* pWnd = CWnd::GetDesktopWindow(); pWnd->UnlockWindowUpdate(); if (m_pDC != NULL) { pWnd->ReleaseDC(m_pDC); m_pDC = NULL; } }
BOOL CSkinItemEdit::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* lpResult) { *lpResult = CSkinItem::DefWndProc(uMsg, wParam, lParam); CWnd* pWnd = CWnd::FromHandle(m_hWnd); CDC* pDC = NULL; if (m_bSystemEdit) pDC = pWnd->GetDC(); else pDC = pWnd->GetWindowDC(); DrawFrame(pDC); pWnd->ReleaseDC(pDC); return TRUE; }
int GraphicsMisc::GetTextWidth(const CString& sText, CWnd& wndRef, CFont* pRefFont) { CDC* pDC = wndRef.GetDC(); ASSERT(pDC); if (!pDC) return -1; if (pRefFont == NULL) pRefFont = wndRef.GetFont(); CFont* pOldFont = pDC->SelectObject(pRefFont); int nLength = pDC->GetTextExtent(sText).cx; pDC->SelectObject(pOldFont); wndRef.ReleaseDC(pDC); return nLength; }
void COXDragDockContext::CancelDrag() { DrawFocusRect(TRUE); // gets rid of focus rect ReleaseCapture(); CWnd* pWnd = CWnd::GetDesktopWindow(); #ifndef _MAC pWnd->UnlockWindowUpdate(); #endif if (m_pDC != NULL) { pWnd->ReleaseDC(m_pDC); m_pDC = NULL; } // Tell main window to clear it's status bar CWnd* pMainWnd = AfxGetMainWnd(); ASSERT(pMainWnd != NULL); pMainWnd->SendMessage(WM_SETMESSAGESTRING, (WPARAM)AFX_IDS_IDLEMESSAGE); }
void CLoadEzdFile::OnDrawPreview() { CWnd* pWnd = GetDlgItem(IDC_STATIC_WND); if(pWnd==NULL) return; // pWnd = this; CRect rect; pWnd->GetClientRect(rect); rect.InflateRect(-2,-2); CDC* pDC = pWnd->GetDC(); CRgn pRgn; pRgn.CreateRectRgnIndirect(rect); pDC->SelectClipRgn(&pRgn); //CBrush Brsh(GetSysColor(COLOR_BTNFACE)); CBrush Brsh(RGB(255,255,255)); pDC->FillRect(rect,&Brsh); if(m_pPrevBmp != NULL) {//显示预览图片 CDC memDC; CBitmap* pOld=NULL; memDC.CreateCompatibleDC(pDC); pOld = memDC.SelectObject(m_pPrevBmp); BITMAP bm; m_pPrevBmp->GetBitmap(&bm); CPoint ptCen = rect.CenterPoint (); ::SetStretchBltMode(pDC->GetSafeHdc(), COLORONCOLOR); pDC->BitBlt (ptCen.x - bm.bmWidth/2,ptCen.y - bm.bmHeight/2,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY); memDC.SelectObject(pOld); } pWnd->ReleaseDC( pDC ); return; }
void ZoomBox_NcPaint(HWND hwnd, HRGN hrgn) /************************************************************************/ { CRect r, rTitle, rMenu, rCaption, rCookie; TCHAR Caption[80]; GetWindowRect(hwnd,&r); r.OffsetRect(-r.left, -r.top); CalcTitleRect(hwnd,TRUE, rTitle); CalcSysMenuRect(hwnd,TRUE, rMenu); rCookie.SetRect( rMenu.left + SYS_COOKIE_OFFSET + 1, rMenu.top + SYS_COOKIE_OFFSET + 1, rMenu.left + SYS_COOKIE_OFFSET + SYS_COOKIE_WIDTH, rMenu.top + SYS_COOKIE_OFFSET + SYS_COOKIE_HEIGHT); // Exclude the Caption Bar area and Have default draw HDC hDC = ::GetDCEx(hwnd, hrgn, DCX_USESTYLE | DCX_WINDOW | DCX_INTERSECTRGN | DCX_LOCKWINDOWUPDATE); int level = ::SaveDC(hDC); CRgn rgn1; CRgn rgn2; rCaption.UnionRect((LPRECT)&rTitle,(LPRECT)&rMenu); ::ClientToScreen(hwnd,(LPPOINT)&rCaption); ::ClientToScreen(hwnd,(LPPOINT)&rCaption.right); rgn1.FromHandle(hrgn); rgn2.CreateRectRgn(rCaption.left,rCaption.top,rCaption.right,rCaption.bottom); int ret = rgn2.CombineRgn(&rgn1,&rgn2,RGN_DIFF); /* ERROR 0 NULLREGION 1 SIMPLEREGION 2 COMPLEXREGION 3 */ DefWindowProc(hwnd, WM_NCPAINT, (WPARAM)(HRGN)(rgn2.GetSafeHandle()), (LPARAM)0L); ::RestoreDC(hDC,level); ::ReleaseDC(hwnd,hDC); // Draw the title bar, sys menu cookie, and border CWnd *pWnd = CWnd::FromHandle(hwnd); CDC *pDC = pWnd->GetWindowDC(); if (!pDC) return; CBrush TitleBrush(GetSysColor(COLOR_ACTIVECAPTION)); CBrush FrameBrush(COLOR_BORDER); CBrush MenuBrush(COLOR_SYSMENU); CBrush CkBrush(COLOR_COOKIEFILL); CBrush CkBrushShadow(COLOR_SYSSHADOW); pDC->FillRect(rTitle, &TitleBrush); pDC->FillRect(rMenu, &MenuBrush); pDC->FrameRect(rTitle, &FrameBrush); pDC->FrameRect(r, &FrameBrush); pDC->FrameRect(rMenu, &FrameBrush); pDC->FrameRect(rCookie, &CkBrushShadow); rCookie.OffsetRect(-1, -1); pDC->FillRect(rCookie, &CkBrush); pDC->FrameRect(rCookie, &FrameBrush); CFont fnt; int FntHeight = 12; if (fnt.CreateFont(FntHeight,0,0,0,FW_NORMAL,FALSE,FALSE,0,0,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE|TMPF_TRUETYPE,NULL)) { pDC->SelectObject(&fnt); pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(GetSysColor(COLOR_CAPTIONTEXT)); if (::GetWindowText(hwnd,Caption,80) == 0) lstrcpy(Caption,_T("QuickZoom")); pDC->DrawText((LPCSTR)Caption,-1,&rTitle,DT_CENTER|DT_VCENTER); fnt.DeleteObject(); } pWnd->ReleaseDC(pDC); }
void CSkinWin::OnNcPaint(HRGN rgn1) { CWnd *pWnd = CWnd::FromHandle(m_hWnd); CDC * pDC = pWnd->GetWindowDC(); CRect wr; pWnd->GetWindowRect( wr ); //SKIN_SHANG 右边框 //wr.left+=m_BorderRightWidth; DWORD style = GetWindowLong( m_hWnd, GWL_STYLE ); DWORD nCaption = style & WS_CAPTION ; if (nCaption == 0) { //wyw pWnd->ReleaseDC(pDC); return; } //f ( (DWORD)rgn) //pDC->SelectClipRgn( CRgn::FromHandle(rgn) ); //m_bActive = GetActiveWindow() == m_hWnd; int state = 0; if ( m_bActive) state = 0; else state = 1; pDC->ExcludeClipRect(0, 0, wr.Width(), m_TitleHeight ); DrawFrame(pDC, 0, 0, wr.Width(), wr.Height(), state, 0); pDC->SelectClipRgn( NULL ); CDC memDC, *pNewDC; CMyBitmap bmp; CBitmap *obmp; memDC.CreateCompatibleDC( pDC ); bmp.CreateCompatibleBitmap( pDC, wr.Width(), m_TitleHeight ); obmp = memDC.SelectObject(&bmp); pNewDC = &memDC; DrawTitle( pNewDC, m_BorderLeftWidth , 0, wr.Width() - m_BorderRightWidth - m_BorderLeftWidth + 1, state ); DrawLeft( pNewDC, 0, 0, m_bmpLeft.Height(), state ); //SKIN_SHANG 右边框 DrawRight( pNewDC, wr.Width() - m_BorderRightWidth , 0, m_bmpRight.Height(), state ); CRgn newrgn; newrgn.CreateRectRgn( 0, 0, wr.Width(), wr.Height()); if ( m_bTrans ) { CRgn rgn; rgn.CreateRectRgn( 0, m_TitleHeight, wr.Width(), wr.Height() ); HRGN hrgn = bmp.CreateRgnFromFile( m_colTrans ); //wyw 防止内存增大 // newrgn.CombineRgn( &rgn, CRgn::FromHandle(hrgn), RGN_XOR); pDC->SelectClipRgn( &newrgn ); //wyw DeleteObject(hrgn); rgn.DeleteObject(); } else SetWindowRgn(m_hWnd, newrgn, FALSE); if (m_sysmenu){ if( m_downHitTest == HTCLOSE ) DrawButton( pNewDC, 0, 1 ); else if ( m_moveHitTest == HTCLOSE) DrawButton( pNewDC, 0, 2 ); else DrawButton( pNewDC, 0, 0 ); } /*if ( m_downHitTest == HTMAXBUTTON ) DrawButton( pNewDC, 1, 1 ); else if ( m_moveHitTest == HTMAXBUTTON) DrawButton( pNewDC, 1, 2 ); else DrawButton( pNewDC, 1, 0 ); if ( m_downHitTest == HTMINBUTTON ) DrawButton( pNewDC, 2, 1 ); else if ( m_moveHitTest == HTMINBUTTON) DrawButton( pNewDC, 2, 2 ); else DrawButton( pNewDC, 2, 0 ); // liub_modify 去除弹出面板(去掉按钮) if ( m_downHitTest == HTMINBUTTON ) DrawButton( pNewDC, 2, 1 ); else if ( m_moveHitTest == HTMINBUTTON) DrawButton( pNewDC, 2, 2 ); else DrawButton( pNewDC, 2, 0 ); */ if ( m_downHitTest == HTMINBUTTON ) DrawButton( pNewDC, 1, 1 ); else if ( m_moveHitTest == HTMINBUTTON) DrawButton( pNewDC, 1, 2 ); else DrawButton( pNewDC, 1, 0 ); int cx = GetSystemMetrics(SM_CXSMICON); int cy = GetSystemMetrics(SM_CYSMICON); HICON hi = (HICON)SendMessage( m_hWnd, WM_GETICON, ICON_SMALL, 0); if ( !hi ) { //#ifdef IDR_MAINFRAME hi = AfxGetApp()->LoadIcon(g_SetData.Main_szMainIcon); //#endif } //draw icon // ::DrawIconEx( pNewDC->GetSafeHdc(), m_BorderLeftWidth, 5, (HICON) // CopyImage( hi, IMAGE_ICON, // cx, cy, 0), cx, cy, 0, 0, DI_NORMAL); #if 0 //wyw //draw icon ::DrawIconEx( pNewDC->GetSafeHdc(), m_BorderLeftWidth, 5, (HICON) CopyImage( hi, IMAGE_ICON, cx, cy, 0), cx, cy, 0, 0, DI_NORMAL); #else if (NULL != hi) { HICON hIcon = (HICON)CopyImage( hi, IMAGE_ICON, cx, cy, 0); ASSERT(NULL != hIcon); ::DrawIconEx( pNewDC->GetSafeHdc(), m_BorderLeftWidth, 5, hIcon, cx, cy, 0, 0, DI_NORMAL); DestroyIcon(hIcon); } #endif //draw text if ( m_title.IsEmpty() ) pWnd->GetWindowText(m_title); if (m_bActive) pNewDC->SetTextColor( m_colTitle1 ); else pNewDC->SetTextColor( m_colTitle2 ); CFont font, *ofont; font.CreatePointFont( GetSystemMetrics(SM_CYSMCAPTION), _T("System") ); ofont = pNewDC->SelectObject(&font); pNewDC->SetBkMode(TRANSPARENT); pNewDC->DrawText( m_title, CRect( m_textShift, m_textShiftVer, wr.Width() - m_bmpTitle.Width() + m_titleoff2, m_TitleHeight ), DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_WORD_ELLIPSIS ); pNewDC->SelectObject(&font); pDC->BitBlt( 0, 0, wr.Width(), m_TitleHeight, pNewDC, 0, 0, SRCCOPY ); pDC->SelectClipRgn(NULL); //wyw memDC.SelectObject(obmp); #ifdef FEATURE_VERSION_ITELCO if(m_pHookedWnd == AfxGetMainWnd()) { pWnd = CWnd::FromHandle(m_hWnd); pDC = pWnd->GetWindowDC(); CRect rtWnd,rtTitle; pWnd->GetWindowRect(&rtWnd); CRect m_rtIcon; rtTitle.left = GetSystemMetrics(SM_CXFRAME); rtTitle.top = GetSystemMetrics(SM_CYFRAME); //rtTitle.right = rtWnd.right - rtWnd.left - GetSystemMetrics(SM_CXFRAME); rtTitle.bottom = rtTitle.top + GetSystemMetrics(SM_CYSIZE); m_rtIcon.left = rtTitle.left + 350; m_rtIcon.top = rtTitle.top - 1; //m_rtIcon.right = m_rtIcon.left + 323; //323 //m_rtIcon.bottom = m_rtIcon.top + 20; //25 HICON hLogInfo; hLogInfo = (HICON)::LoadImage(NULL, g_SetData.Main_szTitleLogoIcon, IMAGE_ICON, 248, 24, LR_LOADFROMFILE|LR_DEFAULTCOLOR); DWORD dword = GetLastError(); //IDR_MAINFRAME IDI_ICON_INFO BOOL BRes = ::DrawIconEx(pDC->m_hDC, m_rtIcon.left, m_rtIcon.top, hLogInfo, 0, 0, 0, NULL, DI_NORMAL); dword = GetLastError(); } #endif //wyw font.DeleteObject(); bmp.DeleteObject(); newrgn.DeleteObject(); memDC.DeleteDC(); pWnd->ReleaseDC(pDC); }
/*--------------------------------------*/ void CFrontier_API_SVDlg::OnPaitMap(void) { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } int m_CXpos=0,m_CYpos=0,m_CorYLenth = 160,m_CorXLenth = 160; int GraphLimit; struct { int RobRadia;// 机器人的半径 }VisRobot = {25};// 机器人的图形显示参数 CRect rect2,rect3; CWnd* pWnd = GetDlgItem(IDC_LOCDRAW);// CDC* pControlDC = pWnd->GetDC(); pWnd->Invalidate(); pWnd->UpdateWindow(); pWnd->GetWindowRect(rect2); m_CXpos = (rect2.right-rect2.left)/2; m_CYpos = (rect2.bottom-rect2.top)/2; GraphLimit = 150; pControlDC->MoveTo(m_CXpos,m_CYpos-m_CorYLenth);// 机器人朝向,纵轴 pControlDC->LineTo(m_CXpos,m_CYpos+m_CorYLenth); pControlDC->SelectStockObject(LTGRAY_BRUSH);//LTGRAY_BRUSH pControlDC->Ellipse(m_CXpos-5, m_CYpos-m_CorYLenth-5,m_CXpos+5, m_CYpos-m_CorYLenth+5 ); pControlDC->MoveTo(m_CXpos-m_CorXLenth,m_CYpos);// 机器人横轴 pControlDC->LineTo(m_CXpos+m_CorXLenth,m_CYpos); pControlDC->SelectStockObject(LTGRAY_BRUSH);//LTGRAY_BRUSH pControlDC->Ellipse(m_CXpos-m_CorXLenth-5, m_CYpos-5,m_CXpos-m_CorXLenth+5, m_CYpos+5 ); pControlDC->SelectStockObject(HOLLOW_BRUSH);//LTGRAY_BRUSH pControlDC->Ellipse(m_CXpos-140-VisRobot.RobRadia, m_CYpos-140-VisRobot.RobRadia,m_CXpos+140+VisRobot.RobRadia, m_CYpos+140+VisRobot.RobRadia); // 远处 pControlDC->Ellipse(m_CXpos-20-VisRobot.RobRadia, m_CYpos-20-VisRobot.RobRadia,m_CXpos+20+VisRobot.RobRadia,m_CYpos+20+VisRobot.RobRadia); //近处 float temp_dist,temp_ang; int temp_far,temp_near; temp_far = 2500; temp_near = 300; int m_tempXPos; int m_tempYPos; BOOL temp_Blob[6]; temp_Blob[0] = m_Blob1; temp_Blob[1] = m_Blob2; temp_Blob[2] = m_Blob3; temp_Blob[3] = m_Blob4; temp_Blob[4] = m_Blob5; temp_Blob[5] = m_Blob6; UpdateData(TRUE); /*------目标物显示------*/ for (int k=0;k<6;k++) { if (temp_Blob[k] && VisionBlob[k][0].area>0) { DISTANG temp_DistAng; memcpy(&temp_DistAng,&VisionDistAng[k][0],sizeof(temp_DistAng)); CPen pen,*ppen; COLORREF ObjColor; ObjColor = ColorHLSToRGB((WORD)VisionBlob[k][0].hue,150,240); pen.CreatePen(PS_SOLID,1,ObjColor); CBrush ObjBrush; ObjBrush.CreateSolidBrush(ObjColor); pControlDC->SelectObject(&ObjBrush); ppen = pControlDC->SelectObject(&pen); if (temp_DistAng.Dist >= temp_far) { temp_dist = (float)temp_far; } else if (temp_DistAng.Dist <= temp_near) { temp_dist = (float)temp_near; } else { temp_dist = (float)temp_DistAng.Dist; } temp_dist = (temp_dist-temp_near)*120/(temp_far-temp_near+300)+(20+VisRobot.RobRadia); temp_ang = temp_DistAng.Angle; m_tempXPos = (int)(m_CXpos - temp_dist*sin(temp_ang*PI/180)); m_tempYPos = (int)(m_CYpos - temp_dist*cos(temp_ang*PI/180)); if (m_bVision) pControlDC->Ellipse(m_tempXPos-10,m_tempYPos-10,m_tempXPos+10,m_tempYPos+10); pen.DeleteObject(); ppen->DeleteObject(); } } pWnd->ReleaseDC(pControlDC); }
BOOL CTrayNotifyIcon::GetDynamicDCAndBitmap(CDC* pDC, CBitmap* pBitmap) { //Validate our parameters ATLASSERT(pDC != NULL); ATLASSERT(pBitmap != NULL); //Get the HWND for the desktop #ifdef _AFX CWnd* pWndScreen = CWnd::GetDesktopWindow(); if (pWndScreen == NULL) return FALSE; #else CWindow WndScreen(::GetDesktopWindow()); if (!WndScreen.IsWindow()) return FALSE; #endif //Get the desktop HDC to create a compatible bitmap from #ifdef _AFX CDC* pDCScreen = pWndScreen->GetDC(); if (pDCScreen == NULL) return FALSE; #else CDC DCScreen(WndScreen.GetDC()); if (DCScreen.IsNull()) return FALSE; #endif //Get the width and height of a small icon int w = GetSystemMetrics(SM_CXSMICON); int h = GetSystemMetrics(SM_CYSMICON); //Create an off-screen bitmap that the dynamic tray icon //can be drawn into. (Compatible with the desktop DC). #ifdef _AFX BOOL bSuccess = pBitmap->CreateCompatibleBitmap(pDCScreen, w, h); #else BOOL bSuccess = (pBitmap->CreateCompatibleBitmap(DCScreen.operator HDC(), w, h) != NULL); #endif if (!bSuccess) { #ifdef _AFX pWndScreen->ReleaseDC(pDCScreen); #else WndScreen.ReleaseDC(DCScreen); #endif return FALSE; } //Get a HDC to the newly created off-screen bitmap #ifdef _AFX bSuccess = pDC->CreateCompatibleDC(pDCScreen); #else bSuccess = (pDC->CreateCompatibleDC(DCScreen.operator HDC()) != NULL); #endif if (!bSuccess) { //Release the Screen DC now that we are finished with it #ifdef _AFX pWndScreen->ReleaseDC(pDCScreen); #else WndScreen.ReleaseDC(DCScreen); #endif //Free up the bitmap now that we are finished with it pBitmap->DeleteObject(); return FALSE; } //Select the bitmap into the offscreen DC #ifdef _AFX pDC->SelectObject(pBitmap); #else pDC->SelectBitmap(pBitmap->operator HBITMAP()); #endif //Release the Screen DC now that we are finished with it #ifdef _AFX pWndScreen->ReleaseDC(pDCScreen); #else WndScreen.ReleaseDC(DCScreen); #endif return TRUE; }
CString CRichEditCtrlExtn::GetTextFormatting(const CString &csHTML, int &iError) { CString csText, csToken, csHTMLTag; int iCurrentFontSize, iCurrentFontPointSize; int iDefaultFontSize, iDefaultFontPointSize; int iTextPosition(0); int curPos, oldPos; int ierrorcode(0); bool bHTMLTag; m_vFormat.clear(); m_vALink.clear(); st_format this_format; ALink this_ALink; std::bitset<3> bsFontChange; // facename, size, color std::vector<CString> vLastFacenames; std::vector<COLORREF> vLastColours; std::vector<int> vLastSizes; std::vector<int> vFontChangeStart; std::vector<std::bitset<3>> vFontChange; std::stack<st_format> format_stack; std::stack<int> type_stack; // Validate the HTML curPos = 0; oldPos = 0; int iBold(0), iItalic(0), iUnderline(0), iFont(0), iAnchor(0); bool bNestedBold(false), bNestedItalic(false), bNestedUnderline(false), bNestedAnchor(false), bOverlapped(false); csToken = csHTML.Tokenize(L"<>", curPos); while (csToken != L"" && curPos != -1) { oldPos = curPos - csToken.GetLength() - 1; CString a = csHTML.Mid(oldPos - 1, 1); CString b = csHTML.Mid(curPos - 1, 1); if (csHTML.Mid(oldPos - 1, 1) == L"<" && csHTML.Mid(curPos - 1, 1) == L">") { bHTMLTag = true; } else bHTMLTag = false; if (bHTMLTag) { // Must be a HTML Tag csHTMLTag = csToken; csHTMLTag.MakeLower(); if (csHTMLTag == L"b") { type_stack.push(Bold); iBold++; if (iBold != 1) bNestedBold = true; goto vnext; } else if (csHTMLTag == L"/b") { int &iLastType = type_stack.top(); if (iLastType != Bold) bOverlapped = true; iBold--; type_stack.pop(); goto vnext; } else if (csHTMLTag == L"i") { type_stack.push(Italic); iItalic++; if (iItalic != 1) bNestedItalic = true; goto vnext; } else if (csHTMLTag == L"/i") { int &iLastType = type_stack.top(); if (iLastType != Italic) bOverlapped = true; iItalic--; type_stack.pop(); goto vnext; } else if (csHTMLTag == L"u") { type_stack.push(Underline); iUnderline++; if (iUnderline != 1) bNestedUnderline = true; goto vnext; } else if (csHTMLTag == L"/u") { int &iLastType = type_stack.top(); if (iLastType != Underline) bOverlapped = true; iUnderline--; type_stack.pop(); goto vnext; } else if (csHTMLTag.Left(4) == L"font") { type_stack.push(Font); iFont++; goto vnext; } else if (csHTMLTag == L"/font") { int &iLastType = type_stack.top(); if (iLastType != Font) bOverlapped = true; iFont--; type_stack.pop(); goto vnext; } else if (csHTMLTag.Left(6) == L"a href") { type_stack.push(Link); iAnchor++; if (iAnchor != 1) bNestedAnchor = true; goto vnext; } else if (csHTMLTag == L"/a") { int &iLastType = type_stack.top(); if (iLastType != Link) bOverlapped = true; iAnchor--; type_stack.pop(); goto vnext; } else { // unsupported tag or typo - return raw string return csHTML; } } vnext: oldPos = curPos; csToken = csHTML.Tokenize(L"<>", curPos); }; if (bNestedBold) ierrorcode += 1; if (iBold != 0) ierrorcode += 2; if (bNestedItalic) ierrorcode += 4; if (iItalic != 0) ierrorcode += 8; if (bNestedUnderline) ierrorcode += 16; if (iUnderline != 0) ierrorcode += 32; if (bNestedAnchor) ierrorcode += 64; if (iAnchor != 0) ierrorcode += 128; if (iFont != 0) ierrorcode += 256; if (bOverlapped) ierrorcode +=512; iError = ierrorcode; if (ierrorcode != 0) { return L""; } // Now really process the HTML NONCLIENTMETRICS ncm ={0}; ncm.cbSize = sizeof(NONCLIENTMETRICS); SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, NULL); CWnd *pWndDesk = GetDesktopWindow(); CDC *pDCDesk = pWndDesk->GetWindowDC(); int logPixY = pDCDesk->GetDeviceCaps(LOGPIXELSY); pWndDesk->ReleaseDC(pDCDesk); iDefaultFontPointSize = MulDiv(ncm.lfMessageFont.lfHeight, 72, logPixY); iCurrentFontPointSize = iDefaultFontPointSize; iDefaultFontSize = ConvertPointsToSize(iCurrentFontPointSize); iCurrentFontSize = iDefaultFontSize; curPos = 0; oldPos = 0; csToken = csHTML.Tokenize(L"<>", curPos); while (csToken != L"" && curPos != -1) { oldPos = curPos - csToken.GetLength() - 1; CString a = csHTML.Mid(oldPos - 1, 1); CString b = csHTML.Mid(curPos - 1, 1); if (csHTML.Mid(oldPos - 1, 1) == L"<" && csHTML.Mid(curPos - 1, 1) == L">") { bHTMLTag = true; } else bHTMLTag = false; if (!bHTMLTag && iAnchor != 0) goto next; if (bHTMLTag) { // Must be a HTML Tag csHTMLTag = csToken; csHTMLTag.MakeLower(); if (csHTMLTag == L"b") { this_format.entrytype = Bold; this_format.iStart = iTextPosition; format_stack.push(this_format); goto next; } else if (csHTMLTag == L"/b") { st_format& cur_format = format_stack.top(); cur_format.iEnd = iTextPosition; m_vFormat.push_back(cur_format); format_stack.pop(); goto next; } else if (csHTMLTag == L"i") { this_format.entrytype = Italic; this_format.iStart = iTextPosition; format_stack.push(this_format); goto next; } else if (csHTMLTag == L"/i") { st_format& cur_format = format_stack.top(); cur_format.iEnd = iTextPosition; m_vFormat.push_back(cur_format); format_stack.pop(); goto next; } else if (csHTMLTag == L"u") { this_format.entrytype = Underline; this_format.iStart = iTextPosition; format_stack.push(this_format); goto next; } else if (csHTMLTag == L"/u") { st_format& cur_format = format_stack.top(); cur_format.iEnd = iTextPosition; m_vFormat.push_back(cur_format); format_stack.pop(); goto next; } else if (csHTMLTag == L"/font") { if (vFontChange.empty()) { // malformed <font> token return csHTML; } std::bitset<3> &bsLastFont = vFontChange.back(); int &iFontChangeStart = vFontChangeStart.back(); st_format& cur_format = format_stack.top(); if (bsLastFont.test(FACENAMECHANGED)) { CString &csLastFaceName = vLastFacenames.back(); cur_format.entrytype = Name; cur_format.iStart = iFontChangeStart; cur_format.iEnd = iTextPosition; SecureZeroMemory(cur_format.tcszFACENAME, sizeof(cur_format.tcszFACENAME)); #if (_MSC_VER >= 1400) wcscpy_s(cur_format.tcszFACENAME, LF_FACESIZE, (LPCWSTR)csLastFaceName); #else wcscpy(cur_format.tcszFACENAME, (LPCWSTR)csLastFaceName); #endif m_vFormat.push_back(cur_format); vLastFacenames.pop_back(); } if (bsLastFont.test(SIZECHANGED)) { int &iLastSize = vLastSizes.back(); cur_format.entrytype = Size; cur_format.iStart = iFontChangeStart; cur_format.iEnd = iTextPosition; cur_format.iSize = iLastSize; m_vFormat.push_back(cur_format); vLastSizes.pop_back(); if (!vLastSizes.empty()) { int &i = vLastSizes.back(); iCurrentFontPointSize = i; iCurrentFontSize = ConvertPointsToSize(iCurrentFontPointSize); } else { iCurrentFontPointSize = iDefaultFontPointSize; iCurrentFontSize = iDefaultFontSize; } } if (bsLastFont.test(COLOURCHANGED)) { COLORREF &c = vLastColours.back(); cur_format.entrytype = Colour; cur_format.iStart = iFontChangeStart; cur_format.iEnd = iTextPosition; cur_format.cr = c; m_vFormat.push_back(cur_format); vLastColours.pop_back(); } vFontChange.pop_back(); vFontChangeStart.pop_back(); format_stack.pop(); goto next; } else if (csHTMLTag == L"/a") { goto next; } // Check for fonts // <font face="xxxxx" size="n" color="xxxxx">....</font> if (csHTMLTag.Left(5) == L"font ") { CString csFontToken, csFontVerb, csFontVerbValue; int curFontPos(0); bsFontChange.reset(); csFontToken = csHTMLTag.Tokenize(L"\"", curFontPos); csFontVerb = csFontToken.Right(6); csFontVerb.TrimLeft(); // Skip over first token of 'font verb=' csFontVerbValue = csHTMLTag.Tokenize(L"\"", curFontPos); while (csFontVerbValue != L"" && curFontPos != -1) { if (csFontVerb == L"face=") { bsFontChange.set(FACENAMECHANGED); vLastFacenames.push_back(csFontVerbValue); } else if (csFontVerb == L"size=") { bsFontChange.set(SIZECHANGED); iCurrentFontPointSize = ConvertSizeToPoints(csFontVerbValue, iCurrentFontSize); vLastSizes.push_back(iCurrentFontPointSize); } else if (csFontVerb == L"color=") { bsFontChange.set(COLOURCHANGED); COLORREF crNewFontColour = ConvertColourToColorRef(csFontVerbValue); vLastColours.push_back(crNewFontColour); } csFontVerb = csHTMLTag.Tokenize(L"\"", curFontPos); if (csFontVerb.IsEmpty() && curFontPos == -1) break; csFontVerbValue = csHTMLTag.Tokenize(L"\"", curFontPos); }; vFontChange.push_back(bsFontChange); vFontChangeStart.push_back(iTextPosition); format_stack.push(this_format); goto next; } // check for hyperlink // <a href="http://www.microsoft.com">Friendly name</a> if (csHTMLTag.Left(7) == L"a href=") { long dwTEnd; CString csURL; dwTEnd = csHTMLTag.Find(L"\"", 8); if (dwTEnd >= 0) { csURL = csHTMLTag.Mid(8, dwTEnd - 8); if (!csURL.IsEmpty()) { csURL.MakeLower(); #if (_MSC_VER >= 1400) wcscpy_s(this_ALink.tcszURL, _MAX_PATH, csURL); #else wcscpy(this_ALink.tcszURL, csURL); #endif } } // Now get Friendly Name (note doing this within the while loop!) oldPos = curPos; csToken = csHTML.Tokenize(L"<>", curPos); csText += csToken; this_ALink.iStart = iTextPosition; iTextPosition += csToken.GetLength(); this_ALink.iEnd = iTextPosition; m_vALink.push_back(this_ALink); goto next; } } csToken.Replace(L"<", L"<"); csToken.Replace(L">", L">"); // Real text or unknown HTML tag if (bHTMLTag) { // We didn't recognise it! Put back the < & > csText += L"<" + csToken + L">"; iTextPosition += csToken.GetLength() + 2; } else { csText += csToken; iTextPosition += csToken.GetLength(); } next: oldPos = curPos; csToken = csHTML.Tokenize(L"<>", curPos); }; return csText; }
void CLDlg::OnPaint() { /////////////////////////////////////////////////////////////////////////////////////// ////OnPaint redefined // CBitmap bm; // bm.LoadBitmap(IDB_BITMAP2); //DisplayBitmap(pControlDC,&bm,0,0,100,100); CWnd* pWnd = GetDlgItem(IDC_STATIC1); // IDC_STATIC1 specified // in the dialog editor CDC* pControlDC = pWnd->GetDC(); pWnd->Invalidate(); pWnd->UpdateWindow(); pControlDC->SelectStockObject(0); pBrush=new CBrush(); pBrush->CreateSolidBrush(RGB(50,25,50)); CRect rect; rect.left=0; rect.top=0; rect.bottom=650; rect.right=650; pControlDC->Rectangle(rect); // black square bullet // pControlDC->Ellipse(CRect(0,0,100,100)); pControlDC->FillRect(rect,pBrush); switch(lflag) { case 0: { int intrval=650/cnt; for(int cntr=1;cntr<cnt;cntr++) { pControlDC->MoveTo(0,intrval*cntr); pControlDC->LineTo(650,intrval*cntr); } } break; case 1: { if(flDV) { int interval=650/flrows[crflid]; for(int i=1;i<flrows[crflid];i++) { pControlDC->MoveTo(0,interval*i); pControlDC->LineTo(650,interval*i); } interval=650/flclmns[crflid]; for(i=1;i<flclmns[crflid];i++) { pControlDC->MoveTo(interval*i,0); pControlDC->LineTo(interval*i,650); } } ///////// formation of labs /////////// CBrush *pBrush=new CBrush(); pBrush->CreateSolidBrush(RGB(0,0,155)); for(int tempcntr=0;tempcntr<labcount;tempcntr++) { if(labfl[tempcntr]==crflid) { //int x1=pt1[tempcntr].y*(650/flclmns[crflid]),y1=pt1[tempcntr].x*(650/flrows[crflid]) ; //int x2=pt2[tempcntr].y*(650/flclmns[crflid]),y2=pt2[tempcntr].x*(650/flrows[crflid]) ; long xx1=pt1[tempcntr].x,yy1=pt1[tempcntr].y; long xx2=pt2[tempcntr].x,yy2=pt2[tempcntr].y; if(xx1>xx2) { int temp=xx1; xx1=xx2; xx2=temp; } if(yy1>yy2) { int temp=yy1; yy1=yy2; yy2=temp; } char str1[30],str2[10]; itoa(xx1,str1,10); itoa(yy1,str2,10); strcat(str1,"#"); strcat(str1,str2); itoa(xx2,str2,10); strcat(str1,"#"); strcat(str1,str2); itoa(yy2,str2,10); strcat(str1,"#"); strcat(str1,str2); //AfxMessageBox(str1); pControlDC->SelectStockObject(1); //rect.left=5000; //rect.top=5000; //rect.right=0; //rect.bottom=0; //int xyflag=1; //int xleft,ytop,xright,ybottom; //for(int i=xx1;i<=xx2;i++) // for(int j=yy1;j<=yy2;j++) //{ rect.left=yy1*(650/flclmns[crflid]); rect.top=xx1*(650/flrows[crflid]); rect.bottom=(xx2+1)*(650/flrows[crflid]); rect.right=(yy2+1)*(650/flclmns[crflid]); //} pControlDC->FillRect(rect,pBrush); pControlDC->Draw3dRect(rect,COLORREF(RGB(255,0,0)),COLORREF(RGB(255,0,0))); } } ///////// formation of labs /////////// } break; case 2: { int interval=650/crrows; for(int i=1;i<crrows;i++) { pControlDC->MoveTo(0,interval*i); pControlDC->LineTo(650,interval*i); } interval=650/crclmns; for(i=1;i<crclmns;i++) { pControlDC->MoveTo(interval*i,0); pControlDC->LineTo(interval*i,650); } //////////////////// placing computers /////////////// for(int tempcntr=0;tempcntr<cmcount;tempcntr++) { if(cmlabid[tempcntr]==crlabid) { long xx1=cmpt[tempcntr].x,yy1=cmpt[tempcntr].y; /////////////// place computer img ///////////////////// /// ........................... rect.left=yy1*(650/crclmns); rect.top=xx1*(650/crrows); rect.bottom=(xx1+1)*(650/crrows); rect.right=(yy1+1)*(650/crclmns); //} pControlDC->FillRect(rect,pBrush); pControlDC->Draw3dRect(rect,COLORREF(RGB(255,0,0)),COLORREF(RGB(255,0,0))); /////////////// place computer img ///////////////////// } } //////////////////// placing computers /////////////// }break; } pWnd->ReleaseDC(pControlDC); //////////////////////////////////////////////////////////////////////////////////////// if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } }
void CSimpleDcmViewerDlg::drawPictCtrl() { if (TFileManager::getInst()->m_D == 0) return; static bool first = true; if (first) { CWnd *cwndPC = GetDlgItem(IDC_PC); first = false; CRect r; WINDOWPLACEMENT winplace; cwndPC->GetClientRect(&r); cwndPC->GetWindowPlacement(&winplace); m_pcW = m_pcH = PC_SIZE;//-2 m_pcX = winplace.rcNormalPosition.left; m_pcY = winplace.rcNormalPosition.top; } // picture ControlのCWndを取得 CWnd *pcWnd = GetDlgItem(IDC_PC); CDC *pcDC = pcWnd->GetDC(); BITMAPINFO binfo; ZeroMemory(&binfo, sizeof(binfo)); binfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); binfo.bmiHeader.biBitCount = 32;//1pixel 32-bit (4-byte) binfo.bmiHeader.biPlanes = 1; binfo.bmiHeader.biWidth = PC_SIZE; binfo.bmiHeader.biHeight = -PC_SIZE; //if negative : origin --> left top byte *bmpbits; HBITMAP hbmp = CreateDIBSection(NULL, &binfo, DIB_RGB_COLORS, (void **)(&bmpbits), NULL, 0); CBitmap *cbmp = CBitmap::FromHandle(hbmp); CDC cbmpDC; cbmpDC.CreateCompatibleDC(pcDC); CBitmap *oldBmp = cbmpDC.SelectObject(cbmp); const int imgW = TFileManager::getInst()->m_W; const int imgH = TFileManager::getInst()->m_H; const int imgD = TFileManager::getInst()->m_D; const int imgZ = m_slider_z .GetPos(); const float vMax = (float)m_slider_winLvMax.GetPos(); const float vMin = (float)m_slider_winLvMin.GetPos(); int x0 = m_spin_clipXmin.GetPos32(), x1 = m_spin_clipXmax.GetPos32(); t_cropI(x0, 0, imgW - 1); t_cropI(x0, 0, imgW - 1); int y0 = m_spin_clipYmin.GetPos32(), y1 = m_spin_clipYmax.GetPos32(); t_cropI(y0, 0, imgH - 1); t_cropI(y0, 0, imgH - 1); int z0 = m_spin_clipZmin.GetPos32(), z1 = m_spin_clipZmax.GetPos32(); t_cropI(z0, 0, imgD - 1); t_cropI(z0, 0, imgD - 1); if (imgZ < 0 || imgZ > imgD - 1) return; const int WH = imgW * imgH; float *sliceImg = TFileManager::getInst()->m_volume[imgZ]; double xCoef = imgW / (double)PC_SIZE; double yCoef = imgH / (double)PC_SIZE; for (int y = 0; y < PC_SIZE; ++y) { for (int x = 0; x < PC_SIZE; ++x) { int imgX = (int)((x + 0.5) * xCoef); int imgY = (int)((y + 0.5) * yCoef); int imgI = imgX + imgY * imgW; const float imgV = sliceImg[imgI]; int bmpI = (x + y * PC_SIZE) * 4; if (x0 <= imgX && imgX <= x1 && y0 <= imgY && imgY <= y1 && z0 <= imgZ && imgZ <= z1) { byte c = (byte)(255.0 * min(1, max(0, (imgV - vMin) / (vMax - vMin)))); bmpbits[bmpI + 0] = bmpbits[bmpI + 1] = bmpbits[bmpI + 2] = c; } else { bmpbits[bmpI + 0] = 192; bmpbits[bmpI + 1] = bmpbits[bmpI + 2] = 0; } } } pcDC->BitBlt(1, 1, PC_SIZE - 2, PC_SIZE - 2, &cbmpDC, 0, 0, SRCCOPY); //解放 cbmpDC.SelectObject(oldBmp); DeleteDC(cbmpDC); DeleteObject(hbmp); pcWnd->ReleaseDC(pcDC); }
void InformApp::SetFonts(void) { // Clear existing fonts m_fonts[FontDisplay].DeleteObject(); m_fonts[FontFixedWidth].DeleteObject(); // Look for registry settings CRegKey registryKey; if (registryKey.Open(HKEY_CURRENT_USER,REGISTRY_PATH_WINDOW,KEY_READ) == ERROR_SUCCESS) { char fontName[MAX_PATH]; ULONG len = sizeof fontName; if (registryKey.QueryStringValue("Font Name",fontName,&len) == ERROR_SUCCESS) m_fontNames[FontDisplay] = fontName; len = sizeof fontName; if (registryKey.QueryStringValue("Fixed Font Name",fontName,&len) == ERROR_SUCCESS) m_fontNames[FontFixedWidth] = fontName; DWORD fontSize = 0; if (registryKey.QueryDWORDValue("Font Size",fontSize) == ERROR_SUCCESS) { m_fontSizes[FontDisplay] = fontSize; m_fontSizes[FontFixedWidth] = fontSize; } } // Get a device context for the display CWnd* wnd = CWnd::GetDesktopWindow(); CDC* dc = wnd->GetDC(); if (m_fontNames[FontFixedWidth].IsEmpty()) { const char* fixedFonts[] = { "Consolas", "Lucida Console", "Courier New", "Courier" }; // Search the list of known fixed width fonts for a match LOGFONT fontInfo; ::ZeroMemory(&fontInfo,sizeof fontInfo); fontInfo.lfCharSet = DEFAULT_CHARSET; bool found = false; for (int i = 0; i < sizeof fixedFonts / sizeof fixedFonts[0]; i++) { strcpy(fontInfo.lfFaceName,fixedFonts[i]); ::EnumFontFamiliesEx(dc->GetSafeHdc(),&fontInfo,(FONTENUMPROC)EnumFontProc,(LPARAM)&found,0); if (found) { m_fontNames[FontFixedWidth] = fontInfo.lfFaceName; break; } } } // Get desktop settings, and use the message font as a default NONCLIENTMETRICS ncm; ::ZeroMemory(&ncm,sizeof ncm); ncm.cbSize = sizeof ncm; ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,sizeof ncm,&ncm,0); int fontSize = abs(MulDiv(ncm.lfMessageFont.lfHeight,72,dc->GetDeviceCaps(LOGPIXELSY))); fontSize = max(fontSize,(theOS.GetWindowsVersion() < 6) ? 8 : 9); for (int i = 0; i < 3; i++) { if (m_fontNames[i].IsEmpty()) m_fontNames[i] = ncm.lfMessageFont.lfFaceName; if (m_fontSizes[i] == 0) m_fontSizes[i] = fontSize; } if ((HFONT)m_fonts[FontPanel] == 0) { LOGFONT fontInfo; ::ZeroMemory(&fontInfo,sizeof fontInfo); GetFont(InformApp::FontSystem)->GetLogFont(&fontInfo); fontInfo.lfHeight = (LONG)(Panel::GetFontScale(wnd,dc) * fontInfo.lfHeight); m_fontNames[FontPanel] = m_fontNames[FontSystem]; m_fontSizes[FontPanel] = abs(::MulDiv(fontInfo.lfHeight,72,dc->GetDeviceCaps(LOGPIXELSY))); m_fonts[FontPanel].CreateFontIndirect(&fontInfo); } // Release the desktop device context wnd->ReleaseDC(dc); }