//畫圈 void MsrFlow::DrawACircle(CPoint point) { /* 在此畫出來的圈是以160*160大小 以中心點為參考點畫出來的 原函數是以左上角為參考點,在此修正誤差,將決定好的參考點 再往左往上各算一個半徑的距離,畫出來 */ //設定圈圈顏色=與背景相反顏色 COLORREF CircleColor; CircleColor = RGB(255,255,255)-BackGroundColor; //設定畫圈目標物位址 CWnd* pWndGrid = GetDlgItem(IDC_COLOR_PATTERN); CDC* pDC = pWndGrid->GetDC(); //設定畫筆 CPen aPen; aPen.CreatePen(PS_INSIDEFRAME,5,CircleColor); //設定暫存畫筆空間 CPen* pOldPen = pDC ->SelectObject(&aPen); //對圓修正誤差,從左上調到中心(開方形可繪區塊) CPoint StartDrawPoint(-80,-80); CPoint EndDrawPoint(80,80); CRect* pRect = new CRect(point+StartDrawPoint,point+EndDrawPoint); //畫下去(畫下圓形,起點0,0,終點0,0) CPoint Start(0,0); CPoint End(0,0); pDC->Arc(pRect,Start,End); //畫筆換回預設值 pDC->SelectObject(pOldPen); }
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 SetWidthByContentInListBox(CDialog* pDlg, int nID) { if (nID <= 0|| pDlg == NULL) return; CWnd* pWnd = (CWnd*)pDlg; CListBox* pCB = (CListBox*)pWnd->GetDlgItem(nID); if (pCB == NULL) return; int origSize = pCB->GetHorizontalExtent(); int maxSize = origSize; CDC* pDC = pWnd->GetDC(); CString cStr; int str_num = pCB->GetCount(); for (int i = 0; i < str_num; i++) { pCB->GetText(i, cStr); CSize strSize = pDC->GetOutputTextExtent(cStr); if (strSize.cx > maxSize) maxSize = strSize.cx; } // in case when adding to list, existing items may be // longer than newer ones, so may not want to resize if (maxSize > origSize) pCB->SetHorizontalExtent(maxSize); }
BOOL CreditsDialog::OnInitDialog() { char legalFilePath[MAX_PATH]; strcpy_s(legalFilePath, sizeof(legalFilePath), getCormanLispDirectory()); strcat_s(legalFilePath, sizeof(legalFilePath), "\\documentation\\credits.txt"); DWORD length; mappedFile = MapFile(legalFilePath, &length); char buf[0x6000]; if (mappedFile) memcpy(buf, mappedFile, length); buf[length] = 0; CWnd* item = GetDlgItem(IDC_LEGALTEXT); if (item && mappedFile) item->SetWindowText(buf); CDC* cdc = item->GetDC(); HDC hDC = cdc->m_hDC; CFont* font = theApp.getCourierFont(hDC, 10); item->SetFont(font, TRUE); SelectObject(hDC, *font); item = GetDlgItem(IDOK); if (item) ((CButton*)item)->SetButtonStyle(BS_DEFPUSHBUTTON); SetDefID(IDOK); return FALSE; }
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; }
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; }
void TimeTestDlg::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: 在此处添加消息处理程序代码 // 不为绘图消息调用 CDialog::OnPaint() //绘制背景图片 CRect rect; GetClientRect(&rect); CDC dcMem; dcMem.CreateCompatibleDC(&dc); CBitmap bmpBackground; bmpBackground.LoadBitmap(IDB_BITMAP27); BITMAP bitmap; bmpBackground.GetBitmap(&bitmap); CBitmap* pbmpPri = dcMem.SelectObject(&bmpBackground); dc.StretchBlt(0,0,rect.Width(), rect.Height(), &dcMem,0,0,bitmap.bmWidth, bitmap.bmHeight, SRCCOPY); //绘制直方图等图 CWnd* graphFrame = (CWnd*)GetDlgItem(IDC_STATIC); CDC* pDC = graphFrame->GetDC(); testGraph->DrawGraph(pDC); ReleaseDC(pDC); }
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); }
CString CGrammarBuilderComplxConDlg::FormatSamplePopup(CString strPopupText,int* nWidth,int* nHeight) { int i,x,nNumberOfLines,nW,nH; CString Q,R,S,T,CR,strNewPopupText; wchar_t cr[5]; CSize sizeText; CWnd* pWnd; CDC* pDC; cr[0]=0x0D; cr[1]=0x0A; cr[2]=0; CR=cr; S=L""; nNumberOfLines=0; nW=0; nH=0; pWnd=&m_recPopup; pDC=pWnd->GetDC(); strPopupText+=L" "; while (strPopupText!=L"") { i=strPopupText.Find(L" "); if (i>-1) { T=strPopupText.Left(i); strPopupText=strPopupText.Mid(i+1); } else { T=strPopupText; strPopupText=L""; } sizeText=pDC->GetTextExtent(S+T); //GetTextExtent depends on pDC->SelectObject(m_fontTarget), not the rec's default font if (sizeText.cx<700) //if this word will fit on this line { S+=L" "+T; //add this word to this line } else { strNewPopupText+=S+L" "+CR; //add current line to new text S=L" "+T; //set new line to first word nNumberOfLines++; //inc the line counter sizeText=pDC->GetTextExtent(strNewPopupText); //GetTextExtent depends on pDC->SelectObject(m_fontTarget), not the rec's default font x=sizeText.cx; if (x>nW) nW=x; //save width of longest line } } strNewPopupText+=L" "+S; //add the last line nNumberOfLines++; //inc the line counter sizeText=pDC->GetTextExtent(S); //GetTextExtent depends on pDC->SelectObject(m_fontTarget), not the rec's default font x=sizeText.cx; if (x>nW) nW=x; //save width of longest line nH=(sizeText.cy+2)*nNumberOfLines; *nHeight=nH; if (nW>660) nW=660; *nWidth=nW; return strNewPopupText; }
void CGrammarBuilderComplxConDlg::OnMouseMoveDatatblctrlcomplexconcepts(short Button, short Shift, long X, long Y) { int nFirstVisibleRow,nRow,nRows,nTableTop,nTableLeft,x,y,nWidth,nHeight; static float left, top, right, bottom; CRect rect; BOOL B; CString T,strPopupText; LPRECT lpRect; LPPOINT lpPoint; CPoint pt; CSize sizeText; CWnd* pWnd; CDC* pDC; lpRect=▭ lpPoint=&pt; if (X>left && X<right && Y>top && Y<bottom) return; //if mouse still in same region, don't redisplay popup window if (m_bPopupVisible) HidePopup(); pWnd=&m_datatblComplexConcepts; pWnd->GetWindowRect(rect); //get location of table nTableTop=rect.top; //get top of table nTableLeft=rect.left; //get left side of table nFirstVisibleRow=m_datatblComplexConcepts.GetRowSet().GetFirstVisible(paneTop); pWnd=&m_recPopup; pDC=pWnd->GetDC(); nRows=m_datatblComplexConcepts.GetRowSet().GetCount(); for (nRow=nFirstVisibleRow;nRow<nRows;nRow++) { B=m_datatblComplexConcepts.GetCellSet().GetItem(nRow,1).GetRect(paneLeftTop,&left,&top,&right,&bottom); //get concept cell if (B) //if cell is visible { rect=CRect((int) left, (int) top, (int) right, (int) bottom); if (X>left && X<right && Y>top && Y<bottom) //if mouse over cell { T=m_datatblComplexConcepts.GetRowSet().GetItem(nRow).GetLabel(); nRow=_wtoi(T); //get the concept's true row nRow--; strPopupText=m_pDoc->GetComplexConceptsSpelloutRuleComment(m_nSyntacticCategory,nRow); //get this rule's comment if (strPopupText.GetLength()>0) { strPopupText=FormatSamplePopup(strPopupText,&nWidth,&nHeight); //break text into multiple lines if necessary x=(int)left-20; if (x+nWidth>700) x=(int)(left-nWidth+100); if (x<10) x=10; y=(int)bottom+30-nHeight; if (y<10) y=10; pWnd=&m_recPopup; pWnd->MoveWindow(x,y,nWidth,nHeight); m_recPopup.SetSel(0,-1); //delete the previous text m_recPopup.SetWindowText(strPopupText); pWnd->ShowWindow(SW_SHOW); m_bPopupVisible=TRUE; } return; } } } }
BOOL palEditDlg::OnInitDialog() { CDialog::OnInitDialog(); InitCommonProps(); switch(m_lightingType) { case TS::Material::ShadingSmooth: m_lightingSmooth.SetCheck(1); break; case TS::Material::ShadingFlat: m_lightingFlat.SetCheck(1); break; case TS::Material::ShadingNone: m_lightingUnlit.SetCheck(1); break; } // Set up the selection box... // RECT listRect; int nHeight, nWidth; m_palListBox.GetClientRect(&listRect); nHeight = listRect.bottom / 16; nWidth = listRect.right / 16; m_palListBox.SetItemHeight(0, nHeight); m_palListBox.SetColumnWidth(nWidth); //get the system palette PALETTEENTRY pal[256]; CWnd* pWnd = GetDlgItem( ID_PAL_LIST ); CDC* pListDC = pWnd->GetDC(); int err = GetSystemPaletteEntries( pListDC->GetSafeHdc(), 0, 256, pal ); AssertFatal(err == 256, "Error retreiving palette!"); for (int i = 0; i < 256; i++) { m_palListBox.AddString((LPCTSTR)i); } if (m_selectedColor >= 0 && m_selectedColor <= 255) { m_palListBox.SetCurSel(m_selectedColor); } else { m_palListBox.SetCurSel(0); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should 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 DlgMidf::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: 在此处添加消息处理程序代码 // 不为绘图消息调用 CDialogEx::OnPaint() CWnd* pWnd = GetDlgItem(IDC_pic); CDC* pDC = pWnd->GetDC(); pWnd->Invalidate(); pWnd->UpdateWindow(); m_adp->Draw(pDC); }
LRESULT CloseButton::OnMouseLeave(WPARAM wParam, LPARAM lParam) { // 鼠标离开控件,显示小控件 m_isMouseInWindow = FALSE; CWnd* pWnd = GetParent(); CDC* ParentDC = pWnd->GetDC(); CRect rectW; GetWindowRect(&rectW); pWnd->ScreenToClient(rectW); GetParent()->InvalidateRect(rectW); Invalidate(FALSE); return 0; }
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 CStaffManageView::OnDraw(CDC *pDC) { if(!m_hPhotoBitmap) return; CWnd *pPictureWnd = GetDlgItem(IDC_STATIC_PHOTO); if (!pPictureWnd) return; HBITMAP OldBitmap; CDC MemDC; MemDC.CreateCompatibleDC(pPictureWnd->GetDC()); OldBitmap=(HBITMAP)MemDC.SelectObject(m_hPhotoBitmap); CRect rect; pPictureWnd->GetWindowRect(rect); pPictureWnd->GetDC()->BitBlt(0 ,0 , rect.Width() , rect.Height(), &MemDC , 0 , 0 ,SRCCOPY); MemDC.SelectObject(OldBitmap); if (m_bClearPicture) ClearPhotoView(); }
void CStaffManageView::ClearPhotoView() { CWnd *pPictureWnd = GetDlgItem(IDC_STATIC_PHOTO); if (!pPictureWnd) return; CRect rect; pPictureWnd->GetClientRect(rect); CDC *pDC = pPictureWnd->GetDC(); CBrush brush(RGB(255,255,255)); CBrush * pOldBrush = (CBrush*)pDC->SelectObject(&brush); pDC->Rectangle(rect); pDC->SelectObject(pOldBrush); }
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; }
void CGrammarTopicOrderDlg::OnMouseMove(UINT nFlags, CPoint point) { if (m_bDragging) { int nTreeHeight; BOOL b; CDC* pDC; CWnd* pWnd; CRect rect; LPRECT lpRect; HWND hWnd; //handle of this window pWnd=&m_ctrltreeTopics; pDC=pWnd->GetDC(); pWnd->RedrawWindow(); //erase the previously drawn drag image point.y-=30; point.x-=20; b=m_pDragImage->Draw(pDC,0,point,ILD_NORMAL); HTREEITEM hTest; UINT i; UINT* pFlags; pFlags=&i; CPoint pt; pt=point; pt.y+=7; hTest=m_pTree->HitTest(pt,pFlags); if (hTest!=NULL) { b=m_pTree->SelectDropTarget(hTest); hDropTarget=hTest; //save for LButtonUp b=m_pDragImage->Draw(pDC,0,point,ILD_NORMAL); } //now check if cursor near top or bottom of tree so that tree needs to be scrolled pWnd=&m_ctrltreeTopics; hWnd=pWnd->GetSafeHwnd(); lpRect=▭ pWnd->GetWindowRect(lpRect); nTreeHeight=rect.bottom-rect.top-25; if ((point.y>=0 && point.y<=15) || (point.y>=nTreeHeight-10 && point.y<=nTreeHeight)) //if cursor still in tree but near top or bottom { i=(UINT)SetTimer(1,500,NULL); //init timer to 500 msecs, if timer expires, OnTimer will scroll the tree ASSERT(i!=0); } } CDialog::OnMouseMove(nFlags, point); }
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; }
CSize CGumpStatic::GetTextExtend() const { CGumpEditorDoc* pDoc = GfxGetGumpDocument(); ASSERT(pDoc); CWnd* pWnd = AfxGetMainWnd(); //pDoc->FindView(RUNTIME_CLASS(CGumpEditorView)); CDC* pDC = pWnd->GetDC(); CFont* pFont = pDoc->GetFont(m_fontId); CFont* pOld = pDC->SelectObject(pFont); pDC->SelectObject(pFont); CSize size = pDC->GetTextExtent(GetTitle()); pDC->SelectObject(pOld); return size; }
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; }
BOOL CThetaGridAdjustmentSimpleOutputDlg::OnInitDialog() { int i; CString T; BOOL b; CWnd* pWnd; CDC* pDC; pWnd=this; pWnd->CenterWindow(); if (m_nType==1) pWnd->SetWindowTextW(L"Simple Output - Event's Arguments"); //if dealing with the event's arguments else if (m_nType==2) pWnd->SetWindowTextW(L"Simple Output - Complement Clause"); //if dealing with the event's complement clause CDialog::OnInitDialog(); m_bSubjectRaised=FALSE; m_strTargetFontName=m_pDoc->GetTargetLanguageFontName(); //used in ChangeFont if (HFONT(m_fontTarget)==NULL) //first time this modeless dialog activated { //create the fonts that will be used in the combo boxes pWnd=&m_datatblInput; pDC=pWnd->GetDC(); //get a pointer to the device context T=m_pDoc->GetSourceLanguageFontName(4); b=m_fontArial.CreatePointFont(90,L"Arial",pDC); if (b==FALSE) AfxMessageBox(L"Unable to create Arial font.",MB_OK); i=m_pDoc->GetTargetLanguageFontSize(); b=m_fontTarget.CreatePointFont(10*i,m_strTargetFontName,pDC); if (b==FALSE) AfxMessageBox(L"Unable to create Target font.",MB_OK); } SetupTable(); if (m_nType==2) //if specifying features for object complement clause { pWnd=GetDlgItem(IDC_BUTTONFEATURESET); pWnd->MoveWindow(12,68,75,22); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
void CEditGlow::ShowSearchEditFrame(CDC *pdc, bool bUse) { CRect rectEdit; // ËÑË÷¿òλÖà CWnd *pWnd = GetParent(); this->GetWindowRect(rectEdit); pWnd->ScreenToClient(&rectEdit); //CDC* pdc = pWnd->GetDC(); Gdiplus::Graphics graph(pdc->m_hDC); graph.SetSmoothingMode(Gdiplus::SmoothingModeNone); if(m_pImgBorder && m_pImgBorderGlow) { if(m_bMouseOn || m_bFocus) { Rect rr(rectEdit.left-2 , rectEdit.top-2 , m_pImgBorderGlow->GetWidth(), m_pImgBorderGlow->GetHeight()); graph.DrawImage(m_pImgBorderGlow, rr, (int)0, (int)0, (int)m_pImgBorderGlow->GetWidth(), (int)m_pImgBorderGlow->GetHeight(), UnitPixel ); } else { Rect rr(rectEdit.left-2 , rectEdit.top-2 , m_pImgBorder->GetWidth(), m_pImgBorder->GetHeight()); graph.DrawImage(m_pImgBorder, rr, (int)0, (int)0, (int)m_pImgBorder->GetWidth(), (int)m_pImgBorder->GetHeight(), UnitPixel ); } } return; ISkinMgr* pSkinMgr = AfxGetUIManager()->UIGetSkinMgr(); CDibBitmap* m_bmpEditLeft = pSkinMgr->GetDibBmp("LoginEditLeftBorder"); CDibBitmap* m_bmpEditTop = pSkinMgr->GetDibBmp("LoginEditTopBorder"); CDibBitmap* m_bmpEditRight = pSkinMgr->GetDibBmp("LoginEditRightBorder"); CDibBitmap* m_bmpEditBottom = pSkinMgr->GetDibBmp("LoginEditBottomBorder"); CDibBitmap* m_bmpEditLiftGray = pSkinMgr->GetDibBmp("AuthorListPanelSearchLeftGray"); CDibBitmap* m_bmpEditCenterGray = pSkinMgr->GetDibBmp("AuthorListPanelSearchCenterGray"); CDibBitmap* m_bmpEditRightGray = pSkinMgr->GetDibBmp("AuthorListPanelSearchRightGray"); int nTop = rectEdit.top - m_bmpEditTop->GetHeight(); int nLeft = rectEdit.left-m_bmpEditLeft->GetWidth(); if( bUse ) { CDC* pdc = pWnd->GetDC(); m_bmpEditLeft->SetCDibRect( CRect(nLeft,nTop, nLeft+m_bmpEditLeft->GetWidth(), nTop+m_bmpEditLeft->GetHeight()) ); m_bmpEditLeft->Draw( pdc, FALSE ); m_bmpEditRight->SetCDibRect( CRect(rectEdit.right,nTop, rectEdit.right+m_bmpEditRight->GetWidth(), nTop+m_bmpEditRight->GetHeight()) ); m_bmpEditRight->Draw( pdc, FALSE ); m_bmpEditTop->SetCDibRect( CRect(rectEdit.left,nTop, rectEdit.left+rectEdit.Width(), nTop+m_bmpEditTop->GetHeight()) ); m_bmpEditTop->Draw( pdc, FALSE ); ReleaseDC(pdc); } else { CDC* pdc = pWnd->GetDC(); m_bmpEditLiftGray->SetCDibRect( CRect(nLeft,nTop, nLeft+m_bmpEditLiftGray->GetWidth(), nTop+m_bmpEditLiftGray->GetHeight()) ); m_bmpEditLiftGray->Draw( pdc, FALSE ); m_bmpEditRightGray->SetCDibRect( CRect(rectEdit.right,nTop, rectEdit.right+m_bmpEditRightGray->GetWidth(), nTop+m_bmpEditRightGray->GetHeight()) ); m_bmpEditRightGray->Draw( pdc, FALSE ); //m_bmpEditCenterGray->SetCDibRect( CRect(rectEdit.left,nTop, rectEdit.left+rectEdit.Width(), nTop+m_bmpEditCenter->GetHeight()) ); //m_bmpEditCenter->Draw( pdc, FALSE ); ReleaseDC(pdc); } }
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 CDlgIntensity::OnPaint() { // 字符串 CString str; // 循环变量 LONG i; // 最大计数 LONG lMaxCount = 0; // 设备上下文 CPaintDC dc(this); // 获取绘制坐标的文本框 CWnd* pWnd = GetDlgItem(IDC_COORD); // 指针 CDC* pDC = pWnd->GetDC(); pWnd->Invalidate(); pWnd->UpdateWindow(); pDC->Rectangle(0,0,330,300); // 创建画笔对象 CPen* pPenRed = new CPen; // 红色画笔 pPenRed->CreatePen(PS_SOLID,1,RGB(255,0,0)); // 创建画笔对象 CPen* pPenBlue = new CPen; // 蓝色画笔 pPenBlue->CreatePen(PS_SOLID,1,RGB(0,0, 255)); // 创建画笔对象 CPen* pPenGreen = new CPen; // 绿色画笔 pPenGreen->CreatePen(PS_DOT,1,RGB(0,255,0)); // 选中当前红色画笔,并保存以前的画笔 CGdiObject* pOldPen = pDC->SelectObject(pPenRed); // 绘制坐标轴 pDC->MoveTo(10,10); // 垂直轴 pDC->LineTo(10,280); // 水平轴 pDC->LineTo(320,280); // 写X轴刻度值 str.Format("0"); pDC->TextOut(10, 283, str); str.Format("50"); pDC->TextOut(60, 283, str); str.Format("100"); pDC->TextOut(110, 283, str); str.Format("150"); pDC->TextOut(160, 283, str); str.Format("200"); pDC->TextOut(210, 283, str); str.Format("255"); pDC->TextOut(265, 283, str); // 绘制X轴刻度 for (i = 0; i < 256; i += 5) { if ((i & 1) == 0) { // 10的倍数 pDC->MoveTo(i + 10, 280); pDC->LineTo(i + 10, 284); } else { // 10的倍数 pDC->MoveTo(i + 10, 280); pDC->LineTo(i + 10, 282); } } // 绘制X轴箭头 pDC->MoveTo(315,275); pDC->LineTo(320,280); pDC->LineTo(315,285); // 绘制X轴箭头 pDC->MoveTo(10,10); pDC->LineTo(5,15); pDC->MoveTo(10,10); pDC->LineTo(15,15); // 计算最大计数值 for (i = m_iLowGray; i <= m_iUpGray; i ++) { // 判断是否大于当前最大值 if (m_lCount[i] > lMaxCount) { // 更新最大值 lMaxCount = m_lCount[i]; } } // 输出最大计数值 pDC->MoveTo(10, 25); pDC->LineTo(14, 25); str.Format("%d", lMaxCount); pDC->TextOut(11, 26, str); // 更改成绿色画笔 pDC->SelectObject(pPenGreen); // 绘制窗口上下限 pDC->MoveTo(m_iLowGray + 10, 25); pDC->LineTo(m_iLowGray + 10, 280); pDC->MoveTo(m_iUpGray + 10, 25); pDC->LineTo(m_iUpGray + 10, 280); // 更改成蓝色画笔 pDC->SelectObject(pPenBlue); // 判断是否有计数 if (lMaxCount > 0) { // 绘制直方图 for (i = m_iLowGray; i <= m_iUpGray; i ++) { pDC->MoveTo(i + 10, 280); pDC->LineTo(i + 10, 281 - (int) (m_lCount[i] * 256 / lMaxCount)); } } // 恢复以前的画笔 pDC->SelectObject(pOldPen); // 删除新的画笔 delete pPenRed; delete pPenBlue; delete pPenGreen; }
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 CDlgPointWin::OnPaint() { // 字符串 CString str; // 设备上下文 CPaintDC dc ( this ); // 获取绘制坐标的文本框 CWnd* pWnd = GetDlgItem ( IDC_COORD ); // 指针 CDC* pDC = pWnd->GetDC(); pWnd->Invalidate(); pWnd->UpdateWindow(); pDC->Rectangle ( 0, 0, 330, 300 ); // 创建画笔对象 CPen* pPenRed = new CPen; // 红色画笔 pPenRed->CreatePen ( PS_SOLID, 2, RGB ( 255, 0, 0 ) ); // 创建画笔对象 CPen* pPenBlue = new CPen; // 蓝色画笔 pPenBlue->CreatePen ( PS_SOLID, 2, RGB ( 0, 0, 255 ) ); // 创建画笔对象 CPen* pPenGreen = new CPen; // 绿色画笔 pPenGreen->CreatePen ( PS_DOT, 1, RGB ( 0, 255, 0 ) ); // 选中当前红色画笔,并保存以前的画笔 CGdiObject* pOldPen = pDC->SelectObject ( pPenRed ); // 绘制坐标轴 pDC->MoveTo ( 10, 10 ); // 垂直轴 pDC->LineTo ( 10, 280 ); // 水平轴 pDC->LineTo ( 320, 280 ); // 写坐标 str.Format ( L"0" ); pDC->TextOut ( 10, 281, str ); str.Format ( L"255" ); pDC->TextOut ( 265, 281, str ); pDC->TextOut ( 11, 25, str ); // 绘制X轴箭头 pDC->LineTo ( 315, 275 ); pDC->MoveTo ( 320, 280 ); pDC->LineTo ( 315, 285 ); // 绘制X轴箭头 pDC->MoveTo ( 10, 10 ); pDC->LineTo ( 5, 15 ); pDC->MoveTo ( 10, 10 ); pDC->LineTo ( 15, 15 ); // 更改成绿色画笔 pDC->SelectObject ( pPenGreen ); // 绘制窗口上下限 pDC->MoveTo ( m_bLow + 10, 25 ); pDC->LineTo ( m_bLow + 10, 280 ); pDC->MoveTo ( m_bUp + 10, 25 ); pDC->LineTo ( m_bUp + 10, 280 ); // 更改成蓝色画笔 pDC->SelectObject ( pPenBlue ); // 绘制坐标值 str.Format ( L"(%d, %d)", m_bLow, m_bLow ); pDC->TextOut ( m_bLow + 10, 281 - m_bLow, str ); str.Format ( L"(%d, %d)", m_bUp, m_bUp ); pDC->TextOut ( m_bUp + 10, 281 - m_bUp, str ); // 绘制用户指定的窗口(注意转换坐标系) pDC->MoveTo ( 10, 280 ); pDC->LineTo ( m_bLow + 10, 280 ); pDC->LineTo ( m_bLow + 10, 280 - m_bLow ); pDC->LineTo ( m_bUp + 10, 280 - m_bUp ); pDC->LineTo ( m_bUp + 10, 25 ); pDC->LineTo ( 265, 25 ); // 恢复以前的画笔 pDC->SelectObject ( pOldPen ); // 绘制边缘 pDC->MoveTo ( 10, 25 ); pDC->LineTo ( 265, 25 ); pDC->LineTo ( 265, 280 ); // 删除新的画笔 delete pPenRed; delete pPenBlue; delete pPenGreen; }
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; }
/*--------------------------------------*/ 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); }