void CPalGroup::SortPal(int nIndex, int nStartIndex, int nSortFlag) { if(!rgPalettes[nIndex].bAvail) { return; //Most likeley wont happen } double * pHSLArray; int nPalSz = rgPalettes[nIndex].uPalSz; if(rgPalettes[nIndex].pSortTable) { delete [] rgPalettes[nIndex].pSortTable; } pHSLArray = new double[nPalSz * 3]; rgPalettes[nIndex].pSortTable = new UINT16[nPalSz]; for(int i = 0; i < nPalSz; i++) { rgPalettes[nIndex].pSortTable[i] = (UINT16)i; RGBtoHLS(rgPalettes[nIndex].pPal[i], &pHSLArray[i], &pHSLArray[i + nPalSz], &pHSLArray[i + (nPalSz*2)]); //pHSLArray[i] = (double)(rgPalettes[nIndex].pPal[i] & 0x00FFFFFF); } //Go through array again for(int i = 0; i < nPalSz; i++) { //pHSLArray[i] = pHSLArray[i] * pHSLArray[i + nPalSz] / pHSLArray[i + (nPalSz*2)]; double fpPage; double fpPageSz = 20.0f; double fpPageAmt; pHSLArray[i] *= 360.0f; fpPageAmt = (double)((int)(pHSLArray[i] / fpPageSz)); //pHSLArray[i] = fpPageSz * fpPageAmt; pHSLArray[i] += fpPageSz;// fpPage = 4096.0 * fpPageAmt; //pHSLArray[i] /= fabs((pHSLArray[i + nPalSz * 2])-(pHSLArray[i + nPalSz])); //pHSLArray[i] /= pHSLArray[i + nPalSz] + ((pHSLArray[i + (nPalSz * 2)]) / 3.0); //pHSLArray[i] /= (double)(rgPalettes[nIndex].pPal[i] & 0x00FFFFFF); //if(i && pHSLArray[i -1] == pHSLArray[i]) //{ // pHSLArray[i] += pHSLArray[i + nPalSz]; //} COLORREF crCol = rgPalettes[nIndex].pPal[i]; double nR = (double)GetRValue(rgPalettes[nIndex].pPal[i])/255.0, nG = (double)GetGValue(rgPalettes[nIndex].pPal[i])/255.0, nB = (double)GetBValue(rgPalettes[nIndex].pPal[i])/255.0; double fpX, fpY, fpZ; ccRGBtoXYZ(nR, nG, nB, &fpX, &fpY, &fpZ); //pHSLArray[i] /= sqrt(sq(fpX) + sq(fpY) + sq(fpZ)); pHSLArray[i] /= sqrt(sq(nR - 0) + sq(nG - 0) + sq(nB- 0)); //pHSLArray[i] /= // pHSLArray[i + nPalSz] + ((pHSLArray[i + (nPalSz * 2)]) / 0.5) + sqrt(sq(nR - 0) + sq(nG - 0) + sq(nB- 0)) + fpX*4; pHSLArray[i] += fpPage; } /* */ //for(int i = 0; i < nPalSz; i++) //{ // COLORREF crCol = rgPalettes[nIndex].pPal[i]; // double nR = (double)GetRValue(rgPalettes[nIndex].pPal[i]), // nG = (double)GetGValue(rgPalettes[nIndex].pPal[i]), // nB = (double)GetBValue(rgPalettes[nIndex].pPal[i]); // // pHSLArray[i] /= // sqrt(sq(nR*0.3 - 0) + sq(nG*0.6 - 0) + sq(nB*0.1 - 0)); // //} //Sort again if((nSortFlag & SORT_HUE) == SORT_HUE) { for(int i = 0; i < 10; i++) { ShellSort( &pHSLArray[nStartIndex], &pHSLArray[nStartIndex + nPalSz], &pHSLArray[nStartIndex + (nPalSz * 2)], (int *)&(rgPalettes[nIndex].pPal)[nStartIndex], (UINT16 *)&(rgPalettes[nIndex].pSortTable)[nStartIndex], nPalSz-nStartIndex ); } } delete [] pHSLArray; }
VOID AdjustBrightness(HBITMAP hOrigBitmap, HBITMAP hNewBitmap, HWND hwnd, HDC hdcMem, INT RedVal, INT GreenVal, INT BlueVal) { BITMAPINFO bi; BITMAP bitmap; BOOL bRes; DWORD Count = 0; INT i, j; PBYTE pBits; RECT rc; GetObject(hNewBitmap, sizeof(BITMAP), &bitmap); /* Bitmap header */ bi.bmiHeader.biSize = sizeof(bi.bmiHeader); bi.bmiHeader.biWidth = bitmap.bmWidth; bi.bmiHeader.biHeight = bitmap.bmHeight; bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 32; bi.bmiHeader.biCompression = BI_RGB; bi.bmiHeader.biSizeImage = bitmap.bmWidth * bitmap.bmHeight * 4; bi.bmiHeader.biClrUsed = 0; bi.bmiHeader.biClrImportant = 0; /* Buffer */ pBits = (PBYTE)HeapAlloc(ProcessHeap, 0, bitmap.bmWidth * bitmap.bmHeight * 4); if (!pBits) return; /* get the bits from the original bitmap */ bRes = GetDIBits(hdcMem, hOrigBitmap, 0, bitmap.bmHeight, pBits, &bi, DIB_RGB_COLORS); for (i = 0; i < bitmap.bmHeight; i++) { for (j = 0; j < bitmap.bmWidth; j++) { DWORD Val = 0; INT b, g, r; CopyMemory(&Val, &pBits[Count], 4); /* Get pixels in reverse order */ b = GetRValue(Val); g = GetGValue(Val); r = GetBValue(Val); /* Red */ r += RedVal; if (r > 255) r = 255; else if (r < 0) r = 0; /* Green */ g += GreenVal; if (g > 255) g = 255; else if (g < 0) g = 0; /* Blue */ b += BlueVal; if (b > 255) b = 255; else if (b < 0) b = 0; /* Store in reverse order */ Val = RGB(b, g, r); CopyMemory(&pBits[Count], &Val, 4); /* RGB color take 4 bytes.The high-order byte must be zero */ Count += 4; } } /* Set the new pixel bits */ SetDIBits(hdcMem, hNewBitmap, 0, bRes, pBits, &bi, DIB_RGB_COLORS); HeapFree(ProcessHeap, 0, pBits); GetClientRect(hwnd, &rc); InvalidateRect(hwnd, &rc, FALSE); }
//属性菜单 void CGuiderView::OnAttribute() { // TODO: 在此添加命令处理程序代码 CPoint p; if(App_Veriable::RelativeContextMenuPos.x==-1&&App_Veriable::RelativeContextMenuPos.y==-1)//没有菜单 { //快捷键 GetCursorPos(&p); this->ScreenToClient(&p); } else//有菜单 { p=App_Veriable::RelativeContextMenuPos; } int sp=sitelist.OnSite(p.x,p.y);//获取地点对象 Route* rp=routelist.OnRoute(p.x,p.y);//获取路径对象 if(sp!=0)//优先选中地点 { Site * s=sitelist.GetOfID(sp); dlgDySiteAttr.DynamicSiteID=s->ID; CString s0; s0.Format(L"(%d,%d)",s->Position.x,s->Position.y); dlgDySiteAttr.DynamicSitePosition=s0; switch(s->Style) { case'C':s0.Format(L"圆");break; case'T':s0.Format(L"三角形");break; case'R':s0.Format(L"矩形");break; default:s0.Format(L"");break; } dlgDySiteAttr.DynamicSiteStyle=s0; dlgDySiteAttr.DynamicSiteColorR=GetRValue(s->Color); dlgDySiteAttr.DynamicSiteColorG=GetGValue(s->Color); dlgDySiteAttr.DynamicSiteColorB=GetBValue(s->Color); dlgDySiteAttr.DynamicSiteSize=s->Size; dlgDySiteAttr.DynamicSiteInfo=s->SiteInfo; dlgDySiteAttr.DoModal(); } else if(rp!=NULL) { dlgDyRouteAttr.DynamicRouteID1=rp->ID1; Site * s=sitelist.GetOfID(rp->ID1); CString s1; s1.Format(L"(%d,%d)",s->Position.x,s->Position.y); dlgDyRouteAttr.DynamicRoutePosition1=s1; dlgDyRouteAttr.DynamicRouteID2=rp->ID2; s=sitelist.GetOfID(rp->ID2); s1.Format(L"(%d,%d)",s->Position.x,s->Position.y); dlgDyRouteAttr.DynamicRoutePosition2=s1; double l=routelist.GetRouteLength(rp->ID1,rp->ID2); l*=2.287;//长度系数 s1.Format(_T("%.4f m"),l); dlgDyRouteAttr.DynamicRouteLength=s1; dlgDyRouteAttr.DynamicRouteWidth=rp->Width; dlgDyRouteAttr.DynamicRouteColorR=GetRValue(rp->Color); dlgDyRouteAttr.DynamicRouteColorG=GetGValue(rp->Color); dlgDyRouteAttr.DynamicRouteColorB=GetBValue(rp->Color); dlgDyRouteAttr.DynamicRouteInfo=rp->RouteInfo; dlgDyRouteAttr.DynamicRoutePointSize=rp->Points->size; dlgDyRouteAttr.DynamicRoutePointColorR=GetRValue(rp->Points->color); dlgDyRouteAttr.DynamicRoutePointColorG=GetGValue(rp->Points->color); dlgDyRouteAttr.DynamicRoutePointColorB=GetBValue(rp->Points->color); dlgDyRouteAttr.DoModal(); } CPoint q(-1,-1); App_Veriable::RelativeContextMenuPos=q;//还原菜单变量 }
INT_PTR CJabberDlgGcJoin::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_DELETEITEM: { LPDELETEITEMSTRUCT lpdis = (LPDELETEITEMSTRUCT)lParam; if (lpdis->CtlID != IDC_ROOM) break; RoomInfo *info = (RoomInfo *)lpdis->itemData; mir_free(info->line1); mir_free(info->line2); mir_free(info); } break; case WM_MEASUREITEM: { LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT)lParam; if (lpmis->CtlID != IDC_ROOM) break; lpmis->itemHeight = 2 * sttTextLineHeight; if (lpmis->itemID == -1) lpmis->itemHeight = sttTextLineHeight - 1; } break; case WM_DRAWITEM: { LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam; if (lpdis->CtlID != IDC_ROOM) break; RoomInfo *info = (RoomInfo *)SendDlgItemMessage(m_hwnd, IDC_ROOM, CB_GETITEMDATA, lpdis->itemID, 0); COLORREF clLine1, clBack; if (lpdis->itemState & ODS_SELECTED) { FillRect(lpdis->hDC, &lpdis->rcItem, GetSysColorBrush(COLOR_HIGHLIGHT)); clBack = GetSysColor(COLOR_HIGHLIGHT); clLine1 = GetSysColor(COLOR_HIGHLIGHTTEXT); } else { FillRect(lpdis->hDC, &lpdis->rcItem, GetSysColorBrush(COLOR_WINDOW)); clBack = GetSysColor(COLOR_WINDOW); clLine1 = GetSysColor(COLOR_WINDOWTEXT); } COLORREF clLine2 = RGB( GetRValue(clLine1) * 0.66 + GetRValue(clBack) * 0.34, GetGValue(clLine1) * 0.66 + GetGValue(clBack) * 0.34, GetBValue(clLine1) * 0.66 + GetBValue(clBack) * 0.34); SetBkMode(lpdis->hDC, TRANSPARENT); RECT rc = lpdis->rcItem; rc.bottom -= (rc.bottom - rc.top) / 2; rc.left += 20; SetTextColor(lpdis->hDC, clLine1); DrawText(lpdis->hDC, info->line1, -1, &rc, DT_LEFT | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS); rc = lpdis->rcItem; rc.top += (rc.bottom - rc.top) / 2; rc.left += 20; SetTextColor(lpdis->hDC, clLine2); DrawText(lpdis->hDC, info->line2, -1, &rc, DT_LEFT | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS); DrawIconEx(lpdis->hDC, lpdis->rcItem.left + 1, lpdis->rcItem.top + 1, m_proto->LoadIconEx("group"), 16, 16, 0, NULL, DI_NORMAL); switch (info->overlay) { case RoomInfo::ROOM_WAIT: DrawIconEx(lpdis->hDC, lpdis->rcItem.left + 1, lpdis->rcItem.top + 1, m_proto->LoadIconEx("disco_progress"), 16, 16, 0, NULL, DI_NORMAL); break; case RoomInfo::ROOM_FAIL: DrawIconEx(lpdis->hDC, lpdis->rcItem.left + 1, lpdis->rcItem.top + 1, m_proto->LoadIconEx("disco_fail"), 16, 16, 0, NULL, DI_NORMAL); break; case RoomInfo::ROOM_BOOKMARK: DrawIconEx(lpdis->hDC, lpdis->rcItem.left + 1, lpdis->rcItem.top + 1, m_proto->LoadIconEx("disco_ok"), 16, 16, 0, NULL, DI_NORMAL); break; } } break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_SERVER: switch (HIWORD(wParam)) { case CBN_EDITCHANGE: case CBN_SELCHANGE: { int iqid = GetWindowLongPtr(GetDlgItem(m_hwnd, IDC_ROOM), GWLP_USERDATA); if (iqid) { m_proto->m_iqManager.ExpireIq(iqid); SetWindowLongPtr(GetDlgItem(m_hwnd, IDC_ROOM), GWLP_USERDATA, 0); } SendDlgItemMessage(m_hwnd, IDC_ROOM, CB_RESETCONTENT, 0, 0); } break; } break; case IDC_ROOM: switch (HIWORD(wParam)) { case CBN_DROPDOWN: if (!SendDlgItemMessage(m_hwnd, IDC_ROOM, CB_GETCOUNT, 0, 0)) { int iqid = GetWindowLongPtr(GetDlgItem(m_hwnd, IDC_ROOM), GWLP_USERDATA); if (iqid) { m_proto->m_iqManager.ExpireIq(iqid); SetWindowLongPtr(GetDlgItem(m_hwnd, IDC_ROOM), GWLP_USERDATA, 0); } SendDlgItemMessage(m_hwnd, IDC_ROOM, CB_RESETCONTENT, 0, 0); int len = GetWindowTextLength(GetDlgItem(m_hwnd, IDC_SERVER)) + 1; TCHAR *server = (TCHAR*)_alloca(len * sizeof(TCHAR)); GetDlgItemText(m_hwnd, IDC_SERVER, server, len); if (*server) { sttRoomListAppend(GetDlgItem(m_hwnd, IDC_ROOM), RoomInfo::ROOM_WAIT, TranslateT("Loading..."), TranslateT("Please wait for room list to download."), _T("")); CJabberIqInfo *pInfo = m_proto->AddIQ(&CJabberProto::OnIqResultDiscovery, JABBER_IQ_TYPE_GET, server, 0, -1, (void*)GetDlgItem(m_hwnd, IDC_ROOM)); pInfo->SetTimeout(30000); XmlNodeIq iq(pInfo); iq << XQUERY(JABBER_FEAT_DISCO_ITEMS); m_proto->m_ThreadInfo->send(iq); SetWindowLongPtr(GetDlgItem(m_hwnd, IDC_ROOM), GWLP_USERDATA, pInfo->GetIqId()); } else sttRoomListAppend(GetDlgItem(m_hwnd, IDC_ROOM), RoomInfo::ROOM_FAIL, TranslateT("Jabber Error"), TranslateT("Please specify group chat directory first."), _T("")); } break; } break; case IDC_BOOKMARKS: { HMENU hMenu = CreatePopupMenu(); LISTFOREACH(i, m_proto, LIST_BOOKMARK) { JABBER_LIST_ITEM *item = 0; if (item = m_proto->ListGetItemPtrFromIndex(i)) if (!mir_tstrcmp(item->type, _T("conference"))) AppendMenu(hMenu, MF_STRING, (UINT_PTR)item, item->name); } AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); AppendMenu(hMenu, MF_STRING, (UINT_PTR)-1, TranslateT("Bookmarks...")); AppendMenu(hMenu, MF_STRING, (UINT_PTR)0, TranslateT("Cancel")); RECT rc; GetWindowRect(GetDlgItem(m_hwnd, IDC_BOOKMARKS), &rc); CheckDlgButton(m_hwnd, IDC_BOOKMARKS, BST_CHECKED); int res = TrackPopupMenu(hMenu, TPM_RETURNCMD, rc.left, rc.bottom, 0, m_hwnd, NULL); CheckDlgButton(m_hwnd, IDC_BOOKMARKS, BST_UNCHECKED); DestroyMenu(hMenu); if (res == -1) m_proto->OnMenuHandleBookmarks(0, 0); else if (res) { JABBER_LIST_ITEM *item = (JABBER_LIST_ITEM *)res; TCHAR *room = NEWTSTR_ALLOCA(item->jid); if (room) { TCHAR *server = _tcschr(room, _T('@')); if (server) { *server++ = 0; SendMessage(m_hwnd, WM_COMMAND, MAKEWPARAM(IDC_SERVER, CBN_EDITCHANGE), (LPARAM)GetDlgItem(m_hwnd, IDC_SERVER)); SetDlgItemText(m_hwnd, IDC_SERVER, server); SetDlgItemText(m_hwnd, IDC_ROOM, room); SetDlgItemText(m_hwnd, IDC_NICK, item->nick); SetDlgItemText(m_hwnd, IDC_PASSWORD, item->password); } } } } break; case IDC_RECENT1: case IDC_RECENT2: case IDC_RECENT3: case IDC_RECENT4: case IDC_RECENT5: JabberGcRecentInfo info(m_proto, LOWORD(wParam) - IDC_RECENT1); info.fillForm(m_hwnd); if (GetAsyncKeyState(VK_CONTROL)) break; OnBtnOk(NULL); Close(); } break; case WM_JABBER_CHECK_ONLINE: if (!m_proto->m_bJabberOnline) EndDialog(m_hwnd, 0); break; }
void CSliderCtrlEx::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) { int loopMax = colorList.GetSize(); // number of color ranges to process LPNMCUSTOMDRAW lpCustDraw = (LPNMCUSTOMDRAW)pNMHDR; //////////////////////////////////////////////////////////////////////////////// // OnCustomDraw() is called at many different stages during the painting process // of the control. We only care about the PREPAINT state or the ITEMPREPAINT // state and not always then. // // If we want to be notified about subcontrol painting, we have to say so when // we get the initial PREPAINT message. //////////////////////////////////////////////////////////////////////////////// if(lpCustDraw->dwDrawStage == CDDS_PREPAINT) { // should we report slider's position? int curVal = GetPos(); if((m_Callback != NULL) && (curVal != m_oldPosition)) { m_oldPosition = curVal; m_Callback(m_p2Object, m_data1, curVal, m_IsDragging); } // If we don't have any special coloring to do, skip all the silliness... if(loopMax <= 0) { *pResult = CDRF_DODEFAULT; } else { // We want to be informed when each part of the control is being // processed so we can intercept the channel drawing. *pResult = CDRF_NOTIFYITEMDRAW; // send messages for each piece-part } return; } /////////////////////////////////////////////////////////////////////////////// // A slider (track control) is drawn in several steps: // 1. Erase // 2. Tics // 3. Channel // 4. Thumb // // It would be nice to capture when the background has been painted and // before the other sub-pieces have been painted. Then we could just // substitute our own painting routine. But this doesn't seem to be // available. // // So this routine captures the tics by inserting operations before // painting the thumb. // // Look at the help on NMCUSTOMDRAW for complete details, but the pNMHDR // pointer looks at a structure like: // // typedef struct tagNMCUSTOMDRAWINFO { // NMHDR hdr; // DWORD dwDrawStage; // This indicates what stage of the drawing process is involved // HDC hdc; // graphics context of the control (or sub-component) // RECT rc; // DWORD dwItemSpec; // This is the particular piece-part of the slider involved // UINT uItemState; // LPARAM lItemlParam; // } NMCUSTOMDRAW // // The stages include CDDS_PREPAINT, which is just before painting of the entire // control. However, unless the *pResult parameter is set to CDRF_NOTIFYITEMDRAW, // we will get notification for the control as a whole, not for each piece-part. // So the first thing to do is set *pResult. Thereafter, we must intercept // the sub-parts. // // We don't care about painting the background (we will re-paint later on). We // don't care about PREPAINT on the CHANNEL or the TICS since we will overwrite // everything when we get to the THUMB. ///////////////////////////////////////////////////////////////////////////////// if((lpCustDraw->dwDrawStage == CDDS_ITEMPREPAINT) && (lpCustDraw->dwItemSpec != TBCD_THUMB)) { *pResult = CDRF_DODEFAULT; return; } // get channel orientation BOOL IsVertical = (TBS_VERT & GetStyle()) ? TRUE : FALSE; // Get the coordinates of the control's window CRect crect; GetClientRect(crect); // client coordinates (top = left = 0, bottom = height, right = width) // Much of this is "paraphrased" from Nic Wilson's work -- see the header file ////////////////////////////////////////////////////////////////////////////////// // This bit does the tics marks transparently. // Create a memory dc to hold a copy of the oldbitmap data that includes the tics, // because when we add the background in we will lose the tic marks. /////////////////////////////////////////////////////////////////////////////////// CDC *pDC = CDC::FromHandle(lpCustDraw->hdc); CDC SaveCDC; CBitmap SaveCBmp; //set the colours for the monochrome mask bitmap COLORREF crOldBack = pDC->SetBkColor(RGB(0,0,0)); // set to Black COLORREF crOldText = pDC->SetTextColor(RGB(255,255,255)); // set to White int iWidth = crect.Width(); // channel width int iHeight = crect.Height(); // channel height //////////////////////////////////////////////////////////////////////////// // Create an in-memory copy of displayed bitmap, including the tics. // This is a monochrome bitmap since it was created from a memory DC. // If it had been created from pDC (an actual device DC, not a memory // DC) then this would be something with 8, 16, 24, or 32 bits per pixel. // // This will have a black background, with the tic marks in white. // // For reasons I don't yet understand, this saves only the tic marks and // the channel's centerline (both originally in black), and not the other // colors (such as drawn AROUND the channel's centerline). I am not sure // what would have happened if the tic marks were not black... //////////////////////////////////////////////////////////////////////////// SaveCDC.CreateCompatibleDC(pDC); SaveCBmp.CreateCompatibleBitmap(&SaveCDC, iWidth, iHeight); CBitmap* SaveCBmpOld = (CBitmap *)SaveCDC.SelectObject(SaveCBmp); SaveCDC.BitBlt(0, 0, iWidth, iHeight, pDC, crect.left, crect.top, SRCCOPY); if(m_dumpBitmaps) // debugging stuff { SaveBitmap("MonoTicsMask.bmp",SaveCBmp); } // Do as much of this stuff in memory as possible, then blit it to the screen CDC memDC; memDC.CreateCompatibleDC(pDC); CBitmap memBM; memBM.CreateCompatibleBitmap(pDC,iWidth,iHeight); // create from pDC, not memDC CBitmap *oldbm = memDC.SelectObject(&memBM); //////////////////////////////////////////////////////////////////////////////// // copy screen bitmap to memory bitmap for manipulation. If this is the very // first time the control has been updated, the screen bitmap will show only // the tic marks (in black) and the default background color (RGB(214,207,189)). // If the control has been updated before, remnants of the previously drawn // background color ranges will also show up. //////////////////////////////////////////////////////////////////////////////// memDC.BitBlt(0,0,iWidth,iHeight,pDC,0,0,SRCCOPY); if(m_dumpBitmaps) // debugging { SaveBitmap("ScrnStart.bmp",memBM); } ///////////////////////////////////////////////////////////////////////////// // Color parts of the channel if necessary. It SHOULD be necessary since we // don't get notifications unless there are colors to print, but we may have // a race condition and it is best to check. ///////////////////////////////////////////////////////////////////////////// if(loopMax) { ///////////////////////////////////////////////////////////////////////////////// // We need to draw colors over the subrange of the channel that the center of the // thumb traverses, rather than the entire client window. Later on, extend these // colors outwards to the ends of the client window (for nicer appearance). This // allows for more precise correlation with color and thumb position. ///////////////////////////////////////////////////////////////////////////////// CRect chanRect; GetChannelRect(&chanRect); CRect thmbRect; GetThumbRect(&thmbRect); // For unknown reasons, GetChannelRect() returns a rectangle // as though it were a horizonally oriented slider, even if it isn't! if(IsVertical) { CRect n; // could probably just change chanRect directly n.left = chanRect.top; n.right = chanRect.bottom; n.top = chanRect.left; n.bottom = chanRect.right; n.NormalizeRect(); chanRect.CopyRect(&n); } // Offset into client rectangle for beginning of coloring range int Offset = chanRect.left + thmbRect.Width()/2; if(IsVertical) { Offset = chanRect.top + thmbRect.Height()/2; } // Range for center of thumb on the channel int ht = chanRect.Height() - thmbRect.Height(); int wd = chanRect.Width() - thmbRect.Width(); // scaling between control range and bitmap int min,max; GetRange(min,max); // range of values for the slider double scale = (double(max) - double(min))/double(IsVertical ? ht : wd); BOOL gotStartColor = FALSE; BOOL gotEndColor = FALSE; COLORREF startColor = 0, endColor = 0; int loop; // Loop through the array of color ranges for(loop = 0; loop < loopMax; loop++) { clrRange clr; clr = colorList[loop]; // Get the good values. If not set, then entire range is good int lval = clr.lval; int hval = clr.hval; if((lval < min) || (lval > max)) lval = min; if((hval > max) || (hval < min)) hval = max; if(lval == min) { gotStartColor = TRUE; startColor = clr.strColor; } if(hval == max) { gotEndColor = TRUE; endColor = clr.endColor; } int minVal = lval - min; // offset into bitmap for this color minVal = int(double(minVal)/scale); // width (or height for vertical slider) inside bitmap for this color int widthVal = hval - lval; widthVal = int((double(widthVal)/scale) + 1.0); // For drawing a gradient, we need to know the individual RGB values int sR,eR,sG,eG,sB,eB; // start and end R, G, and B values sR = GetRValue(clr.strColor); eR = GetRValue(clr.endColor); sG = GetGValue(clr.strColor); eG = GetGValue(clr.endColor); sB = GetBValue(clr.strColor); eB = GetBValue(clr.endColor); if(GradientFill != NULL) { TRIVERTEX vert[2]; // for specifying range to gradient fill GRADIENT_RECT gRect; // Warning C4244: conversion from 'int' to 'unsigned short', possible loss of data #pragma warning (push) #pragma warning (disable : 4244) vert[0].Red = sR<<8; // expects 16-bit color values! vert[0].Green = sG<<8; vert[0].Blue = sB<<8; vert[0].Alpha = 0; // no fading/transparency vert[1].Red = eR<<8; vert[1].Green = eG<<8; vert[1].Blue = eB<<8; vert[1].Alpha = 0; #pragma warning (pop) gRect.UpperLeft = 0; gRect.LowerRight = 1; BOOL retval; if(IsVertical) // vertically oriented? { vert[0].x = 0; vert[0].y = Offset + minVal; vert[1].x = iWidth; vert[1].y = Offset + minVal + widthVal; retval = GradientFill(memDC,vert,2,&gRect,1,GRADIENT_FILL_RECT_V); } else { vert[0].x = Offset + minVal; vert[0].y = 0; vert[1].x = Offset + minVal + widthVal; vert[1].y = iHeight; retval = GradientFill(memDC,vert,2,&gRect,1,GRADIENT_FILL_RECT_H); } } else { // Homebrew version of GradientFill for rectangles -- works pretty well, sort of. int i; for(i = 0; i < widthVal; i++) // for each pixel column in bitmap color range { int R = sR; int G = sG; int B = sB; if(widthVal) { R += ::MulDiv(eR - sR, i, widthVal); G += ::MulDiv(eG - sG, i, widthVal); B += ::MulDiv(eB - sB, i, widthVal); } if(IsVertical) { // widthVal really refers to height //memDC.FillSolidRect(0,minVal+i,iWidth,widthVal-i,GetNearestColor(memDC,RGB(R,G,B))); memDC.FillSolidRect( 0, // starting X value Offset + minVal + i, // starting Y value iWidth, // full width 1, // one pixel height GetNearestColor(memDC,RGB(R,G,B))); } else { //memDC.FillSolidRect(minVal+i,0,widthVal-i,iHeight,GetNearestColor(memDC,RGB(R,G,B))); memDC.FillSolidRect( Offset + minVal + i, // Starting X value 0, // Starting Y value 1, // 1 pixel wide iHeight, // full height GetNearestColor(memDC,RGB(R,G,B))); } } } } if(m_extendColors) { // If we have put in colors at the slider ends, then extend those same // colors to the rest of the background. We could try to determine the // colors by examining the bitmap, but this is awkward and it is just // as easy to grab them on-the-fly in the coloring loop above. // // If you want to see why this is done, just set m_extendColors to FALSE // and take a look at the control. Ugly. But there might be a legitimate // reason for it so leave the option to suppress. if(IsVertical) { if(gotStartColor) { memDC.FillSolidRect(0, 0, iWidth, Offset, startColor); } if(gotEndColor) { memDC.FillSolidRect(0, iHeight - Offset - 1, iWidth, Offset, endColor); } } else { if(gotStartColor) { memDC.FillSolidRect(0, 0, Offset, iHeight, startColor); } if(gotEndColor) { memDC.FillSolidRect(iWidth - Offset - 1, 0, Offset, iHeight, endColor); } } } } // The screen bitmap should now have only the color ranges filled in, no tic // marks should be visible. if(m_dumpBitmaps) // debugging { SaveBitmap("ScrnColors.bmp",memBM); } ////////////////////////////////////////////////////////////// // More "paraphrasing" from Nic Wilson's work... ////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// // At this point, memDC's bitmap contains just the color ranges drawn above. // No tic marks are visible. Doing SRCINVERT with the mask will draw in the // tic marks, but all the colors will be backwards. Also, the tics will be // whatever color was drawn in the color range stuff, rather than solid, // normal tic marks. SRCINVERT means the RGB values are changed by subtracting // from 255: // // RGB(255,0,0) --> RGB(0,255,255) // RGB(247,8,0) --> RGB(8,247,255) // RGB(214,40,255) --> RGB(41,215,0) // ///////////////////////////////////////////////////////////////////////////// memDC.SetBkColor(pDC->GetBkColor()); memDC.SetTextColor(pDC->GetTextColor()); memDC.BitBlt(0, 0, iWidth, iHeight, &SaveCDC, 0, 0, SRCINVERT); if(m_dumpBitmaps) // debugging { SaveBitmap("ScrnInvert.bmp",memBM); } // Change the tic marks from the color range to the background color. This // changes only the tic marks (and the channel centerline) and leaves the // rest alone. The tic marks wind up black. memDC.BitBlt(0, 0, iWidth, iHeight, &SaveCDC, 0, 0, SRCAND); if(m_dumpBitmaps) // debugging { SaveBitmap("ScrnAnd.bmp",memBM); } // Finally, invert the color ranges to their normal values. Since the tic // marks in the SaveCDC bitmap are white, they get inverted to black. memDC.BitBlt(0, 0, iWidth, iHeight, &SaveCDC, 0, 0, SRCINVERT); if(m_dumpBitmaps) // debugging { SaveBitmap("ScrnFinal.bmp",memBM); } // Now copy out to screen pDC->BitBlt(0,0,iWidth,iHeight,&memDC,0,0,SRCCOPY); // restore and clean up pDC->SetBkColor(crOldBack); pDC->SetTextColor(crOldText); DeleteObject(SelectObject(SaveCDC, SaveCBmpOld)); DeleteDC(SaveCDC); DeleteObject(SelectObject(memDC,oldbm)); DeleteDC(memDC); *pResult = CDRF_DODEFAULT; m_dumpBitmaps = FALSE; // only do this once! }
void CPenBrushUnit::ErasedDraw(CDC *memDC, DataInfo &pDataInfo,HRGN ErasedRgn) { CPoint sPoint,ePoint,psPoint,pePoint,ptPoint; double dx,dy,xlen,ylen; double preWidth,nWidth; int count=1; int alpha; int v=0; int Red,Green,Blue; Red=GetRValue(pDataInfo.penColor); Green=GetGValue(pDataInfo.penColor); Blue=GetBValue(pDataInfo.penColor); Color colors[]={Color(10,Red,Green,Blue)}; Graphics mGraphics(memDC->m_hDC); /////////////////////////////////// Matrix matrix; Region tRgn; Region *ptRgn=tRgn.FromHRGN(ErasedRgn); mGraphics.ExcludeClip(ptRgn); matrix.Reset(); delete ptRgn; //////////////////////////////////// mGraphics.TranslateTransform(pDataInfo.CenterPoint.x,pDataInfo.CenterPoint.y); mGraphics.RotateTransform(pDataInfo.RotateAngle); mGraphics.SetSmoothingMode(SmoothingModeAntiAlias); sPoint=CaculatePoint(pDataInfo.StartPoint,pDataInfo); ePoint=CaculatePoint(pDataInfo.EndPoint,pDataInfo); xlen=ePoint.x-sPoint.x; ylen=ePoint.y-sPoint.y; preWidth=pDataInfo.AllRate[0].preWidth; alpha=pDataInfo.AllRate[0].alpha; psPoint.x=sPoint.x+xlen*pDataInfo.AllRate[0].xRate; psPoint.y=sPoint.y+ylen*pDataInfo.AllRate[0].yRate; int Size=pDataInfo.AllRate.size(); for(int Index=1;Index<Size;Index++) { pePoint.x=sPoint.x+xlen*pDataInfo.AllRate[Index].xRate; pePoint.y=sPoint.y+ylen*pDataInfo.AllRate[Index].yRate; dx=(pePoint.x-psPoint.x); dy=(pePoint.y-psPoint.y); nWidth=pDataInfo.AllRate[0].preWidth; float Angle=atan2(dy,dx)*Rate; GraphicsPath path(FillModeWinding); GraphicsPath path1,path2,path3,path4; RectF sRectF(psPoint.x,psPoint.y,0,0); sRectF.Inflate(preWidth,preWidth); RectF eRectF(pePoint.x,pePoint.y,0,0); eRectF.Inflate(nWidth,nWidth); /////////////////////////////////////////// REAL left=sRectF.GetLeft(); REAL top=sRectF.GetTop(); REAL bottom=sRectF.GetBottom(); REAL right=sRectF.GetRight(); Point pts0[]={Point((left+right)/2,top),Point((left+right)/2,bottom)}; matrix.RotateAt(Angle,PointF(psPoint.x,psPoint.y)); matrix.TransformPoints(pts0,2); Point LeftTop(pts0[0].X,pts0[0].Y); Point LeftBottom(pts0[1].X,pts0[1].Y); path1.AddArc(sRectF,270.0f,-180.0f); path1.Transform(&matrix); matrix.Reset(); top=eRectF.GetTop(); bottom=eRectF.GetBottom(); right=eRectF.GetRight(); left=eRectF.GetLeft(); Point pts1[]={Point((right+left)/2,bottom),Point((right+left)/2,top)}; matrix.RotateAt(Angle,PointF(pePoint.x,pePoint.y)); matrix.TransformPoints(pts1,2); Point RightBottom(pts1[0].X,pts1[0].Y); Point RightTop(pts1[1].X,pts1[1].Y); path3.AddArc(eRectF,90.0f,-180.0f); path3.Transform(&matrix); matrix.Reset(); Point pts[]={LeftTop,RightTop,RightBottom,LeftBottom}; /////////////////////////////////////////// path2.AddLine(LeftBottom,RightBottom); path4.AddLine(RightTop,LeftTop); path.AddPath(&path1,true); path.AddPath(&path2,true); path.AddPath(&path3,true); path.AddPath(&path4,true); SolidBrush brush(Color(255,Red,Green,Blue)); mGraphics.FillPath(&brush,&path); Pen pen(Color(255,Red,Green,Blue),1); mGraphics.DrawPath(&pen,&path); preWidth=nWidth; psPoint=pePoint; } mGraphics.ResetTransform(); }
void CPenBrushUnit::ReDraw(CDC* memDC,DataInfo &pDataInfo) { CPoint sPoint,ePoint,psPoint,pePoint,ptPoint; double dx,dy,xlen,ylen; double preWidth,nWidth; Matrix matrix; int count=1; int alpha; int v=0; int Red,Green,Blue; Red=GetRValue(pDataInfo.penColor); Green=GetGValue(pDataInfo.penColor); Blue=GetBValue(pDataInfo.penColor); SolidBrush brush(Color(255,Red,Green,Blue)); SolidBrush brush1(Color(200,Red,Green,Blue)); Graphics mGraphics(memDC->m_hDC); mGraphics.TranslateTransform(pDataInfo.CenterPoint.x,pDataInfo.CenterPoint.y); mGraphics.RotateTransform(pDataInfo.RotateAngle); mGraphics.SetSmoothingMode(SmoothingModeAntiAlias); mGraphics.ScaleTransform(pDataInfo.xScale,pDataInfo.yScale); /////////////////////////////////// Region tRgn; Region *ptRgn=tRgn.FromHRGN(pDataInfo.hRgn); if(ptRgn != NULL) mGraphics.ExcludeClip(ptRgn); delete ptRgn; //////////////////////////////////// int Size=pDataInfo.AllRate.size(); sPoint=CaculatePoint(pDataInfo.StartPoint,pDataInfo); ePoint=CaculatePoint(pDataInfo.EndPoint,pDataInfo); xlen=ePoint.x-sPoint.x; ylen=ePoint.y-sPoint.y; if(xlen<1) xlen=1; if(ylen<1) ylen=1; if(fwidth.size()!=0) fwidth.clear(); fwidth.insert(std::map<DWORD,float>::value_type(0,pDataInfo.AllRate[0].preWidth)); alpha=pDataInfo.AllRate[0].alpha; psPoint.x=sPoint.x+xlen*pDataInfo.AllRate[0].xRate; psPoint.y=sPoint.y+ylen*pDataInfo.AllRate[0].yRate; for(int Index=1;Index<Size;Index++) { pePoint.x=sPoint.x+xlen*pDataInfo.AllRate[Index].xRate; pePoint.y=sPoint.y+ylen*pDataInfo.AllRate[Index].yRate; if(Index==1) PushStart(psPoint,0); if(Push(psPoint,pePoint,0)) { RectF headRect; RectF tailRect; float width,dx,dy; PointF lfCenter,rtCenter; mGraphics.FillPolygon(&brush,pts,npts); mGraphics.DrawPolygon(&Pen(Color(200,Red,Green,Blue),1),pts,npts); if(npts==4) { headRect=RectF((pts[0].X+pts[3].X)/2.0f,(pts[0].Y+pts[3].Y)/2.0f,0.0f,0.0f); tailRect=RectF((pts[1].X+pts[2].X)/2.0f,(pts[1].Y+pts[2].Y)/2.0f,0.0f,0.0f); dx=pts[3].X-pts[0].X; dy=pts[3].Y-pts[0].Y; width=sqrt(dx*dx+dy*dy)/2.0f+0.5f; headRect.Inflate(width,width); dx=pts[2].X-pts[1].X; dy=pts[2].Y-pts[1].Y; width=sqrt(dx*dx+dy*dy)/2.0f+0.5f; tailRect.Inflate(width,width); } else { headRect=RectF((pts[0].X+pts[9].X)/2.0f,(pts[0].Y+pts[9].Y)/2.0f,0.0f,0.0f); tailRect=RectF((pts[4].X+pts[5].X)/2.0f,(pts[4].Y+pts[5].Y)/2.0f,0.0f,0.0f); dx=pts[9].X-pts[0].X; dy=pts[9].Y-pts[0].Y; width=sqrt(dx*dx+dy*dy)/2.0f+0.5f; headRect.Inflate(width,width); dx=pts[5].X-pts[4].X; dy=pts[5].Y-pts[4].Y; width=sqrt(dx*dx+dy*dy)/2.0f+0.5f; tailRect.Inflate(width,width); } mGraphics.FillEllipse(&brush1,headRect); mGraphics.FillEllipse(&brush1,tailRect); //preWidth=nWidth; psPoint=pePoint; } } mGraphics.ResetTransform(); }
//按照等距自动进行分段 void CRangeRenderPage::OnBnClickedBtnAutoSetrange() { UpdateData(TRUE); if(m_Breaknum<=0 || m_renderField.IsEmpty()) { return; } double dmin=0.0,dmax =0.0; //获得字段的最大最小值 GetMinMaxValue(dynamic_cast<Geodatabase::IFeatureClass*>(m_pLayer->GetDataObject().get()), m_renderField,&dmax,&dmin); m_Classes.clear(); m_list.DeleteAll(); COLORREF beginColor =m_ctlColorRamp.get_curStartColor(); COLORREF endColor =m_ctlColorRamp.get_curEndColor(); RangeItem item; Display::ISymbolPtr pDefaultSymbol =CreateDefaultSymbol(dynamic_cast<Geodatabase::IFeatureClass*>(m_pLayer->GetDataObject().get())); Display::ISymbolPtr pSymbol; //如果最大最小值相等,则只分一个段 if(dmin ==dmax) { item.max =dmax; item.min =dmin; pSymbol =pDefaultSymbol->Clone(); pSymbol->SetColor(beginColor); item.pSymbol =pSymbol; item.strLabel.Format("%.6f%s%.6f",item.min,"-",item.max); m_Classes.push_back(item); } else { //获取过渡色彩的各个分量 int begin_r_color = (int)GetRValue(beginColor); int begin_g_color = (int)GetGValue(beginColor); int begin_b_color = (int)GetBValue(beginColor); int end_r_color =(int) GetRValue(endColor); int end_g_color =(int) GetGValue(endColor); int end_b_color =(int) GetBValue(endColor); double dr,dg,db; BYTE markr,markg,markb; if(m_Breaknum == 1) { dr = end_r_color - begin_r_color; dg = end_g_color - begin_g_color; db = end_b_color - begin_b_color; } else { dr = (end_r_color - begin_r_color) / (double)(m_Breaknum - 1); dg = (end_g_color - begin_g_color) / (double)(m_Breaknum - 1); db = (end_b_color - begin_b_color) / (double)(m_Breaknum - 1); } double step =(dmax-dmin)/m_Breaknum; //分段的方法 /* upper = min + i * step 保留六位有效位 下一个区间为上一个的上限+0.000001 */ //依次加入区间 for(int i=0;i<m_Breaknum;i++) { markr =begin_r_color+i*dr; markg =begin_g_color+i*dg; markb =begin_b_color +i*db; item.min =dmin+step*i+0.000001; item.max =dmin+step*(i+1); pSymbol =pDefaultSymbol->Clone(); pSymbol->SetColor(RGB(markr,markg,markb)); item.pSymbol =pSymbol; item.strLabel.Format("%.6f%s%.6f",item.min,"-",item.max); m_Classes.push_back(item); } //设置第一个和最后一个区间 m_Classes[0].min =dmin; m_Classes[m_Breaknum-1].max =dmax; } //将各个分段添加到列表中 for(size_t i=0;i<m_Classes.size();i++) { m_list.AddSymbolItem(m_Classes[i].pSymbol,m_Classes[i].strLabel,m_Classes[i].strLabel); } }
HBITMAP KGUISkin::CreateGradient(HDC hDC, COLORREF clrBase, COLORREF clrHigh, COLORREF clrLow, bool bVert) { HDC hMemDC = CreateCompatibleDC (hDC) ; HBITMAP hDDB = CreateCompatibleBitmap (hDC, m_nWidth, m_nWidth); if (hDDB == NULL) { ::DeleteDC (hMemDC) ; assert(false); return NULL; } HGDIOBJ hOldBmp = ::SelectObject (hMemDC, hDDB); TRIVERTEX vertex[4]; vertex[0].x = 0; vertex[0].y = 0; vertex[0].Red = GetRValue(clrHigh) * 256; vertex[0].Green = GetGValue(clrHigh) * 256; vertex[0].Blue = GetBValue(clrHigh) * 256; vertex[0].Alpha = 0x0000; vertex[1].Red = GetRValue(clrBase) * 256; vertex[1].Green = GetGValue(clrBase) * 256; vertex[1].Blue = GetBValue(clrBase) * 256; vertex[1].Alpha = 0x0000; if (bVert) { vertex[1].x = m_nWidth; vertex[1].y = m_nWidth / 2; vertex[3].x = 0; vertex[3].y = m_nWidth / 2; } else { vertex[3].y = 0; vertex[3].x = m_nWidth / 2; vertex[1].y = m_nWidth; vertex[1].x = m_nWidth / 2; } vertex[3].Red = GetRValue(clrBase) * 256; vertex[3].Green = GetGValue(clrBase) * 256; vertex[3].Blue = GetBValue(clrBase) * 256; vertex[3].Alpha = 0x0000; vertex[2].x = m_nWidth; vertex[2].y = m_nWidth; vertex[2].Red = GetRValue(clrLow) * 256; vertex[2].Green = GetGValue(clrLow) * 256; vertex[2].Blue = GetBValue(clrLow) * 256; vertex[2].Alpha = 0x0000; GRADIENT_RECT gRect; gRect.UpperLeft = 0; gRect.LowerRight= 1; GRADIENT_RECT gTriangle2; gTriangle2.UpperLeft = 0; gTriangle2.LowerRight = 1; if (bVert) { GradientFill(hMemDC, vertex, 2, &gRect, 1, GRADIENT_FILL_RECT_V); GradientFill(hMemDC, &vertex[2], 2, &gTriangle2, 1, GRADIENT_FILL_RECT_V); } else { GradientFill(hMemDC, vertex, 2, &gRect, 1, GRADIENT_FILL_RECT_H); GradientFill(hMemDC, &vertex[2], 2, &gTriangle2, 1, GRADIENT_FILL_RECT_H); } BITMAPINFO info; UInt32 nPitch = (m_nWidth * 24 + 31) / 32 * 4; UInt32 dibSize = sizeof(BITMAPINFOHEADER) + (nPitch * m_nWidth); BYTE * pBuf = new BYTE[dibSize]; BYTE *pData = (BYTE*)pBuf; memset(pBuf, 0, dibSize); memset(&info, 0, sizeof(BITMAPINFOHEADER)); info.bmiHeader.biBitCount = 24; info.bmiHeader.biCompression= BI_RGB; info.bmiHeader.biClrUsed = 0; info.bmiHeader.biHeight = m_nWidth; info.bmiHeader.biPlanes = 1; info.bmiHeader.biSizeImage = 0; info.bmiHeader.biSize = 40; info.bmiHeader.biWidth = m_nWidth; pData += sizeof(BITMAPINFOHEADER); // Copy the bitmap ::GetDIBits (hMemDC, hDDB, 0, m_nWidth, pData, &info, DIB_RGB_COLORS) ; HBITMAP hBitmap = ::CreateDIBitmap(hDC, &info.bmiHeader, CBM_INIT, pData, &info, DIB_RGB_COLORS); delete[] pBuf; ::SelectObject (hMemDC, hOldBmp); DeleteObject (hDDB) ; DeleteDC (hMemDC) ; return hBitmap; }
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HWND hwndParent = hWndParent; HWND hwndImage = hWndImage; if (hwnd == hwndParent) { if (message == WM_SIZE) { ShowWindow(hwndImage, wParam == SIZE_MINIMIZED ? SW_HIDE : SW_SHOW); } if (message == WM_WINDOWPOSCHANGED) { SetWindowPos(hwndImage, hwndParent, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); } return CallWindowProc( (long (__stdcall *)(HWND,unsigned int,unsigned int,long))oldProc, hwnd, message, wParam, lParam ); } switch (message) { case WM_PAINT: if (bgBitmap.bReady) { ECS(); PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); if (bgBitmap.iType == MIL_BITMAP) { HDC cdc = CreateCompatibleDC(hdc); SelectObject(cdc, bgBitmap.hBitmap); for (unsigned int x = 0; x < uWndWidth; x += bgBitmap.rPos.right) { for (unsigned int y = 0; y < uWndHeight; y += bgBitmap.rPos.bottom) { BitBlt(hdc, x, y, bgBitmap.rPos.right, bgBitmap.rPos.bottom, cdc, 0, 0, SRCCOPY); } } DeleteDC(cdc); } else { int r = GetRValue(bgBitmap.cGradientFrom) << 10; int g = GetGValue(bgBitmap.cGradientFrom) << 10; int b = GetBValue(bgBitmap.cGradientFrom) << 10; int dr = ((GetRValue(bgBitmap.cGradientTo) << 10) - r) / (int)uWndHeight * 4; int dg = ((GetGValue(bgBitmap.cGradientTo) << 10) - g) / (int)uWndHeight * 4; int db = ((GetBValue(bgBitmap.cGradientTo) << 10) - b) / (int)uWndHeight * 4; RECT rect; rect.left = 0; rect.top = 0; rect.right = uWndWidth; rect.bottom = 4; while (rect.top < (int)uWndHeight) { HBRUSH brush = CreateSolidBrush(RGB(r>>10,g>>10,b>>10)); FillRect(hdc, &rect, brush); DeleteObject(brush); rect.top+=4; rect.bottom+=4; r+=dr; g+=dg; b+=db; } } myImageList *img = bgBitmap.next; while (img) { if (img->iType == MIL_TEXT) { SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, img->cTextColor); SelectObject(hdc, img->hFont); DrawText(hdc, img->szText, -1, &img->rPos, DT_TOP | DT_LEFT | DT_NOPREFIX | DT_WORDBREAK); } else if (img->iType == MIL_BITMAP) { HDC cdc = CreateCompatibleDC(hdc); SelectObject(cdc, img->hBitmap); BitBlt(hdc, img->rPos.left, img->rPos.top, img->rPos.right - img->rPos.left, img->rPos.bottom - img->rPos.top, cdc, 0, 0, SRCCOPY); DeleteDC(cdc); } else { COLORREF cColor; HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave; HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld; HDC hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave; POINT ptSize; HBITMAP hBitmap = img->hBitmap; hdcTemp = CreateCompatibleDC(hdc); SelectObject(hdcTemp, hBitmap); // Select the bitmap ptSize.x = img->rPos.right - img->rPos.left; ptSize.y = img->rPos.bottom - img->rPos.top; DPtoLP(hdcTemp, &ptSize, 1); // Convert from device to logical points // Create some DCs to hold temporary data. hdcBack = CreateCompatibleDC(hdc); hdcObject = CreateCompatibleDC(hdc); hdcMem = CreateCompatibleDC(hdc); hdcSave = CreateCompatibleDC(hdc); // Create a bitmap for each DC. DCs are required for a number of // GDI functions. // Monochrome DC bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL); // Monochrome DC bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL); bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y); bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y); // Each DC must select a bitmap object to store pixel data. bmBackOld = (HBITMAP)SelectObject(hdcBack, bmAndBack); bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject); bmMemOld = (HBITMAP)SelectObject(hdcMem, bmAndMem); bmSaveOld = (HBITMAP)SelectObject(hdcSave, bmSave); // Set proper mapping mode. SetMapMode(hdcTemp, GetMapMode(hdc)); // Save the bitmap sent here, because it will be overwritten. BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY); // Set the background color of the source DC to the color. // contained in the parts of the bitmap that should be transparent cColor = SetBkColor(hdcTemp, img->cTransparent); // Create the object mask for the bitmap by performing a BitBlt // from the source bitmap to a monochrome bitmap. BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY); // Set the background color of the source DC back to the original // color. SetBkColor(hdcTemp, cColor); // Create the inverse of the object mask. BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, NOTSRCCOPY); // Copy the background of the main DC to the destination. BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, img->rPos.left, img->rPos.top, SRCCOPY); // Mask out the places where the bitmap will be placed. BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND); // Mask out the transparent colored pixels on the bitmap. BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND); // XOR the bitmap with the background on the destination DC. BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT); // Copy the destination to the screen. BitBlt(hdc, img->rPos.left, img->rPos.top, ptSize.x, ptSize.y, hdcMem, 0, 0, SRCCOPY); // Place the original bitmap back into the bitmap sent here. BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY); // Delete the memory bitmaps. DeleteObject(SelectObject(hdcBack, bmBackOld)); DeleteObject(SelectObject(hdcObject, bmObjectOld)); DeleteObject(SelectObject(hdcMem, bmMemOld)); DeleteObject(SelectObject(hdcSave, bmSaveOld)); // Delete the memory DCs. DeleteDC(hdcMem); DeleteDC(hdcBack); DeleteDC(hdcObject); DeleteDC(hdcSave); DeleteDC(hdcTemp); } img = img->next; } LCS(); EndPaint(hwnd, &ps); } break; case WM_WINDOWPOSCHANGING: if (IsWindow(hwndParent)) { LPWINDOWPOS wp = (LPWINDOWPOS) lParam; wp->flags |= SWP_NOACTIVATE; wp->hwndInsertAfter = hwndParent; } break; case WM_CLOSE: DestroyWindow(hwnd); break; default: return DefWindowProc(hwnd, message, wParam, lParam); }
void CColourPopup::DrawCell(CDC* pDC, int nIndex) { // For the Custom Text area if (m_strCustomText.GetLength() && nIndex == CUSTOM_BOX_VALUE) { // The extent of the actual text button CRect TextButtonRect = m_CustomTextRect; TextButtonRect.top += 2*m_nMargin; // Fill background pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DFACE)); // Draw horizontal line pDC->FillSolidRect(m_CustomTextRect.left+2*m_nMargin, m_CustomTextRect.top, m_CustomTextRect.Width()-4*m_nMargin, 1, ::GetSysColor(COLOR_3DSHADOW)); pDC->FillSolidRect(m_CustomTextRect.left+2*m_nMargin, m_CustomTextRect.top+1, m_CustomTextRect.Width()-4*m_nMargin, 1, ::GetSysColor(COLOR_3DHILIGHT)); TextButtonRect.DeflateRect(1,1); // fill background if (m_nChosenColourSel == nIndex && m_nCurrentSel != nIndex) pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DLIGHT)); else pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DFACE)); // Draw button if (m_nCurrentSel == nIndex) pDC->DrawEdge(TextButtonRect, BDR_RAISEDINNER, BF_RECT); else if (m_nChosenColourSel == nIndex) pDC->DrawEdge(TextButtonRect, BDR_SUNKENOUTER, BF_RECT); // Draw custom text CFont *pOldFont = (CFont*) pDC->SelectObject(&m_Font); pDC->SetBkMode(TRANSPARENT); pDC->DrawText(m_strCustomText, TextButtonRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); pDC->SelectObject(pOldFont); return; } // For the Default Text area if (m_strDefaultText.GetLength() && nIndex == DEFAULT_BOX_VALUE) { // Fill background pDC->FillSolidRect(m_DefaultTextRect, ::GetSysColor(COLOR_3DFACE)); // The extent of the actual text button CRect TextButtonRect = m_DefaultTextRect; TextButtonRect.DeflateRect(1,1); // fill background if (m_nChosenColourSel == nIndex && m_nCurrentSel != nIndex) pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DLIGHT)); else pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DFACE)); // Draw thin line around text CRect LineRect = TextButtonRect; LineRect.DeflateRect(2*m_nMargin,2*m_nMargin); CPen pen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW)); CPen* pOldPen = pDC->SelectObject(&pen); pDC->SelectStockObject(NULL_BRUSH); pDC->Rectangle(LineRect); pDC->SelectObject(pOldPen); // Draw button if (m_nCurrentSel == nIndex) pDC->DrawEdge(TextButtonRect, BDR_RAISEDINNER, BF_RECT); else if (m_nChosenColourSel == nIndex) pDC->DrawEdge(TextButtonRect, BDR_SUNKENOUTER, BF_RECT); // Draw custom text CFont *pOldFont = (CFont*) pDC->SelectObject(&m_Font); pDC->SetBkMode(TRANSPARENT); pDC->DrawText(m_strDefaultText, TextButtonRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); pDC->SelectObject(pOldFont); return; } CRect rect; if (!GetCellRect(nIndex, rect)) return; // Select and realize the palette CPalette* pOldPalette = NULL; if (pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) { pOldPalette = pDC->SelectPalette(&m_Palette, FALSE); pDC->RealizePalette(); } // fill background if (m_nChosenColourSel == nIndex && m_nCurrentSel != nIndex) pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DHILIGHT)); else pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DFACE)); // Draw button if (m_nCurrentSel == nIndex) pDC->DrawEdge(rect, BDR_RAISEDINNER, BF_RECT); else if (m_nChosenColourSel == nIndex) pDC->DrawEdge(rect, BDR_SUNKENOUTER, BF_RECT); CBrush brush(PALETTERGB(GetRValue(GetColour(nIndex)), GetGValue(GetColour(nIndex)), GetBValue(GetColour(nIndex)) )); CPen pen; pen.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW)); CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush); CPen* pOldPen = (CPen*) pDC->SelectObject(&pen); // Draw the cell colour rect.DeflateRect(m_nMargin+1, m_nMargin+1); pDC->Rectangle(rect); // restore DC and cleanup pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldPen); brush.DeleteObject(); pen.DeleteObject(); if (pOldPalette && pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) pDC->SelectPalette(pOldPalette, FALSE); }
void ProgressWindow::draw(int count) { HDC hDC = GetDC(hWnd); int prgBase = getProgress(); int prg = min((prgBase * p_width)/1000, p_width-1); int center = int(prg*((cos(count*0.1)+1)*0.8) / 2); DWORD c=GetSysColor(COLOR_ACTIVECAPTION); double red=GetRValue(c); double green=GetGValue(c); double blue=GetBValue(c); double blue1=min(255., blue*1.4); double green1=min(255., green*1.4); double red1=min(255., red*1.4); int blueD=int(blue/2); int redD=int(red/2); int greenD=int(green/2); SelectObject(hDC, GetStockObject(DC_PEN)); SelectObject(hDC, GetStockObject(NULL_BRUSH)); SetDCPenColor(hDC, RGB(redD,greenD,blueD)); Rectangle(hDC, 0, 0, p_width, p_height-1); SelectObject(hDC, GetStockObject(DC_BRUSH)); SelectObject(hDC, GetStockObject(NULL_PEN)); SetDCBrushColor(hDC, GetSysColor(COLOR_3DHIGHLIGHT)); Rectangle(hDC, prg, 1, p_width-1, p_height-2); TRIVERTEX vert[4]; vert [0] .x = 1; vert [0] .y = 1; vert [0] .Red = 0xff00&DWORD(red*256); vert [0] .Green = 0xff00&DWORD(green*256); vert [0] .Blue = 0xff00&DWORD(blue*256); vert [0] .Alpha = 0x0000; vert [1] .x = center; vert [1] .y = p_height-2; vert [1] .Red = 0xff00&DWORD(red1*256); vert [1] .Green = 0xff00&DWORD(green1*256); vert [1] .Blue = 0xff00&DWORD(blue1*256); vert [1] .Alpha = 0x0000; vert [2] .x = center; vert [2] .y = 1; vert [2] .Red = 0xff00&DWORD(red1*256); vert [2] .Green = 0xff00&DWORD(green1*256); vert [2] .Blue = 0xff00&DWORD(blue1*256); vert [2] .Alpha = 0x0000; vert [3] .x = prg; vert [3] .y = p_height-2; vert [3] .Red = 0xff00&DWORD(red*256); vert [3] .Green = 0xff00&DWORD(green*256); vert [3] .Blue = 0xff00&DWORD(blue*256); vert [3] .Alpha = 0x0000; GRADIENT_RECT gr[2]; gr[0].UpperLeft=0; gr[0].LowerRight=1; gr[1].UpperLeft=2; gr[1].LowerRight=3; GradientFill(hDC,vert, 4, gr, 2, GRADIENT_FILL_RECT_H); ReleaseDC(hWnd, hDC); }
bool CRTFParser::ParseBlock (const STextFormatDesc &InitFormat, CString *retsError) // ParseBlock // // Parses a block and leaves the input position at the first character after // the end of the block. { // Better be the beginning of a block if (*m_pInput++ != '{') { *retsError = ERR_BRACE_EXPECTED; return false; } // Keep track of the current format and text STextFormatDesc Format = InitFormat; // Keep looping until we hit the end of the block bool bBlockStart = true; while (*m_pInput != '}') { // End of stream if (*m_pInput == '\0') { *retsError = ERR_UNEXPECTED_EOS; return false; } // If an escape character then parse an op code else if (*m_pInput == '\\' || *m_pInput == '/') { m_pInput++; // If this is the beginning of the block then parse some codes if (bBlockStart) { CString sCode; CString sParam; if (!ParseCode(&sCode, &sParam, retsError)) return false; // Interpret code if (strEquals(sCode, CODE_BOLD)) Format.bBold = true; else if (strEquals(sCode, CODE_COLOR)) { DWORD dwRGB = (DWORD)strToInt(sParam, 0); Format.wColor = CG16bitImage::RGBValue(GetRValue(dwRGB), GetGValue(dwRGB), GetBValue(dwRGB)); } else if (strEquals(sCode, CODE_TYPEFACE)) Format.sTypeface = sParam; else if (strEquals(sCode, CODE_ITALIC)) Format.bItalic = true; else if (strEquals(sCode, CODE_RTF)) ; else { *retsError = strPatternSubst(ERR_UNKNOWN_CODE, sCode); return false; } } // Parse some escape characters else { switch (*m_pInput) { case '{': case '}': case '\\': case '/': AddSpan(CString(m_pInput, 1), Format); break; case 'n': AddSpan(NULL_STR, Format, true); break; default: { *retsError = strPatternSubst(ERR_UNKNOWN_CODE, CString(m_pInput, 1)); return false; } } m_pInput++; } } // Special characters else if (*m_pInput == '\n') { AddSpan(NULL_STR, Format, true); m_pInput++; } // If we have an open brace, then we recurse else if (*m_pInput == '{') { if (!ParseBlock(Format, retsError)) return false; bBlockStart = false; } // Otherwise, this is some text else { char *pStart = m_pInput; // Find the end of the span while (*m_pInput != '\\' && *m_pInput != '/' && *m_pInput != '{' && *m_pInput != '}' && *m_pInput != '\n' && *m_pInput != '\0') m_pInput++; // Add the text as a span if (pStart != m_pInput) AddSpan(CString(pStart, (int)(m_pInput - pStart)), Format); bBlockStart = false; } } m_pInput++; // Done return true; }
void HighlightHexColor(const HWND h_scintilla, const int start_position, const int end_position){ int match_count = 0; int search_start = start_position; while (match_count < MAX_COLOR_CODE_HIGHTLIGHT && search_start < end_position) { Sci_TextToFind tf; tf.chrg.cpMin = search_start; tf.chrg.cpMax = end_position+1; tf.lpstrText = "#"; int target_pos = ::SendMessage(h_scintilla, SCI_FINDTEXT, 0, (LPARAM)&tf); // not found if(target_pos == -1) { break; } // read in the possible color code sequence char hex_color[8]; int index = 0; for(; index<6; index++){ char t = (char)::SendMessage(h_scintilla, SCI_GETCHARAT, target_pos+1 + index, 0); if( t=='\0' ) break; if( strchr("0123456789abcdefABCDEF", t) == NULL ) break; hex_color[index] = t; } hex_color[index] = '\0'; // align the positions int target_length = strlen(hex_color); int target_start = target_pos; int target_end = target_pos + target_length + 1; // don't forget the '#' // invalid hex color length if (target_length !=3 && target_length != 6) { search_start = target_end; // move on continue; } // pad 3 char hex string if (target_length == 3) { hex_color[6] = '\0'; hex_color[5] = hex_color[2]; hex_color[4] = hex_color[2]; hex_color[3] = hex_color[1]; hex_color[2] = hex_color[1]; hex_color[1] = hex_color[0]; hex_color[0] = hex_color[0]; } // parse hex color string to COLORREF COLORREF color = strtol(hex_color, NULL, 16); color = RGB(GetBValue(color),GetGValue(color),GetRValue(color)); bool can_proceed = HighlightCode(h_scintilla, color, target_start, target_end); // exceeded the indicator count if(!can_proceed) break; search_start = target_end; // move on match_count++; } }
COLORREF CColorListCtrl::InvertColor(COLORREF cf) { return RGB(abs(220-GetRValue(cf)),abs(220-GetGValue(cf)),abs(220-GetBValue(cf))); }
BOOL CRasterPropPage::OnApply() { if(!m_wndPropList) return FALSE; CBCGPProp* pProp = m_wndPropList.GetProperty(0); int nCount = pProp->GetSubItemsCount(); std::string str = _T("波段组合"); CBCGPProp* pSubProp = NULL; for (int i=0; i<nCount; i++) { pSubProp = pProp->GetSubItem(i); if (0 == strcmp(str.c_str(),pSubProp->GetName())) { break; } } // Carto::CRasterLayer* pRasLayer = dynamic_cast<Carto::CRasterLayer*>(m_player); Carto::IRasterRenderPtr pRender =pRasLayer->GetRender(); Carto::RASTER_RENDER_TYPE rendertype =pRender->GetRenderType(); if(rendertype != Carto::RASTER_RGBRENDER) return FALSE; Carto::CRasterRGBRender* pRGBRender = dynamic_cast<Carto::CRasterRGBRender*>(pRasLayer->GetRender().get()); if (pRGBRender->GetRGBMode()) { pRGBRender->SetRedBandIndex(long(pSubProp->GetSubItem(0)->GetValue())); pRGBRender->SetGreenBandIndex(long(pSubProp->GetSubItem(1)->GetValue())); pRGBRender->SetBlueBandIndex(long(pSubProp->GetSubItem(2)->GetValue())); } std::string strColormap = _T("调色板"); pSubProp = NULL; bool bfind=false; for (int i=0; i<nCount; i++) { pSubProp = pProp->GetSubItem(i); if (0 == strcmp(strColormap.c_str(),pSubProp->GetName())) { bfind=true; break; } } if (!bfind) return TRUE; Geodatabase::IRasterDatasetPtr pRaster = m_player->GetDataObject(); BYTE byRed[256]; BYTE byGreen[256]; BYTE byBlue[256]; for (int i=0; i<256; i++) { long lValue = pSubProp->GetSubItem(i)->GetValue(); byRed[i] = GetRValue(lValue); byGreen[i] = GetGValue(lValue); byBlue[i] = GetBValue(lValue); } pRaster->SetChannelPalette(1,byRed,byGreen,byBlue); return TRUE; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Function Header void CStaticCounter::Draw(CStaticDC* pDC, DWORD dwChar, int nCol) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// { COLORREF crNotchColor = m_crForeground; if (dwChar == STCOUNTERALL && !m_bSpecifiedFadeColour) // The colour used will be a dim version of normal foreground { int r = GetRValue(m_crForeground)/3; int g = GetGValue(m_crForeground)/3; int b = GetBValue(m_crForeground)/3; crNotchColor = RGB(r,g,b); } else if (dwChar == STCOUNTERALL && m_bSpecifiedFadeColour) crNotchColor = m_crDimForeground; // Create the Pen accordingly CPen pen(PS_SOLID | PS_ENDCAP_ROUND, m_nNotchWidth, crNotchColor); CPen* pOldPen=pDC->SelectObject(&pen); if ( (dwChar & NOTCH1) || dwChar == STCOUNTERALL) { // should I draw the first bar in the display? pDC->MoveTo( nCol + m_nMargin*2, m_nMargin ); pDC->LineTo( nCol + m_nNotchLength, m_nMargin ); } if ( dwChar & NOTCH2 || dwChar == STCOUNTERALL) { // should I draw the 2nd bar in the display? [minus sign] pDC->MoveTo(nCol + m_nNotchLength + m_nMargin, m_nMargin*2); pDC->LineTo(nCol + m_nNotchLength + m_nMargin, m_nNotchLength + (m_nMargin*2) ); } if ( dwChar & NOTCH3 || dwChar == STCOUNTERALL) { // should I draw the 3rd bar in the display? pDC->MoveTo(nCol + m_nNotchLength + m_nMargin, m_nNotchLength + (m_nMargin*4) ); pDC->LineTo(nCol + m_nNotchLength + m_nMargin, m_nNotchLength*2 + (m_nMargin*3) ); } if ( dwChar & NOTCH4 || dwChar == STCOUNTERALL) { // should I draw the 4th bar in the display? pDC->MoveTo( nCol + m_nMargin*2, m_nNotchLength*2 + (m_nMargin*4) ); pDC->LineTo( nCol + m_nNotchLength, m_nNotchLength*2 + (m_nMargin*4) ); } if ( dwChar & NOTCH5 || dwChar == STCOUNTERALL) { // should I draw the 5th bar in the display? pDC->MoveTo(nCol + m_nMargin, m_nNotchLength + (m_nMargin*4) ); pDC->LineTo(nCol + m_nMargin, m_nNotchLength*2 + (m_nMargin*3) ); } if ( dwChar & NOTCH6 || dwChar == STCOUNTERALL) { // should I draw the 6th bar in the display? pDC->MoveTo(nCol + m_nMargin, m_nMargin*2); pDC->LineTo(nCol + m_nMargin, m_nNotchLength + (m_nMargin*2) ); } if ( dwChar & NOTCH7 || dwChar == STCOUNTERALL) { // should I draw the 7th bar in the display? pDC->MoveTo(nCol + m_nMargin*2, m_nNotchLength + (m_nMargin*3) ); pDC->LineTo(nCol + m_nMargin + m_nNotchLength - m_nMargin, m_nNotchLength + (m_nMargin*3) ); } if ( dwChar == STCOUNTER11 ) { // should I draw the point? pDC->MoveTo( nCol + m_nMargin*2, m_nNotchLength*2 + (m_nMargin*4) ); pDC->LineTo( nCol + (m_nNotchLength/2), m_nNotchLength*2 + (m_nMargin*4) ); } if ( dwChar == STCOUNTER12 ) { // should I draw the colon? // Upper dot: pDC->MoveTo( nCol + m_nMargin*2+(m_nMargin*2), m_nNotchLength ); pDC->LineTo( nCol + (m_nNotchLength/2)+(m_nMargin*2), m_nNotchLength ); // Lower dot: pDC->MoveTo( nCol + m_nMargin*2+(m_nMargin*2), m_nNotchLength*2 + (m_nMargin) ); pDC->LineTo( nCol + (m_nNotchLength/2)+(m_nMargin*2), m_nNotchLength*2 + (m_nMargin) ); } pDC->SelectObject(pOldPen); }
void CPrefsStatic::MakeCaptionBitmap() { if (m_bm.m_hObject) return; // already have bitmap; return CRect cr; GetClientRect(cr); int w = cr.Width(); int h = cr.Height(); // Create bitmap same size as caption area and select into memory DC // CWindowDC dcWin(this); CDC dc; dc.CreateCompatibleDC(&dcWin); m_bm.DeleteObject(); m_bm.CreateCompatibleBitmap(&dcWin, w, h); CBitmap* pOldBitmap = dc.SelectObject(&m_bm); COLORREF clrBG = ::g_PaintManager->GetColor(COLOR_ACTIVECAPTION); // background color int r = GetRValue(clrBG); // red.. int g = GetGValue(clrBG); // ..green int b = GetBValue(clrBG); // ..blue color vals int x = 8*cr.right/8; // start 5/6 of the way right int w1 = x - cr.left; // width of area to shade int NCOLORSHADES = 1; // this many shades in gradient int xDelta= max( w / NCOLORSHADES , 1); // width of one shade band PaintRect(dc, x, 0, cr.right-x, h, clrBG); while (x > xDelta) { // paint bands right to left x -= xDelta; // next band int wmx2 = (w1-x)*(w1-x); // w minus x squared int w2 = w1*w1; // w squared PaintRect(dc, x, 0, xDelta, h, RGB(r-(r*wmx2)/w2, g-(g*wmx2)/w2, b-(b*wmx2)/w2)); } PaintRect(dc,0,0,x,h,RGB(GetRValue(clrBG),GetGValue(clrBG),GetBValue(clrBG))); // whatever's left ==> black // draw the 'constant' text // create a font, if we need to if (m_nameFont.GetSafeHandle()==NULL) { m_nameFont.CreateFont( 18, 0, 0, 0, FW_BOLD, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, FF_MODERN, m_csFontName); } CFont * OldFont = dc.SelectObject(&m_nameFont); // restore old font dc.SelectObject(OldFont); // Restore DC dc.SelectObject(pOldBitmap); }
void CPenBrushUnit::DrawMultiPenBrush(CDC *memDC,CPoint ePoint,std::vector<temSavePoint> &MultipsPoint,MultiInfo &GetMultiInfo,DWORD mouseid) { int Red,Green,Blue; Red=GetRValue(GetMultiInfo.penColor); Green=GetGValue(GetMultiInfo.penColor); Blue=GetBValue(GetMultiInfo.penColor); Graphics mGraphics(memDC->m_hDC); mGraphics.SetSmoothingMode(SmoothingModeAntiAlias); SolidBrush brush(Color(255,Red,Green,Blue)); UINT Size=MultipsPoint.size(); CPoint sPoint=MultipsPoint[Size-1].point; if(Size==1) { if(fwidth.find(mouseid)!=fwidth.end()) fwidth.erase(mouseid); fwidth.insert(std::map<DWORD,float>::value_type(mouseid,MultipsPoint[0].preWidth)); PushStart(ePoint,mouseid); } if(Push(sPoint,ePoint,mouseid)) { RectF headRect; RectF tailRect; float width,dx,dy; PointF lfCenter,rtCenter; mGraphics.FillPolygon(&brush,pts,npts); mGraphics.DrawPolygon(&Pen(Color(255,Red,Green,Blue),0.5f),pts,npts); if(npts==4) { headRect=RectF((pts[0].X+pts[3].X)/2.0f,(pts[0].Y+pts[3].Y)/2.0f,0.0f,0.0f); tailRect=RectF((pts[1].X+pts[2].X)/2.0f,(pts[1].Y+pts[2].Y)/2.0f,0.0f,0.0f); dx=pts[3].X-pts[0].X; dy=pts[3].Y-pts[0].Y; width=sqrt(dx*dx+dy*dy)/2.0f+0.5f; headRect.Inflate(width,width); dx=pts[2].X-pts[1].X; dy=pts[2].Y-pts[1].Y; width=sqrt(dx*dx+dy*dy)/2.0f+0.5f; tailRect.Inflate(width,width); } else { headRect=RectF((pts[0].X+pts[9].X)/2.0f,(pts[0].Y+pts[9].Y)/2.0f,0.0f,0.0f); tailRect=RectF((pts[4].X+pts[5].X)/2.0f,(pts[4].Y+pts[5].Y)/2.0f,0.0f,0.0f); dx=pts[9].X-pts[0].X; dy=pts[9].Y-pts[0].Y; width=sqrt(dx*dx+dy*dy)/2.0f+0.5f; headRect.Inflate(width,width); dx=pts[5].X-pts[4].X; dy=pts[5].Y-pts[4].Y; width=sqrt(dx*dx+dy*dy)/2.0f+0.5f; tailRect.Inflate(width,width); } brush.SetColor(Color(255,Red,Green,Blue)); mGraphics.FillEllipse(&brush,headRect); mGraphics.FillEllipse(&brush,tailRect); temSavePoint addPoint; addPoint.point=ePoint; addPoint.alpha=MultipsPoint[Size-1].alpha; addPoint.preWidth=MultipsPoint[Size-1].preWidth; MultipsPoint.push_back(addPoint); } }
void MaterialPreviewPropView::OnPropertyChangeNotification( NMHDR *nmhdr, LRESULT *lresult ) { idVec3 testColor; int lightId = 0; COLORREF color; NMPROPTREE *nmProp; CPropTreeItem *item; CPropTreeItem *parent; nmProp = (NMPROPTREE *)nmhdr; item = nmProp->pItem; // Determine which light this item modifies parent = item->GetParent(); if ( parent ) { lightId = parent->GetCtrlID(); } idStr itemLabel = item->GetLabelText(); if ( itemLabel == "Model Type" ) { materialPreview->OnModelChange( item->GetItemValue() ); } else if ( itemLabel == "Custom Model" ) { materialPreview->OnCustomModelChange( (const char *)item->GetItemValue() ); } else if ( itemLabel == "Show Lights" ) { materialPreview->OnShowLightsChange( item->GetItemValue() ? true : false ); } else if ( itemLabel == "Shader" ) { CPropTreeItemCombo *combo = (CPropTreeItemCombo *)item; CString materialName; combo->GetLBText( combo->GetCurSel(), materialName ); materialPreview->OnLightShaderChange( lightId, materialName.GetBuffer() ); } else if ( itemLabel == "Radius" ) { materialPreview->OnLightRadiusChange( lightId, atof( (char *)item->GetItemValue() ) ); } else if ( itemLabel == "Color" ) { color = item->GetItemValue(); testColor.x = (float)GetRValue( color ) * (float)( 1.f/255.f ); testColor.y = (float)GetGValue( color ) * (float)( 1.f/255.f ); testColor.z = (float)GetBValue( color ) * (float)( 1.f/255.f ); materialPreview->OnLightColorChange( lightId, testColor ); } else if ( itemLabel == "Move light" ) { materialPreview->OnLightAllowMoveChange( lightId, item->GetItemValue() ? true : false ); } else if ( itemLabel.Left(4) == "parm" ) { int index; itemLabel.Strip( "parm" ); index = atoi( itemLabel.c_str() ); materialPreview->OnLocalParmChange( index, atof( (char *)item->GetItemValue() ) ); } else if ( itemLabel.Left(6) == "global" ) { int index; itemLabel.Strip( "global" ); index = atoi( itemLabel.c_str() ); materialPreview->OnGlobalParmChange( index, atof( (char *)item->GetItemValue() ) ); } }
static void DrawCoolBox (HWND hWnd, HDC hdc, PCOOLBARCTRL pdata) { COOLBARITEMDATA* tmpdata; RECT rc; int l,t; WINDOWINFO *info = (WINDOWINFO*)GetWindowInfo (hWnd); DWORD color; DWORD mainc = GetWindowElementAttr (hWnd, WE_MAINC_THREED_BODY); GetClientRect (hWnd, &rc); if (pdata->BackBmp) { FillBoxWithBitmap (hdc, 0, 0, rc.right, rc.bottom, pdata->BackBmp); } color = info->we_rdr->calc_3dbox_color (mainc, LFRDR_3DBOX_COLOR_DARKEST); SetPenColor (hdc, RGBA2Pixel (hdc, GetRValue (color), GetGValue (color), GetBValue (color), GetAValue (color))); MoveTo (hdc, 0, 0); LineTo (hdc, rc.right, 0); MoveTo (hdc, 0, rc.bottom - 2); LineTo (hdc, rc.right, rc.bottom - 2); color = info->we_rdr->calc_3dbox_color (mainc, LFRDR_3DBOX_COLOR_LIGHTEST); SetPenColor (hdc, RGBA2Pixel (hdc, GetRValue (color), GetGValue (color), GetBValue (color), GetAValue (color))); MoveTo (hdc, 0, 1); LineTo (hdc, rc.right, 1); MoveTo (hdc, 0, rc.bottom - 1); LineTo (hdc, rc.right, rc.bottom - 1); tmpdata = pdata->head; while (tmpdata) { l = tmpdata->RcTitle.left; t = tmpdata->RcTitle.top; switch (tmpdata->ItemType) { case TYPE_BARITEM: { WINDOWINFO *info = (WINDOWINFO*)GetWindowInfo (hWnd); RECT rcTmp; rcTmp.left = l + 2; rcTmp.top = 4; rcTmp.right = l + 4; rcTmp.bottom = rc.bottom - 4; info->we_rdr->draw_3dbox (hdc, &rcTmp, GetWindowElementAttr (hWnd, WE_MAINC_THREED_BODY), LFRDR_BTN_STATUS_PRESSED); } break; case TYPE_BMPITEM: FillBoxWithBitmap (hdc, l + 2, t + 2, pdata->ItemWidth, pdata->ItemHeight, tmpdata->Bmp); break; case TYPE_TEXTITEM: { SIZE size; int h; WINDOWINFO *info; RECT rc; if (tmpdata->Caption == NULL || tmpdata->Caption [0] == '\0') break; GetTextExtent (hdc, tmpdata->Caption, -1, &size); h = (pdata->ItemHeight - size.cy) / 2; SetBkMode (hdc, BM_TRANSPARENT); if (tmpdata->Disable) { info = (WINDOWINFO*)GetWindowInfo (hWnd); rc.left = l + 2; rc.top = t + h + 2; rc.right = rc.left + size.cx; rc.bottom = rc.top + size.cy; info->we_rdr->disabled_text_out (hWnd, hdc, tmpdata->Caption, &rc, DT_SINGLELINE); } else { SetBkColor (hdc, GetWindowBkColor (hWnd)); SetTextColor (hdc, PIXEL_black); TextOut (hdc, l+2, t + h + 2, tmpdata->Caption); } break; } default: break; } tmpdata = tmpdata->next; } if ((tmpdata = GetCurSel (pdata)) == NULL) return; draw_hilight_box (hWnd, hdc, tmpdata); }
// // Add a splash of colour // COLORREF _CombineBasedOnType(int iTabType, COLORREF clrSource) { RGBQUAD source = { 0 }; source.rgbBlue = GetBValue(clrSource); source.rgbGreen = GetGValue(clrSource); source.rgbRed = GetRValue(clrSource); COLORREF clr; switch (iTabType) { case TAB_PIC: // green { RGBQUAD tint = { 15, 255, 165 }; clr = RGB_TO_COLORREF(_Combine(tint, source)); } break; case TAB_TEXT: // cyan { RGBQUAD tint = { 255, 255, 155 }; clr = RGB_TO_COLORREF(_Combine(tint, source)); } break; case TAB_SOUND: // orange? { RGBQUAD tint = { 255, 0, 0 }; clr = RGB_TO_COLORREF(_Combine(tint, source)); } break; case TAB_VIEW: // blue { RGBQUAD tint = { 239, 132, 33 }; clr = RGB_TO_COLORREF(_Combine(tint, source)); } break; case TAB_FONT: // yellow { RGBQUAD tint = { 0, 255, 255}; clr = RGB_TO_COLORREF(_Combine(tint, source)); } break; case TAB_VOCAB: // flesh { RGBQUAD tint = { 162, 206, 255 }; clr = RGB_TO_COLORREF(_Combine(tint, source)); } break; case TAB_SCRIPT: // red { RGBQUAD tint = { 25, 25, 255 }; clr = RGB_TO_COLORREF(_Combine(tint, source)); } break; case TAB_CURSOR: // pink { RGBQUAD tint = { 172, 172, 255 }; clr = RGB_TO_COLORREF(_Combine(tint, source)); } break; case TAB_GAME: // grey { RGBQUAD tint = { 128, 128, 128 }; clr = RGB_TO_COLORREF(_Combine(tint, source)); } break; default: clr = clrSource; break; } return clr; }
static inline QRgb colorref2qrgb(COLORREF col) { return qRgb(GetRValue(col),GetGValue(col),GetBValue(col)); }
void DLrtfhtml::addProToArr(CStringArray &arr,CArray<rtfProperty,rtfProperty&> &proArr) { CString temp; CString protemp; int count=arr.GetCount(); int j=0; rtfProperty pro;//property struct for(int i=0;i<arr.GetCount();i++) { temp=arr.GetAt(i); memset(&pro,0,sizeof(rtfProperty)); if(temp.Compare(_T("\\b"))==0) { if(proIsExist(temp,proArr)==-1) { pro.data=0; lstrcpy(pro.rtfType,temp.GetBuffer()); temp.ReleaseBuffer(); lstrcpy(pro.htmlTagB,_T("<b>")); lstrcpy(pro.htmlTagE,_T("</b>")); proArr.Add(pro); } } else if(temp.Compare(_T("\\b0"))==0) { int id=proIsExist(temp,proArr); if(id!=-1) proArr.RemoveAt(id); } else if(temp.Compare(_T("\\i"))==0) { if(proIsExist(temp,proArr)==-1) { pro.data=0; lstrcpy(pro.rtfType,temp.GetBuffer()); temp.ReleaseBuffer(); lstrcpy(pro.htmlTagB,_T("<i>")); lstrcpy(pro.htmlTagE,_T("</i>")); proArr.Add(pro); } } else if(temp.Compare(_T("\\i0"))==0) { int id=proIsExist(temp,proArr); if(id!=-1) proArr.RemoveAt(id); } else if(temp.Compare(_T("\\ul"))==0) { if(proIsExist(temp,proArr)==-1) { pro.data=0; lstrcpy(pro.rtfType,temp.GetBuffer()); temp.ReleaseBuffer(); lstrcpy(pro.htmlTagB,_T("<u>")); lstrcpy(pro.htmlTagE,_T("</u>")); proArr.Add(pro); } } else if(temp.Compare(_T("\\ulnono"))==0) { int id=proIsExist(temp,proArr); if(id!=-1) proArr.RemoveAt(id); } else if(temp.Compare(_T("\\strike"))==0) { if(proIsExist(temp,proArr)==-1) { pro.data=0; lstrcpy(pro.rtfType,temp.GetBuffer()); temp.ReleaseBuffer(); lstrcpy(pro.htmlTagB,_T("<strike>")); lstrcpy(pro.htmlTagE,_T("</strike>")); proArr.Add(pro); } } else if(temp.Compare(_T("\\strike0"))==0) { int id=proIsExist(temp,proArr); if(id!=-1); proArr.RemoveAt(id); } else if(temp.Find(_T("\\fs"))>=0) { int num=strGetNumber(temp); if(num<=0) num=24; int id=proIsExist(_T("\\fs"),proArr); if(id==-1) { pro.data=num; lstrcpy(pro.rtfType,_T("\\fs")); //temp.ReleaseBuffer(); protemp.Format(_T("font-size:%d;"),num); lstrcpy(pro.htmlTagB,protemp.GetBuffer()); protemp.ReleaseBuffer(); pro.single=TRUE; proArr.Add(pro); } else{ proArr.GetAt(id).data=num; } } else if(temp.Find(_T("\\cf"))>=0) //颜色 { int num=strGetNumber(temp); if(num==-1) continue; int id=proIsExist(_T("\\cf"),proArr); if(num>m_cg.GetCount()) protemp.Format(_T("color:#%FFFFFF")); else if(num>=1) protemp.Format(_T("color:#%02x%02x%02x;"),GetRValue(m_cg.GetAt(num-1)),GetGValue(m_cg.GetAt(num-1)),GetBValue(m_cg.GetAt(num-1))); if(num==0 && id!=-1) { proArr.RemoveAt(id); //protemp.Format(_T("color:#%FF#FF#FF")); } else if(num>=1 && id!=-1) //修改 { proArr.GetAt(id).data=num; lstrcpy(proArr.GetAt(id).htmlTagB,protemp.GetBuffer()); protemp.ReleaseBuffer(); } else if(id==-1) //添加 { pro.data=num; lstrcpy(pro.rtfType,_T("\\cf")); //temp.ReleaseBuffer(); lstrcpy(pro.htmlTagB,protemp.GetBuffer()); protemp.ReleaseBuffer(); pro.single=TRUE; proArr.Add(pro); } }else if(temp.Find(_T("\\highlight"))>=0) //颜色 { int num=strGetNumber(temp); if(num==-1) continue; int id=proIsExist(_T("\\highlight"),proArr); if(num>m_cg.GetCount()) protemp.Format(_T("color:#%FFFFFF")); else if(num>=1) protemp.Format(_T("color:#%02x%02x%02x;"),GetRValue(m_cg.GetAt(num-1)),GetGValue(m_cg.GetAt(num-1)),GetBValue(m_cg.GetAt(num-1))); if(num==0 && id!=-1) { proArr.RemoveAt(id); }else if(num>=1 && id!=-1) //修改 { proArr.GetAt(id).data=num; lstrcpy(proArr.GetAt(id).htmlTagB,protemp.GetBuffer()); protemp.ReleaseBuffer(); }else if(id==-1) //添加 { pro.data=num; lstrcpy(pro.rtfType,_T("\\highlight")); lstrcpy(pro.htmlTagB,protemp.GetBuffer()); protemp.ReleaseBuffer(); pro.single=TRUE; proArr.Add(pro); } } } }
void CCoolBar::NcPaintGripper(CDC* pDC, CRect rcClient) { if (!HasGripper()) return; #ifndef _SCB_STYLE_FLAT CRect gripper = rcClient; CRect rcbtn = m_biHide.GetRect(); BOOL bHorz = IsHorzDocked(); gripper.DeflateRect(1, 1); if (bHorz) { // gripper at left gripper.left -= m_cyGripper; gripper.right = gripper.left + 3; gripper.top = rcbtn.bottom + 3; } else { // gripper at top gripper.top -= m_cyGripper; gripper.bottom = gripper.top + 3; gripper.right = rcbtn.left - 3; } pDC->Draw3dRect(gripper, ::GetSysColor(COLOR_BTNHIGHLIGHT), ::GetSysColor(COLOR_BTNSHADOW)); gripper.OffsetRect(bHorz ? 3 : 0, bHorz ? 0 : 3); pDC->Draw3dRect(gripper, ::GetSysColor(COLOR_BTNHIGHLIGHT), ::GetSysColor(COLOR_BTNSHADOW)); m_biHide.Paint(pDC); #else // compute the caption rectangle BOOL bHorz = IsHorzDocked(); CRect rcGrip = rcClient; CRect rcBtn = m_biHide.GetRect(); if (bHorz) { // right side gripper rcGrip.left -= m_cyGripper + 1; rcGrip.right = rcGrip.left + 11; rcGrip.top = rcBtn.bottom + 3; } else { // gripper at top rcGrip.top -= m_cyGripper + 1; rcGrip.bottom = rcGrip.top + 11; rcGrip.right = rcBtn.left - 3; } rcGrip.InflateRect(bHorz ? 1 : 0, bHorz ? 0 : 1); // draw the caption background //CBrush br; COLORREF clrCptn = m_bActive ? ::GetSysColor(COLOR_ACTIVECAPTION) : ::GetSysColor(COLOR_INACTIVECAPTION); // query gradient info (usually TRUE for Win98/Win2k) BOOL bGradient = FALSE; ::SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &bGradient, 0); if (!bGradient) pDC->FillSolidRect(&rcGrip, clrCptn); // solid color else { // gradient from left to right or from bottom to top // get second gradient color (the right end) COLORREF clrCptnRight = m_bActive ? ::GetSysColor(COLOR_GRADIENTACTIVECAPTION) : ::GetSysColor(COLOR_GRADIENTINACTIVECAPTION); // this will make 2^6 = 64 fountain steps int nShift = 6; int nSteps = 1 << nShift; for (int i = 0; i < nSteps; i++) { // do a little alpha blending int nR = (GetRValue(clrCptn) * (nSteps - i) + GetRValue(clrCptnRight) * i) >> nShift; int nG = (GetGValue(clrCptn) * (nSteps - i) + GetGValue(clrCptnRight) * i) >> nShift; int nB = (GetBValue(clrCptn) * (nSteps - i) + GetBValue(clrCptnRight) * i) >> nShift; COLORREF cr = RGB(nR, nG, nB); // then paint with the resulting color CRect r2 = rcGrip; if (bHorz) { r2.bottom = rcGrip.bottom - ((i * rcGrip.Height()) >> nShift); r2.top = rcGrip.bottom - (((i + 1) * rcGrip.Height()) >> nShift); if (r2.Height() > 0) pDC->FillSolidRect(r2, cr); } else { r2.left = rcGrip.left + ((i * rcGrip.Width()) >> nShift); r2.right = rcGrip.left + (((i + 1) * rcGrip.Width()) >> nShift); if (r2.Width() > 0) pDC->FillSolidRect(r2, cr); } } }
BOOL ImageFilter_Glow::Control(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam) { switch (message) { case WM_INITDIALOG: CenterWindow(hWnd,GetParent(hWnd)); SetCursor(LoadCursor(NULL,IDC_ARROW)); CheckRadioButton( hWnd, IDC_MTLID_BUTT, IDC_NODEID_BUTT, data.type ); CheckRadioButton( hWnd, IDC_MTLCOLOR_BUTT, IDC_USERCOLOR_BUTT, data.colorsrc ); colorSwatch = GetIColorSwatch( GetDlgItem(hWnd, IDC_COLOR_SWATCH), RGB(data.color.r>>8,data.color.g>>8,data.color.b>>8), GetString(IDS_DB_GLOW_COLOR)); mtlspin = GetISpinner(GetDlgItem(hWnd, IDC_MTLID_SPIN)); mtlspin->LinkToEdit( GetDlgItem(hWnd,IDC_MTLID_EDIT), EDITTYPE_INT ); mtlspin->SetLimits( 0,15, FALSE ); mtlspin->SetValue(data.mtl,FALSE); nodspin = GetISpinner(GetDlgItem(hWnd, IDC_NODEID_SPIN)); nodspin->LinkToEdit( GetDlgItem(hWnd,IDC_NODEID_EDIT), EDITTYPE_INT ); nodspin->SetLimits( 1,65535, FALSE ); nodspin->SetValue(data.node,FALSE); sizespin = GetISpinner(GetDlgItem(hWnd, IDC_SIZE_SPIN)); sizespin->LinkToEdit( GetDlgItem(hWnd,IDC_SIZE_EDIT), EDITTYPE_INT ); sizespin->SetLimits( 1,100, FALSE ); sizespin->SetValue(data.size,FALSE); HandleInputs(hWnd); return 1; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_MTLID_BUTT: case IDC_NODEID_BUTT: case IDC_MTLCOLOR_BUTT: case IDC_USERCOLOR_BUTT: HandleInputs(hWnd); break; case IDOK: data.type= (IsDlgButtonChecked(hWnd,IDC_MTLID_BUTT) ? IDC_MTLID_BUTT : IDC_NODEID_BUTT); data.mtl= mtlspin->GetIVal(); data.node= nodspin->GetIVal(); data.size= sizespin->GetIVal(); data.colorsrc= (IsDlgButtonChecked(hWnd, IDC_MTLCOLOR_BUTT) ? IDC_MTLCOLOR_BUTT : IDC_USERCOLOR_BUTT); colorref = colorSwatch->GetColor(); data.color.r = GetRValue(colorref)<<8|0xFF; data.color.g = GetGValue(colorref)<<8|0xFF; data.color.b = GetBValue(colorref)<<8|0xFF; EndDialog(hWnd,1); break; case IDCANCEL: EndDialog(hWnd,0); break; } return 1; case WM_DESTROY: if (mtlspin) { ReleaseISpinner(mtlspin); mtlspin = NULL; } if (nodspin) { ReleaseISpinner(nodspin); nodspin = NULL; } if (sizespin) { ReleaseISpinner(sizespin); sizespin = NULL; } if (colorSwatch) { ReleaseIColorSwatch(colorSwatch); colorSwatch = NULL; } break; } return 0; }
HBITMAP CDlgCarveRilievo::CarveOrRilievo(COLORREF* pco,BITMAP bm,BITMAPINFOHEADER RGBBITSBITMAPINFO) { HBITMAP bmp; int i,j; int nWidth = bm.bmWidth; int nHeight = bm.bmHeight; int r[2],g[2],b[2]; int r0,g0,b0; COLORREF *pcol=new COLORREF[bm.bmHeight*bm.bmWidth]; for(int k=0; k<bm.bmHeight*bm.bmWidth; k++) { pcol[k]=pco[k]; } switch(m_laplas) { case 1: { for(i=0; i<nWidth-1; i++) { for(j=0; j<nHeight-1; j++) { r[0]=GetRValue(pcol[(i)+(j)*nWidth]); g[0]=GetGValue(pcol[(i)+(j)*nWidth]); b[0]=GetBValue(pcol[(i)+(j)*nWidth]); r[1]=GetRValue(pcol[(i+1)+(j+1)*nWidth]); g[1]=GetGValue(pcol[(i+1)+(j+1)*nWidth]); b[1]=GetBValue(pcol[(i+1)+(j+1)*nWidth]); r0=r[1]-r[0]+128; g0=g[1]-g[0]+128; b0=b[1]-b[0]+128; if(r0>255) r0 = 255; else if(r0<0) r0 = 0; if(g0>255) g0 = 255; else if(r0<0) g0 = 0; if(b0>255) b0 = 255; else if(r0<0) b0 = 0; pcol[i+j*nWidth]=RGB(r0,g0,b0); } } break; } case 2: { for(i=nWidth-1; i>0; i--) { for(j=nHeight-1; j>0; j--) { r[0]=GetRValue(pcol[(i)+(j)*nWidth]); g[0]=GetGValue(pcol[(i)+(j)*nWidth]); b[0]=GetBValue(pcol[(i)+(j)*nWidth]); r[1]=GetRValue(pcol[(i-1)+(j-1)*nWidth]); g[1]=GetGValue(pcol[(i-1)+(j-1)*nWidth]); b[1]=GetBValue(pcol[(i-1)+(j-1)*nWidth]); r0=r[1]-r[0]+128; g0=g[1]-g[0]+128; b0=b[1]-b[0]+128; if(r0>255) r0 = 255; else if(r0<0) r0 = 0; if(g0>255) g0 = 255; else if(r0<0) g0 = 0; if(b0>255) b0 = 255; else if(r0<0) b0 = 0; pcol[i+j*nWidth]=RGB(r0,g0,b0); } } break; } } bmp=CreateDIBitmap(m_dib.memdc,&RGBBITSBITMAPINFO, CBM_INIT,pcol,(BITMAPINFO*)&RGBBITSBITMAPINFO,DIB_RGB_COLORS); delete [] pcol; return bmp; }
void CMyDrawPictureClass::drawPicture() { this->UpdateData(); CString offsetColorStr=_T("0"); DWORD lowColor=0; this->GetDlgItem(IDC_EDIT_OffsetColor1)->GetWindowTextW(offsetColorStr); lowColor = ::wcstol(offsetColorStr,0,16); BYTE offr,offg,offb; offr = GetRValue(lowColor); offg = GetGValue(lowColor); offb = GetBValue(lowColor); CRect rctWindowSize,rctTargetPic; m_LoadSourcePic.GetWindowRect(rctWindowSize); this->GetDlgItem(IDC_STATIC_TARGET)->GetWindowRect(&rctTargetPic); //CClientDC cDC(this); HDC hScrDC,hMemDC; ////为屏幕创建设备描述表 hScrDC = CreateDC(_T("DISPLAY"), NULL, NULL, NULL); //为屏幕设备描述表创建兼容的内存设备描述表 hMemDC = CreateCompatibleDC(hScrDC); //////////////////创建一个原图大小的位图////////////////////// HBITMAP hBitmap = ::CreateCompatibleBitmap(hScrDC,m_Width,this->m_Height); HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC,hBitmap); BitBlt(hMemDC, 0, 0, m_Width,m_Height,hScrDC, rctWindowSize.left, rctWindowSize.top, CAPTUREBLT|SRCCOPY); hBitmap = (HBITMAP)SelectObject(hMemDC,hOldBitmap); // 24位图的BITMAPINFO BITMAPINFO *pBITMAPINFO = (BITMAPINFO*)malloc(sizeof(BITMAPINFOHEADER)); memset(pBITMAPINFO, 0, sizeof(BITMAPINFOHEADER)); BITMAPINFOHEADER *pInfo_Header = (BITMAPINFOHEADER *)pBITMAPINFO; pInfo_Header->biSize = sizeof(BITMAPINFOHEADER); pInfo_Header->biWidth = m_Width; pInfo_Header->biHeight = m_Height; pInfo_Header->biPlanes = 1; pInfo_Header->biBitCount = 24; pInfo_Header->biCompression = BI_RGB; // 获得数据buf DWORD bufSize = (pInfo_Header->biWidth * 3 + 3) / 4 * 4 * pInfo_Header->biHeight; BYTE * pBuffer = new BYTE[bufSize]; int aHeight=pInfo_Header->biHeight; if(::GetDIBits(hMemDC, hBitmap, 0, aHeight, pBuffer,pBITMAPINFO, DIB_RGB_COLORS) == 0) { return ; } BYTE fr,fg,fb,lr,lg,lb; fr = GetRValue(m_ForegroundColor); fg = GetGValue(m_ForegroundColor); fb = GetBValue(m_ForegroundColor); lr = GetRValue(m_LowColor); lg = GetGValue(m_LowColor); lb = GetBValue(m_LowColor); int pitch=m_Width%4; for(int i=0;i<m_Height;i++) { int realPitch=i*pitch; for(int j=0;j<m_Width;j++) { UCHAR b=pBuffer[(i*m_Width+j)*3+realPitch]; UCHAR g=pBuffer[(i*m_Width+j)*3+1+realPitch]; UCHAR r=pBuffer[(i*m_Width+j)*3+2+realPitch]; //helpcolor=RGB(r,g,b); if(abs(r-fr)<=offr&&abs(g-fg)<=offg&&abs(b-fb)<=offb) { continue; } else { pBuffer[(i*m_Width+j)*3+realPitch] = lb; pBuffer[(i*m_Width+j)*3+1+realPitch] = lg; pBuffer[(i*m_Width+j)*3+2+realPitch] = lr; } } } //保存到文件并创建位图结构 BITMAPFILEHEADER bmfh; ZeroMemory(&bmfh,sizeof(BITMAPFILEHEADER)); *((char*)&bmfh.bfType) = 'B'; *(((char*)&bmfh.bfType) + 1) = 'M'; bmfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); bmfh.bfSize = bmfh.bfOffBits + (m_Width * m_Height) * pInfo_Header->biBitCount / 8; CFile file; if(file.Open(g_CurrentExePath+_T("TCTEMP.bmp"),CFile::modeWrite|CFile::modeCreate)) { file.Write(&bmfh,sizeof(BITMAPFILEHEADER)); file.Write(&(pBITMAPINFO->bmiHeader),sizeof(BITMAPINFOHEADER)); file.Write(pBuffer,bufSize); file.Close(); } //HBITMAP hBitmapTTT = (HBITMAP)LoadImage( AfxGetInstanceHandle(),_T("TCTEMP.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); HBITMAP hBitmapTTT = (HBITMAP)LoadImage( NULL,g_CurrentExePath+_T("TCTEMP.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); if(hBitmapTTT==NULL) { //::AfxMessageBox(_T("加载位图资源失败!")); return ; } m_TargetPic.SetBitmap(hBitmapTTT); //helpBMP =(HBITMAP)SelectObject(hMemDC,m_Hbitmap); //helpBMP =(HBITMAP)SelectObject(cDC.GetSafeHdc(),m_Hbitmap); //CRect rt; //m_LoadSourcePic.GetClientRect(&rt); //m_SourcePic.GetClientRect(&rt); //int width = rt.right-rt.left; //int height = rt.bottom-rt.top; //StretchBlt(cDC.GetSafeHdc(),rt.left+8,rt.top+8,width,height,hMemDC,0,0,width,height,SRCCOPY); //::BitBlt(cDC.GetSafeHdc(),rt.left+8,rt.top+8,width,height,hMemDC,0,0,SRCCOPY); //::StretchBlt(hMemDC,rt.left+8,rt.top+8,width,height,cDC.GetSafeHdc(),0,0,width,height,SRCCOPY); //SelectObject(hMemDC,helpBMP); //m_SourcePic.SetBitmap(helpBMP); delete [] pBuffer; ::DeleteDC(hMemDC); ::DeleteDC(hScrDC); TCHAR currentPath[MAX_PATH]={0}; ::GetCurrentDirectoryW(MAX_PATH,currentPath); m_SavePicPath.Format(_T("%s\\TCTEMP.bmp"),g_CurrentExePath); return ; }
SRGB CRtoRGB( COLORREF rc ) { return SRGB( GetRValue( rc ), GetGValue( rc ), GetBValue( rc ) ); }
void CPalGroup::SetHLSA(COLORREF * crTarget, double dH, double dL, double dS, UINT8 aVal) { *crTarget = HLStoRGB(LimitHLS(dH), LimitHLS(dL), LimitHLS(dS)); *crTarget = RGB(ROUND_R(GetRValue(*crTarget)),ROUND_G(GetGValue(*crTarget)),ROUND_B(GetBValue(*crTarget))); *crTarget |= (UINT32)aVal << 24; }