BOOL COBSButton::ChangeSubPic(STATE index, LPCTSTR lpszImage) { if (m_hWnd == NULL || lpszImage == NULL) { return FALSE; } Gdiplus::Image* pImage = Gdiplus::Image::FromFile(lpszImage); if ((pImage == NULL) || (pImage->GetLastStatus() != Gdiplus::Ok)) { if (pImage) { delete pImage; pImage = NULL; } return FALSE; } int nPos = pImage->GetWidth()*index;//¼ÆËã4ÕÅͼƬÐèÒª¶àÉÙÏñËØ Gdiplus::Graphics graph(m_hdcMemory); graph.SetSmoothingMode(Gdiplus::SmoothingModeNone); graph.DrawImage(pImage, nPos, 0, pImage->GetWidth(), pImage->GetHeight()); return TRUE; }
// description: load image from file using gdi+ NaImage * NaImage::Load(const wchar_t * filename) { NaImage *pImage = new NaImage; HDC hDC = NaScreenModule::GetDesktopDC(); pImage->m_hMemoryDC = ::CreateCompatibleDC(hDC); // initialize gdi+ Gdiplus::GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); // load image Gdiplus::Image* pGdiImage = new Gdiplus::Image(filename); // converting to bitmap Gdiplus::Bitmap* pGdiBitmap = static_cast<Gdiplus::Bitmap*>(pGdiImage); pGdiBitmap->GetHBITMAP(Gdiplus::Color(0, 0, 0), &pImage->m_hBitmap); pImage->m_rc.left = 0; pImage->m_rc.top = 0; pImage->m_rc.right = pGdiImage->GetWidth(); pImage->m_rc.bottom = pGdiImage->GetHeight(); // shutdown gdi+ delete pGdiImage; Gdiplus::GdiplusShutdown(gdiplusToken); return pImage; }
/** Blend 'A''B''C''D' sign onto the image. */ static void BlendSelSign( Gdiplus::Graphics *g, const Gdiplus::RectF &render_rect, int sel ) { CFileListManager &file_manager = GetInst( CFileListManager ); Gdiplus::Image *img = CreateImgFromBuffer( file_manager.GetSelSign( sel ) ); Gdiplus::PointF render_pos = GetRandPosInULRect( img->GetWidth(), img->GetHeight(), render_rect ); img_alpha( g, img, render_pos.X, render_pos.Y, 255 ); delete img; }
BOOL LoadImage(const HINSTANCE& inst, DWORD res, const TCHAR* name, IMGINFO* img_info, const HDC* mdc) { HRSRC src = FindResource(inst, MAKEINTRESOURCE(res), name); if (src == NULL) return FALSE; DWORD len = SizeofResource(inst, src); BYTE* byte = (BYTE*)LoadResource(inst, src); if (byte == NULL) return FALSE; HGLOBAL global = GlobalAlloc(GMEM_FIXED, len); BYTE* mem = (BYTE*)GlobalLock(global); CopyMemory(mem, byte, len); IStream* stream = NULL; Gdiplus::Image* image = NULL; HRESULT hr = CreateStreamOnHGlobal(mem, FALSE, &stream); if (SUCCEEDED(hr)) { image = Gdiplus::Image::FromStream(stream); img_info->hdc = CreateCompatibleDC(*mdc); HBITMAP hbitmap = CreateCompatibleBitmap(*mdc, image->GetWidth(), image->GetHeight()); SelectObject(img_info->hdc, hbitmap); Gdiplus::Graphics graphics(img_info->hdc); Gdiplus::Rect rect; rect.X = 0.0F; rect.Y = 0.0F; rect.Width = image->GetWidth(); rect.Height = image->GetHeight(); Gdiplus::Status s = graphics.DrawImage(image, rect); DeleteObject(hbitmap); img_info->image = image; } GlobalUnlock(mem); SAFE_RELEASE(stream); FreeResource(byte); if (SUCCEEDED(hr)) return TRUE; else return FALSE; }
// ôóíêöèÿ îòêðûòèÿ ôàéëà äëÿ ïðîñìîòðà ñ âõîäÿùèì ïàðàìåòðîì - èìåíåì îòêðûâàåìîãî ãðàôè÷åñêîãî ôàéëà void BrouseFile(AnsiString FN) { float ho=0; float wo; if (FN!=""){//åñëè èìÿ ôàéëà óêàçàíî òî âûïîëíèòü äåéñòâèÿ Form1->Image1->Align=alClient;//ðàçâîðà÷èâàåì îáëàñòü ïðîñìîòðà íà âñþ äîñòóïíþ ïëîùàäü Form1->Image1->Picture->Assign(0);//î÷èùàåì îáëàñòü ïðîñìîòðà WCHAR buff[10001]; Graphics::TBitmap *Buf = new Graphics::TBitmap();//ñîçäàåì îáúåêò êëàññà TBitmap Gdiplus::Image *image =new Gdiplus::Image (FN.WideChar(buff,10000)); //ñîçäàåì îáúåêò êëàññà Gdiplus::Image è çàãðóæàåì â íåãî èçîáðàæåíèå èç âûáðàííîãî ôàéëà Buf->Width=image->GetWidth();//óêàçûâàåì øèðèíó è âûñîòó èçîáðàæåíèÿ Buf->Height=image->GetHeight(); Gdiplus::Graphics graphics(Buf->Canvas->Handle);//ïåðåäàåì óêàçàòåëü íà îáúåêò Buf graphics.DrawImage(image, 0, 0, image->GetWidth(), image->GetHeight()); //ïðîðèñîâûâàåì âçÿòîå èç ôàéëà èçîáðàæåíèå â îáúåêòå Buf Form1->Image1->Picture->Assign(Buf);//âûâîäì ïðîðèñîâàííîå èçîáðàæåíèå â îáëàñòü ïðîñìîòðà Form1->ScrollBox1->Refresh();//îáíîâëÿåì ðàçìåðíîñòü îáëàñòè ïðîñìîòðà z_min=1;//èíèöèàëèçèðåì ïåðåìåííûå ìàñøàáèðîâàíèÿ z_max=1; Form1->StatusBar1->Panels->Items[1]->Text="Ôàéë - "+Form1->FileListBox1->Items->Strings[Form1->FileListBox1->ItemIndex];//âûâîäèì ñëóæåáíóþ èíôîðìàöèþ Form1->StatusBar1->Panels->Items[2]->Text="Ðàçìåð - "+IntToStr(image->GetWidth())+"x"+IntToStr(image->GetHeight()); // B->Assign(0);//î÷èùàåì ðåçåðâíûé îáúåêò êëàññà TBitmap B->Width=Form1->Image1->Picture->Bitmap->Width;//çàäàåì ðàçìåðû ðåçåðâíîãî îáúåêòà B->Height=Form1->Image1->Picture->Bitmap->Height; B->Canvas->Draw(0,0,Form1->Image1->Picture->Bitmap);//ïðîðèñîâûâàåì èçîáðàæåíèå â ðåçåðâíîì îáúåêòå èç îáëàñòè ïðîñìîòðà //åñëè êàðòèíêà èçíà÷àëüíî áîëüøå îáëàñòè ïðîñìîòðà //òî îíà áóäåò àâòîìàòè÷åñêè óìåíüøåíà //äàëåå îïðåäåëÿåì êîýô. óìåíüøåíèÿ if ((B->Height>Form1->Image1->Height)||(B->Width>Form1->Image1->Width)) //åñëè ïàðìåòðû êàðòèíêè ïðåâûøàþò ïàðàìåòðû îáëàñòè { ho=float(Form1->Image1->Height)/float(B->Height); //âû÷èñëÿåì ñîîòíîøåíèÿ âåëè÷èí wo=float(Form1->Image1->Width)/float(B->Width); if (ho>wo) //îïåðåäåëÿåì áîëüøóþ èç âåëè÷èí, ÷òîáû èçîáðàæåíèå ïîìåñòèëîñü â îáëàñòè ïðîñìîòðà {z_min=1+ho;} //óñòàíàâëèâàåì êîýô. else {z_min=1+wo;} } delete image;//î÷èùàåì ïàìÿòü delete Buf; } }
cgSize cgGdiplusRender::GetImageSize( cgID image ) { cgSize size; Gdiplus::Image* pkImage = m_kImageStorage.Find(image); if (pkImage) { size.w = pkImage->GetWidth(); size.h = pkImage->GetHeight(); } return size; }
/** generate some small images and render them on the backgroun. */ static void GenSmallImage( int img_count, Gdiplus::Graphics *g, const Gdiplus::RectF &render_rect, int sel ) { #define RAND_ALPHA ( 100 + random( 55 ) ) if( img_count < 1 ) { return; } CFileListManager &file_manager = GetInst( CFileListManager ); // render without alpha value Gdiplus::Image *img = CreateImgFromBuffer( file_manager.GetRandSmall() ); Gdiplus::PointF render_pos = GetRandPosInULRect( img->GetWidth(), img->GetHeight(), render_rect ); Gdiplus::RectF img_rect( render_pos.X, render_pos.Y, (float)img->GetWidth(), (float)img->GetHeight() ); img_alpha( g, img, render_pos.X, render_pos.Y, img_count == 1 ? 255 : RAND_ALPHA ); delete img; // render with random alpha value and random rotation degree g->SetClip( img_rect ); for( int i = 1; i < img_count; ++ i ) { img = CreateImgFromBuffer( file_manager.GetRandSmall() ); img_rotate( g, img, render_pos.X, render_pos.Y, img->GetWidth() / 2, img->GetHeight() / 2, random( 360 ), // [0-360) RAND_ALPHA ); // [100-155) delete img; } g->ResetClip(); // blend a 'X' sign onto the picture if it's not the answer if( img_count > 1 ) { //BlendXSign( g, img_rect ); } // blend 'A''B''C''D' sign. BlendSelSign( g, img_rect, sel ); }
void SetAspectRatio(Gdiplus::Image &image, RECT &rc) { double dWidth = (rc.right - rc.left); double dHeight = (rc.bottom - rc.top); double dAspectRatio = dWidth / dHeight; double dImageWidth = image.GetWidth(); double dImageHeight = image.GetHeight(); double dImageAspectRatio = dImageWidth / dImageHeight; if (dImageAspectRatio > dAspectRatio) { double nNewHeight = (dWidth / dImageWidth*dImageHeight); double nCenteringFactor = (dHeight - nNewHeight) / 2; SetRect(&rc, 0, (int)nCenteringFactor, (int)dWidth, (int)(nNewHeight + nCenteringFactor)); } else if (dImageAspectRatio < dAspectRatio) { double nNewWidth = (dHeight / dImageHeight*dImageWidth); double nCenteringFactor = (dWidth - nNewWidth) / 2; SetRect(&rc, (int)nCenteringFactor, 0, (int)(nNewWidth + nCenteringFactor), (int)(dHeight)); } }
BOOL COBSButton::Create(LPCTSTR lpszCaption, const RECT& rect, HWND hParentWnd, \ UINT nID, LPCTSTR lpszImage,int nSubPic) { if (m_hWnd) return FALSE; if (nSubPic>4||nSubPic<=0) { return FALSE; } m_hWnd = CreateWindow(TEXT("BUTTON"), lpszCaption, \ WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_OWNERDRAW, \ rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, \ hParentWnd, (HMENU)nID, NULL, NULL); if (NULL == m_hWnd) { goto CREATE_FAIL; } SendMessage(m_hWnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE); m_OldProc = (WNDPROC)SetWindowLong(m_hWnd, GWLP_WNDPROC /*GWL_WNDPROC*/, (LONG)ButtonProc); SetWindowLong(m_hWnd, GWLP_USERDATA, (LONG)this); m_hFont = CreateFont(16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, 0, DEFAULT_CHARSET, \ OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, TEXT("Arial")); Gdiplus::Image* pImage = NULL; //¼ÓÔØͼƬ if (lpszImage != NULL) { pImage = Gdiplus::Image::FromFile(lpszImage); if ((pImage == NULL) || (pImage->GetLastStatus() != Gdiplus::Ok)) { if (pImage) { delete pImage; pImage = NULL; } return FALSE; } RECT windowRect; GetWindowRect(m_hWnd, &windowRect); SIZE sizeWindow; sizeWindow.cx = (pImage->GetWidth() / nSubPic)*4;//¼ÆËã4ÕÅͼƬÐèÒª¶àÉÙÏñËØ sizeWindow.cy = pImage->GetHeight(); HDC hDC = GetDC(m_hWnd); m_hdcMemory = CreateCompatibleDC(hDC); if (m_hdcMemory == NULL) return FALSE; m_hFourStateBitmap = CreateCompatibleBitmap(hDC, sizeWindow.cx, sizeWindow.cy); if (m_hFourStateBitmap == NULL) return FALSE; m_hOldBmp = (HBITMAP)::SelectObject(m_hdcMemory, m_hFourStateBitmap); if (m_hOldBmp == NULL) return FALSE; Gdiplus::Graphics graph(m_hdcMemory); graph.SetSmoothingMode(Gdiplus::SmoothingModeNone); graph.DrawImage(pImage, 0, 0, sizeWindow.cx, sizeWindow.cy); if (NULL == m_hFourStateBitmap) { goto CREATE_FAIL; } } if (pImage) { delete pImage; pImage = NULL; } return TRUE; CREATE_FAIL: if (m_hFourStateBitmap) { DeleteObject(m_hFourStateBitmap); } return FALSE; }
int Image::GetWidth() { Gdiplus::Image* gdiImage = reinterpret_cast<Gdiplus::Image*>(_private); return gdiImage->GetWidth(); }
static Image *ReadEMFImage(const ImageInfo *image_info, ExceptionInfo *exception) { Gdiplus::Bitmap *bitmap; Gdiplus::BitmapData bitmap_data; Gdiplus::GdiplusStartupInput startup_input; Gdiplus::Graphics *graphics; Gdiplus::Image *source; Gdiplus::Rect rect; GeometryInfo geometry_info; Image *image; MagickStatusType flags; register Quantum *q; register ssize_t x; ssize_t y; ULONG_PTR token; unsigned char *p; wchar_t fileName[MagickPathExtent]; assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); image=AcquireImage(image_info,exception); if (Gdiplus::GdiplusStartup(&token,&startup_input,NULL) != Gdiplus::Status::Ok) ThrowReaderException(CoderError, "GdiplusStartupFailed"); MultiByteToWideChar(CP_UTF8,0,image->filename,-1,fileName,MagickPathExtent); source=Gdiplus::Image::FromFile(fileName); if (source == (Gdiplus::Image *) NULL) { Gdiplus::GdiplusShutdown(token); ThrowReaderException(FileOpenError,"UnableToOpenFile"); } image->resolution.x=source->GetHorizontalResolution(); image->resolution.y=source->GetVerticalResolution(); image->columns=(size_t) source->GetWidth(); image->rows=(size_t) source->GetHeight(); if (image_info->density != (char *) NULL) { flags=ParseGeometry(image_info->density,&geometry_info); image->resolution.x=geometry_info.rho; image->resolution.y=geometry_info.sigma; if ((flags & SigmaValue) == 0) image->resolution.y=image->resolution.x; if ((image->resolution.x > 0.0) && (image->resolution.y > 0.0)) { image->columns=(size_t) floor((Gdiplus::REAL) source->GetWidth() / source->GetHorizontalResolution() * image->resolution.x + 0.5); image->rows=(size_t)floor((Gdiplus::REAL) source->GetHeight() / source->GetVerticalResolution() * image->resolution.y + 0.5); } } bitmap=new Gdiplus::Bitmap((INT) image->columns,(INT) image->rows, PixelFormat32bppARGB); graphics=Gdiplus::Graphics::FromImage(bitmap); graphics->SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic); graphics->SetSmoothingMode(Gdiplus::SmoothingModeHighQuality); graphics->SetTextRenderingHint(Gdiplus::TextRenderingHintClearTypeGridFit); graphics->Clear(Gdiplus::Color((BYTE) ScaleQuantumToChar( image->background_color.alpha),(BYTE) ScaleQuantumToChar( image->background_color.red),(BYTE) ScaleQuantumToChar( image->background_color.green),(BYTE) ScaleQuantumToChar( image->background_color.blue))); graphics->DrawImage(source,0,0,(INT) image->columns,(INT) image->rows); delete graphics; delete source; rect=Gdiplus::Rect(0,0,(INT) image->columns,(INT) image->rows); if (bitmap->LockBits(&rect,Gdiplus::ImageLockModeRead,PixelFormat32bppARGB, &bitmap_data) != Gdiplus::Ok) { delete bitmap; Gdiplus::GdiplusShutdown(token); ThrowReaderException(FileOpenError,"UnableToReadImageData"); } image->alpha_trait=BlendPixelTrait; for (y=0; y < (ssize_t) image->rows; y++) { p=(unsigned char *) bitmap_data.Scan0+(y*abs(bitmap_data.Stride)); if (bitmap_data.Stride < 0) q=GetAuthenticPixels(image,0,image->rows-y-1,image->columns,1,exception); else q=GetAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (Quantum *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { SetPixelBlue(image,ScaleCharToQuantum(*p++),q); SetPixelGreen(image,ScaleCharToQuantum(*p++),q); SetPixelRed(image,ScaleCharToQuantum(*p++),q); SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); q+=GetPixelChannels(image); } if (SyncAuthenticPixels(image,exception) == MagickFalse) break; } bitmap->UnlockBits(&bitmap_data); delete bitmap; Gdiplus::GdiplusShutdown(token); return(image); }
void Graphics::DrawImage(Image* image, const Rect& rc, const ImageAttributes* attr) { Gdiplus::Graphics* g = reinterpret_cast<Gdiplus::Graphics*>(_private); Gdiplus::Image* gdiImage = reinterpret_cast<Gdiplus::Image*>(image->_private); if(attr!=0) { Gdiplus::ImageAttributes* ia = reinterpret_cast<Gdiplus::ImageAttributes*>(attr->_private); g->DrawImage(gdiImage, Gdiplus::Rect(rc.GetLeft(), rc.GetTop(), rc.GetWidth(), rc.GetHeight()), 0, 0, gdiImage->GetWidth(), gdiImage->GetHeight(), Gdiplus::UnitPixel, ia); } else { g->DrawImage(gdiImage, ToGDIRect<Rect, Gdiplus::Rect>(rc)); } }
int DrawSdk::Image::WriteScaledImageFile(WCHAR* scaledImageName, float scaleX, float scaleY, const WCHAR* format) { int hr = S_OK; // // Starting the Gdiplus machine should be executed outside of this method // Gdiplus::GdiplusStartupInput gdiplusStartupInput; // ULONG_PTR gdiplusToken; // Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); Gdiplus::ImageCodecInfo *pImageCodecInfo = NULL; CLSID *pClsid = NULL; HDC hdc = CreateCompatibleDC(NULL); // Get the encoder CLSID depending on the image format (image/jpeg, image/gif, image/png) UINT num = 0; UINT size = 0; Gdiplus::GetImageEncodersSize(&num, &size); if (size == 0) hr = -1; // Failure if (SUCCEEDED(hr)) { pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size)); if (pImageCodecInfo == NULL) hr = -1; // Failure } if (SUCCEEDED(hr)) { Gdiplus::GetImageEncoders(num, size, pImageCodecInfo); for(int j = 0; j < num; ++j) { if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 ) { pClsid = &pImageCodecInfo[j].Clsid; break; // Success } } if (pClsid == NULL) hr = -1; // Failure } // Bugfix 5301: // If 'gdipImage_' is NULL then it was not kept in memory and therefore // a temporary Gdiplus::Image object is created for the rescaling. // This avoids having too much image data in the memory. Gdiplus::Image *tmpImage = NULL; if (SUCCEEDED(hr) && gdipImage_ == NULL) { // convert char-String in WCHAR-String int iStringLength = _tcslen(imageName_) + 1; WCHAR *wcFilename = (WCHAR *)malloc(iStringLength*sizeof(WCHAR)); #ifdef _UNICODE wcscpy(wcFilename, imageName_); #else MultiByteToWideChar( CP_ACP, 0, imageName, iStringLength, wcFilename, iStringLength); #endif tmpImage = new Gdiplus::Image(wcFilename, FALSE); if (wcFilename) free(wcFilename); } else { tmpImage = gdipImage_; } if (SUCCEEDED(hr) && tmpImage != NULL) { // Resize the image by scaling factors Gdiplus::REAL destWidth = scaleX * this->GetWidth(); Gdiplus::REAL destHeight = scaleY * this->GetHeight(); // If no correct size is defined in the object queue, use the real image size instead if ( (this->GetWidth() <= 0.0f) && (this->GetHeight() <= 0.0f) ) { destWidth = scaleX * tmpImage->GetWidth(); destHeight = scaleY * tmpImage->GetHeight(); } // At least we have to write one pixel if (destWidth < 1.0f) destWidth = 1.0f; if (destHeight < 1.0f) destHeight = 1.0f; Gdiplus::Bitmap scaledImage((int)(destWidth + 0.5f), (int)(destHeight + 0.5f)); scaledImage.SetResolution(tmpImage->GetHorizontalResolution(), tmpImage->GetVerticalResolution()); Gdiplus::Graphics grPhoto(&scaledImage); grPhoto.SetCompositingQuality(Gdiplus::CompositingQualityHighSpeed); grPhoto.SetCompositingMode(Gdiplus::CompositingModeSourceOver); grPhoto.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic); Gdiplus::Rect destRect(0, 0, (int)(destWidth + 0.5f), (int)(destHeight + 0.5f)); hr = grPhoto.DrawImage(tmpImage, destRect, 0, 0, tmpImage->GetWidth(),tmpImage->GetHeight(), Gdiplus::UnitPixel); // Write the scaled image to a file if (SUCCEEDED(hr)) hr = scaledImage.Save(scaledImageName, pClsid, NULL); } // Cleanup if (hdc) { ::DeleteDC(hdc); hdc = NULL; } if (pImageCodecInfo) { free(pImageCodecInfo); pImageCodecInfo = NULL; } if (tmpImage != NULL && tmpImage != gdipImage_) delete tmpImage; // // Stop the Gdiplus machine --> this should be executed outside of this method (see above) // Gdiplus::GdiplusShutdown(gdiplusToken); return hr; }
int ServentData::drawServent(Gdiplus::Graphics *g, int x, int y){ REAL xx = x * 1.0f; REAL yy = y * 1.0f; int w/*,h*/; // 位置を保存 posX = x; posY = y; if (getWidth() == 0){ if (gWS){ w = gWS; } else { w = 400; } } else { w = getWidth(); gWS = w; } // 描画基点 PointF origin(xx, yy); // フォント設定 Font font(L"MS Pゴシック",9); // 文字色 SolidBrush *strBrush; if (chanHit.firewalled){ strBrush = ::new SolidBrush(Color::Red); } else { if (getSelected()){ // 選択中 strBrush = ::new SolidBrush(Color::White); } else { // 非選択 strBrush = ::new SolidBrush(Color::Black); } } // ServantData表示 g->SetTextRenderingHint(TextRenderingHintAntiAlias); // 文字列作成 char tmp[256]; char host1[256]; host.toStr(host1); if (infoFlg){ if (chanHit.version_ex_number){ // 拡張バージョン sprintf(tmp, "%c%c%04d - %d/%d - %s(%s)", chanHit.version_ex_prefix[0], chanHit.version_ex_prefix[1], chanHit.version_ex_number, totalListeners, totalRelays, host1, hostname.cstr() ); } else if (chanHit.version_vp){ sprintf(tmp, "VP%04d - %d/%d - %s(%s)", chanHit.version_vp, totalListeners, totalRelays, host1, hostname.cstr() ); } else { sprintf(tmp, "(-----) - %d/%d - %s(%s)", totalListeners, totalRelays, host1, hostname.cstr() ); } } else { sprintf(tmp, "(-----) - %d/%d - %s(%s)", totalListeners, totalRelays, host1, hostname.cstr() ); } _bstr_t bstr1(tmp); // ステータス表示 Gdiplus::Image *img = NULL; unsigned int nowTime = sys->getTime(); switch(getStatus()){ case Servent::S_CONNECTING: img = img_connect; break; case Servent::S_CONNECTED: if (lastSkipTime + 120 > nowTime){ if (chanHit.relay){ img = img_conn_ok_skip; } else { if (chanHit.numRelays){ img = img_conn_full_skip; } else { img = img_conn_over_skip; } } } else { if (chanHit.relay){ img = img_conn_ok; } else { if (chanHit.numRelays){ img = img_conn_full; } else { img = img_conn_over; } } } break; default: break; } // 文字描画範囲指定 RectF r1(origin.X + img->GetWidth() + 2, origin.Y, 800.0f, 13.0f); RectF r2; StringFormat format; format.SetAlignment(StringAlignmentNear); g->MeasureString(bstr1, -1, &font, r1, &format, &r2); w = (INT)r2.Width + img->GetWidth() + 2; // ServentData表示部の背景を塗る if (getSelected()){ // 選択中 SolidBrush b(Color(160,49,106,197)); g->FillRectangle(&b, x, y, w, 13); } else { // 非選択 SolidBrush b(Color(160,200,200,200)); g->FillRectangle(&b, x, y, w, 13); } // ステータス表示位置 Rect img_rect((INT)origin.X, (INT)origin.Y+1, img ? img->GetWidth() : 12, 12); // ステータス描画 ImageAttributes att; // att.SetColorKey(Color::White, Color::White, ColorAdjustTypeBitmap); g->DrawImage(img, img_rect, 0, 0, img_rect.Width, 12, UnitPixel, &att); // 次の基点 origin.X += 12; g->DrawString(bstr1, -1, &font, r2, &format, strBrush); // 次の基点 origin.X += r2.Width; origin.Y += 13; setWidth((int)origin.X-posX); setHeight((int)origin.Y - posY); ::delete strBrush; return 0; }
int ChannelData::drawChannel(Graphics *g, int x, int y){ REAL xx = x * 1.0f; REAL yy = y * 1.0f; ServentData* sd; // 位置を保存 posX = x; posY = y; int w/*,h*/; if (getWidth() == 0){ if (gW){ w = gW; } else { w = 400; } } else { w = getWidth(); gW = w; } // チャンネル表示部の背景を塗る if (isSelected()){ // 選択中 SolidBrush b(Color(160,49,106,197)); g->FillRectangle(&b, x, y, w, 14); } else { // 非選択 SolidBrush b(Color(160,255,255,255)); g->FillRectangle(&b, x, y, w, 14); } // ステータス表示 Gdiplus::Image *img = NULL; unsigned int nowTime = sys->getTime(); if (this->type != Servent::T_COUT) { // COUT以外 Channel *ch = chanMgr->findChannelByChannelID(this->channel_id); switch(this->getStatus()){ case Channel::S_IDLE: img = img_idle; break; case Channel::S_SEARCHING: case Channel::S_CONNECTING: img = img_connect; break; case Channel::S_RECEIVING: if ((skipCount > 2) && (lastSkipTime + 120 > nowTime)){ if (chDisp.relay){ img = img_conn_ok_skip; } else { if (chDisp.numRelays){ img = img_conn_full_skip; } else { img = img_conn_over_skip; } } } else { if (chDisp.relay){ img = img_conn_ok; } else { if (chDisp.numRelays){ img = img_conn_full; } else { img = img_conn_over; } } } break; case Channel::S_BROADCASTING: img = img_broad_ok; break; case Channel::S_ERROR: // bump時にエラーが表示されるのを防止 if (ch && ch->bumped) { img = img_connect; } else { img = img_error; } break; default: img = img_idle; break; } } else { // COUT用 img = img_broad_ok; } // 描画基点 PointF origin(xx, yy); // ステータス表示位置 Rect img_rect((INT)origin.X, (INT)origin.Y + 1, img ? img->GetWidth() : 12, 12); // ステータス描画 ImageAttributes att; // att.SetColorKey(Color::White, Color::White, ColorAdjustTypeBitmap); g->DrawImage(img, img_rect, 0, 0, img_rect.Width, 12, UnitPixel, &att); // 次の基点 origin.X += img_rect.Width; // フォント設定 Gdiplus::Font font(L"MS Pゴシック",10); // 文字色 SolidBrush *strBrush; if (servMgr->getFirewall() == ServMgr::FW_ON){ strBrush = ::new SolidBrush(Color::Red); } else if (isTracker() && (getStatus() == Channel::S_RECEIVING)){ strBrush = ::new SolidBrush(Color::Green); } else { if (isSelected()){ // 選択中 strBrush = ::new SolidBrush(Color::White); } else { // 非選択 strBrush = ::new SolidBrush(Color::Black); } } if (this->type != Servent::T_COUT) { // COUT以外 // チャンネル名表示 g->SetTextRenderingHint(TextRenderingHintAntiAlias); _bstr_t bstr1(getName()); // 文字描画範囲指定 RectF r1(origin.X, origin.Y, 120.0f, 13.0f); StringFormat format; format.SetAlignment(StringAlignmentNear); g->DrawString(bstr1, -1, &font, r1, &format, strBrush); // 次の基点 origin.X += r1.Width; //// 上流IP/リスナー数/リレー数表示 //// NOTE: //// ぴあかすの動作勉強用。リリースビルドでは元のコードを使用の事。 //// 文字表示範囲は幅220ぐらいでおk //char tmp[512]; // 表示用バッファ //char hostip[256]; // IPアドレスバッファ //chDisp.uphost.toStr(hostip); // 上流IP //sprintf(tmp, "%d/%d - [%d/%d] - %s", // getTotalListeners(), // getTotalRelays(), // getLocalListeners(), // getLocalRelays(), // hostip // ); // リスナー数/リレー数表示 char tmp[256]; sprintf(tmp, "%d/%d - [%d/%d]", getTotalListeners(), getTotalRelays(), getLocalListeners(), getLocalRelays()); _bstr_t bstr2(tmp); // 文字表示範囲指定 RectF r2(origin.X, origin.Y, 100.0f, 13.0f); format.SetAlignment(StringAlignmentCenter); g->DrawString(bstr2, -1, &font, r2, &format, strBrush); // 次の基点 origin.X += r2.Width; // bps表示 Font *f; if (isStayConnected()){ f = ::new Font(L"Arial", 9.0f, FontStyleItalic|FontStyleBold, UnitPoint); } else { f = ::new Font(L"Arial", 9.0f); } sprintf(tmp, "%dkbps", getBitRate()); _bstr_t bstr3(tmp); format.SetAlignment(StringAlignmentFar); // 文字表示範囲指定 RectF r3(origin.X, origin.Y, 80.0f, 13.0f); g->DrawString(bstr3, -1, f, r3, &format, strBrush); // フォント開放 ::delete f; // 次の基点 origin.X += r3.Width; // ブラシ削除 ::delete strBrush; // Servent表示 if (!openFlg){ int count = getServentCount(); // Servent表示部の背景を白にする SolidBrush b(Color(160,255,255,255)); g->FillRectangle(&b, (INT)origin.X, (INT)origin.Y, 14*count, 14); sd = serventDataTop; int index = 0; while(sd){ SolidBrush *serventBrush; if (sd->getInfoFlg()){ ChanHit *hit = sd->getChanHit(); if (hit->firewalled){ SolidBrush bb(Color(180,255,0,0)); g->FillRectangle(&bb, (INT)origin.X + 14*index, (INT)origin.Y, 14, 14); } if (hit->relay){ // リレーOK serventBrush = ::new SolidBrush(Color::Green); } else { // リレー不可 if (hit->numRelays){ // リレー一杯 serventBrush = ::new SolidBrush(Color::Blue); } else { // リレーなし serventBrush = ::new SolidBrush(Color::Purple); } } } else { // 情報なし serventBrush = ::new SolidBrush(Color::Black); } // 四角描画 backGra->FillRectangle(serventBrush, (INT)origin.X + index*14 + 1, (INT)origin.Y + 1, 12, 12); ::delete serventBrush; sd = sd->getNextData(); index++; } } // 次の基点 origin.Y += 15; // サイズを保存 setWidth((int)origin.X - posX); setHeight((int)origin.Y - posY); // ServentData表示 sd = serventDataTop; while(sd){ if (openFlg || sd->getSelected()){ sd->drawServent(g, (INT)x+12, (INT)origin.Y); // 次の基点 origin.Y += 15; } sd = sd->getNextData(); } } else { // COUT g->SetTextRenderingHint(TextRenderingHintAntiAlias); RectF r1(origin.X, origin.Y, 120.0f+100.0f+80.0f, 13.0f); origin.X += r1.Width; StringFormat format; format.SetAlignment(StringAlignmentNear); _bstr_t bstr1("COUT"); g->DrawString(bstr1, -1, &font, r1, &format, strBrush); ::delete strBrush; origin.Y += 15; setWidth((int)origin.X - posX); setHeight((int)origin.Y - posY); } return (int)(origin.Y); }
LRESULT BlobMgmt::ShowImage() { #ifndef VC6 HDC hdc; RECT rectwin; wyInt32 renderwidth, renderheight; PAINTSTRUCT ps; LPSTREAM stream = NULL; HGLOBAL glbmem; void *glbbuffer; wyWChar tempfilename[MAX_PATH+1] = {0}, path[MAX_PATH + 1] = {0}; wyString tempstr; HANDLE hfile = INVALID_HANDLE_VALUE; DWORD byteswritten = 0; if(!m_piub->m_data || m_piub->m_datasize == 0) { VERIFY(hdc = BeginPaint(m_hwndimage, &ps)); VERIFY(EndPaint(m_hwndimage, &ps)); return 0; } /* allocate global memory and copy image data in it*/ VERIFY(glbmem = GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD, m_piub->m_datasize)); if(!glbmem) return 0; /* lock the global memory and get a pointer */ glbbuffer = GlobalLock(glbmem); /* copy the memory to buffer */ CopyMemory(glbbuffer, m_piub->m_data, m_piub->m_datasize); /* unlock it */ VERIFY(GlobalUnlock(glbmem)== NO_ERROR); /* create the stream */ VERIFY(CreateStreamOnHGlobal(glbmem, FALSE, &stream)== S_OK); /* prepare window for painting */ VERIFY(hdc = BeginPaint(m_hwndimage, &ps)); /* clear the window */ PrepareScreen(ps.hdc); if(pGlobals->m_configdirpath.GetLength() || SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, (LPWSTR)path))) { if(pGlobals->m_configdirpath.GetLength()) { //wcscpy(path, pGlobals->m_configdirpath.GetAsWideChar()); wcsncpy(path, pGlobals->m_configdirpath.GetAsWideChar(), MAX_PATH); path[MAX_PATH] = '\0'; } else { wcscat(path, L"\\"); wcscat(path, L"SQLyog"); } VERIFY(GetTempFileName(path, L"img", 0, tempfilename)); hfile = CreateFile(tempfilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, NULL, NULL); VERIFY(hfile != INVALID_HANDLE_VALUE); VERIFY(WriteFile(hfile, m_piub->m_data, m_piub->m_datasize, &byteswritten, NULL)); VERIFY(CloseHandle(hfile)); } tempstr.SetAs(tempfilename); WCHAR *wpath = GetWideString(tempstr.GetString()); Gdiplus::Graphics graphics(hdc); Gdiplus::Image *image = new Gdiplus::Image(wpath); HeapFree(GetProcessHeap(), 0, wpath); /* in win95 image will be null so we exit */ if(!image) goto ExitPara; /* the binary data might not be image so image.getlastatus will not return Ok */ if(image->GetLastStatus()!= Gdiplus::Ok) { delete image; goto ExitPara; } /* get the window width and calculate the correct render stats */ VERIFY(GetClientRect(m_hwndimage, &rectwin)); renderheight =(((LONG)image->GetHeight())> rectwin.bottom)?(rectwin.bottom):(image->GetHeight()); renderwidth =(((LONG)image->GetWidth())> rectwin.right)?(rectwin.right):(image->GetWidth()); graphics.DrawImage(image, 0, 0, renderwidth, renderheight); delete image; EndPaint(m_hwndimage, &ps); ExitPara: /* free up stuff */ VERIFY(DeleteFile(tempfilename)); if(stream) stream->Release(); VERIFY(GlobalFree(glbmem)== NULL); #endif return 0; }
void CListViewCtrlEx::_DrawNormalItem( LPDRAWITEMSTRUCT lpdis, const TListItem *pItem ) { if (!pItem) return; int nItem = lpdis->itemID; CDCHandle dc; dc.Attach(lpdis->hDC); HFONT hOldFont = dc.SelectFont(m_fontDef); BOOL bSelect = FALSE ; if ((lpdis->itemAction | ODA_SELECT) && (lpdis->itemState & ODS_SELECTED)) { bSelect = TRUE ; } if ( bSelect ) dc.FillSolidRect( &lpdis->rcItem, RGB(185,219,255)); else dc.FillSolidRect( &lpdis->rcItem, pItem->clrBg); // draw check box if( pItem->dwFlags&(LISTITEM_CHECKBOX|LISTITEM_RADIOBOX) ) _DrawCheckBox(dc, lpdis->rcItem, _super::GetCheckState(nItem), pItem->dwFlags); COLORREF oldClr = dc.GetTextColor(); for(int i=0; i<pItem->subItems.size(); ++i) { CRect rcSubItem; DWORD nMarginWidth = 0; CRect rcBounds; GetSubItemRect(nItem, i, LVIR_LABEL, &rcSubItem); nMarginWidth = LEFT_MARGIN_TEXT_COLUMN+3; if(i==0) { if( pItem->dwFlags&(LISTITEM_CHECKBOX|LISTITEM_RADIOBOX) ) { nMarginWidth+=rcSubItem.left; } else { rcSubItem.left -= 19; nMarginWidth+=5; } } #define DT_FLAGS_DRAW_TEXT (DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_END_ELLIPSIS|DT_VCENTER) rcSubItem.left += LEFT_MARGIN_TEXT_COLUMN; rcSubItem.right -= 3; const TListSubItem &subItem = pItem->subItems[i]; if(subItem.type == SUBITEM_LINK) { dc.SelectFont(m_fontLink); dc.SetTextColor(COLOR_LIST_LINK); CRect rcProbeItem; dc.DrawText( subItem.str, -1, &rcProbeItem, DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_VCENTER|DT_CALCRECT); dc.DrawText( subItem.str, -1, &rcSubItem, DT_FLAGS_DRAW_TEXT); DWORD nMaxWidth = rcProbeItem.Width()+nMarginWidth; _SetColumnNeedWidth(i,nMaxWidth); } else { if (subItem.type == SUBITEM_ICON && subItem.nImg != NULL) { dc.DrawIconEx( rcSubItem.left, rcSubItem.top + 3, (HICON)subItem.nImg, 16 , 16, 0, 0, DI_NORMAL ); rcSubItem.left = rcSubItem.left + 18; } else if (subItem.type == SUBITEM_PNG) { Gdiplus::Image* pImg = BkPngPool::Get(subItem.nImg); if (pImg) { Gdiplus::Graphics graphics(dc); SIZE size = {0, 0}; if (pImg) { size.cx = pImg->GetWidth(); size.cy = pImg->GetHeight(); } graphics.DrawImage(pImg, Gdiplus::Rect(rcSubItem.left, rcSubItem.top + 5, size.cx, size.cy)); } rcSubItem.left = rcSubItem.left + 18; } else if(subItem.type==SUBITEM_COMBO) { CDC dcTmp; dcTmp.CreateCompatibleDC(dc); HBITMAP hBmpOld = dcTmp.SelectBitmap(m_bitmapCombo); dc.BitBlt(rcSubItem.right-20, rcSubItem.top + 3, 20, 20, dcTmp, 0, 0, SRCCOPY); dcTmp.SelectBitmap(hBmpOld); dcTmp.DeleteDC(); } UINT uFormat = DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_PATH_ELLIPSIS|DT_VCENTER; if (i == 3) { if (pItem->nLevel == enumLevelRisk) { rcSubItem.DeflateRect(2, 3); CPen penBorder; penBorder.CreatePen( PS_SOLID, 1, RGB(224, 0, 0) ); CBrush bshInterior; bshInterior.CreateSolidBrush( RGB(224, 0, 0) ); HPEN hOldPen = dc.SelectPen( penBorder ); HBRUSH hOldBrush = dc.SelectBrush( bshInterior ); dc.RoundRect( rcSubItem, CPoint( 3, 3 ) ); dc.SelectPen(hOldPen); dc.SelectBrush(hOldBrush); dc.SetTextColor( RGB(255, 255, 255) ); } else if (pItem->nLevel == enumLevelUnknown) { rcSubItem.DeflateRect(2, 3); CPen penBorder; penBorder.CreatePen( PS_SOLID, 1, RGB(250, 115, 5) ); CBrush bshInterior; bshInterior.CreateSolidBrush( RGB(250, 115, 5) ); HPEN hOldPen = dc.SelectPen( penBorder ); HBRUSH hOldBrush = dc.SelectBrush( bshInterior ); dc.RoundRect( rcSubItem, CPoint( 3, 3 ) ); dc.SelectPen(hOldPen); dc.SelectBrush(hOldBrush); dc.SetTextColor( RGB(255, 255, 255) ); } else dc.SetTextColor( subItem.clr ); uFormat = DT_SINGLELINE|DT_CENTER|DT_NOPREFIX|DT_PATH_ELLIPSIS|DT_VCENTER; } else dc.SetTextColor( subItem.clr ); dc.DrawText( subItem.str, -1, &rcSubItem, uFormat); if (subItem.type == SUBITEM_ICON || subItem.type == SUBITEM_PNG) rcSubItem.left = rcSubItem.left - 18; CRect rcProbeItem; dc.DrawText( subItem.str, -1, &rcProbeItem, DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_VCENTER|DT_CALCRECT); DWORD nMaxWidth = rcProbeItem.Width()+nMarginWidth; _SetColumnNeedWidth(i,nMaxWidth); } } CPen penx; penx.CreatePen(PS_SOLID,1,pItem->clrBtmGapLine); HPEN penOld = dc.SelectPen(penx); dc.MoveTo( lpdis->rcItem.left, lpdis->rcItem.bottom-1 ); CRect rcClient; GetClientRect(rcClient); dc.LineTo( lpdis->rcItem.left + rcClient.Width(), lpdis->rcItem.bottom-1); dc.SelectPen(penOld); dc.SelectFont(hOldFont); dc.SetTextColor(oldClr); dc.Detach(); }
LRESULT CBeikeSafeSoftmgrNecessHandler::OnListBoxGetDispInfo( LPNMHDR pnmh ) { BKLBMGETDISPINFO* pdi = (BKLBMGETDISPINFO*)pnmh; if ( pdi->nListItemID >= m_arrRightList.GetSize() ) return 0; NECESS_SOFT_LIST_DATA& datalist = m_arrRightList[pdi->nListItemID]; if (datalist.bTitle) { // 标题的绘制 pdi->nHeight = SOFT_LIST_TITLE_HEIGHT; m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_TITLE,TRUE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_ITEM,FALSE); m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_TITLE_NAME,datalist.strTitleName); } else { // 里面软件list的绘制 pdi->nHeight = SOFT_LIST_ITEM_HEIGHT; m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_TITLE,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_ITEM,TRUE); m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_DIV_ITEM,"crbg",pdi->bSelect?"EBF5FF":"FFFFFF"); CSoftListItemData* pSoftData = GetSoftDataByID(datalist.strSoftId); int nPosX = 0; Gdiplus::Image *pImage = NULL; { CDC dcx = GetDC(m_pMainDlg->m_hWnd); HFONT hFntTmp; int nTypeWidth = 0; if (m_bShowType) { hFntTmp = dcx.SelectFont(BkFontPool::GetFont(BKF_DEFAULTFONT)); CRect rcType; CString strType; strType.Format(L"[%s]", pSoftData->m_strTypeShort); dcx.DrawText(strType, -1, &rcType, DT_VCENTER | DT_SINGLELINE | DT_CALCRECT); nTypeWidth = rcType.Width(); dcx.SelectFont(hFntTmp); } hFntTmp = dcx.SelectFont(BkFontPool::GetFont(BKF_BOLDFONT)); CRect rcProb; dcx.DrawText(pSoftData->m_strName, -1, &rcProb, DT_VCENTER | DT_SINGLELINE | DT_CALCRECT); dcx.SelectFont(hFntTmp); ReleaseDC(m_pMainDlg->m_hWnd, dcx); CRect rcWin; GetWindowRect(m_necessList->m_hWnd, &rcWin); int nLablesWidth = 0; if ((pSoftData->m_attri&SA_Green) == SA_Green) { pImage = BkPngPool::Get(IDP_SOFTMGR_GREEN_SOFT); nLablesWidth += pImage->GetWidth(); } if (pSoftData->m_bCharge == TRUE) { if (nLablesWidth != 0) nLablesWidth += 2; pImage = BkPngPool::Get(IDP_SOFTMGR_CHARGE_SOFT); nLablesWidth += pImage->GetWidth(); } if (pSoftData->m_bPlug == TRUE) { if (nLablesWidth != 0) nLablesWidth += 2; pImage = BkPngPool::Get(IDP_SOFTMGR_PLUGIN_SOFT); nLablesWidth += pImage->GetWidth(); } if ((pSoftData->m_attri&SA_New) == SA_New) { if (nLablesWidth != 0) nLablesWidth += 2; pImage = BkPngPool::Get(IDP_SOFTMGR_NEW_SOFT); nLablesWidth += pImage->GetWidth(); } int nLeft = 50 + nTypeWidth; nPosX = rcWin.Width() - 310 - nLablesWidth; if (rcProb.Width() < rcWin.Width() - 310 - nLablesWidth - nLeft) nPosX = nLeft + rcProb.Width(); CStringA strPosA; strPosA.Format("%d,12,%d,27", nLeft, nPosX); m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_TXT_SOFT_TITLE, "pos", strPosA); if (m_bShowType) { CString strTypeShort; strTypeShort.Format(L"[%s]", pSoftData->m_strTypeShort); m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_SOFT_TYPE, strTypeShort); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_TYPE,TRUE); } else m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_TYPE,FALSE); } m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_GREEN,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_CHARGE,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_PLUGIN,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_NEW,FALSE); int nPosY = 10; if ((pSoftData->m_attri&SA_Green) == SA_Green) { nPosX += 2; CStringA strPosA; strPosA.Format("%d,%d", nPosX, nPosY); m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_GREEN, "pos", strPosA); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_GREEN,TRUE); nPosX += 45; } if (pSoftData->m_bCharge == TRUE) { nPosX += 2; CStringA strPosA; strPosA.Format("%d,%d", nPosX, nPosY); m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_CHARGE, "pos", strPosA); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_CHARGE,TRUE); nPosX += 45; } if (pSoftData->m_bPlug == TRUE) { nPosX += 2; CStringA strPosA; strPosA.Format("%d,%d", nPosX, nPosY); m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_PLUGIN, "pos", strPosA); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_PLUGIN,TRUE); nPosX += 45; } if ((pSoftData->m_attri&SA_New) == SA_New) { nPosX += 2; CStringA strPosA; strPosA.Format("%d,%d", nPosX, nPosY); m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_NEW, "pos", strPosA); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_NEW,TRUE); } if (pSoftData != NULL) { // 图标的绘制 if (TRUE) { CStringA strMem; strMem.Format("%d",pSoftData->m_pImage); m_necessList->SetItemAttribute( IDC_SOFTMGR_LISTTMP_ICON_SOFT, "mempointer",strMem ); } //画评分 for (int i = IDC_SOFTMGR_LISTTMP_STAR_ONE; i <= IDC_SOFTMGR_LISTTMP_STAR_FIVE; i++) { CStringA strSkin; if ((i - IDC_SOFTMGR_LISTTMP_STAR_ONE + 1)*2 <= pSoftData->m_fMark) strSkin = "star"; else if ((i - IDC_SOFTMGR_LISTTMP_STAR_ONE + 1)*2 - 1 <= pSoftData->m_fMark) strSkin = "star_half"; else strSkin = "star_off"; m_necessList->SetItemAttribute(i, "skin", strSkin); } CString strMark; strMark.Format(L"%.1f分 投票", pSoftData->m_fMark); m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_SOFT_MARK, strMark); // 下载图标 if (!pSoftData->m_bIcon) m_pSoftMgrMainUI->OnDownLoadIcon( pSoftData->m_strSoftID ); // 标题,描述,大小 m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_SOFT_TITLE, pSoftData->m_strName); m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_SOFT_DESC, pSoftData->m_strDescription); m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_SOFT_SIZE, pSoftData->m_strSize); m_necessList->SetItemStringAttribute(IDC_SOFTMGR_LISTTMP_TXT_SOFT_DESC,"tip",pSoftData->m_strDescription); m_necessList->SetItemStringAttribute(IDC_SOFTMGR_LISTTMP_TXT_SOFT_TITLE,"tip",BkString::Get(IDS_SOFTMGR_8100)); m_necessList->SetItemStringAttribute(IDC_SOFTMGR_LISTTMP_ICON_SOFT,"tip",BkString::Get(IDS_SOFTMGR_8100)); if (pSoftData->m_bUpdate) { CDC dcx = GetDC(m_pMainDlg->m_hWnd); HFONT hFntTmp; hFntTmp = dcx.SelectFont(BkFontPool::GetFont(BKF_DEFAULTFONT)); CRect rcProb; dcx.DrawText(pSoftData->m_strDescription, -1, &rcProb, DT_VCENTER | DT_SINGLELINE | DT_CALCRECT); dcx.SelectFont(hFntTmp); ReleaseDC(m_pMainDlg->m_hWnd, dcx); CRect rcWin; GetWindowRect(m_necessList->m_hWnd, &rcWin); int nPos = 0; CStringA strPosDes; CStringA strPosNew; if (rcProb.Width() > rcWin.Width() - 50 - 310 - 50 - 2) { strPosDes = "50,32,-52,47"; strPosNew = "-50,32,-0,47"; } else { strPosDes.Format("50,32,%d,47", 50 + rcProb.Width()); strPosNew.Format("%d,32,-0,47", 50 + rcProb.Width() + 2); } m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_TXT_SOFT_DESC, "pos", strPosDes); m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_TXT_SOFT_NEW, "pos", strPosNew); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_NEW,TRUE); } else { m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_TXT_SOFT_DESC, "pos", "50,32,-0,47"); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_NEW,FALSE); } if ( /*!pSoftData->m_bSetup && */pSoftData->m_bDownloading && !pSoftData->m_bWaitDownload && !pSoftData->m_bUsingForOneKey ) { m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_SIZE,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_MARK,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_MARK,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_DOWN,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_UPDATE,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_REINST,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_USE_ONKEY,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_PROG_DOWN_DOWNING,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_DOWN_PROG,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_SOFT_DOWNING_DOWN,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_SOFT_DOWNING_DOWNED,FALSE); CStringA strProg; strProg.Format("%d",pSoftData->m_dwProgress); m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_PROG_DOWN_DOWNING,"value",strProg); if (pSoftData->m_bLinking) { if (pSoftData->m_bLinkFailed) m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_DOWN_PROG,BkString::Get(IDS_SOFTMGR_8089)); else m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_DOWN_PROG,BkString::Get(IDS_SOFTMGR_8090)); } else { strProg += "%"; m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_DOWN_PROG, CA2W(strProg) ); } if ( !pSoftData->m_bDownLoad ) { m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_PROG_DOWN_DOWNING,TRUE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_DOWN_PROG,TRUE); // 正在下载中的 m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_SOFT_DOWNING_DOWN,TRUE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_LNK_SOFT_RETRY,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_FEEDBACK,FALSE); if (pSoftData->m_bLinking) { m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_DOWN_STATE,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_DOWN_PAUSE,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_DOWN_CONTINUE,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_DOWN_STOP,!pSoftData->m_bLinkFailed); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_LNK_SOFT_RETRY,pSoftData->m_bLinkFailed); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_FEEDBACK,pSoftData->m_bLinkFailed); } else { m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_DOWN_STATE,TRUE); if (pSoftData->m_bPause) m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_DOWN_STATE,BkString::Get(IDS_SOFTMGR_8091)); else m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_DOWN_STATE,pSoftData->m_strSpeed); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_DOWN_PAUSE,!pSoftData->m_bPause); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_DOWN_CONTINUE,pSoftData->m_bPause); } } else { m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_SIZE,TRUE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_MARK,TRUE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_MARK,TRUE); // 已下载完毕的 m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_SOFT_DOWNING_DOWNED,TRUE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_DOWNED_INSTALL,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_INST_STATE,TRUE); if (pSoftData->m_bWaitInstall) m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_SOFT_INST_STATE,BkString::Get(IDS_SOFTMGR_8102)); else if (pSoftData->m_bInstalling) m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_SOFT_INST_STATE,BkString::Get(IDS_SOFTMGR_8085)); else { m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_INST_STATE,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_DOWNED_INSTALL,TRUE); } if ((pSoftData->m_attri&SA_Green) == SA_Green) { m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_BTN_DOWNED_INSTALL, "class", "btndetaildownloaded"); } else { m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_BTN_DOWNED_INSTALL, "class", "btndetaildown"); } } } else { m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_SIZE,TRUE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_MARK,TRUE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_MARK,TRUE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_PROG_DOWN_DOWNING,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_DOWN_PROG,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_SOFT_DOWNING_DOWN,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_SOFT_DOWNING_DOWNED,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_DOWN,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_UPDATE,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_REINST,FALSE); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_USE_ONKEY,FALSE); if (!pSoftData->m_bUsingForOneKey) { m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_DOWN,!pSoftData->m_bUpdate&&!pSoftData->m_bSetup); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_UPDATE,pSoftData->m_bUpdate); m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_REINST,pSoftData->m_bSetup&&!pSoftData->m_bUpdate); } else { m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_USE_ONKEY,TRUE); } m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_CHARGE,FALSE); } } } return 0; }
BOOL ReadImageProperty(const TCHAR *lpszImage, PROPID propId, TCHAR *szProperty, int cchMax) { Gdiplus::GdiplusStartupInput gdiplusStartupInput; ULONG_PTR token; Gdiplus::Status status = GdiplusStartup(&token, &gdiplusStartupInput, NULL); if(status != Gdiplus::Ok) { return FALSE; } BOOL bSuccess = FALSE; /* This object needs to be deleted before GdiplusShutdown is called. If it were stack allocated, it would go out of scope _after_ the call to GdiplusShutdown. By allocating it on the heap, the lifetime can be directly controlled. */ Gdiplus::Image *image = new Gdiplus::Image(lpszImage, FALSE); if(image->GetLastStatus() == Gdiplus::Ok) { if(propId == PropertyTagImageWidth) { bSuccess = TRUE; StringCchPrintf(szProperty, cchMax, _T("%u pixels"), image->GetWidth()); } else if(propId == PropertyTagImageHeight) { bSuccess = TRUE; StringCchPrintf(szProperty, cchMax, _T("%u pixels"), image->GetHeight()); } else { UINT size = image->GetPropertyItemSize(propId); if(size != 0) { Gdiplus::PropertyItem *propertyItem = reinterpret_cast<Gdiplus::PropertyItem *>(malloc(size)); if(propertyItem != NULL) { status = image->GetPropertyItem(propId, size, propertyItem); if(status == Gdiplus::Ok) { if(propertyItem->type == PropertyTagTypeASCII) { int iRes = MultiByteToWideChar(CP_ACP, 0, reinterpret_cast<LPCSTR>(propertyItem->value), -1, szProperty, cchMax); if(iRes != 0) { bSuccess = TRUE; } } } free(propertyItem); } } } } delete image; Gdiplus::GdiplusShutdown(token); return bSuccess; }