2012-07-01 4 views
1

시스템 트레이에 아이콘을 표시하고 싶습니다.HICON은 어떻게 그립니 까?

너무 단순해야하는 것처럼 보이지만, HICON을 작성하고 그려내는 방법을 이해할 수 없습니다! 모든 "호환 가능한 비트 맵", "호환 가능한 DC"등은 정말 혼란 스럽습니다.

어떻게 아이콘을 그립니 까?

+0

당신이를로드하려고 정적 아이콘을 HICON으로 가져 오거나 트레이에 동적/변경 아이콘을 그리시겠습니까? – Zac

+0

@ Zac : 가장 확실한 것은 후자입니다. :) – Mehrdad

+0

MFC, WTL, Qt를 사용하고 있습니까? 아니면 그냥 Win32? – Zac

답변

3

너무 자세하지 않고 다음 C++ 클래스를 사용할 수 있습니다.

IT는 Windows Template Library 사용하지만 정말가 쉽습니다 클래스를 사용하여 일반 C.

using namespace WTL; 
class CIconDC : public CDC 
{ 
public: 
    HBITMAP hBmpOld; 

    CIconDC(int cx = GetSystemMetrics(SM_CXSMICON), // width 
      int cy = GetSystemMetrics(SM_CYSMICON), // height 
      HDC templateDC = CClientDC(NULL)) // automatically calls ReleaseDC 
    { 
     this->CreateCompatibleDC(templateDC); 
     hBmpOld = this->SelectBitmap(CreateCompatibleBitmap(templateDC, cx, cy)); 
    } 

    ~CIconDC() { DeleteObject(this->SelectBitmap(hBmpOld)); } 

    HICON CreateIcon() const 
    { 
     // temporarily swap bitmaps to get handle of current bitmap 
     HBITMAP hBitmap = this->GetCurrentBitmap(); 
     ICONINFO ii = { TRUE, 0, 0, hBitmap, hBitmap }; 
     return CreateIconIndirect(&ii); 
    } 
}; 

로 변환하는 것은 매우 간단합니다 :

CIconDC dc; 
dc.LineTo(10, 10); // for example -- you can do whatever you want with the DC 
CIcon hIcon = dc.CreateIcon(); // converted to an HICON! 
관련 문제