//**************************************************************************** void CBCGPDialogBar::OnScrollClient(UINT uiScrollCode) { #ifndef _BCGSUITE_ if (m_scrollSize == CSize(0, 0)) { return; } CRect rectClient; GetClientRect (rectClient); CSize sizeScroll (0, 0); switch (LOBYTE(uiScrollCode)) { case SB_LEFT: sizeScroll.cx = -m_scrollPos.x; break; case SB_RIGHT: sizeScroll.cx = m_scrollSize.cx; break; case SB_LINELEFT: sizeScroll.cx -= m_scrollLine.cx; break; case SB_LINERIGHT: sizeScroll.cx += m_scrollLine.cx; break; case SB_PAGELEFT: sizeScroll.cx -= rectClient.Width(); break; case SB_PAGERIGHT: sizeScroll.cx += rectClient.Width(); break; } const int nScrollButtonSize = GetScrollButtonSize(); if (m_scrollPos.x == 0 && sizeScroll.cx > 0) { sizeScroll.cx += nScrollButtonSize; } if ((m_scrollPos.x + sizeScroll.cx) <= nScrollButtonSize && sizeScroll.cx < 0) { sizeScroll.cx -= nScrollButtonSize; } switch (HIBYTE(uiScrollCode)) { case SB_TOP: sizeScroll.cy = -m_scrollPos.y; break; case SB_BOTTOM: sizeScroll.cy = m_scrollSize.cy; break; case SB_LINEUP: sizeScroll.cy -= m_scrollLine.cy; break; case SB_LINEDOWN: sizeScroll.cy += m_scrollLine.cy; break; case SB_PAGEUP: sizeScroll.cy -= rectClient.Height(); break; case SB_PAGEDOWN: sizeScroll.cy += rectClient.Height(); break; } if (m_scrollPos.y == 0 && sizeScroll.cy > 0) { sizeScroll.cy += nScrollButtonSize; } if ((m_scrollPos.y + sizeScroll.cy) <= nScrollButtonSize && sizeScroll.cy < 0) { sizeScroll.cy -= nScrollButtonSize; } ScrollClient(sizeScroll); #else UNREFERENCED_PARAMETER(uiScrollCode); #endif }
void CSizingControlBar::StartTracking(UINT nHitTest, CPoint point) { SetCapture(); // make sure no updates are pending if (!m_bDragShowContent) RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_UPDATENOW); m_htEdge = nHitTest; m_bTracking = TRUE; BOOL bHorz = IsHorzDocked(); BOOL bHorzTracking = m_htEdge == HTLEFT || m_htEdge == HTRIGHT; m_nTrackPosOld = bHorzTracking ? point.x : point.y; CRect rcBar, rcEdge; GetWindowRect(rcBar); GetEdgeRect(rcBar, m_htEdge, rcEdge); m_nTrackEdgeOfs = m_nTrackPosOld - (bHorzTracking ? rcEdge.CenterPoint().x : rcEdge.CenterPoint().y); CSCBArray arrSCBars; int nThis; GetRowSizingBars(arrSCBars, nThis); m_nTrackPosMin = m_nTrackPosMax = m_nTrackPosOld; if (!IsSideTracking()) { // calc minwidth as the max minwidth of the sizing bars on row int nMinWidth = bHorz ? m_szMinHorz.cy : m_szMinVert.cx; for (int i = 0; i < arrSCBars.GetSize(); i++) nMinWidth = max(nMinWidth, bHorz ? arrSCBars[i]->m_szMinHorz.cy : arrSCBars[i]->m_szMinVert.cx); int nExcessWidth = (bHorz ? m_szHorz.cy : m_szVert.cx) - nMinWidth; // the control bar cannot grow with more than the width of // remaining client area of the mainframe CRect rcT; m_pDockSite->RepositionBars(0, 0xFFFF, AFX_IDW_PANE_FIRST, reposQuery, &rcT, NULL, TRUE); int nMaxWidth = bHorz ? rcT.Height() - 2 : rcT.Width() - 2; BOOL bTopOrLeft = m_htEdge == HTTOP || m_htEdge == HTLEFT; m_nTrackPosMin -= bTopOrLeft ? nMaxWidth : nExcessWidth; m_nTrackPosMax += bTopOrLeft ? nExcessWidth : nMaxWidth; } else { // side tracking: // max size is the actual size plus the amount the other // sizing bars can be decreased until they reach their minsize if (m_htEdge == HTBOTTOM || m_htEdge == HTRIGHT) nThis++; for (int i = 0; i < arrSCBars.GetSize(); i++) { CSizingControlBar* pBar = arrSCBars[i]; int nExcessWidth = bHorz ? pBar->m_szHorz.cx - pBar->m_szMinHorz.cx : pBar->m_szVert.cy - pBar->m_szMinVert.cy; if (i < nThis) m_nTrackPosMin -= nExcessWidth; else m_nTrackPosMax += nExcessWidth; } } OnTrackInvertTracker(); // draw tracker }
void ETSOuterSplitter::CloseSplitter() { CWnd *pWnd = (CWnd*)this->GetParent(); pWnd->SetRedraw(false); //int min = m_pane->GetOuterPaneMinPosition(); //m_nMinConstrainHorz = (min == 0) ? m_nMinConstrainHorz : min; if(!m_pane->IsClosed()) { m_pane->setOpenConstrain(); int step = m_pane->m_nSplOpendPos / CLOSE_STEP; //TRACE("dd%d\n", step); int offset = 0; if(m_pane->m_nClosedOri == 0) offset = m_pane->getCloseConstrain(-step); else offset = m_pane->getCloseConstrain(step); if(abs(offset) <= step) { m_pane->SetClosed(true); m_pane->resizeTo(offset, true); } else m_pane->resizeTo(offset); //// LoadSkin(m_pSkin); pWnd->SetRedraw(true); CRect r; pWnd->GetWindowRect(&r); r.right -= offset; pWnd->SetWindowPos(NULL, r.left, r.top , r.Width(), r.Height(), NULL); ::AfxGetUIManager()->UIGetLayoutMgr()->UpdateLayout(::AfxGetMainWindow()->m_hWnd); //m_rootPanel->UpdateLayout(this->GetParent()->m_hWnd); m_nMouseOffset = 0; } else { int offset = 0; int step = m_pane->m_nSplOpendPos / CLOSE_STEP; if(step == 0) step = m_pane->GetOuterPaneMinPosition(); if(m_pane->m_nClosedOri == 0) offset = m_pane->getOpenConstrain(step); else offset = m_pane->getOpenConstrain(-step); if(abs(offset) <= step) { m_pane->SetClosed(false); m_pane->resizeTo(offset, true); } else m_pane->resizeTo(offset); //// LoadSkin(this->m_pSkin); pWnd->SetRedraw(true); m_nMouseOffset = 0; CRect r; pWnd->GetWindowRect(&r); r.right -= offset; pWnd->SetWindowPos(NULL, r.left, r.top , r.Width(), r.Height(), NULL); } }
void BHeader::Paint() { CRect cr; GetClientRect(&cr); CPaintDC dc(this); CDC* pDC = &dc; CDC* pParsedDC = pDC; CDC MemDC; CBitmap MemBM; MemBM.CreateCompatibleBitmap(pParsedDC,cr.Width(),cr.Height()); MemDC.CreateCompatibleDC(pParsedDC); MemDC.SelectObject(&MemBM); pDC = &MemDC; //umple backgroundul CRect fillRect; fillRect.SetRect(0,0,cr.Width(),cr.Height()); pDC->FillSolidRect(&fillRect, RGB(220,220,220)); // cr.left = 0; // cr.right = LabelWidth; // pDC->FillSolidRect(&cr,RGB(255,0,0)); pDC->DrawEdge(&cr,BDR_RAISEDINNER,BF_RECT); //pDC->SetBkMode(TRANSPARENT); // pDC->SetBkColor(RGB(240,240,240)); pDC->SelectObject(&simpleFont); CRect textRext; textRext.SetRect(cr.left+5,cr.Height()/2 - 7,cr.right-20,cr.Height()); pDC->SetTextColor(RGB(0,0,0)); pDC->DrawText(label,-1,textRext,DT_LEFT); // fillRect.left =cr.right+SPACE_BETWEEN_ELEMENT; // fillRect.right = 500; // pDC->FillSolidRect(&fillRect,RGB(255,0,0)); //deseneaza buotnul de plus //CRect plusButton; if(collapsed) { CRect collapseButton; collapseButton.SetRect(cr.right-15,5,cr.right-4,16); pDC->DrawEdge(&collapseButton,BDR_RAISEDINNER,BF_RECT); collapseButton.SetRect(cr.right-13,4,cr.right-7,15); pDC->SelectObject(&smallFont); pDC->MoveTo(cr.right-12,10); pDC->LineTo(cr.right-7,10); if(collapsed == ITEM_COLLAPSED) { pDC->MoveTo(cr.right-10,8); pDC->LineTo(cr.right-10,13); } } //-------------------------- // flicker //-------------------------- //pDC->SetViewportOrg(0,0); //MemDC.SetViewportOrg(0,0); pParsedDC->BitBlt( 0 , 0 , cr.Width() , cr.Height() , &MemDC , 0 , 0 , SRCCOPY ); }
//用户放弃 bool CGameClientDlg::OnSubGiveUp(const void * pBuffer, WORD wDataSize) { //效验数据 if (wDataSize!=sizeof(CMD_S_GiveUp)) return false; CMD_S_GiveUp * pGiveUp=(CMD_S_GiveUp *)pBuffer; //设置变量 m_cbPlayStatus[pGiveUp->wGiveUpUser]=FALSE; //界面设置 m_GameClientView.m_SmallCardControl[pGiveUp->wGiveUpUser].SetCardData(NULL,0); m_GameClientView.m_CardControl[pGiveUp->wGiveUpUser].SetCardData(NULL,0); m_GameClientView.UpdateWindow(); m_GameClientView.DrawMoveCard(pGiveUp->wGiveUpUser,TO_GIVEUP_CARD,0); //状态设置 if ((IsLookonMode()==false)&&(pGiveUp->wGiveUpUser==GetMeChairID())) SetGameStatus(GS_FREE); //变量定义 WORD wGiveUpUser=pGiveUp->wGiveUpUser; //环境设置 if (wGiveUpUser==GetTimeChairID()) KillGameTimer(IDI_USER_ADD_SCORE); if ((IsLookonMode()==true)||(wGiveUpUser!=GetMeChairID())) PlayGameSound(AfxGetInstanceHandle(),TEXT("GIVE_UP")); //显示积分 if (wGiveUpUser==GetMeChairID()) { if(m_lTableScore[wGiveUpUser]!=0L) { m_GameClientView.DrawMoveAnte(wGiveUpUser,CGameClientView::AA_BASEDEST_TO_CENTER,m_lTableScore[wGiveUpUser]); m_GameClientView.SetUserTableScore(wGiveUpUser,0L); m_lTableScore[wGiveUpUser] = 0L; } if(!IsLookonMode()) { //调整位置 CRect rcControl; m_GameClientView.m_ScoreView.GetWindowRect(&rcControl); CRect rcView ; m_GameClientView.GetWindowRect( &rcView ); m_GameClientView.m_ScoreView.MoveWindow(rcView.left+5,rcView.bottom-15-rcControl.Height()*3/2,rcControl.Width(),rcControl.Height()); m_GameClientView.m_ScoreView.SetGameScore(wGiveUpUser,pGiveUp->lLost); m_GameClientView.m_ScoreView.ShowWindow(SW_SHOW); m_GameClientView.m_ScoreView.SetShowTimes(); } } else { if(m_lTableScore[wGiveUpUser]!=0L) { m_GameClientView.DrawMoveAnte(wGiveUpUser,CGameClientView::AA_BASEDEST_TO_CENTER,m_lTableScore[wGiveUpUser]); m_GameClientView.SetUserTableScore(wGiveUpUser,0L); m_lTableScore[wGiveUpUser] = 0L; } } return true; }
void CToolTipCtrlX::OnNMCustomDraw(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTTCUSTOMDRAW pNMCD = reinterpret_cast<LPNMTTCUSTOMDRAW>(pNMHDR); if (pNMCD->nmcd.dwDrawStage == CDDS_PREPAINT) { CWnd* pwnd = CWnd::FromHandle(pNMCD->nmcd.hdr.hwndFrom); CDC* pdc = CDC::FromHandle(pNMCD->nmcd.hdc); CString strText; pwnd->GetWindowText(strText); CRect rcWnd; pwnd->GetWindowRect(&rcWnd); CRect rcBorder; rcBorder.left = pNMCD->nmcd.rc.left - rcWnd.left; rcBorder.top = pNMCD->nmcd.rc.top - rcWnd.top; rcBorder.right = rcWnd.right - pNMCD->nmcd.rc.right; rcBorder.bottom = rcWnd.bottom - pNMCD->nmcd.rc.bottom; if (m_bCol1Bold && m_fontBold.m_hObject == NULL) { CFont* pFont = pwnd->GetFont(); if (pFont) { LOGFONT lf; pFont->GetLogFont(&lf); lf.lfWeight = FW_BOLD; VERIFY( m_fontBold.CreateFontIndirect(&lf) ); } } int iTextHeight = 0; int iMaxCol1Width = 0; int iMaxCol2Width = 0; int iMaxSingleLineWidth = 0; CSize sizText(0); int iPos = 0; while (iPos != -1) { CString strLine = GetNextString(strText, _T('\n'), iPos); int iColon = strLine.Find(_T(':')); if (iColon != -1) { CFont* pOldFont = m_bCol1Bold ? pdc->SelectObject(&m_fontBold) : NULL; CSize siz = pdc->GetTextExtent(strLine, iColon + 1); if (pOldFont) pdc->SelectObject(pOldFont); iMaxCol1Width = max(iMaxCol1Width, siz.cx); iTextHeight = siz.cy; // update height with 'col1' string, because 'col2' string might be empty and therefore has no height sizText.cy += siz.cy; LPCTSTR pszCol2 = (LPCTSTR)strLine + iColon + 1; while (_istspace(*pszCol2)) pszCol2++; if (*pszCol2 != _T('\0')) { siz = pdc->GetTextExtent(pszCol2, ((LPCTSTR)strLine + strLine.GetLength()) - pszCol2); iMaxCol2Width = max(iMaxCol2Width, siz.cx); } } else if (!strLine.IsEmpty()) { CSize siz = pdc->GetTextExtent(strLine); iMaxSingleLineWidth = max(iMaxSingleLineWidth, siz.cx); sizText.cy += siz.cy; } else { CSize siz = pdc->GetTextExtent(_T(" "), 1); sizText.cy += siz.cy; } } iMaxCol1Width = min(m_iScreenWidth4, iMaxCol1Width); iMaxCol2Width = min(m_iScreenWidth4*2, iMaxCol2Width); const int iMiddleMargin = 6; iMaxSingleLineWidth = max(iMaxSingleLineWidth, iMaxCol1Width + iMiddleMargin + iMaxCol2Width); sizText.cx = iMaxSingleLineWidth; rcWnd.right = rcWnd.left + rcBorder.left + sizText.cx + rcBorder.right; rcWnd.bottom = rcWnd.top + rcBorder.top + sizText.cy + rcBorder.bottom; if (rcWnd.left >= m_rcScreen.left) { if (rcWnd.right > m_rcScreen.right && rcWnd.Width() <= m_rcScreen.Width()) rcWnd.OffsetRect(-(rcWnd.right - m_rcScreen.right), 0); } if (rcWnd.top >= m_rcScreen.top) { if (rcWnd.bottom > m_rcScreen.bottom && rcWnd.Height() <= m_rcScreen.Height()) rcWnd.OffsetRect(0, -(rcWnd.bottom - m_rcScreen.bottom)); } pwnd->MoveWindow(&rcWnd); pwnd->ScreenToClient(&rcWnd); pdc->FillSolidRect(&rcWnd, m_crTooltipBkColor); CPoint ptText(pNMCD->nmcd.rc.left, pNMCD->nmcd.rc.top); iPos = 0; while (iPos != -1) { CString strLine = GetNextString(strText, _T('\n'), iPos); int iColon = strLine.Find(_T(':')); if (iColon != -1) { CRect rcDT(ptText.x, ptText.y, ptText.x + iMaxCol1Width, ptText.y + iTextHeight); // don't draw empty <col1> strings (they are still handy to use for skipping the <col1> space) if (iColon > 0) { CFont* pOldFont = m_bCol1Bold ? pdc->SelectObject(&m_fontBold) : NULL; pdc->DrawText(strLine, iColon + 1, &rcDT, m_dwCol1DrawTextFlags); if (pOldFont) pdc->SelectObject(pOldFont); } LPCTSTR pszCol2 = (LPCTSTR)strLine + iColon + 1; while (_istspace(*pszCol2)) pszCol2++; if (*pszCol2 != _T('\0')) { rcDT.left = ptText.x + iMaxCol1Width + iMiddleMargin; rcDT.right = rcDT.left + iMaxCol2Width; pdc->DrawText(pszCol2, ((LPCTSTR)strLine + strLine.GetLength()) - pszCol2, &rcDT, m_dwCol2DrawTextFlags); } ptText.y += iTextHeight; } else { CSize siz = pdc->TabbedTextOut(ptText.x, ptText.y, strLine, 0, NULL, 0); ptText.y += siz.cy; } } *pResult = CDRF_SKIPDEFAULT; return; } *pResult = CDRF_DODEFAULT; }
void CGuiMiniFrame::OnNcPaint() { CGuiControlBar* pBar=(CGuiControlBar* )GetChildWnd(); if (!pBar) return; if (IsGuiControlBar==TRUE && !pBar->IsAutoHide()) { CMiniDockFrameWnd::OnNcPaint(); return; } //if (!pBar->GetComplete()) return; CRect rcWindow; CRect rcClient; CWindowDC dc(this); CDC m_dc; //contexto de dispositivo en memoria CBitmap m_bitmap; CPen Dark(PS_SOLID,1,GuiDrawLayer::GetRGBColorShadow(GuiDrawLayer::m_Style)); //la idea es tomar el area de la ventana y area cliente , luego debemos //igualar el area de coordenadas de ventana al cliente GetWindowRect(&rcWindow); GetClientRect(&rcClient); int nSize=rcClient.right; ScreenToClient(rcWindow); rcClient.OffsetRect(-rcWindow.TopLeft()); rcWindow.OffsetRect(-rcWindow.TopLeft()); m_dc.CreateCompatibleDC(&dc); m_bitmap.CreateCompatibleBitmap(&dc,rcWindow.Width(),rcWindow.Height()); CBitmap *m_OldBitmap=m_dc.SelectObject(&m_bitmap); //aqui debe utilizarse la brocha que define GuiDrawLayer, si no hacemos la siguiente //linea usted vera un horrible color negro, a cambio del dibujo. CBrush cb; COLORREF clrBrush; if(IsGuiControlBar!=TRUE ) clrBrush= GuiDrawLayer::GetRGBColorShadow(GuiDrawLayer::m_Style); else clrBrush=GuiDrawLayer::GetRGBColorFace(GuiDrawLayer::m_Style); cb.CreateSolidBrush(clrBrush); m_dc.FillRect(rcWindow, &cb); if (IsGuiControlBar==TRUE && pBar->IsAutoHide()) { CRect m_rc=rcWindow; if (pBar->GetLastDocking() == CBRS_ALIGN_LEFT) { m_rc.left=m_rc.right-1; m_rc.top+=3; cb.DeleteObject(); cb.CreateSolidBrush(RGB(0,0,0)); } if (pBar->GetLastDocking() == CBRS_ALIGN_RIGHT) { m_rc.right=m_rc.left+1; m_rc.top+=2; cb.DeleteObject(); cb.CreateSolidBrush(GuiDrawLayer::GetRGBColorBTNHigh()); } if (pBar->GetLastDocking() == CBRS_ALIGN_TOP) { m_rc.top=m_rc.bottom-1; cb.DeleteObject(); cb.CreateSolidBrush(RGB(0,0,0)); } m_dc.FillRect(m_rc, &cb); } CRect rcCaption=rcClient; rcCaption.InflateRect(1,1); if(IsGuiControlBar!=TRUE ) dc.Draw3dRect(rcCaption,GuiDrawLayer::GetRGBColorBTNHigh(),GuiDrawLayer::GetRGBColorBTNHigh()); DrawGripper(&m_dc,&rcClient); dc.IntersectClipRect(rcWindow); dc.ExcludeClipRect(rcClient);//asi evitamos el parpadeo //rcWindow.InflateRect(1,1); dc.BitBlt(rcWindow.left,rcWindow.top,rcWindow.Width(),rcWindow.Height(),&m_dc,0,0,SRCCOPY); ReleaseDC(&dc); m_dc.SelectObject(m_OldBitmap); m_bitmap.DeleteObject(); m_dc.DeleteDC(); // SetTimer(1,200,NULL); // TODO: Add your message handler code here // Do not call CMiniDockFrameWnd::OnNcPaint() for painting messages }
void CBCGPHeaderCtrl::OnDrawItem (CDC* pDC, int iItem, CRect rect, BOOL bIsPressed, BOOL bIsHighlighted) { ASSERT_VALID (this); ASSERT_VALID (pDC); const int nTextMargin = 5; //------------- // Draw border: //------------- CBCGPVisualManager::GetInstance ()->OnDrawHeaderCtrlBorder (this, pDC, rect, bIsPressed, bIsHighlighted); if (iItem < 0) { return; } int nSortVal = 0; if (m_mapColumnsStatus.Lookup (iItem, nSortVal) && nSortVal != 0) { //----------------- // Draw sort arrow: //----------------- CRect rectArrow = rect; rectArrow.DeflateRect (5, 5); rectArrow.left = rectArrow.right - rectArrow.Height (); if (bIsPressed) { rectArrow.right++; rectArrow.bottom++; } rect.right = rectArrow.left - 1; int dy2 = (int) (.134 * rectArrow.Width ()); rectArrow.DeflateRect (0, dy2); m_bAscending = nSortVal > 0; OnDrawSortArrow (pDC, rectArrow); } HD_ITEM hdItem; memset (&hdItem, 0, sizeof (hdItem)); hdItem.mask = HDI_FORMAT | HDI_BITMAP | HDI_TEXT | HDI_IMAGE; TCHAR szText [256]; hdItem.pszText = szText; hdItem.cchTextMax = 255; if (!GetItem (iItem, &hdItem)) { return; } //----------------------- // Draw bitmap and image: //----------------------- if ((hdItem.fmt & HDF_IMAGE) && hdItem.iImage >= 0) { // By Max Khiszinsky: //--------------------------------------- // The column has a image from imagelist: //--------------------------------------- CImageList* pImageList = GetImageList (); if (pImageList != NULL) { int cx = 0; int cy = 0; VERIFY (::ImageList_GetIconSize (*pImageList, &cx, &cy)); CPoint pt = rect.TopLeft (); pt.x ++; pt.y = (rect.top + rect.bottom - cy) / 2; VERIFY (pImageList->Draw (pDC, hdItem.iImage, pt, ILD_NORMAL)); rect.left += cx; } } if ((hdItem.fmt & (HDF_BITMAP | HDF_BITMAP_ON_RIGHT)) && hdItem.hbm != NULL) { CBitmap* pBmp = CBitmap::FromHandle (hdItem.hbm); ASSERT_VALID (pBmp); BITMAP bmp; pBmp->GetBitmap (&bmp); CRect rectBitmap = rect; if (hdItem.fmt & HDF_BITMAP_ON_RIGHT) { rectBitmap.right--; rect.right = rectBitmap.left = rectBitmap.right - bmp.bmWidth; } else { rectBitmap.left++; rect.left = rectBitmap.right = rectBitmap.left + bmp.bmWidth; } rectBitmap.top += max (0, (rectBitmap.Height () - bmp.bmHeight) / 2); rectBitmap.bottom = rectBitmap.top + bmp.bmHeight; pDC->DrawState (rectBitmap.TopLeft (), rectBitmap.Size (), pBmp, DSS_NORMAL); } //----------- // Draw text: //----------- if (hdItem.fmt & HDF_STRING) { COLORREF clrText = CBCGPVisualManager::GetInstance ()->GetHeaderCtrlTextColor (this, bIsPressed, bIsHighlighted); COLORREF clrTextOld = (COLORREF)-1; if (clrText != (COLORREF)-1) { clrTextOld = pDC->SetTextColor (clrText); } CRect rectLabel = rect; rectLabel.DeflateRect (nTextMargin, 0); CString strLabel = hdItem.pszText; UINT uiTextFlags = DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX; if (hdItem.fmt & HDF_CENTER) { uiTextFlags |= DT_CENTER; } else if (hdItem.fmt & HDF_RIGHT) { uiTextFlags |= DT_RIGHT; } pDC->DrawText (strLabel, rectLabel, uiTextFlags); if (clrText != (COLORREF)-1) { pDC->SetTextColor (clrTextOld); } } }
/////////////////////////////////////////////////////////////////////////////// // Name: SetLed // Description: This method will draw the LED to the specified DC. // // Entry: // CDC *pDC - DC to draw to // // int iLedColor - Where color is defined by: // LED_COLOR_RED // LED_COLOR_GREEN // LED_COLOR_YELLOW // LED_COLOR_BLUE // // int iMode - where mode is defined by: // LED_ON // LED_OFF // LED_DISABLED // // int iShape - where shape is defined by: // LED_ROUND // LED_SQUARE /////////////////////////////////////////////////////////////////////////////// void CLed::DrawLed(CDC *pDC,int nLEDColor, int nMode, int nShape) { CRect rect; GetClientRect(&rect); // // Center led within an oversized window // if(rect.Width() >= LED_SIZE && rect.Height() >= LED_SIZE) { int nWidth = rect.Width(); int nHeight = rect.Height(); rect.left += (nWidth - LED_SIZE)/2; rect.right -= (nWidth - LED_SIZE)/2; rect.top += (nHeight - LED_SIZE)/2; rect.bottom -= (nHeight - LED_SIZE)/2; } // // Prepare temporary DCs and bitmaps // CBitmap TransBitmap; TransBitmap.CreateBitmap(LED_SIZE,LED_SIZE,1,1,NULL); CBitmap bitmapTemp; CBitmap* pBitmap = &m_LedBitmap; CDC srcDC; CDC dcMask; CDC TempDC; TempDC.CreateCompatibleDC(pDC); srcDC.CreateCompatibleDC(pDC); dcMask.CreateCompatibleDC(pDC); CBitmap* pOldBitmap = srcDC.SelectObject(pBitmap); CBitmap* pOldMaskbitmap = dcMask.SelectObject(&TransBitmap); bitmapTemp.CreateCompatibleBitmap(pDC,LED_SIZE,LED_SIZE); // // Work with tempDC and bitmapTemp to reduce flickering // CBitmap *pOldBitmapTemp = TempDC.SelectObject(&bitmapTemp); TempDC.BitBlt(0, 0, LED_SIZE, LED_SIZE, pDC, rect.left, rect.top, SRCCOPY); // // Create mask // COLORREF OldBkColor = srcDC.SetBkColor(RGB(255,0,255)); dcMask.BitBlt(0, 0, LED_SIZE, LED_SIZE,&srcDC, nMode*LED_SIZE, nLEDColor+nShape, SRCCOPY); TempDC.SetBkColor(OldBkColor); // // Using the IDB_LEDS bitmap, index into the bitmap for the appropriate // LED. By using the mask color (RGB(255,0,255)) a mask has been created // so the bitmap will appear transparent. // TempDC.BitBlt(0, 0, LED_SIZE, LED_SIZE, &srcDC, nMode*LED_SIZE, nLEDColor+nShape, SRCINVERT); TempDC.BitBlt(0, 0, LED_SIZE, LED_SIZE,&dcMask, 0, 0, SRCAND); TempDC.BitBlt(0, 0, LED_SIZE, LED_SIZE, &srcDC, nMode*LED_SIZE, nLEDColor+nShape, SRCINVERT); // // Since the actual minipulation is done to tempDC so there is minimal // flicker, it is now time to draw the result to the screen. // pDC->BitBlt(rect.left, rect.top, LED_SIZE, LED_SIZE, &TempDC, 0, 0, SRCCOPY); // // House cleaning // srcDC.SelectObject(pOldBitmap); dcMask.SelectObject(pOldMaskbitmap); TempDC.SelectObject(pOldBitmapTemp); VERIFY(srcDC.DeleteDC()); VERIFY(dcMask.DeleteDC()); VERIFY(TempDC.DeleteDC()); VERIFY(TransBitmap.DeleteObject()); VERIFY(bitmapTemp.DeleteObject()); }
//调整控件 void CGameClientView::RectifyGameView(int nWidth, int nHeight) { //设置坐标 if (m_bDeasilOrder==true) { m_ptFace[1].x=nWidth-m_nXBorder-m_nXFace-5; m_ptFace[1].y=nHeight/2-m_nYFace; m_ptName[1].x=m_ptFace[1].x+8; m_ptName[1].y=nHeight/2-m_nYFace+3+m_nXFace; m_ptTimer[1].x=nWidth-m_nXBorder-m_nXFace-5; m_ptTimer[1].y=nHeight/2-m_nYFace-m_nYTimer-5; m_ptReady[1].x=nWidth-m_nXBorder-m_nXTimer-5; m_ptReady[1].y=nHeight/2-m_nYFace-m_nYTimer/2-5; m_ptScore[1].x=nWidth-m_nXBorder-m_nXFace-180; m_ptScore[1].y=nHeight/2-m_nYFace+5; m_ptLand[1].x=nWidth-m_nXBorder-m_LandSize.cx-3; m_ptLand[1].y=nHeight/2+5-m_nYFace-80; m_ptBomb[1].x =m_ptLand[1].x; m_ptBomb[1].y =m_ptLand[1].y; m_ptFace[3].x=m_nXBorder+5; m_ptFace[3].y=nHeight/2-m_nYFace; m_ptName[3].x=m_ptFace[3].x; m_ptName[3].y=nHeight/2-m_nYFace+3+m_nXFace; m_ptTimer[3].x=m_nXBorder+5; m_ptTimer[3].y=nHeight/2-m_nYFace-5-m_nYTimer; m_ptReady[3].x=m_nXBorder+5+m_nXTimer; m_ptReady[3].y=nHeight/2-m_nYFace-m_nYTimer/2-5; m_ptScore[3].x=m_nXBorder+m_nXFace+137; m_ptScore[3].y=nHeight/2-m_nYFace+5; m_ptLand[3].x=m_nXBorder+3; m_ptLand[3].y=nHeight/2+5-m_nYFace-80; m_ptBomb[3].x =m_ptLand[3].x; m_ptBomb[3].y =m_ptLand[3].y; } else { m_ptFace[3].x=nWidth-m_nXBorder-m_nXFace-5; m_ptFace[3].y=nHeight/2-m_nYFace-15; m_ptName[3].x=m_ptFace[3].x+m_nYFace+5; m_ptName[3].y=nHeight/2-m_nYFace+20; m_ptTimer[3].x=nWidth-m_nXBorder-m_nXTimer/2; m_ptTimer[3].y=nHeight/2-m_nYFace-m_nYTimer; m_ptReady[3].x=nWidth-m_nXBorder-m_nXTimer-50; m_ptReady[3].y=nHeight/2-m_nYFace-m_nYTimer/2-5; m_ptScore[3].x=nWidth-m_nXBorder-m_nXFace-240; m_ptScore[3].y=nHeight/2-m_nYFace+5; m_ptLand[3].x=nWidth-m_nXBorder-m_LandSize.cx-3; m_ptLand[3].y=nHeight/2-m_nYFace-m_nYTimer-30-m_LandSize.cy; m_ptBomb[3].x =m_ptLand[3].x-5; m_ptBomb[3].y =m_ptLand[3].y; m_ptFace[1].x=m_nXBorder+5; m_ptFace[1].y=nHeight/2-m_nYFace-15; m_ptName[1].x=m_ptFace[1].x-5; m_ptName[1].y=nHeight/2-m_nYFace+20; m_ptTimer[1].x=m_nXBorder+m_nXTimer/2; m_ptTimer[1].y=nHeight/2-m_nYFace-m_nYTimer; m_ptReady[1].x=m_nXBorder+5+m_nXTimer+50; m_ptReady[1].y=nHeight/2-m_nYFace-m_nYTimer/2-5; m_ptScore[1].x=m_nXBorder+m_nXFace+197; m_ptScore[1].y=nHeight/2-m_nYFace+5; m_ptLand[1].x=m_nXBorder+3; m_ptLand[1].y=nHeight/2-m_nYFace-m_nYTimer-30-m_LandSize.cy; m_ptBomb[1].x =m_ptLand[1].x; m_ptBomb[1].y =m_ptLand[1].y; } m_ptFace[0].x=nWidth/2-m_nXFace/2; m_ptFace[0].y=m_nYBorder+5; m_ptName[0].x=nWidth/2+5+m_nXFace/2; m_ptName[0].y=m_nYBorder+5; m_ptTimer[0].x=nWidth/2-m_nXFace/2-m_nXTimer/2-5; m_ptTimer[0].y=m_nYBorder+m_nYTimer/2; m_ptReady[0].x=nWidth/2-m_nXFace/2+15; m_ptReady[0].y=m_nYBorder+m_nYTimer/2+80; m_ptScore[0].x=nWidth/2-21; m_ptScore[0].y=m_nYBorder+m_nYFace+120; m_ptLand[0].x=nWidth/2-m_nXFace/2-m_LandSize.cx-m_nXTimer-8; m_ptLand[0].y=m_nXBorder+5; m_ptBomb[0].x =m_ptLand[0].x; m_ptBomb[0].y =m_ptLand[0].y; m_ptFace[2].x=nWidth/2-m_nXFace/2; m_ptFace[2].y=nHeight-m_nYBorder-m_nYFace-5; m_ptName[2].x=nWidth/2+5+m_nXFace/2; m_ptName[2].y=nHeight-m_nYBorder-m_nYFace/2; m_ptTimer[2].x=nWidth/2-m_nXFace/2-m_nXTimer/2-5; m_ptTimer[2].y=nHeight-m_nYBorder-m_nYTimer/2; m_ptReady[2].x=nWidth/2-m_nXFace/2+15; m_ptReady[2].y=nHeight-m_nYBorder-m_nYTimer/2-80; m_ptScore[2].x=nWidth/2-21; m_ptScore[2].y=nHeight-m_nYBorder-m_nYFace-210; m_ptLand[2].x=nWidth/2-m_nXFace/2-m_LandSize.cx-m_nXTimer-8; m_ptLand[2].y=nHeight-m_nXBorder-m_LandSize.cy-5; m_ptBomb[2].x =m_ptLand[2].x; m_ptBomb[2].y =m_ptLand[2].y; //移动按钮 CRect rcButton; HDWP hDwp=BeginDeferWindowPos(32); m_btStart.GetWindowRect(&rcButton); const UINT uFlags=SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOCOPYBITS|SWP_NOSIZE; DeferWindowPos(hDwp,m_btStart,NULL,(nWidth-rcButton.Width())/2,nHeight-210-m_nYBorder,0,0,uFlags); DeferWindowPos(hDwp,m_btOutCard,NULL,nWidth/2-rcButton.Width()-5,nHeight-210-m_nYBorder,0,0,uFlags); DeferWindowPos(hDwp,m_btPassCard,NULL,nWidth/2+5,nHeight-210-m_nYBorder,0,0,uFlags); DeferWindowPos(hDwp,m_btOneScore,NULL,nWidth/2-rcButton.Width()*5/2-10,nHeight-195-m_nYBorder,0,0,uFlags); DeferWindowPos(hDwp,m_btTwoScore,NULL,nWidth/2-rcButton.Width()*3/2-5,nHeight-195-m_nYBorder,0,0,uFlags); DeferWindowPos(hDwp,m_btThreeScore,NULL,nWidth/2-rcButton.Width()/2,nHeight-195-m_nYBorder,0,0,uFlags); DeferWindowPos(hDwp,m_btShowCard,NULL,nWidth/2+rcButton.Width()/2+5,nHeight-195-m_nYBorder,0,0,uFlags); DeferWindowPos(hDwp,m_btGiveUpScore,NULL,nWidth/2+rcButton.Width()*3/2+10,nHeight-195-m_nYBorder,0,0,uFlags); m_btSortByNum.GetWindowRect(&rcButton); DeferWindowPos(hDwp,m_btSortByNum,NULL,nWidth-rcButton.Width()-8-rcButton.Width(),nHeight-rcButton.Height()-2-m_nYBorder,0,0,uFlags); DeferWindowPos(hDwp,m_btSortBySize,NULL,nWidth-rcButton.Width()-8,nHeight-rcButton.Height()-2-m_nYBorder,0,0,uFlags); EndDeferWindowPos(hDwp); //移动扑克 m_BackCardControl.SetBenchmarkPos(nWidth/2-80,nHeight/2-70,enXLeft,enYTop); m_HandCardControl[2].SetBenchmarkPos(nWidth/2,nHeight-m_nYFace-m_nYBorder-20,enXCenter,enYBottom); m_UserCardControl[0].SetBenchmarkPos(nWidth/2,nHeight/2-208,enXCenter,enYTop); m_UserCardControl[2].SetBenchmarkPos(nWidth/2,nHeight-208-m_nYBorder,enXCenter,enYBottom); m_HandCardControl[0].SetBenchmarkPos(nWidth/2,m_nXBorder+50,enXCenter,enYTop); //用户扑克 if (m_bDeasilOrder==true) { m_UserCardControl[1].SetBenchmarkPos(nWidth-m_nXFace-m_nXBorder-130,nHeight/2-30,enXRight,enYCenter); m_UserCardControl[3].SetBenchmarkPos(m_nXBorder+m_nXFace+130,nHeight/2-30,enXLeft,enYCenter); m_HandCardControl[1].SetBenchmarkPos(nWidth-m_nXBorder-m_nXFace-50,nHeight/2-30,enXRight,enYCenter); m_HandCardControl[3].SetBenchmarkPos(m_nXBorder+m_nXFace+50,nHeight/2-30,enXLeft,enYCenter); } else { m_UserCardControl[3].SetBenchmarkPos(nWidth-m_nXFace-m_nXBorder-130,nHeight/2-30,enXRight,enYCenter); m_UserCardControl[1].SetBenchmarkPos(m_nXBorder+m_nXFace+130,nHeight/2-30,enXLeft,enYCenter); m_HandCardControl[3].SetBenchmarkPos(nWidth-m_nXBorder-m_nXFace-50,nHeight/2-30,enXRight,enYCenter); m_HandCardControl[1].SetBenchmarkPos(m_nXBorder+m_nXFace+50,nHeight/2-30,enXLeft,enYCenter); } //积分视图 CRect rcControl; m_ScoreView.GetWindowRect(&rcControl); m_ScoreView.SetWindowPos(NULL,(nWidth)/2-30,(nHeight)/2,0,0,SWP_NOZORDER|SWP_NOSIZE); //视频位置设置 #ifdef VIDEO_GAME RectifyVideoView(nWidth,nHeight); #endif //m_ScoreView.ShowWindow(1); return; }
//调整视频位置 void CGameClientView::RectifyVideoView(int nWidth, int nHeight) { //BYTE card[]={ 1,1,1,1,1,1,1,1,1,1, // 1,1,1,1,1,1,1,1,1,1, // 1,1,1,1,1,1,1,1,1,1, // 1,1,1,}; //for(WORD i=0;i<4;i++) //{ // m_UserCardControl[i].SetCardData(card,10); // m_UserCardControl[i].ShowWindow(1); //} //m_HandCardControl[0].SetCardData(card,30); //m_HandCardControl[1].SetCardData(card,30); //m_HandCardControl[2].SetCardData(card,30); //m_HandCardControl[3].SetCardData(card,30); m_UserCardControl[1].SetDirection(0); m_UserCardControl[1].SetCardSpace(10,15,0); m_UserCardControl[3].SetDirection(0); m_UserCardControl[3].SetCardSpace(10,15,0); m_HandCardControl[2].ShowWindow(SW_SHOW); m_HandCardControl[0].ShowWindow(SW_HIDE); m_HandCardControl[1].ShowWindow(SW_HIDE); m_HandCardControl[3].ShowWindow(SW_HIDE); HDWP hDwp=BeginDeferWindowPos(32); const UINT uFlags=SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOCOPYBITS|SWP_NOSIZE; //视频窗口 CRect rcAVDlg; m_DlgVideoService[0].GetWindowRect(&rcAVDlg); if( m_bDeasilOrder==false) { DeferWindowPos(hDwp,m_DlgVideoService[3],NULL,nWidth-m_nXBorder-5-rcAVDlg.Width(),nHeight/2-10,0,0,uFlags); DeferWindowPos(hDwp,m_DlgVideoService[1],NULL,m_nXBorder+5,nHeight/2-10,0,0,uFlags); }else { DeferWindowPos(hDwp,m_DlgVideoService[1],NULL,nWidth-m_nXBorder-5-rcAVDlg.Width(),nHeight/2-rcAVDlg.Height()/2,0,0,uFlags); DeferWindowPos(hDwp,m_DlgVideoService[3],NULL,m_nXBorder+5,nHeight/2-rcAVDlg.Height()/2,0,0,uFlags); } DeferWindowPos(hDwp,m_DlgVideoService[0],NULL,nWidth-rcAVDlg.Width()-5,5,0,0,uFlags); m_DlgVideoService[2].GetWindowRect(&rcAVDlg); DeferWindowPos(hDwp,m_DlgVideoService[2],NULL,m_nXBorder+5,nHeight-m_nYBorder-3-rcAVDlg.Height(),0,0,uFlags); CRect rcButton; m_btOneScore.GetWindowRect(&rcButton); DeferWindowPos(hDwp,m_btOneScore,NULL,nWidth/2-rcButton.Width()*3/2-5-30,nHeight-195-m_nYBorder,0,0,uFlags); DeferWindowPos(hDwp,m_btTwoScore,NULL,nWidth/2-rcButton.Width()/2-30,nHeight-195-m_nYBorder,0,0,uFlags); DeferWindowPos(hDwp,m_btThreeScore,NULL,nWidth/2+rcButton.Width()/2+5-30,nHeight-195-m_nYBorder,0,0,uFlags); DeferWindowPos(hDwp,m_btGiveUpScore,NULL,nWidth/2+rcButton.Width()*3/2+10-30,nHeight-195-m_nYBorder,0,0,uFlags); m_btShowCard.ShowWindow(SW_HIDE); EndDeferWindowPos(hDwp); //用户扑克 m_HandCardControl[2].SetBenchmarkPos(nWidth/2,nHeight-m_nYFace-m_nYBorder-20,enXCenter,enYBottom); if (m_bDeasilOrder==true) { m_UserCardControl[1].SetBenchmarkPos(nWidth-m_nXFace-m_nXBorder-130,nHeight/2-30,enXRight,enYCenter); m_UserCardControl[3].SetBenchmarkPos(m_nXBorder+m_nXFace+130,nHeight/2-30,enXLeft,enYCenter); m_HandCardControl[1].SetBenchmarkPos(nWidth-m_nXBorder-m_nXFace-145,nHeight/2-20,enXRight,enYCenter); m_HandCardControl[3].SetBenchmarkPos(m_nXBorder+m_nXFace+145,nHeight/2-20,enXLeft,enYCenter); } else { m_UserCardControl[3].SetBenchmarkPos(nWidth-m_nXFace-m_nXBorder-150,nHeight/2-30,enXRight,enYCenter); m_UserCardControl[1].SetBenchmarkPos(m_nXBorder+m_nXFace+150,nHeight/2-30,enXLeft,enYCenter); m_HandCardControl[3].SetBenchmarkPos(nWidth-m_nXBorder-m_nXFace-145,nHeight/2-20,enXRight,enYCenter); m_HandCardControl[1].SetBenchmarkPos(m_nXBorder+m_nXFace+145,nHeight/2-20,enXLeft,enYCenter); } //变量定义 int nViewHeight=nHeight-m_nYBorder; //设置坐标 if (m_bDeasilOrder==true) { m_ptFace[1].x=nWidth-m_nXBorder-m_nXFace-5; m_ptFace[1].y=nViewHeight/2-m_nYFace-25; m_ptName[1].x=nWidth-m_nXBorder-5; m_ptName[1].y=m_ptFace[1].y+m_nYFace+5; m_ptTimer[1].x=nWidth-m_nXBorder-m_nXTimer/2-5; m_ptTimer[1].y=m_ptFace[1].y-5-m_nYTimer/2; m_ptReady[1].x=nWidth-m_nXBorder-m_nXFace-55; m_ptReady[1].y=m_ptFace[1].y + m_nYFace/2 - 5; m_ptScore[1].x=nWidth-m_nXBorder-m_nXFace-180; m_ptScore[1].y=nHeight/2-m_nYFace+5; m_ptLand[1].x=nWidth-m_nXBorder-m_LandSize.cx-3; m_ptLand[1].y=nHeight/2+5-m_nYFace-80; m_ptBomb[1].x =m_ptLand[1].x; m_ptBomb[1].y =m_ptLand[1].y; m_ptFace[3].x=m_nXBorder+5; m_ptFace[3].y=nViewHeight/2-m_nYFace-25; m_ptName[3].x=m_nXBorder+5; m_ptName[3].y=m_ptFace[3].y+m_nYFace+5; m_ptTimer[3].x=m_nXBorder+m_nXTimer/2+5; m_ptTimer[3].y=m_ptFace[3].y-5-m_nYTimer/2; m_ptReady[3].x=m_ptFace[3].x + m_nXFace + 55; m_ptReady[3].y=m_ptFace[3].y+m_nYFace/2-5; m_ptScore[3].x=m_nXBorder+m_nXFace+137; m_ptScore[3].y=nHeight/2-m_nYFace+5; m_ptLand[3].x=m_nXBorder+3; m_ptLand[3].y=nHeight/2+5-m_nYFace-80; m_ptBomb[3].x =m_ptLand[3].x; m_ptBomb[3].y =m_ptLand[3].y; } else { m_ptFace[3].x=nWidth-m_nXBorder-m_nXFace-5; m_ptFace[3].y=nHeight/2-m_nYFace-15; m_ptName[3].x=m_ptFace[3].x-5; m_ptName[3].y=nHeight/2-m_nYFace+5; m_ptTimer[3].x=nWidth-m_nXBorder-m_nXTimer/2; m_ptTimer[3].y=nHeight/2-m_nYFace-m_nYTimer; m_ptReady[3].x=nWidth-m_nXBorder-m_nXTimer-50; m_ptReady[3].y=nHeight/2-m_nYFace-m_nYTimer/2-5; m_ptScore[3].x=nWidth-m_nXBorder-m_nXFace-240; m_ptScore[3].y=nHeight/2-m_nYFace+5; m_ptLand[3].x=nWidth-m_nXBorder-m_LandSize.cx-3; m_ptLand[3].y=nHeight/2-m_nYFace-m_nYTimer-30-m_LandSize.cy; m_ptBomb[3].x =m_ptLand[3].x-5; m_ptBomb[3].y =m_ptLand[3].y; m_ptFace[1].x=m_nXBorder+5; m_ptFace[1].y=nHeight/2-m_nYFace-15; m_ptName[1].x=m_ptFace[1].x+m_nXFace+5; m_ptName[1].y=nHeight/2-m_nYFace+5; m_ptTimer[1].x=m_nXBorder+m_nXTimer/2; m_ptTimer[1].y=nHeight/2-m_nYFace-m_nYTimer; m_ptReady[1].x=m_nXBorder+5+m_nXTimer+50; m_ptReady[1].y=nHeight/2-m_nYFace-m_nYTimer/2-5; m_ptScore[1].x=m_nXBorder+m_nXFace+197; m_ptScore[1].y=nHeight/2-m_nYFace+5; m_ptLand[1].x=m_nXBorder+3; m_ptLand[1].y=nHeight/2-m_nYFace-m_nYTimer-30-m_LandSize.cy; m_ptBomb[1].x =m_ptLand[1].x; m_ptBomb[1].y =m_ptLand[1].y; } m_ptFace[0].x=nWidth/2-m_nXFace/2; m_ptFace[0].y=m_nYBorder+5; m_ptName[0].x=nWidth/2+5+m_nXFace/2; m_ptName[0].y=m_nYBorder+5; m_ptTimer[0].x=nWidth/2-m_nXFace/2-m_nXTimer/2-5; m_ptTimer[0].y=m_nYBorder+m_nYTimer/2; m_ptReady[0].x=nWidth/2-m_nXFace/2+15; m_ptReady[0].y=m_nYBorder+m_nYTimer/2+80; m_ptScore[0].x=nWidth/2-21; m_ptScore[0].y=m_nYBorder+m_nYFace+120; m_ptLand[0].x=nWidth/2-m_nXFace/2-m_LandSize.cx-m_nXTimer-8; m_ptLand[0].y=m_nXBorder+5; m_ptBomb[0].x =m_ptLand[0].x; m_ptBomb[0].y =m_ptLand[0].y; m_ptFace[2].x=nWidth/2-m_nXFace/2; m_ptFace[2].y=nHeight-m_nYBorder-m_nYFace-5; m_ptName[2].x=nWidth/2+5+m_nXFace/2; m_ptName[2].y=nHeight-m_nYBorder-m_nYFace/2; m_ptTimer[2].x=nWidth/2-m_nXFace/2-m_nXTimer/2-5; m_ptTimer[2].y=nHeight-m_nYBorder-m_nYTimer/2; m_ptReady[2].x=nWidth/2-m_nXFace/2+15; m_ptReady[2].y=nHeight-m_nYBorder-m_nYTimer/2-80; m_ptScore[2].x=nWidth/2-21; m_ptScore[2].y=nHeight-m_nYBorder-m_nYFace-210; m_ptLand[2].x=nWidth/2-m_nXFace/2-m_LandSize.cx-m_nXTimer-8; m_ptLand[2].y=nHeight-m_nXBorder-m_LandSize.cy-5; m_ptBomb[2].x =m_ptLand[2].x; m_ptBomb[2].y =m_ptLand[2].y; }
BOOL CLoginDlg::OnInitDialog() { CDialogEx::OnInitDialog(); SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon CServer::GetInstance()->SetHttp(new CJsHttpImpl(&m_webHttpView)); CRect rt; SystemParametersInfo(SPI_GETWORKAREA, 0, &rt, 0); // 获得工作区大小 MoveWindow(rt.left, rt.top, rt.Width(), rt.Height()); //SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0); //Util::SetWindowSize(m_hWnd, 1024, 728); //m_btnVPN.Create(this, IDC_VPN); //m_btnVPN.SetWindowText(_T("VPN/代理 设置 >>")); //m_btnVPN.MoveWindow(695, 452, 130, 24); //m_btnVPN.SetBackgroundColor(COL_GRAY); this->SetWindowTextW(_T("蓝光集团生产管控平台")); m_btnClose.Create(this, IDC_CLOSE); m_btnClose.SetWindowText(_T("×")); m_btnClose.MoveWindow(rt.Width() - 37, 0, 35, 25); m_btnClose.SetBackgroundColor(COL_GRAY); m_btnClose.SetBSFont(22, FALSE, TRUE); m_btnClose.SetColorBorder(enumBSBtnState::BS_NORMAL, COL_GRAY); m_btnClose.SetColorBorder(enumBSBtnState::BS_HOVER, COL_WHITE); m_btnClose.SetColorBorder(enumBSBtnState::BS_CLICK, COL_DARK_GRAY); m_btnClose.SetColorInside(enumBSBtnState::BS_NORMAL, COL_GRAY); m_btnClose.SetColorInside(enumBSBtnState::BS_HOVER, COL_WHITE); m_btnClose.SetColorInside(enumBSBtnState::BS_CLICK, COL_DARK_GRAY); m_btnMin.Create(this, IDC_MIN); m_btnMin.SetWindowText(_T("-")); m_btnMin.SetBSFont(30, FALSE, TRUE); m_btnMin.MoveWindow(rt.Width() - 72, 0, 35, 25); m_btnMin.SetBackgroundColor(COL_GRAY); m_btnMin.SetColorBorder(enumBSBtnState::BS_NORMAL, COL_GRAY); m_btnMin.SetColorBorder(enumBSBtnState::BS_HOVER, COL_WHITE); m_btnMin.SetColorBorder(enumBSBtnState::BS_CLICK, COL_DARK_GRAY); m_btnMin.SetColorInside(enumBSBtnState::BS_NORMAL, COL_GRAY); m_btnMin.SetColorInside(enumBSBtnState::BS_HOVER, COL_WHITE); m_btnMin.SetColorInside(enumBSBtnState::BS_CLICK, COL_DARK_GRAY); // m_btnForgetPassword.Create(this, IDC_FORGET_PSW); // m_btnForgetPassword.SetWindowText(_T("忘记密码 >>")); // m_btnForgetPassword.MoveWindow(667, 440, 130, 24); // m_btnForgetPassword.SetBackgroundColor(COL_GRAY); m_btnLogin.Create(this, IDC_LOGIN); m_btnLogin.SetWindowText(_T("登陆")); m_btnLogin.SetBSFont(12, FALSE, TRUE); m_btnLogin.MoveWindow(893, 362, 80, 63); m_bsVersion.Create(this, IDC_LOGIN_VERSION); m_bsVersion.SetTextColor(COL_BLACK); m_bsVersion.SetWindowText(_T("蓝光集团生产管控平台")); m_bsVersion.SetBSFont(_T("Microsoft YaHei"), 32, FALSE, TRUE); m_bsVersion.SetTextAlign(DT_LEFT | DT_SINGLELINE); m_bsVersion.MoveWindow(300, 180, 450, 45); m_bsCopyright.Create(this, IDC_LOGIN_COPYRIGHT); m_bsCopyright.SetTextColor(COL_BLACK); CString strCopyright(_T("2015 @ 蓝光集团 . All rights reserved.\r\n \r\n build number: ")); m_bsCopyright.SetWindowText(strCopyright+IDS_VERSION_NUMBER); m_bsCopyright.SetBSFont(_T("Microsoft YaHei"), 12, FALSE, TRUE); m_bsCopyright.SetTextAlign(DT_CENTER | DT_SINGLELINE); m_bsCopyright.MoveWindow(rt.Width()/2 - 150, rt.Height() - 70, 300, 70); m_bsUserName.Create(this, IDC_LOGIN_USERNAME); m_bsUserName.SetTextColor(COL_BLACK); m_bsUserName.SetBSFont(_T("Microsoft YaHei"), 12); m_bsUserName.MoveWindow(613, 361, 82, 24); m_bsUserName.SetWindowText(_T("用户名")); m_bsPassword.Create(this, IDC_LOGIN_PSW); m_bsPassword.SetTextColor(COL_BLACK); m_bsPassword.SetBSFont(_T("Microsoft YaHei"), 12); m_bsPassword.MoveWindow(613, 404, 82, 24); m_bsPassword.SetWindowText(_T("密码")); m_bsLogo.Create(this, IDC_LOGIN_LOGO); m_bsLogo.SetBGPictureID(IDB_LOGO); m_bsLogo.MoveWindow(90,120, 180, 180); m_editPsw.MoveWindow(696, 405, 181, 20); m_editUserName.MoveWindow(0, 0, 0, 0); m_combUserName = Util_Tools::Util::CreateComboBox(this, IDC_LOGIN_COMB_USERNAME, _T("Microsoft YaHei"), 12, FALSE); m_combUserName->MoveWindow(696, 362, 181, 18); m_combUserName->SetCurSel(0); CString rootFolder; Util_Tools::Util::GetExpandPath(IDS_SETTING_LOCATION, rootFolder); vector<CString> vecFolderNames; vecFolderNames.clear(); Util_Tools::Util::FindSubFolders(rootFolder, vecFolderNames); CString strLastUser; int iCulSel = 0; bool bGetUser = Util_Tools::Util::GetLatestLogonUser(strLastUser); for (int i = 0; i < vecFolderNames.size(); i++) { if (bGetUser) { if (0 == strLastUser.CompareNoCase(vecFolderNames[i])) { iCulSel = i; } } m_combUserName->InsertString(i, vecFolderNames[i]); } m_combUserName->SetCurSel(iCulSel); SetTimer(TM_INITUI, 500, NULL); // CString path; // GetModuleFileName(AfxGetInstanceHandle(), path.GetBuffer(MAX_PATH), MAX_PATH); // path.ReleaseBuffer(); // //#ifndef _DEBUG // path.Replace(_T("BlueLightPLM.exe"), _T("test.txt")); // if (!PathFileExists(path)) // { // g_strHostName = _T("192.168.104.253"); // } //#endif CAssociation* asso = CAssociation::GetInstance(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
void CKSInputDialog::OnPaint() { CPaintDC dc(this); // device context for painting CDC memDC; CBitmap bkBit,*oldBkBit; CRect client; RECT clientRect,edtRect; dc.GetClipBox(client); if(memDC.CreateCompatibleDC(&dc)) { memDC.SetBkMode(TRANSPARENT); if(bkBit.CreateCompatibleBitmap(&dc,client.Width(),client.Height())) { oldBkBit = memDC.SelectObject(&bkBit); /* CBrush brh; brh.CreateSolidBrush( RGB(0,0,255) ); brh.UnrealizeObject(); memDC.FillRect( client , &brh ); */ if(m_config) { CRect parentRect; CWnd * parentWnd = GetParent(); ASSERT(parentWnd != NULL); parentWnd->GetWindowRect(parentRect); GetWindowRect(&clientRect); m_config->m_bkImg.m_Dest.x = -(clientRect.left); m_config->m_bkImg.m_Dest.y = -(clientRect.top); m_config->m_bkImg.m_DestSize.cx = parentRect.Width(); m_config->m_bkImg.m_DestSize.cy = parentRect.Height(); m_config->m_bkImg.m_Src.x = 0; m_config->m_bkImg.m_Src.y = 0; m_config->m_bkImg.m_SrcSize.cx = m_config->m_bkImg.GetWidth(); m_config->m_bkImg.m_SrcSize.cy = m_config->m_bkImg.GetHeight(); m_config->m_bkImg.Display(&memDC); /* dc.StretchBlt(0,0,client.Width(),client.Height(),&memDC ,0,0,m_config->m_bkImg.GetWidth(),m_config->m_bkImg.GetHeight(),SRCCOPY); */ } ////////////////////////////////////////////////////////////////////////// // 设置字体 LOGFONT lf; memset(&lf,0,sizeof lf); lf.lfCharSet = GB2312_CHARSET; strcpy(lf.lfFaceName,m_fontName.GetBuffer(1)); lf.lfHeight = m_fontSize; lf.lfWeight = FW_BOLD; CFont font; CFont *pOldFont; // 新添加的老字体资源 font.CreateFontIndirect(&lf); // memDC.SelectObject(font); // 隐掉 pOldFont = memDC.SelectObject(&font); // 新添加获得老字体资源 ////////////////////////////////////////////////////////////////////////// // 取得字体属性 TEXTMETRIC tm; memset(&tm,0,sizeof tm); memDC.GetTextMetrics(&tm); CSize fs = memDC.GetTextExtent(m_prompt); int textWidth = fs.cx;//tm.tmAveCharWidth * (m_prompt.GetLength() + 1); ////////////////////////////////////////////////////////////////////////// // 设置字体颜色 memDC.SetTextColor(m_fontColor); ////////////////////////////////////////////////////////////////////////// GetWindowRect(&clientRect); ScreenToClient(&clientRect); m_edtInput.GetWindowRect(&edtRect); ScreenToClient(&edtRect); int x,y; RECT textRect; if(clientRect.right > textWidth) { x = (clientRect.right - textWidth) / 2; textRect.left = x; textRect.right = textRect.left + textWidth; } else { x = 20; textRect.left = x; textRect.right = clientRect.right - 20; } //y = (edtRect.top - tm.tmHeight - 2); y = 5; memDC.MoveTo(x,y); textRect.top = y; textRect.bottom = y + GetTextLineHeight(fs.cy,textRect.right-textRect.left ,fs.cx); memDC.DrawText(m_prompt,&textRect,DT_WORDBREAK|DT_CENTER); ////////////////////////////////////////////////////////////////////////// dc.BitBlt(0,0,client.Width(),client.Height(),&memDC,0,0,SRCCOPY); memDC.SelectObject(pOldFont); // 新添加的把老字体资源选回去 font.DeleteObject(); //brh.DeleteObject(); memDC.SelectObject(oldBkBit); memDC.DeleteDC(); } } }
void CDuiEdit::DrawControl(CDC &dc, CRect rcUpdate) { Graphics graphics(dc); DrawImageFrame(graphics, m_pImage, m_rc, m_EditState * m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, 4); if(m_pLeftImage) { CRect rc; rc.left = m_rc.left + 2; rc.top = m_rc.top + (m_rc.Height() - m_sizeLeftImage.cy) / 2; rc.right = rc.left + m_sizeLeftImage.cx; rc.bottom = rc.top + m_sizeLeftImage.cy; if(m_nLeftImageCount > m_buttonState) { graphics.DrawImage(m_pLeftImage, RectF((Gdiplus::REAL)rc.left , (Gdiplus::REAL)rc.top, (Gdiplus::REAL)rc.Width(), (Gdiplus::REAL)rc.Height()), (Gdiplus::REAL)(m_buttonState * m_sizeLeftImage.cx), 0, (Gdiplus::REAL)m_sizeLeftImage.cx, (Gdiplus::REAL)m_sizeLeftImage.cy, UnitPixel); }else { graphics.DrawImage(m_pLeftImage, RectF((Gdiplus::REAL)rc.left , (Gdiplus::REAL)rc.top, (Gdiplus::REAL)rc.Width(), (Gdiplus::REAL)rc.Height()), 0, 0, (Gdiplus::REAL)m_sizeLeftImage.cx, (Gdiplus::REAL)m_sizeLeftImage.cy, UnitPixel); } } if(m_pSmallImage) { CRect rc; rc.left = m_rc.right - m_sizeSmallImage.cx - 2; rc.top = m_rc.top + (m_rc.Height() - m_sizeSmallImage.cy) / 2; rc.right = rc.left + m_sizeSmallImage.cx; rc.bottom = rc.top + m_sizeSmallImage.cy; if(m_nSmallImageCount > m_buttonState) { graphics.DrawImage(m_pSmallImage, RectF((Gdiplus::REAL)rc.left , (Gdiplus::REAL)rc.top, (Gdiplus::REAL)rc.Width(), (Gdiplus::REAL)rc.Height()), (Gdiplus::REAL)(m_buttonState * m_sizeSmallImage.cx), 0, (Gdiplus::REAL)m_sizeSmallImage.cx, (Gdiplus::REAL)m_sizeSmallImage.cy, UnitPixel); }else { graphics.DrawImage(m_pSmallImage, RectF((Gdiplus::REAL)rc.left , (Gdiplus::REAL)rc.top, (Gdiplus::REAL)rc.Width(), (Gdiplus::REAL)rc.Height()), 0, 0, (Gdiplus::REAL)m_sizeSmallImage.cx, (Gdiplus::REAL)m_sizeSmallImage.cy, UnitPixel); } } BSTR bsFont = m_strFont.AllocSysString(); FontFamily fontFamily(bsFont); Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel); SolidBrush solidBrush(m_clrText); SolidBrush solidBrushTip(m_clrTooltip); graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit ); ::SysFreeString(bsFont); StringFormat strFormat; strFormat.SetAlignment(StringAlignmentNear); // 水平方向左对齐 if(!m_bMultiLine) { // 单行文字 strFormat.SetLineAlignment(StringAlignmentCenter); // 垂直方向中间对齐 strFormat.SetFormatFlags( StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces); }else { strFormat.SetLineAlignment(StringAlignmentNear); // 垂直方向上对齐 } RectF rect((Gdiplus::REAL)m_rcText.left, (Gdiplus::REAL)(m_rcText.top+2), (Gdiplus::REAL)m_rcText.Width(), (Gdiplus::REAL)(m_rcText.Height()-2)); if(!m_strTitle.IsEmpty()) { // 文字非空 CString strTitle = m_strTitle; if(m_bPassWord) { int nlen = strTitle.GetLength(); strTitle = ""; for(int i = 0; i < nlen; i++) { strTitle += '*'; } } BSTR bsTitle = m_strTitle.AllocSysString(); graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rect, &strFormat, &solidBrush); ::SysFreeString(bsTitle); }else if(!m_strTooltip.IsEmpty()) { // 如果没有文字,但设置了tooltip,则显示tooltip BSTR bsTooltip = m_strTooltip.AllocSysString(); graphics.DrawString(bsTooltip, (INT)wcslen(bsTooltip), &font, rect, &strFormat, &solidBrushTip); ::SysFreeString(bsTooltip); } }
// // Parameters: // [IN] bHasTitle // TRUE if the button has a text // [IN] rpItem // A pointer to a RECT structure indicating the allowed paint area // [IN/OUT]rpTitle // A pointer to a CRect object indicating the paint area reserved for the // text. This structure will be modified if necessary. // [IN] bIsPressed // TRUE if the button is currently pressed // [IN] dwWidth // Width of the image (icon or bitmap) // [IN] dwHeight // Height of the image (icon or bitmap) // [OUT] rpImage // A pointer to a CRect object that will receive the area available to the image // void CButtonST::PrepareImageRect(bool bHasTitle, RECT &rpItem, CRect &rpTitle, bool bIsPressed, DWORD dwWidth, DWORD dwHeight, CRect &rpImage) { CRect rBtn; rpImage = rpItem; switch (m_nAlign) { case ST_ALIGN_HORIZ: if (!bHasTitle) { // Center image horizontally rpImage.left += ((rpImage.Width() - dwWidth)/2); } else { // Image must be placed just inside the focus rect rpImage.left += 3; rpTitle.left += dwWidth + 3; } // Center image vertically rpImage.top += ((rpImage.Height() - dwHeight)/2); break; case ST_ALIGN_HORIZ_RIGHT: GetClientRect(&rBtn); if (bHasTitle == FALSE /*spTitle->IsEmpty()*/) { // Center image horizontally rpImage.left += ((rpImage.Width() - dwWidth)/2); } else { // Image must be placed just inside the focus rect rpTitle.right = rpTitle.Width() - dwWidth - 3; rpTitle.left = 3; rpImage.left = rBtn.right - dwWidth - 3; // Center image vertically rpImage.top += ((rpImage.Height() - dwHeight)/2); } break; case ST_ALIGN_VERT: // Center image horizontally rpImage.left += ((rpImage.Width() - dwWidth)/2); if (bHasTitle == FALSE /*spTitle->IsEmpty()*/) { // Center image vertically rpImage.top += ((rpImage.Height() - dwHeight)/2); } else { rpImage.top = 3; rpTitle.top += dwHeight; } break; } // If button is pressed then press image also if (bIsPressed && !m_bIsCheckBox) { rpImage.OffsetRect(1, 1); } }
void COFSNcDlg::DrawCaption(CDC &dc,const CRect &m_Rect) { if(m_Rect.Width()==0||m_Rect.Height()==0) return; switch(m_CaptionMode) { case CAP_NONE: case CAP_COLOR: { CFont m_font; CBrush m_br; CRect m_TextRect = m_Rect; if(m_bActive) m_br.CreateSolidBrush(m_ActiveColor); else m_br.CreateSolidBrush(m_InactiveColor); dc.FillRect(m_Rect,&m_br); CString str; GetWindowText(str); m_font.Attach(GetStockObject(DEFAULT_GUI_FONT)); dc.SelectObject(&m_font); dc.SetTextColor(RGB(255,255,255)); dc.SetBkMode(TRANSPARENT); m_TextRect.right -= 80; dc.DrawText(str,(LPRECT)&m_TextRect ,DT_LEFT|DT_VCENTER|DT_END_ELLIPSIS|DT_SINGLELINE); } break; case CAP_BITMAP_1: { CDC dcT; dcT.CreateCompatibleDC(&dc); dcT.SelectObject(pActiveBMP); dc.BitBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,SRCCOPY); } break; case CAP_BITMAP_1_ZOOM: { CDC dcT; dcT.CreateCompatibleDC(&dc); dcT.SelectObject(pActiveBMP); dc.StretchBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,m_ActiveBMPSize.cx,m_ActiveBMPSize.cy,SRCCOPY); // dc.BitBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,SRCCOPY); } break; case CAP_BITMAP_2: { CDC dcT; dcT.CreateCompatibleDC(&dc); if(m_bActive) dcT.SelectObject(pActiveBMP); else dcT.SelectObject(pInactiveBMP); dc.BitBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,SRCCOPY); } break; case CAP_BITMAP_2_ZOOM: { CDC dcT; dcT.CreateCompatibleDC(&dc); if(m_bActive) { dcT.SelectObject(pActiveBMP); dc.StretchBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,m_ActiveBMPSize.cx,m_ActiveBMPSize.cy,SRCCOPY); } else { dcT.SelectObject(pInactiveBMP); dc.StretchBlt(m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height(),&dcT,0,0,m_InactiveBMPSize.cx,m_InactiveBMPSize.cy,SRCCOPY); } } break; } DWORD dwStyle = GetStyle(); CRect m_ButtonRect; m_ButtonRect.SetRect(m_Rect.right - CaptionH +2 ,m_Rect.top + 4, m_Rect.right - 2,m_Rect.bottom - 2); if(dwStyle&WS_SYSMENU) dc.DrawFrameControl(&m_ButtonRect,DFC_CAPTION,DFCS_CAPTIONCLOSE); if (dwStyle & WS_MAXIMIZEBOX) { m_ButtonRect-=CPoint(CaptionH-2,0); dc.DrawFrameControl(&m_ButtonRect, DFC_CAPTION, IsZoomed()?DFCS_CAPTIONRESTORE:DFCS_CAPTIONMAX); } if (dwStyle & WS_MINIMIZEBOX) { m_ButtonRect-=CPoint(CaptionH-2,0); dc.DrawFrameControl(&m_ButtonRect, DFC_CAPTION ,DFCS_CAPTIONMIN); } }
void CButtonST::DrawItem(UINT ctrlID, LPDRAWITEMSTRUCT lpDIS) { CDCHandle pDC = lpDIS->hDC; CPenHandle pOldPen; // Checkbox or Radiobutton style ? if (m_bIsCheckBox) { m_bIsPressed = (lpDIS->itemState & ODS_SELECTED) || m_nCheck; } // Normal button OR other button style ... else { m_bIsPressed = (lpDIS->itemState & ODS_SELECTED); } m_bIsFocused = (lpDIS->itemState & ODS_FOCUS) != 0; m_bIsDisabled = (lpDIS->itemState & ODS_DISABLED) != 0; CRect itemRect = lpDIS->rcItem; pDC.SetBkMode(TRANSPARENT); if (!m_bIsFlat) { if (m_bIsFocused || GetDefault()) { CBrush br; br.CreateSolidBrush(RGB(0,0,0)); pDC.FrameRect(&itemRect, br); itemRect.DeflateRect(1, 1); } } // Prepare draw... paint button background // Draw transparent? if (m_bDrawTransparent) { PaintBk(pDC); } else { OnDrawBackground(pDC, &itemRect); } // Draw pressed button if (m_bIsPressed) { if (m_bIsFlat) { if (m_bDrawBorder) { OnDrawBorder(pDC, &itemRect); } } else { CBrush brBtnShadow; brBtnShadow.CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW)); pDC.FrameRect(&itemRect, brBtnShadow); } } else // ...else draw non pressed button { CPen penBtnHiLight; // White CPen pen3DLight; // Light gray CPen penBtnShadow; // Dark gray CPen pen3DDKShadow; // Black penBtnHiLight.CreatePen(PS_SOLID, 0, ::GetSysColor(COLOR_BTNHILIGHT)); // White pen3DLight.CreatePen(PS_SOLID, 0, ::GetSysColor(COLOR_3DLIGHT)); // Light gray penBtnShadow.CreatePen(PS_SOLID, 0, ::GetSysColor(COLOR_BTNSHADOW)); // Dark gray pen3DDKShadow.CreatePen(PS_SOLID, 0, ::GetSysColor(COLOR_3DDKSHADOW)); // Black if (m_bIsFlat) { if (m_bMouseOnButton && m_bDrawBorder) { pDC.Draw3dRect(itemRect, ::GetSysColor(COLOR_BTNHILIGHT), ::GetSysColor(COLOR_BTNSHADOW)); } } else { // Draw top-left borders // White line pOldPen = pDC.SelectPen(penBtnHiLight); pDC.MoveTo(itemRect.left, itemRect.bottom-1); pDC.LineTo(itemRect.left, itemRect.top); pDC.LineTo(itemRect.right, itemRect.top); // Light gray line pDC.SelectPen(pen3DLight); pDC.MoveTo(itemRect.left+1, itemRect.bottom-1); pDC.LineTo(itemRect.left+1, itemRect.top+1); pDC.LineTo(itemRect.right, itemRect.top+1); // Draw bottom-right borders // Black line pDC.SelectPen(pen3DDKShadow); pDC.MoveTo(itemRect.left, itemRect.bottom-1); pDC.LineTo(itemRect.right-1, itemRect.bottom-1); pDC.LineTo(itemRect.right-1, itemRect.top-1); // Dark gray line pDC.SelectPen(penBtnShadow); pDC.MoveTo(itemRect.left+1, itemRect.bottom-2); pDC.LineTo(itemRect.right-2, itemRect.bottom-2); pDC.LineTo(itemRect.right-2, itemRect.top); // pDC.SelectPen(pOldPen); } } // Read the button's title CString sTitle; int nLen = GetWindowTextLength(); int nRetLen = GetWindowText(sTitle.GetBufferSetLength(nLen), nLen + 1); CRect captionRect = lpDIS->rcItem; // Draw the icon if (m_csIcons[0].hIcon != 0) { DrawTheIcon(pDC, !sTitle.IsEmpty(), lpDIS->rcItem, captionRect, m_bIsPressed, m_bIsDisabled); } if (m_csBitmaps[0].hBitmap != 0) { pDC.SetBkColor(RGB(255,255,255)); DrawTheBitmap(pDC, !sTitle.IsEmpty(), lpDIS->rcItem, captionRect, m_bIsPressed, m_bIsDisabled); } // Write the button title (if any) if (!sTitle.IsEmpty()) { // Draw the button's title // If button is pressed then "press" title also if (m_bIsPressed && !m_bIsCheckBox) { captionRect.OffsetRect(1, 1); } // Center text CRect centerRect = captionRect; pDC.DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER | DT_CALCRECT); captionRect.OffsetRect((centerRect.Width() - captionRect.Width())/2, (centerRect.Height() - captionRect.Height())/2); pDC.SetBkMode(TRANSPARENT); if (m_bIsDisabled) { captionRect.OffsetRect(1, 1); pDC.SetTextColor(::GetSysColor(COLOR_3DHILIGHT)); pDC.DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER); captionRect.OffsetRect(-1, -1); pDC.SetTextColor(::GetSysColor(COLOR_3DSHADOW)); pDC.DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER); } else { if (m_bMouseOnButton || m_bIsPressed) { pDC.SetTextColor(m_crColors[BTNST_COLOR_FG_IN]); pDC.SetBkColor(m_crColors[BTNST_COLOR_BK_IN]); } else { pDC.SetTextColor(m_crColors[BTNST_COLOR_FG_OUT]); pDC.SetBkColor(m_crColors[BTNST_COLOR_BK_OUT]); } pDC.DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER); } } if (!m_bIsFlat || (m_bIsFlat && m_bDrawFlatFocus)) { // Draw the focus rect if (m_bIsFocused) { CRect focusRect = itemRect; focusRect.DeflateRect(3, 3); pDC.DrawFocusRect(&focusRect); } } }
void COFSNcDlg::OnMouseMove(UINT nFlags, CPoint point) { if(bMoveNow) { CRect rPos; GetWindowRect(&rPos); int NewX = rPos.left + point.x - m_DownPoint.x; int NewY = rPos.top + point.y - m_DownPoint.y; SetWindowPos(NULL,NewX,NewY,-1,-1,SWP_NOZORDER|SWP_NOSIZE); UpdateWindow(); Sleep(10); } if(bSizeNow) { CRect rPos; GetWindowRect(&rPos); CPoint winPoint = point; ClientToScreen(&winPoint); int NewX = rPos.left;// + point.x - m_DownPoint.x; int NewY = rPos.top;// + point.y - m_DownPoint.y; int NewCX = rPos.Width(); int NewCY = rPos.Height(); switch(SizeMode) { case HTTOP: NewY += (point.y - m_DownPoint.y); NewCY -= (point.y - m_DownPoint.y); break; case HTBOTTOM: //???// if(point.y <= m_DownPoint.y||winPoint.y>=(NewY+NewCY)) NewCY += (point.y - m_DownPoint.y); m_DownPoint.y = point.y; break; case HTLEFT: NewX += (point.x - m_DownPoint.x); NewCX -= (point.x - m_DownPoint.x); break; case HTRIGHT: //???// if(point.x <= m_DownPoint.x||winPoint.x>=(NewX+NewCX)) NewCX += (point.x - m_DownPoint.x); m_DownPoint.x = point.x; break; case HTTOPLEFT: NewY += (point.y - m_DownPoint.y); NewCY -= (point.y - m_DownPoint.y); NewX += (point.x - m_DownPoint.x); NewCX -= (point.x - m_DownPoint.x); break; case HTBOTTOMRIGHT: if(point.y <= m_DownPoint.y||winPoint.y>=(NewY+NewCY)) NewCY += point.y - m_DownPoint.y; if(point.x <= m_DownPoint.x||winPoint.x>=(NewX+NewCX)) NewCX += (point.x - m_DownPoint.x); m_DownPoint = point; break; case HTTOPRIGHT: NewY += (point.y - m_DownPoint.y); NewCY -= (point.y - m_DownPoint.y); NewCX += (point.x - m_DownPoint.x); m_DownPoint.x = point.x; break; case HTBOTTOMLEFT: NewCY += point.y - m_DownPoint.y; NewX += (point.x - m_DownPoint.x); NewCX -= (point.x - m_DownPoint.x); m_DownPoint.y = point.y; break; } SetWindowPos(NULL,NewX,NewY,NewCX ,NewCY,SWP_NOZORDER); UpdateWindow(); Sleep(10); } }
void COXItemTipWnd::Display(CRect& rect, CString sText, int nOffset, int nAlignment, CFont* pFont, COLORREF clrText, COLORREF clrBackground) { ASSERT_VALID(m_pParentWnd); ASSERT(::IsWindow(m_pParentWnd->GetSafeHwnd())); ASSERT(::IsWindow(m_hWnd)); CWnd* pWnd=GetActiveWindow(); if(pWnd==NULL || (!IsDescendant(pWnd,m_pParentWnd) && (m_pParentWnd->GetExStyle()&WS_EX_TOPMOST)!=WS_EX_TOPMOST)) { return; } CClientDC dc(this); // device context for drawing CFont* pOldFont=NULL; if(pFont) { pOldFont=dc.SelectObject(pFont); } COLORREF clrOld=ID_OX_COLOR_NONE; if(clrText!=ID_OX_COLOR_NONE) { clrOld=dc.SetTextColor(clrText); } int nOldBkMode=dc.SetBkMode(TRANSPARENT); CRect rectDraw=rect; dc.DrawText(sText,&rectDraw,DT_CALCRECT|DT_LEFT|DT_SINGLELINE|DT_NOPREFIX); rectDraw.right+=2*nOffset; if(rectDraw.Width()>rect.Width()) { rect.right=rect.left+rectDraw.Width(); } if(rectDraw.Height()>rect.Height()) { rect.bottom=rect.top+rectDraw.Height(); } // it's show time! m_pParentWnd->ClientToScreen(&rect); // adjust rectangle to fit the screen // CWnd* pParentWnd=m_pParentWnd; BOOL bTopMostParent=FALSE; while(pParentWnd!=NULL) { if(pParentWnd->GetExStyle() & WS_EX_TOPMOST) { bTopMostParent=TRUE; break; } pParentWnd=pParentWnd->GetParent(); } DWORD dwMessagePos=::GetMessagePos(); CPoint point(GET_X_LPARAM(dwMessagePos),GET_Y_LPARAM(dwMessagePos)); CRect rectDisplay=GetMonitorRectFromPoint(point,!bTopMostParent); if(rect.right>rectDisplay.right) { rect.OffsetRect(rectDisplay.right-rect.right,0); } if(rect.left<rectDisplay.left) { rect.OffsetRect(rectDisplay.left-rect.left,0); } // ///////////////////////////////////////////////////////////// if(bTopMostParent) { SetWindowPos(&wndTopMost,rect.left,rect.top,rect.Width(), rect.Height(),SWP_NOACTIVATE); } else { SetWindowPos(NULL,rect.left,rect.top,rect.Width(), rect.Height(),SWP_NOZORDER|SWP_NOACTIVATE); } ShowWindow(SW_SHOWNA); if(clrBackground!=ID_OX_COLOR_NONE) { CBrush brush; brush.CreateSolidBrush(clrBackground); CRect rectClient; GetClientRect(rectClient); dc.FillRect(&rectClient,&brush); } else { SendMessage(WM_ERASEBKGND,(WPARAM)(HDC)dc); } rectDraw=rect; rectDraw.DeflateRect(nOffset,0); ScreenToClient(&rectDraw); dc.DrawText(sText,&rectDraw,nAlignment|DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX); if(pOldFont) { dc.SelectObject(pOldFont); } if(clrOld!=ID_OX_COLOR_NONE) { dc.SetTextColor(clrOld); } dc.SetBkMode(nOldBkMode); m_nTimerID=SetTimer(ID_OXITEMTIP_TIMER,ID_OXITEMTIP_TIMER_DELAY,NULL); if(m_nTimerID==0) { TRACE(_T("COXItemTipWnd::Display: failed to set timer to check item tip state\n")); } }
void ColorPicker::OnPaint() { // Setup a backbuffer: CPaintDC dcPaint(this); CDC dc; dc.CreateCompatibleDC(&dcPaint); CRect rectClient; GetClientRect(rectClient); CBitmap bitmap; bitmap.CreateCompatibleBitmap(&dcPaint, rectClient.Width(), rectClient.Height()); CBitmap *oldBitmap = dc.SelectObject(&bitmap); // Fill background first CBrush bgBrush(GetSysColor(COLOR_BTNFACE)); dc.FillRect(&rectClient, &bgBrush); // Draw a border: dc.Draw3dRect ( 0, 0, rectClient.Width(), rectClient.Height(), RGB(0, 0, 0), RGB(0, 0, 0) ); if (hueBarDirty_) generateHueBar(); if (alphaBarDirty_ || (!alphaSelection_ && slGraphDirty_)) generateAlphaBar(); if (slGraphDirty_) generatePicker(); if (slPickerDirty_) setPicker(false); dc.BitBlt ( slGraphRect_.left, slGraphRect_.top, slGraphRect_.Width(), slGraphRect_.Height(), pickerDC_, 0, 0, SRCCOPY ); dc.BitBlt ( hueBarRect_.left, hueBarRect_.top, hueBarRect_.Width(), hueBarRect_.Height(), hueBarDC_, 0, 0, SRCCOPY ); dc.BitBlt ( alphaBarRect_.left, alphaBarRect_.top, alphaBarRect_.Width(), alphaBarRect_.Height(), alphaBarDC_, 0, 0, SRCCOPY ); // Draw sl picker: CSize sz(6, 6); drawCrossAt ( slPickerPosition_, dc, sz ); // Draw hue indicator: sz.cx = hueBarRect_.Width(); sz.cy = 6; CPoint pt ( slGraphRect_.Width() + c_spacer_ + hueBarRect_.Width()/2 + c_borderSpace_, (int)(currentHue_*hueBarRect_.Height()) + c_borderSpace_ ); drawCrossAt(pt, dc, sz); if (alphaSelection_) { // Draw alpha indicator: sz.cx = 6; sz.cy = alphaBarRect_.Height(); pt = CPoint ( (int)(currentAlpha_ * alphaBarRect_.Width()) + c_borderSpace_, (int)(slGraphRect_.Height() + c_spacer_ + alphaBarRect_.Height()/2) + c_borderSpace_ ); drawCrossAt(pt, dc, sz); } // Draw the backbuffer: dcPaint.BitBlt ( rectClient.left, rectClient.top, rectClient.Width(), rectClient.Height(), &dc, 0, 0, SRCCOPY ); dc.SelectObject(oldBitmap); dc.DeleteDC(); bitmap.DeleteObject(); }
void CItemBrowserView::OnSize(UINT nType, int cx, int cy) { // Make sure they all exist... if (!m_lcItems.GetSafeHwnd() || !m_stCountPrompt.GetSafeHwnd() || !m_btnExportList.GetSafeHwnd() || !m_btnExportItem.GetSafeHwnd() || !m_btnAssign.GetSafeHwnd() || !m_stItemCount.GetSafeHwnd() || !m_edDescription.GetSafeHwnd()) return; CRect rAssign; m_btnAssign.GetWindowRect(&rAssign); CSize szAssign(rAssign.Width(),rAssign.Height()); rAssign.left = 0; rAssign.right = cx; rAssign.bottom = cy; rAssign.top = rAssign.bottom - szAssign.cy; m_btnAssign.MoveWindow(&rAssign); CRect rDesc; rDesc.left = 0; rDesc.right = cx; rDesc.top = (long)((cy-szAssign.cy) * .66); // Take up 1/3 of the space left after button. rDesc.bottom = rAssign.top-1; m_edDescription.MoveWindow(&rDesc); CRect rList; rList.left = 0; rList.right = cx - IBV_MARGIN_RIGHT; rList.top = 0; rList.bottom = rDesc.top-1; m_lcItems.MoveWindow(&rList); CRect rPrompt; m_stCountPrompt.GetWindowRect(&rPrompt); CSize szPrompt(rPrompt.Width(),rPrompt.Height()); rPrompt.left = rList.right+7; rPrompt.right = rPrompt.left + szPrompt.cx; rPrompt.bottom = rDesc.top - 5; rPrompt.top = rPrompt.bottom - szPrompt.cy; m_stCountPrompt.MoveWindow(&rPrompt); CRect rCount; rCount.left = rPrompt.right + 2; rCount.right = cx; rCount.top = rPrompt.top; rCount.bottom = rPrompt.bottom; m_stItemCount.MoveWindow(&rCount); CRect rExportItem; m_btnExportList.GetWindowRect(&rExportItem); CSize szExport(rExportItem.Width(),rExportItem.Height()); rExportItem.left = rList.right+7; rExportItem.right = rExportItem.left+szExport.cx; rExportItem.bottom = rPrompt.top - 10; rExportItem.top = rExportItem.bottom - szExport.cy; m_btnExportItem.MoveWindow(&rExportItem); CRect rExportList; rExportList.left = rList.right+7; rExportList.right = rExportItem.right; rExportList.bottom = rExportItem.top - 1; rExportList.top = rExportList.bottom - szExport.cy; m_btnExportList.MoveWindow(&rExportList); CRect rFilterList; rFilterList.left = rList.right+7; rFilterList.right = rExportItem.right; rFilterList.bottom = rExportList.top-7; rFilterList.top = rFilterList.bottom - szExport.cy; m_btnFilter.MoveWindow(&rFilterList); CRect rIcon; rIcon.left = rList.right+7; rIcon.right = rIcon.left + 66; rIcon.top = 7; rIcon.bottom = rIcon.top + 66; m_wndBitmap.MoveWindow(&rIcon); }
void CDynControl::OnUpdate() { if(m_bConfigMode) if(m_pWnd) { CString csDialogName=m_csName; if(csDialogName.IsEmpty()) csDialogName=csPropertyName; csDialogName=CString("<")+csDialogName+">"; if(m_nControlType == ID_DYNBUTTONTREE)//TREE { CTreeCtrl* pControl=(CTreeCtrl*)m_pWnd; pControl->SetRedraw(0); pControl->DeleteAllItems(); HTREEITEM CurParent=pControl->InsertItem(csDialogName,0); pControl->SetItemState(CurParent,TVIS_BOLD,TVIS_BOLD); HTREEITEM CurItem=pControl->InsertItem(csDialogName,CurParent); pControl->Expand(CurParent,TVE_EXPAND); pControl->InsertItem(csDialogName,CurItem); pControl->InsertItem(csDialogName,CurItem); pControl->Expand(CurItem,TVE_EXPAND); CurItem=pControl->InsertItem(csDialogName,CurParent); pControl->InsertItem(csDialogName,CurItem); pControl->InsertItem(csDialogName,CurItem); pControl->Expand(CurItem,TVE_EXPAND); pControl->SetRedraw(1); } if (m_nControlType == ID_DYNBUTTONGRID) // GRID - MFCGridCtrl { CGridCtrl* pControl=(CGridCtrl*)m_pWnd; LOGFONT *pFont; pFont=(LOGFONT *)pControl->GetItemFont(1,0); pFont->lfWeight = FW_BOLD; CGridCellBase *pCell=pControl->GetCell(1,0); pControl->SetItemFormat(1,0, DT_NOCLIP | DT_BOTTOM | DT_LEFT); pControl->SetItemText(1,0,csDialogName); pControl->SetItemFont(1,0,pFont); for(int i=1;i<pControl->GetColumnCount();i++) { pControl->SetItemText(1,i,""); } } else if (m_nControlType == ID_DYNBUTTONEDIT) // EDIT { m_pWnd->SetWindowText(csDialogName); } else if (m_nControlType == ID_DYNBUTTONLISTBOX) // LISTBOX { CListBox* pControl=(CListBox*)m_pWnd; pControl->ResetContent(); for(int i=0;i<5;i++) pControl->AddString(csDialogName); } else if (m_nControlType == ID_DYNBUTTONCOMBO) // COMBOBOX { CComboBox* pControl=(CComboBox*)m_pWnd; pControl->ResetContent(); pControl->AddString(csDialogName); pControl->SetCurSel(0); } else if (m_nControlType == ID_DYNBUTTONLABEL) // LABEL { CXColorStatic* pControl=(CXColorStatic*)m_pWnd; int nHAllign=GetPosNumber(aDataList[5].sData,aDataList[5].nData); int nVAllign=GetPosNumber(aDataList[6].sData,aDataList[6].nData); SetStaticParams(*pControl,nHAllign,nVAllign,"MS Sans Serif",aDataList[1].bData,aDataList[2].bData,aDataList[3].bData,aDataList[0].nData,aDataList[4].Color); if(!m_csValue.IsEmpty()) csDialogName=m_csValue; pControl->SetWindowText(csDialogName); pControl->SetPlainBorder(TRUE); pControl->SetPlainBorder(FALSE); } else if (m_nControlType == ID_DYNBUTTON &&aDataList[5].nData) // BUTTON + картинка { m_pWnd->SetWindowText(m_csValue); } else { if(m_csValue.IsEmpty()) m_pWnd->SetWindowText(csDialogName); else m_pWnd->SetWindowText(m_csValue); } /* глючит... if (m_nControlType == ID_BUTTON_TAB) // Tabl { CMyTabCtrl* pControl=(CMyTabCtrl*)m_pWnd; int nStyle= WS_CHILD | WS_VISIBLE; if(aDataList[1].bData)//Кнопки nStyle |= TCS_BUTTONS; if(aDataList[2].bData)//Многострочный nStyle |= TCS_MULTILINE; if(aDataList[3].bData)//Вертикально nStyle |= TCS_VERTICAL; if(aDataList[4].bData)//Перевернуть nStyle |= TCS_BOTTOM; ::SetWindowLong(pControl->m_hWnd, GWL_STYLE, nStyle); pControl->SetMinTabWidth(-1); } */ if (m_nControlType == ID_BUTTONFORMOBJECT) //Пользовательская форма - микроформа { CMicroForm* pControl=(CMicroForm*)m_pWnd; if(pControl) if(pControl->m_csObjName!=m_csObjName) { CRect Rect; m_pWnd->GetWindowRect(Rect); m_pParentWnd->ScreenToClient(Rect); pControl->ShowWindow(0); m_pWnd=0; CreateMicroForm(); m_pWnd->MoveWindow(Rect.left,Rect.top,Rect.Width(),Rect.Height(),1); } } } //Доп. параметры if (m_nControlType == ID_DYNBUTTON) // BUTTON { CImageButton* pControl=(CImageButton*)m_pWnd; pControl->SetTooltipText(m_csDescription,TRUE); pControl->SetTextColor(aDataList[4].Color); int nPicture=aDataList[5].nData;//картинка if(nPicture) { int nHAllign=GetPosNumber(aDataList[6].sData,aDataList[6].nData); int nVAllign=GetPosNumber(aDataList[7].sData,aDataList[7].nData); int MasHoriz[3]={0x0000,0x0010,0x0002}; int MasVert[3]={0x0000,0x0004,0x0008}; pControl->SetAlignStyle(CImageButton::TEXT_INCLUDE | MasHoriz[nHAllign] | MasVert[nVAllign]); } else { pControl->SetAlignStyle(CImageButton::TEXT_INCLUDE); } pControl->SetImage(nPicture); } else if (m_nControlType == ID_BUTTONFORMOBJECT) //Пользовательская форма - микроформа { m_pWnd->EnableWindow(m_bEnable); } }
void MyGraph::DrawGraph(CDC& dc) { VALIDATE; ASSERT_VALID(&dc); if (GetMaxSeriesSize()) { dc.SetBkMode(TRANSPARENT); // Populate the colors as a group of evenly spaced colors of maximum // saturation. int nColorsDelta(240 / GetMaxSeriesSize()); int baseColorL = 120; int diffColorL = 60; DWORD backgroundColor = ::GetSysColor(COLOR_WINDOW); // If graph is a non-stacked line graph, use darker colors if system window color is light. #if 0 if (m_eGraphType == MyGraph::Line && !m_bStackedGraph) { int backgroundLuma = (GetRValue(backgroundColor) + GetGValue(backgroundColor) + GetBValue(backgroundColor)) / 3; if (backgroundLuma > 128) { baseColorL = 70; diffColorL = 50; } } #endif for (WORD nGroup = 0; nGroup < GetMaxSeriesSize(); ++nGroup) { WORD colorH = (WORD)(nColorsDelta * nGroup); WORD colorL = (WORD)(baseColorL+(diffColorL*(nGroup%2))); WORD colorS = (WORD)(180)+(30*((1-nGroup%2)*(nGroup%3))); COLORREF cr(MyGraph::HLStoRGB(colorH, colorL, colorS)); // Populate colors cleverly m_dwaColors.SetAtGrow(nGroup, cr); } // Reduce the graphable area by the frame window and status bar. We will // leave GAP_PIXELS pixels blank on all sides of the graph. So top-left // side of graph is at GAP_PIXELS,GAP_PIXELS and the bottom-right side // of graph is at (m_rcGraph.Height() - GAP_PIXELS), (m_rcGraph.Width() - // GAP_PIXELS). These settings are altered by axis labels and legends. CRect rcWnd; GetClientRect(&rcWnd); m_rcGraph.left = GAP_PIXELS; m_rcGraph.top = GAP_PIXELS; m_rcGraph.right = rcWnd.Width() - GAP_PIXELS; m_rcGraph.bottom = rcWnd.Height() - GAP_PIXELS; CBrush br; VERIFY(br.CreateSolidBrush(backgroundColor)); dc.FillRect(rcWnd, &br); br.DeleteObject(); // Draw graph title. DrawTitle(dc); // Set the axes and origin values. SetupAxes(dc); // Draw legend if there is one and there's enough space. if (m_saLegendLabels.GetSize() && m_rcGraph.right-m_rcGraph.left > LEGEND_VISIBILITY_THRESHOLD) { DrawLegend(dc); } else{ m_rcLegend.SetRectEmpty(); } // Draw axes unless it's a pie. if (m_eGraphType != MyGraph::PieChart) { DrawAxes(dc); } // Draw series data and labels. switch (m_eGraphType) { case MyGraph::Bar: DrawSeriesBar(dc); break; case MyGraph::Line: if (m_bStackedGraph) DrawSeriesLineStacked(dc); else DrawSeriesLine(dc); break; case MyGraph::PieChart: DrawSeriesPie(dc); break; default: _ASSERTE(! "Bad default case"); break; } } }
void CDynControl::AddControl(CPoint* ppoint) { PrepareDataArray(); if(m_nControlType == ID_DYNBUTTONTREE)//TREE { CTreeCtrl* pControl=new CTreeCtrl(); int nStyle= WS_CHILD | TVS_SHOWSELALWAYS | WS_BORDER; if(aDataList[0].bData) nStyle = nStyle | TVS_HASBUTTONS; if(aDataList[1].bData) nStyle = nStyle | TVS_HASLINES; if(aDataList[2].bData) nStyle = nStyle | TVS_LINESATROOT; AddDialog(pControl,ppoint,200,100,"SysTreeView32",nStyle,WS_EX_CLIENTEDGE); if(aDataList[3].bData) pControl->SetImageList(GetImageList(),TVSIL_NORMAL); OnUpdate(); } else if (m_nControlType == ID_DYNBUTTONGRID) // GRID - MFCGridCtrl { CGridCtrl* pControl=new CGridCtrl(); AddDialog(pControl,ppoint,200,100,"MFCGridCtrl",0,WS_EX_CLIENTEDGE); #ifdef MYDEBUG pControl->SetDoubleBuffering(0); #else pControl->SetDoubleBuffering(1); #endif pControl->SetImageList(GetImageList()); //начальные параметры таблицы pControl->EnableDragAndDrop(false); pControl->SetGridLineColor(0); //pControl->SetFixedColumnSelection(aDataList[5].bData); //pControl->SetFixedRowSelection(aDataList[6].bData); pControl->SetHeaderSort(aDataList[7].bData); if(aDataList[8].nData<=0) aDataList[8].nData=16; pControl->SetDefCellHeight(aDataList[8].nData); if(aDataList[9].nData<=0) aDataList[9].nData=130; pControl->SetDefCellWidth(aDataList[9].nData); pControl->AutoSizeColumns(aDataList[11].bData); pControl->SetGridBkColor(aDataList[13].Color); //pControl->m_NotUseMyExtEdit=TRUE; //pControl->SetCompareFunction(CGridCtrl::pfnCellNumericCompare);//сравнение чисел if(m_bConfigMode) { int nColumn=5; pControl->SetEditable(0); pControl->SetHeaderSort(0); pControl->SetRowCount(20); pControl->SetColumnCount(nColumn); pControl->SetFixedRowCount(1); pControl->SetFixedColumnCount(0); pControl->SetSingleColSelection(1); pControl->SetFixedColumnSelection(1); } else { pControl->EnableSelection(0); pControl->m_bAutoExpandColumnsToFit=TRUE; pControl->SetVirtualMode(aDataList[12].bData); pControl->SetEditable(aDataList[4].bData); pControl->SetRowCount(aDataList[0].nData); pControl->SetColumnCount(aDataList[1].nData); pControl->SetFixedRowCount(aDataList[2].nData); pControl->SetFixedColumnCount(aDataList[3].nData); //pControl->SetSingleRowSelection(aDataList[10].bData); //pControl->SetListMode(aDataList[10].bData); } OnUpdate(); } else if (m_nControlType == ID_DYNBUTTONEDIT) // EDIT { if(aDataList[0].sData=="Дата"&&(!m_bConfigMode)) { m_nControlType = ID_DYNBUTTONDATE; // DATE if(afxAppRunMode!=CONFIG_MODE) if(aDataList[8].bData) m_bEnable=0; } else { int nStyle = WS_CHILD|ES_AUTOHSCROLL; if(aDataList[5].bData) nStyle = nStyle | ES_MULTILINE | WS_VSCROLL | ES_WANTRETURN | WS_HSCROLL ; if(!m_bConfigMode) if(aDataList[6].bData) nStyle = nStyle | ES_PASSWORD; if(aDataList[0].sData=="Число"&&(!m_bConfigMode)) { nStyle = nStyle | ES_RIGHT; if(aDataList[7].bData) { //nStyle = nStyle | ES_NUMBER; CCalcEdit *pControl=new CCalcEdit(1); pControl->nUseFilter=1; AddDialog(pControl,ppoint,90,DEFAULT_DIALOG_H,"EDIT",nStyle,WS_EX_CLIENTEDGE); if(!aDataList[1].bData) pControl->SetLimitText(aDataList[2].nData); if(!m_bConfigMode) pControl->SetReadOnly(aDataList[8].bData); } else { CXrNumericEdit *pControl=new CXrNumericEdit(); AddDialog(pControl,ppoint,90,DEFAULT_DIALOG_H,"EDIT",nStyle,WS_EX_CLIENTEDGE); pControl->SetCountDigitsDecimals(aDataList[2].nData-aDataList[3].nData); pControl->SetCountDigitsAfterDecimals(aDataList[3].nData); pControl->SetDisplayDigitsDecimalsFormat(xrDDDFDataTypeOnlyInputs);//xrDDDFDataTypeFull pControl->SetDisplayLeadingZero(xrDLZDataTypeFull);//xrDLZDataTypeParcial pControl->SetDecimalSymbol('.'); pControl->SetSeparatorGrouping("'"); pControl->SetNegativeValue(aDataList[4].bData); pControl->SetWindowText("0"); if(!m_bConfigMode) pControl->SetReadOnly(aDataList[8].bData); } } else { CDropEdit*pControl=new CDropEdit(aDataList[7].bData); pControl->SetInvalidCharacters(""); AddDialog(pControl,ppoint,90,DEFAULT_DIALOG_H,"EDIT",nStyle,WS_EX_CLIENTEDGE); if(!aDataList[1].bData) pControl->SetLimitText(aDataList[2].nData); if(!m_bConfigMode) pControl->SetReadOnly(aDataList[8].bData); } } } else if (m_nControlType == ID_DYNBUTTONLABEL) // LABEL { int nStyle = WS_CHILD|WS_DISABLED;// | WS_BORDER; if(m_bVisible||m_bConfigMode) nStyle = nStyle | WS_VISIBLE; CXColorStatic *pControl=new CXColorStatic(); AddDialog(pControl,ppoint,90,DEFAULT_DIALOG_H,"STATIC",WS_CHILD|WS_DISABLED | WS_BORDER); CWnd *p=pControl->GetOwner(); pControl->SetOwner(m_pParentWnd); pControl->SetParent(m_pParentWnd); if(aDataList[0].nData==0) aDataList[0].nData=8; int nHAllign=GetPosNumber(aDataList[5].sData,aDataList[5].nData); int nVAllign=GetPosNumber(aDataList[6].sData,aDataList[6].nData); SetStaticParams(*pControl,nHAllign,nVAllign,"MS Sans Serif",aDataList[1].bData,aDataList[2].bData,aDataList[3].bData,aDataList[0].nData,aDataList[4].Color); OnUpdate(); if(!aDataList[7].sData.IsEmpty()||!aDataList[8].sData.IsEmpty()) ::SetWindowLong(pControl->m_hWnd, GWL_STYLE, ::GetWindowLong(pControl->m_hWnd, GWL_STYLE) | SS_NOTIFY); } else if (m_nControlType == ID_DYNBUTTONCOMBO) // COMBO { CComboBox* pControl=new CComboBox(); AddDialog(pControl,ppoint,90,20*6,"COMBOBOX",WS_CHILD | CBS_DROPDOWNLIST | WS_VSCROLL | LBS_NOINTEGRALHEIGHT,0); OnUpdate(); } else if (m_nControlType == ID_DYNBUTTONLISTBOX) // LISTBOX { int nStyle = WS_CHILD|LBS_STANDARD|WS_HSCROLL|LBS_NOINTEGRALHEIGHT; CIconListBox* pControl=new CIconListBox(); if(aDataList[0].bData) { nStyle = nStyle | LBS_OWNERDRAWFIXED |LBS_NOTIFY |LBS_HASSTRINGS; pControl->SetImageList(GetImageList()); } AddDialog(pControl,ppoint,90,20*5,"LISTBOX",nStyle,WS_EX_CLIENTEDGE ); OnUpdate(); } else if (m_nControlType == ID_DYNBUTTONGROUP) // GROUPBOX { AddDialog(new CButton(),ppoint,90,DEFAULT_DIALOG_H*5,"BUTTON",WS_CHILD | BS_GROUPBOX &~WS_TABSTOP,0); OnUpdate(); } else if (m_nControlType == ID_DYNBUTTONCHECK) // CHECK { AddDialog(new CButton(),ppoint,90,DEFAULT_DIALOG_H,"BUTTON",WS_CHILD | BS_AUTOCHECKBOX,0); OnUpdate(); } else if (m_nControlType == ID_DYNBUTTON) // BUTTON { int nStyle = WS_CHILD; if(aDataList[0].bData) nStyle=nStyle | BS_DEFPUSHBUTTON; nStyle=nStyle | BS_OWNERDRAW; AddDialog(new CImageButton(),ppoint,80,22,"BUTTON",nStyle); OnUpdate(); } else if (m_nControlType == ID_DYNBUTTONRADIO) // RADIO { int nStyle = WS_CHILD | BS_AUTORADIOBUTTON; if (aDataList[0].bData) nStyle = nStyle | WS_GROUP; // if (m_csValue.IsEmpty()) // m_csValue = "Переключатель"; AddDialog(new CRadio(),ppoint,110,DEFAULT_DIALOG_H,"BUTTON",nStyle,0); OnUpdate(); } else if (m_nControlType == ID_BUTTONPROGRESS) // CProgressCtrl { int nStyle = WS_CHILD; if (aDataList[2].bData) nStyle = nStyle | PBS_VERTICAL; if (aDataList[3].bData) nStyle = nStyle | PBS_SMOOTH; CProgressCtrl* pControl=new CProgressCtrl(); AddDialog(pControl,ppoint,90,DEFAULT_DIALOG_H,"msctls_progress32",nStyle,0); pControl->SetRange32(aDataList[0].nData,aDataList[1].nData); } else if (m_nControlType == ID_BUTTONSLIDER) // CSliderCtrl { int nStyle = WS_CHILD | TBS_AUTOTICKS; if (aDataList[2].bData) nStyle = nStyle | TBS_VERT; if (aDataList[3].bData) nStyle = nStyle | TBS_TOP; if (!aDataList[4].bData) nStyle = nStyle | TBS_NOTICKS; CSliderCtrl* pControl=new CSliderCtrl(); AddDialog(pControl,ppoint,90,DEFAULT_DIALOG_H,"msctls_trackbar32",nStyle,0); pControl->SetRange(aDataList[0].nData,aDataList[1].nData); } else if (m_nControlType == ID_BUTTONFORMOBJECT) //Пользовательская форма - микроформа { CreateMicroForm(); m_pWnd->MoveWindow(ppoint->x,ppoint->y, 200,100,1); OnUpdate(); } else if (m_nControlType == ID_BUTTON_TAB) // Tabl { CMyTabCtrl* pControl=new CMyTabCtrl(); int nStyle=WS_CHILD; if(aDataList[1].bData)//Кнопки nStyle |= TCS_BUTTONS; if(aDataList[2].bData)//Многострочный nStyle |= TCS_MULTILINE; if(aDataList[3].bData)//Вертикально nStyle |= TCS_VERTICAL; if(aDataList[4].bData)//Перевернуть nStyle |= TCS_BOTTOM; AddDialog(pControl,ppoint,200,60,"SysTabControl32",nStyle ); if(m_bConfigMode) { TCITEM tcItem; tcItem.mask = TCIF_TEXT; tcItem.pszText = "Слой 1"; pControl->InsertItem(0,&tcItem); tcItem.pszText = "Слой 2"; pControl->InsertItem(1,&tcItem); tcItem.pszText = "Слой 3"; pControl->InsertItem(2,&tcItem); } OnUpdate(); } //без else, т.к. возможны превращения CEdit в Дату if (m_nControlType == ID_DYNBUTTONDATE) // DATE { int nStyle = WS_CHILD | WS_BORDER ;//| DTS_SHOWNONE; if(m_bVisible||m_bConfigMode) nStyle = nStyle | WS_VISIBLE; if(!m_nTabOrder) nStyle = nStyle | WS_TABSTOP; CRect rectPos; rectPos.left = ppoint->x; rectPos.top = ppoint->y; rectPos.right = rectPos.left + 110; // width and height rectPos.bottom = rectPos.top + 21; // of the control CDateTimeCtrl* pControl = new CDateTimeCtrl; m_pWnd = pControl; m_hWnd = pControl->GetSafeHwnd(); pControl->CreateEx(0,DATETIMEPICK_CLASS,"DateTime",nStyle, rectPos.left, rectPos.top, rectPos.Width(), rectPos.Height(), m_pParentWnd->m_hWnd,NULL); pControl->SetDlgCtrlID(m_nID); pControl->SetFont(&m_fontDefault); pControl->EnableWindow(m_bEnable); } }
//游戏结束 LRESULT CGameClientDlg::OnGameOver(WPARAM wParam,LPARAM lParam) { //设置状态 SetGameStatus(GS_FREE); if(!m_bExitTag) { if(m_cbPlayStatus[m_wMeChairID] == TRUE) m_GameClientView.m_CardControl[m_wMeChairID].SetCardData(m_cbHandCardData[m_wMeChairID],2); } else { //胜利列表 UserWinList WinnerList; //临时数据 BYTE bTempData[GAME_PLAYER][MAX_CENTERCOUNT]; CopyMemory(bTempData,m_cbOverCardData,GAME_PLAYER*MAX_CENTERCOUNT); //查找胜利者 m_GameLogic.SelectMaxUser(bTempData,WinnerList,NULL); ASSERT(WinnerList.bSameCount>0); //设置扑克 for (WORD i = 0;i<GAME_PLAYER;i++) { if(m_cbPlayStatus[i] == TRUE) m_GameClientView.m_CardControl[i].SetCardData(m_cbHandCardData[i],2); else m_GameClientView.m_CardControl[i].SetCardData(NULL,0); } //特效变量 bool wIsMyWin =false ; WORD wWinnerID = INVALID_CHAIR; BYTE cbEffectHandCard[MAX_COUNT]; BYTE cbEffectCenterCardData[MAX_CENTERCOUNT]; ZeroMemory(cbEffectHandCard,sizeof(cbEffectHandCard)); ZeroMemory(cbEffectCenterCardData,sizeof(cbEffectCenterCardData)); BYTE bTempCount1,bTempCount2; //查找胜利扑克 for (WORD i=0;i<WinnerList.bSameCount;i++) { wWinnerID=WinnerList.wWinerList[i]; if(!wIsMyWin && m_wMeChairID==WinnerList.wWinerList[i]) { wIsMyWin = true; } //查找扑克数据 BYTE bTempCount1=m_GameLogic.GetSameCard(m_cbHandCardData[wWinnerID],bTempData[wWinnerID],MAX_COUNT,MAX_CENTERCOUNT,cbEffectHandCard); BYTE bTempCount2=m_GameLogic.GetSameCard(m_cbCenterCardData,bTempData[wWinnerID],MAX_CENTERCOUNT,MAX_CENTERCOUNT,cbEffectCenterCardData); ASSERT(bTempCount1+bTempCount2<=MAX_CENTERCOUNT); //设置扑克特效数据 m_GameClientView.m_CardControl[wWinnerID].SetCardEffect(cbEffectHandCard,bTempCount1); m_GameClientView.m_CenterCardControl.SetCardEffect(cbEffectCenterCardData,bTempCount2); } //自己扑克 if(!wIsMyWin) { wWinnerID = m_wMeChairID; //自己扑克数据 ZeroMemory(cbEffectHandCard,sizeof(cbEffectHandCard)); ZeroMemory(cbEffectCenterCardData,sizeof(cbEffectCenterCardData)); //查找扑克数据 bTempCount1=m_GameLogic.GetSameCard(m_cbHandCardData[wWinnerID],bTempData[wWinnerID],MAX_COUNT,MAX_CENTERCOUNT,cbEffectHandCard); bTempCount2=m_GameLogic.GetSameCard(m_cbCenterCardData,bTempData[wWinnerID],MAX_CENTERCOUNT,MAX_CENTERCOUNT,cbEffectCenterCardData); ASSERT(bTempCount1+bTempCount2<=MAX_CENTERCOUNT); //设置标志扑克数据 m_GameClientView.m_CardControl[wWinnerID].SetMyCard(cbEffectHandCard,bTempCount1); m_GameClientView.m_CenterCardControl.SetMyCard(cbEffectCenterCardData,bTempCount2); } //游戏结束 m_GameClientView.SetGameEndStart(); } //赢金币 for (WORD i =0;i<GAME_PLAYER;i++) { if(m_cbPlayStatus[i] == FALSE) continue; if(m_dEndScore[i]>0L) { m_lCenterScore = m_lCenterScore -m_dEndScore[i]-m_lTotalScore[i]; m_GameClientView.UpdateWindow(); m_GameClientView.DrawMoveAnte(i,CGameClientView::AA_CENTER_TO_BASEFROM,m_dEndScore[i]+m_lTotalScore[i]); m_GameClientView.SetCenterScore(m_lCenterScore); } else if(m_dEndScore[i] == 0L) { m_GameClientView.DrawMoveAnte(i,CGameClientView::AA_CENTER_TO_BASEFROM,m_lTotalScore[i]); m_lCenterScore = m_lCenterScore-m_lTotalScore[i]; m_GameClientView.SetCenterScore(m_lCenterScore); m_GameClientView.UpdateWindow(); } m_GameClientView.SetTotalScore(i,0L); m_GameClientView.UpdateWindow(); } //播放声音 if (IsLookonMode()==false) { if (m_dEndScore[m_wMeChairID]>=0L) PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_WIN")); else PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_LOST")); } else PlayGameSound(GetModuleHandle(NULL),TEXT("GAME_END")); if(m_cbPlayStatus[m_wMeChairID]==TRUE && !IsLookonMode()) { //调整位置 CRect rcControl; m_GameClientView.m_ScoreView.GetWindowRect(&rcControl); CRect rcView ; m_GameClientView.GetWindowRect( &rcView ); m_GameClientView.m_ScoreView.MoveWindow(rcView.left+5,rcView.bottom-15-rcControl.Height()*3/2,rcControl.Width(),rcControl.Height()/*nWidth/2-rcControl.Width()/2,nHeight/2+56,0,0,SWP_NOZORDER|SWP_NOSIZE*/); m_GameClientView.m_ScoreView.SetGameScore(m_wMeChairID,m_dEndScore[m_wMeChairID]); m_GameClientView.m_ScoreView.ShowWindow(SW_SHOW); m_GameClientView.m_ScoreView.SetShowTimes(); } if(!IsLookonMode()) { //开牌按钮 if(m_bOpenCard) { m_GameClientView.m_btOpenCard.ShowWindow(SW_SHOW); } if (m_GameClientView.m_ScoreView.IsWindowVisible()==TRUE) { m_GameClientView.m_ScoreView.SetStartTimes(); } else if(m_bAutoStart==FALSE) { SetGameTimer(m_wMeChairID,IDI_START_GAME,TIME_START_GAME); } else //自动开始 { m_GameClientView.m_ScoreView.SetStartTimes(); m_GameClientView.m_ScoreView.SetShowTimes(); //OnStart(0,0); } } //状态设置 KillGameTimer(IDI_USER_ADD_SCORE); //开始按钮 if (!IsLookonMode() && m_bAutoStart==FALSE) { m_GameClientView.m_btStart.ShowWindow(SW_SHOW); m_GameClientView.m_btExit.ShowWindow(SW_SHOW); } //成绩显示在即时聊天对话框 TCHAR szBuffer[256]=TEXT(""); _snprintf(szBuffer,CountArray(szBuffer),TEXT("\n本局结束,成绩统计")); InsertGeneralString(szBuffer,RGB(0,128,255),true); if(m_bReset) { for (WORD i=0;i<GAME_PLAYER;i++) { if(m_lTotalScore[i]==0)continue; const tagUserData * pUserData=GetUserData(i); //成绩输出 if (pUserData!=NULL) { _snprintf(szBuffer,CountArray(szBuffer),TEXT("%s:%+ld"),/*%s玩家\n得分:%ld*/ pUserData->szName,m_dEndScore[i]); InsertGeneralString(szBuffer,RGB(0,128,255),true); } else { _snprintf(szBuffer,CountArray(szBuffer),TEXT("用户已离开:%+ld"),-m_lTotalScore[i]);/*\n得分:%ld*/ InsertGeneralString(szBuffer,RGB(0,128,255),true); } } } else //不足金额 { for (WORD i=0;i<GAME_PLAYER;i++) { if(m_lTotalScore[i]==0)continue; //成绩输出 if (m_bUserName[i]!=NULL) { _snprintf(szBuffer,CountArray(szBuffer),TEXT("%s:%+ld"), &m_bUserName[i],m_dEndScore[i]); InsertGeneralString(szBuffer,RGB(0,128,255),true); } else { _snprintf(szBuffer,CountArray(szBuffer),TEXT("用户已离开:%+ld"),-m_lTotalScore[i]); InsertGeneralString(szBuffer,RGB(0,128,255),true); } } } //重值变量 ZeroMemory(m_lTotalScore,sizeof(m_lTotalScore)); ZeroMemory(m_lTableScore,sizeof(m_lTableScore)); m_lCenterScore = 0L; return 0; }
void CDrawWarn::Draw(CDC* pDC) { ASSERT_VALID(this); CRect rect = m_position; rect.NormalizeRect(); if(rect.Width() < 10 || rect.Height()<10) return; pStrWarn = new STRWARN[m_nColCount]; AddWarn("1","2004/12/12","12:00","高报警","电压过低"); AddWarn("2","2004/12/12","12:00","高报警","电压过低"); AddWarn("3","2004/12/12","12:00","高报警","电压过低"); AddWarn("4","2004/12/12","12:00","高报警","电压过低"); AddWarn("5","2004/12/12","12:00","高报警","电压过低"); AddWarn("6","2004/12/12","12:00","高报警","电压过低"); AddWarn("7","2004/12/12","12:00","高报警","电压过低"); AddWarn("8","2004/12/12","12:00","高报警","电压过低"); AddWarn("9","2004/12/12","12:00","高报警","电压过低"); AddWarn("10","2004/12/12","12:00","高报警","电压过低"); AddWarn("11","2004/12/12","12:00","高报警","电压过低"); AddWarn("12","2004/12/12","12:00","高报警","电压过低"); Rect GdiRect (rect.TopLeft().x,rect.TopLeft().y,rect.Size().cx,rect.Size().cy); Color crBackColor,crTitleColor,crLineColor,crTextColor ; crBackColor.SetFromCOLORREF(m_ctlBackColor); crTitleColor.SetFromCOLORREF(m_ctlTitleColor ); crLineColor.SetFromCOLORREF(m_ctlLineColor); crTextColor.SetFromCOLORREF(m_ctlTextColor); Graphics graphics (pDC->m_hDC); Graphics Textgraphics (pDC->m_hDC); SolidBrush solidBrush(crBackColor); SolidBrush TitleBrush(crTitleColor); SolidBrush TextBrush(crTextColor); Pen pen(crLineColor,1); graphics.FillRectangle(&solidBrush,GdiRect); BSTR bstr = _com_util::ConvertStringToBSTR(m_fontName); /// WCHAR *fn = new unsigned short[m_fontName.GetLength()+1];; /// wcscpy(fn,bstr); FontFamily fontFamily(bstr); Font font(&fontFamily, m_fontSize, m_fontStyle, UnitPoint); for(int j =1; j<= m_nColCount; j++) { m_nCellWidth = 0; for(int i=1; i<= m_nRowCount; i++) { CRect rc = rect; if(m_bIsAutoSize) { m_nCellWidth = rect.Width()/m_nRowCount; m_nCellHeight = rect.Height()/m_nColCount; rc.TopLeft().x += (i-1)*m_nCellWidth; rc.TopLeft().y += (j-1)*m_nCellHeight; m_CellRect = CRect(rc.TopLeft(),CSize(m_nCellWidth,m_nCellHeight)); m_CellRect.NormalizeRect(); } else { rc.TopLeft().x += m_nCellWidth; m_nCellWidth += rect.Width()*m_nPercent[i-1]/100; m_nCellHeight = rect.Height()/m_nColCount; rc.TopLeft().y += (j-1)*m_nCellHeight; m_CellRect = CRect(rc.TopLeft(),CSize(rect.Width()*m_nPercent[i-1]/100,m_nCellHeight)); m_CellRect.NormalizeRect(); } Rect CellRect(m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy); graphics.DrawRectangle(&pen,CellRect); if(j == m_nColCount) //画标题 { StringFormat stringFormat; stringFormat.SetAlignment(StringAlignmentCenter); stringFormat.SetLineAlignment(StringAlignmentCenter); stringFormat.SetFormatFlags(StringFormatFlagsDirectionRightToLeft); stringFormat.SetTrimming(m_trimmingSyle); CString m_strButton; if(i == 1) m_strButton = "点号"; if(i == 2) m_strButton = "数据"; if(i == 3) m_strButton = "说明"; if(i == 4) m_strButton = "报警原因"; if(i == 5) m_strButton = "时间"; m_strButton.TrimRight(); /// int len = m_strButton.GetLength(); bstr = _com_util::ConvertStringToBSTR(m_strButton); /// WCHAR *strButton = new unsigned short[len]; /// wcscpy(strButton,bstr); RectF theRect (m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy); Matrix matrix(1,0,0,-1,0,0); Textgraphics.SetTransform(&matrix); theRect.Y *=-1; theRect.Height*=-1; Normallize (theRect); Textgraphics.FillRectangle(&TitleBrush,theRect); Textgraphics.DrawString(bstr,-1,&font, theRect,&stringFormat, &TextBrush); } else //画文字 { StringFormat stringFormat; stringFormat.SetAlignment(StringAlignmentNear); stringFormat.SetLineAlignment(StringAlignmentNear); CString strWarn; if(i == 1) strWarn = pStrWarn[j].strPoint; if(i == 2) strWarn = pStrWarn[j].strDate; if(i == 3) strWarn = pStrWarn[j].strTime; if(i == 4) strWarn = pStrWarn[j].strText; if(i == 5) strWarn = pStrWarn[j].strWarn; strWarn.TrimRight(); /// int len = strWarn.GetLength(); bstr = _com_util::ConvertStringToBSTR(strWarn); /// WCHAR *strButton = new unsigned short[len]; /// wcscpy(strButton,bstr); RectF theRect (m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy); Matrix matrix(1,0,0,-1,0,0); Textgraphics.SetTransform(&matrix); theRect.Y *=-1; theRect.Height*=-1; Normallize (theRect); Textgraphics.DrawString(bstr,-1,&font, theRect,&stringFormat, &TextBrush); } } } graphics.ReleaseHDC(pDC->m_hDC); }
BOOL CSizingControlBar::NegotiateSpace(int nLengthTotal, BOOL bHorz) { ASSERT(bHorz == IsHorzDocked()); int nFirst, nLast, nThis; GetRowInfo(nFirst, nLast, nThis); int nLengthAvail = nLengthTotal; int nLengthActual = 0; int nLengthMin = 2; int nWidthMax = 0; CSizingControlBar* pBar; for (int i = nFirst; i <= nLast; i++) { pBar = (CSizingControlBar*) m_pDockBar->m_arrBars[i]; if (HIWORD(pBar) == 0) continue; // placeholder if (!pBar->IsVisible()) continue; BOOL bIsSizingBar = pBar->IsKindOf(RUNTIME_CLASS(CSizingControlBar)); int nLengthBar; // minimum length of the bar if (bIsSizingBar) nLengthBar = bHorz ? pBar->m_szMinHorz.cx - 2 : pBar->m_szMinVert.cy - 2; else { CRect rcBar; pBar->GetWindowRect(&rcBar); nLengthBar = bHorz ? rcBar.Width() - 2 : rcBar.Height() - 2; } nLengthMin += nLengthBar; if (nLengthMin > nLengthTotal) { // split the row after fixed bar if (i < nThis) { m_pDockBar->m_arrBars.InsertAt(i + 1, (CControlBar*) NULL); return FALSE; } // only this sizebar remains on the row, adjust it to minsize if (i == nThis) { if (bHorz) m_szHorz.cx = m_szMinHorz.cx; else m_szVert.cy = m_szMinVert.cy; return TRUE; // the dockbar will split the row for us } // we have enough bars - go negotiate with them m_pDockBar->m_arrBars.InsertAt(i, (CControlBar*) NULL); nLast = i - 1; break; } if (bIsSizingBar) { nLengthActual += bHorz ? pBar->m_szHorz.cx - 2 : pBar->m_szVert.cy - 2; nWidthMax = max(nWidthMax, bHorz ? pBar->m_szHorz.cy : pBar->m_szVert.cx); } else nLengthAvail -= nLengthBar; } CSCBArray arrSCBars; GetRowSizingBars(arrSCBars); int nNumBars = arrSCBars.GetSize(); int nDelta = nLengthAvail - nLengthActual; // return faster when there is only one sizing bar per row (this one) if (nNumBars == 1) { ASSERT(arrSCBars[0] == this); if (nDelta == 0) return TRUE; m_bKeepSize = FALSE; (bHorz ? m_szHorz.cx : m_szVert.cy) += nDelta; return TRUE; } // make all the bars the same width for (i = 0; i < nNumBars; i++) if (bHorz) arrSCBars[i]->m_szHorz.cy = nWidthMax; else arrSCBars[i]->m_szVert.cx = nWidthMax; // distribute the difference between the bars, // but don't shrink them below their minsizes while (nDelta != 0) { int nDeltaOld = nDelta; for (i = 0; i < nNumBars; i++) { pBar = arrSCBars[i]; int nLMin = bHorz ? pBar->m_szMinHorz.cx : pBar->m_szMinVert.cy; int nL = bHorz ? pBar->m_szHorz.cx : pBar->m_szVert.cy; if ((nL == nLMin) && (nDelta < 0) || // already at min length pBar->m_bKeepSize) // or wants to keep its size continue; // sign of nDelta int nDelta2 = (nDelta == 0) ? 0 : ((nDelta < 0) ? -1 : 1); (bHorz ? pBar->m_szHorz.cx : pBar->m_szVert.cy) += nDelta2; nDelta -= nDelta2; if (nDelta == 0) break; } // clear m_bKeepSize flags if ((nDeltaOld == nDelta) || (nDelta == 0)) for (i = 0; i < nNumBars; i++) arrSCBars[i]->m_bKeepSize = FALSE; } return TRUE; }
/////////////////////////////////////////////////////////////////////////// // CAxRectTracker operations void CAxRectTracker::Draw(CDC* pDC) const { // set initial DC state VERIFY(pDC->SaveDC() != 0); pDC->SetMapMode(MM_TEXT); pDC->SetViewportOrg(0, 0); pDC->SetWindowOrg(0, 0); // get normalized rectangle CRect rect = m_rect; rect.NormalizeRect(); CPen* pOldPen = NULL; CBrush* pOldBrush = NULL; CGdiObject* pTemp = NULL; int nOldROP; // draw lines if ((m_nStyle & (dottedLine | solidLine)) != 0) { if (m_nStyle & dottedLine) pOldPen = pDC->SelectObject(CPen::FromHandle(s_afxBlackDottedPen)); else pOldPen = (CPen*)pDC->SelectStockObject(BLACK_PEN); pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH); nOldROP = pDC->SetROP2(R2_COPYPEN); rect.InflateRect(+1, +1); // borders are one pixel outside pDC->Rectangle(rect.left, rect.top, rect.right, rect.bottom); pDC->SetROP2(nOldROP); } // if hatchBrush is going to be used, need to unrealize it if ((m_nStyle & (hatchInside | hatchedBorder)) != 0) UnrealizeObject(s_afxHatchBrush); // hatch inside if ((m_nStyle & hatchInside) != 0) { pTemp = pDC->SelectStockObject(NULL_PEN); if (pOldPen == NULL) pOldPen = (CPen*)pTemp; pTemp = pDC->SelectObject(CBrush::FromHandle(s_afxHatchBrush)); if (pOldBrush == NULL) pOldBrush = (CBrush*)pTemp; pDC->SetBkMode(TRANSPARENT); nOldROP = pDC->SetROP2(R2_MASKNOTPEN); pDC->Rectangle(rect.left+1, rect.top+1, rect.right, rect.bottom); pDC->SetROP2(nOldROP); } // draw hatched border if ((m_nStyle & hatchedBorder) != 0) { pTemp = pDC->SelectObject(CBrush::FromHandle(s_afxHatchBrush)); if (pOldBrush == NULL) pOldBrush = (CBrush*)pTemp; pDC->SetBkMode(OPAQUE); CRect rectTrue; GetTrueRect(&rectTrue); pDC->PatBlt(rectTrue.left, rectTrue.top, rectTrue.Width(), rect.top-rectTrue.top, 0x000F0001 /* Pn */); pDC->PatBlt(rectTrue.left, rect.bottom, rectTrue.Width(), rectTrue.bottom-rect.bottom, 0x000F0001 /* Pn */); pDC->PatBlt(rectTrue.left, rect.top, rect.left-rectTrue.left, rect.Height(), 0x000F0001 /* Pn */); pDC->PatBlt(rect.right, rect.top, rectTrue.right-rect.right, rect.Height(), 0x000F0001 /* Pn */); } // draw resize handles if ((m_nStyle & (resizeInside | resizeOutside)) != 0) { UINT mask = GetHandleMask(); for (int i = 0; i < 8; ++i) { if (mask & (1<<i)) { GetHandleRect((TrackerHit)i, &rect); pDC->FillSolidRect(rect, RGB(0, 0, 0)); } } } // cleanup pDC state if (pOldPen != NULL) pDC->SelectObject(pOldPen); if (pOldBrush != NULL) pDC->SelectObject(pOldBrush); VERIFY(pDC->RestoreDC(-1)); }
void CXTPSkinObjectToolBar::DrawButton(CDC* pDC, int nIndex) { CToolBarCtrl* pToolBar = (CToolBarCtrl*)this; TBBUTTON tbb; pToolBar->GetButton(nIndex, &tbb); CRect rc; if (!pToolBar->GetItemRect(nIndex, rc)) return; int dxText = rc.Width() - (2 * GetMetrics()->m_cxEdge); int dyText = rc.Height() - (2 * GetMetrics()->m_cyEdge); NMTBCUSTOMDRAW tbcd; ZeroMemory(&tbcd, sizeof(NMTBCUSTOMDRAW)); tbcd.nmcd.hdc = pDC->GetSafeHdc(); tbcd.nmcd.rc = rc; tbcd.nmcd.dwItemSpec = tbb.idCommand; tbcd.nmcd.lItemlParam = tbb.dwData; SetRect(&tbcd.rcText, 0, 0, dxText, dyText); int nHot = (int)pToolBar->SendMessage(TB_GETHOTITEM); BOOL fHotTrack = nHot == nIndex; BOOL bPressed = tbb.fsState & TBSTATE_PRESSED; BOOL bChecked = tbb.fsState & TBSTATE_CHECKED; BOOL bEnabled = tbb.fsState & TBSTATE_ENABLED; tbcd.nmcd.uItemState = (fHotTrack ? CDIS_HOT : 0) | (bPressed ? CDIS_SELECTED : 0) | (bChecked ? CDIS_CHECKED : 0) | (bEnabled ? 0 : CDIS_DISABLED); LRESULT dwCustom = CustomDrawNotify(CDDS_ITEMPREPAINT, &tbcd.nmcd); fHotTrack = tbcd.nmcd.uItemState & CDIS_HOT; bPressed = tbcd.nmcd.uItemState & CDIS_SELECTED; bChecked = tbcd.nmcd.uItemState & CDIS_CHECKED; bEnabled = (tbcd.nmcd.uItemState & CDIS_DISABLED) == 0; if (!(dwCustom & CDRF_SKIPDEFAULT)) { int dxFace = rc.Width() - 2 * GetMetrics()->m_cxEdge; dxText = tbcd.rcText.right - tbcd.rcText.left; dyText = tbcd.rcText.bottom - tbcd.rcText.top; int x = rc.left + GetMetrics()->m_cxEdge; int y = rc.top + GetMetrics()->m_cyEdge; BOOL bSplit = HasSplitDropDown(&tbb); int cxMenuCheck = bSplit ? GetSystemMetrics(SM_CYMENUCHECK) : 0; if (HasDropDownArrow(&tbb)) { dxFace -= 5; dxText -= bSplit ? cxMenuCheck : 5; } LRESULT lPad = SendMessage(TB_GETPADDING); int yPad = HIWORD(lPad); int xPad = LOWORD(lPad); int yOffset = (yPad - (2 * GetMetrics()->m_cyEdge)) / 2; if (yOffset < 0) yOffset = 0; HIMAGELIST himl = GetImageList(HIML_NORMAL, 0); int iDxBitmap = 16, iDyBitmap = 16; if (himl) { ImageList_GetIconSize(himl, &iDxBitmap, &iDyBitmap); } int xCenterOffset = (dxFace - iDxBitmap) / 2; if (GetStyle() & TBSTYLE_LIST) { xCenterOffset = xPad / 2; } else if (bSplit) { xCenterOffset = (dxFace + GetMetrics()->m_cxEdge * 2 - (iDxBitmap + cxMenuCheck)) / 2; } if ((bPressed || bChecked) && (!(dwCustom & TBCDRF_NOOFFSET))) { xCenterOffset++; yOffset++; } CXTPSkinManagerClass* pClass = GetSkinClass(); if (!(dwCustom & TBCDRF_NOEDGES)) { if (bSplit) { CRect rcSplit(rc), rcSplitDropDown(rc); rcSplit.right -= cxMenuCheck; rcSplitDropDown.left = rcSplit.right; pClass->DrawThemeBackground(pDC, TP_SPLITBUTTON, !bEnabled ? TS_DISABLED : bPressed ? TS_PRESSED : bChecked ? TS_CHECKED : fHotTrack ? TS_HOT : TS_NORMAL, &rcSplit); pClass->DrawThemeBackground(pDC, TP_SPLITBUTTONDROPDOWN, !bEnabled ? TS_DISABLED : bPressed ? TS_PRESSED : bChecked ? TS_CHECKED : fHotTrack ? TS_HOT : TS_NORMAL, &rcSplitDropDown); } else { pClass->DrawThemeBackground(pDC, TP_BUTTON, !bEnabled ? TS_DISABLED : bPressed ? TS_PRESSED : bChecked ? TS_CHECKED : fHotTrack ? TS_HOT : TS_NORMAL, &rc); } } BOOL fImage = HasButtonImage(&tbb); if (fImage) { int yImage = y, xImage = x; if (GetStyle() & TBSTYLE_LIST) { if (iDyBitmap + yPad >= rc.Height()) yImage -= GetMetrics()->m_cyEdge; if (iDxBitmap + xPad >= rc.Width()) xImage -= GetMetrics()->m_cxEdge; } DrawButtonImage(pDC, xImage + xCenterOffset, yImage + yOffset, nIndex); } CString strText; SendMessage(TB_GETBUTTONTEXT, tbb.idCommand, (LPARAM)(LPTSTR)strText.GetBuffer(256)); strText.ReleaseBuffer(); #ifdef _UNICODE if (strText.IsEmpty() && (int)SendMessage(WM_NOTIFYFORMAT, 0, NF_QUERY) == NFR_ANSI) { char tText[256]; tText[0] = 0; SendMessage(TB_GETBUTTONTEXTA, tbb.idCommand, (LPARAM)tText); strText = tText; } #endif if (!strText.IsEmpty()) { if ((bPressed || bChecked) && (!(dwCustom & TBCDRF_NOOFFSET))) { x++; if (GetStyle() & TBSTYLE_LIST) y++; } if (GetStyle() & TBSTYLE_LIST) { int iListGap = (GetMetrics()->m_cxEdge * 2); if (fImage) { x += iDxBitmap + iListGap; dxText -= iDxBitmap + iListGap; } } else { y += yOffset + iDyBitmap; dyText -= yOffset + iDyBitmap; } DWORD uiStyle = DT_END_ELLIPSIS; int nTextRows = (int)SendMessage(TB_GETTEXTROWS); if (nTextRows > 1) uiStyle |= DT_WORDBREAK | DT_EDITCONTROL; else uiStyle |= DT_SINGLELINE; if (GetStyle() & TBSTYLE_LIST) { uiStyle |= DT_LEFT | DT_VCENTER | DT_SINGLELINE; } else { uiStyle |= DT_CENTER; } pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(bEnabled ? GetColor(COLOR_BTNTEXT) : GetColor(COLOR_BTNSHADOW)); if (dxText > 0) { CRect rcText(x + 1, y + 1, x + 1 + dxText, y + 1 + dyText); pDC->DrawText(strText, rcText, uiStyle); } } if (!bSplit && HasDropDownArrow(&tbb)) { CPoint pt(rc.right - 6, rc.CenterPoint().y); if (bPressed) pt.Offset(1, 1); CXTPDrawHelpers::Triangle(pDC, CPoint(pt.x - 2, pt.y - 1), CPoint(pt.x + 2, pt.y - 1), CPoint(pt.x, pt.y + 1), GetColor(COLOR_BTNTEXT)); } } if (dwCustom & CDRF_NOTIFYPOSTPAINT) CustomDrawNotify(CDDS_ITEMPOSTPAINT, &tbcd.nmcd); }
void CuResizableDlgBar::OnLButtonUp(UINT nFlags, CPoint point) { int oldROP2; CRect r; CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd(); pFrame->SetMessageText (""); GetClientRect (r); if (!m_bCapture || IsFloating()) { CDialogBar::OnLButtonUp(nFlags, point); pFrame->RecalcLayout(); return; } TCHAR tchszClass [12]; CRect rFrame; CWnd* WndMDIClient = NULL; CWnd* ChildWPtr = pFrame->GetWindow (GW_CHILD); while (ChildWPtr) { GetClassName (ChildWPtr->m_hWnd, tchszClass, sizeof (tchszClass)); if (lstrcmpi (tchszClass, _T("MDIClient")) == 0) { WndMDIClient = ChildWPtr; break; } ChildWPtr = pFrame->GetWindow (GW_HWNDNEXT); } ASSERT (ChildWPtr != NULL); CClientDC dc(pFrame); WndMDIClient->GetWindowRect (rFrame); ScreenToClient (rFrame); m_pOldPen = dc.SelectObject (m_pXorPen); oldROP2 = dc.SetROP2 (R2_XORPEN); ReleaseCapture(); m_bCapture = FALSE; if (m_Alignment == CBRS_ALIGN_LEFT || m_Alignment == CBRS_ALIGN_RIGHT) { dc.MoveTo (m_Pa.x, m_Pa.y+2); dc.LineTo (m_Pb.x, m_Pb.y-6); } else { dc.MoveTo (m_Pa.x+2, m_Pa.y); dc.LineTo (m_Pb.x-6, m_Pb.y); } dc.SetROP2 (oldROP2); dc.SelectObject (m_pOldPen); // // Calculate the new size (Width) of the Dialog Bar. switch (m_Alignment) { case CBRS_ALIGN_LEFT: if (point.x < XMINSPACE) { m_sizeDocked.cx = XMINSPACE; m_sizeFloating.cx = XMINSPACE; } else if (point.x < (rFrame.right -XMINSPACE)) { m_sizeDocked.cx = point.x; m_sizeFloating.cx = point.x; } else { m_sizeDocked.cx = rFrame.right - XMINSPACE; m_sizeFloating.cx = rFrame.right - XMINSPACE; } break; case CBRS_ALIGN_RIGHT: if (point.x > 0) { if (point.x > (r.Width() - XMINSPACE)) { m_sizeDocked.cx = XMINSPACE; m_sizeFloating.cx = XMINSPACE; } else { m_sizeDocked.cx = r.Width() - point.x; m_sizeFloating.cx = r.Width() - point.x; } } else { if (point.x > (rFrame.left + XMINSPACE)) { m_sizeDocked.cx = r.Width() - point.x; m_sizeFloating.cx = r.Width() - point.x; } else { m_sizeDocked.cx = r.Width() + rFrame.Width() - XMINSPACE; m_sizeFloating.cx = r.Width() + rFrame.Width() - XMINSPACE; } } break; case CBRS_ALIGN_TOP: if (point.y < YMINSPACE) { m_sizeDocked.cy = YMINSPACE; m_sizeFloating.cy = YMINSPACE; } else if (point.y < (rFrame.bottom -YMINSPACE)) { m_sizeDocked.cy = point.y; m_sizeFloating.cy = point.y; } else { m_sizeDocked.cy = rFrame.bottom - YMINSPACE; m_sizeFloating.cy = rFrame.bottom - YMINSPACE; } break; case CBRS_ALIGN_BOTTOM: if (point.y > 0) { if (point.y >= (r.Height() - YMINSPACE)) { m_sizeDocked.cy = YMINSPACE; m_sizeFloating.cy = YMINSPACE; } else { m_sizeDocked.cy = r.Height() - point.y; m_sizeFloating.cy = r.Height() - point.y; } } else { if (point.y > (rFrame.top + YMINSPACE)) { m_sizeDocked.cy = r.Height() - point.y; m_sizeFloating.cy = r.Height() - point.y; } else { m_sizeDocked.cy = r.Height() + rFrame.Height() - YMINSPACE; m_sizeFloating.cy = r.Height() + rFrame.Height() - YMINSPACE; } } break; default: break; } CDialogBar::OnLButtonUp(nFlags, point); pFrame->RecalcLayout(); pFrame->SetMessageText (_T("")); }