Permalink
Browse files

Fixed issue with toolbar icon appearing black if the bitmap is incomp…

…atible with the screen format.
  • Loading branch information...
cmrazek committed Mar 9, 2013
1 parent b1004ba commit 969dab0281ec21f7965d6155aaac66a544a32123
Showing with 31 additions and 3 deletions.
  1. +1 −0 .gitignore
  2. +29 −3 NppSharp/NppInterface.cpp
  3. +1 −0 NppSharp/NppInterface.h
View
@@ -6,6 +6,7 @@
*.lib
*.ncb
*.obj
+*.opensdf
*.pch
*.pdb
*.sdf
View
@@ -287,12 +287,38 @@ namespace NppSharp
Bitmap^ bm = cmd->ToolbarIcon;
if (bm != nullptr)
{
- tbi.hToolbarBmp = (HBITMAP)bm->GetHbitmap().ToInt32();
-
- ::SendMessageW(_nppHandle, NPPM_ADDTOOLBARICON, GetPluginCommandId(cmd), (LPARAM)&tbi);
+ HBITMAP hUserBitmap = (HBITMAP)bm->GetHbitmap().ToInt32();
+ HBITMAP hBitmap = MakeCompatibleBitmap(hUserBitmap);
+ if (hBitmap)
+ {
+ tbi.hToolbarBmp = hBitmap;
+ ::SendMessageW(_nppHandle, NPPM_ADDTOOLBARICON, GetPluginCommandId(cmd), (LPARAM)&tbi);
+ ::DeleteObject(hUserBitmap);
+ }
}
}
+ HBITMAP NppInterface::MakeCompatibleBitmap(HBITMAP hUserBitmap)
+ {
+ BITMAP bmp;
+ if (!::GetObject(hUserBitmap, sizeof(bmp), &bmp)) return hUserBitmap;
+
+ HDC hSrcDC = ::CreateCompatibleDC(NULL);
+ ::SelectObject(hSrcDC, hUserBitmap);
+
+ HDC hNppDC = ::GetDC(_nppHandle);
+ HDC hDstDC = ::CreateCompatibleDC(hNppDC);
+ HBITMAP hBitmap = ::CreateCompatibleBitmap(hNppDC, bmp.bmWidth, bmp.bmHeight);
+ ::SelectObject(hDstDC, hBitmap);
+
+ ::BitBlt(hDstDC, 0, 0, bmp.bmWidth, bmp.bmHeight, hSrcDC, 0, 0, SRCCOPY);
+
+ ::DeleteDC(hSrcDC);
+ ::DeleteDC(hDstDC);
+ ::ReleaseDC(_nppHandle, hNppDC);
+ return hBitmap;
+ }
+
void NppInterface::OnTbModification()
{
RegisterToolbarIcons(this, gcnew EventArgs());
View
@@ -203,6 +203,7 @@ namespace NppSharp
private:
String^ GetFileNameByBufferId(unsigned int bufferId);
void DockWindow_Shutdown();
+ HBITMAP MakeCompatibleBitmap(HBITMAP hUserBitmap);
HWND _nppHandle;
HWND _scHandle1;

0 comments on commit 969dab0

Please sign in to comment.