Page 1 of 1

Problem adding icon to Notepad++

Posted: Fri Mar 29, 2013 7:59 am
by Heinz123
Hello,

as part of an attempt to write a simple plugin for Notepad++ I want to add a new icon to the Notepad++ toolbar

For doing so I need to call sendMessage_ with the correct paramters are described here in this C snippet:

Code: Select all

g_TBWndMgr.hToolbarBmp = (HBITMAP)::LoadImage( (HINSTANCE)g_hInstance, MAKEINTRESOURCE(IDB_EX_MULTICLIPBOARD), IMAGE_BITMAP, 0, 0, (LR_LOADMAP3DCOLORS) );   
::SendMessage( g_NppData._nppHandle, NPPM_ADDTOOLBARICON, (WPARAM)funcItem[0]._cmdID, (LPARAM)&g_TBWndMgr ); }  
This is what I do in PB:

Code: Select all

Structure toolbarIcons 
    hToolbarBmp.l		;Handle for a BMP 
    hToolbarIcon.l		;Handle for a Icon
EndStructure

Global MyToolbaricon.toolbarIcons 

hIcon = CatchImage(1, ?myIcon)    ;get a OS handle to the icon

MyToolbaricon\hToolbarBmp  = hIcon  ;pass OS handle to structure
MyToolbaricon\hToolbarIcon =  0

;send NPPM_ADDTOOLBARICON message  and Icon handle to NPP
ret=SendMessage_(LocalNppData\nppHnd , #NPPM_ADDTOOLBARICON, FI.FuncItem(0)\cmdID, @MyToolbaricon) ; result = black square

DataSection
    myIcon: IncludeBinary "icon.bmp"  ;BMP  16x16, 256 colors, also tested with .ICO file
EndDataSection
Now my problem is that instead of an icon I only see a black square in the toolbar
(But when I click on it then my plugin is started...so this part works....)

From the information found here I understand that the .BMP format that is used in NPP is uncommon:
http://stackoverflow.com/questions/1383 ... hange-them

I have tested different .BMP and .ICO formats (converted with Irfanview) for my Icon but nothing worked –I see a black square only...

I even have extracted some icons from the Notepad++.exe just to have a sample image – but even if I try to add an original Icon to the toolbar it only shows a black square in the toolbar.
So I am not sure if my problem is a wrong BMP format (colors, transparency..) – maybe the problem is the coding, for example the sendmessage call ...?
But on the other hand if I click on that black square then my plugin is started...so it seems that the code basically works...

I dont know...maybe somebody has an idea what I can do..or maybe somebody can send me a .bmp or .ico that definitely works with NPP ..?

Heinz

Re: Problem adding icon to Notepad++

Posted: Fri Mar 29, 2013 3:31 pm
by IdeasVacuum
If you take a look at the 'closeAll.bmp' for example, it opens and displays just fine in IrfanView. It's 16x16x8 BPP.

So, it does not seem to be a special 'custom' format. Try downloading and testing an original NP++ icon with your code and if it does not display correctly, perhaps the code function is not quite right. If it does display correctly, then that means you are not quit getting the image format right?

Re: Problem adding icon to Notepad++

Posted: Sun Mar 31, 2013 8:02 pm
by Heinz123
IdeasVacuum wrote: perhaps the code function is not quite right.
Well, yes this is possible.
Maybe I need to use LoadImage_ and MAKEINTRESOURCE ?

All C++ Snippets that I can find regarding this problem use MAKEINTRESOURCE, for example:

Code: Select all

g_TBWndMgr.hToolbarBmp = (HBITMAP)::LoadImage( (HINSTANCE)g_hInstance, MAKEINTRESOURCE(IDB_EX_MULTICLIPBOARD), IMAGE_BITMAP, 0, 0, (LR_LOADMAP3DCOLORS) );   
::SendMessage( g_NppData._nppHandle, NPPM_ADDTOOLBARICON, (WPARAM)funcItem[1]._cmdID, (LPARAM)&g_TBWndMgr );  
So how would I use MAKEINTRESOURCE (together with WINAPI function LoadImage_ ?) in PB for loading a .bmp or .ico (Get a handle) ?
And does this mean that I must use resource (.rc) files ?
But it seems that LoadImage_ can also load .bmp/.com from disk as described here:
http://msdn.microsoft.com/en-us/library ... s.85).aspx

I would prefer to embed the icon into my .exe but if neccessary I will load the icon during runtime from disk or a .rc file if this will solve my problem.

Heinz

Re: Problem adding icon to Notepad++

Posted: Mon Apr 01, 2013 3:12 pm
by IdeasVacuum
I think how it is stored or loaded probably doesn't matter - the only bit to focus on is how to apply the image to the Notpad++ button. So, did you try testing with a dowloaded icon image?

Re: Problem adding icon to Notepad++

Posted: Mon Apr 01, 2013 3:40 pm
by Heinz123
IdeasVacuum wrote:I think how it is stored or loaded probably doesn't matter
Just 30 minutes ago I was able to add an icon :-)

What I did was that I now use a Resourcefile (.RC) to add the icon to the .DLL (the plugin)
Once the plugin starts it reads the icon basically from itself...

But I would prefer to use the other method using a Datasection and Catchimage.
I will keep trying..but at the moment I'm happy that it works with the resouce file.

So here is what I do:

Code: Select all

;open my DLL
OpenLibrary(0,sMyDLL)  

;get a handle to a bitmap that will become the icon
hicon  = LoadImage_(LibraryID(0),"#1001",#IMAGE_BITMAP,16,16,#LR_LOADMAP3DCOLORS | #LR_LOADTRANSPARENT)

;pass handle to a structure
LocalToolbaricons\hToolbarBmp  = hIcon  ;it seems that .bmp works better than .ico
LocalToolbaricons\hToolbarIcon = 0

;send message to NPP
ret=SendMessage_(LocalNppData\nppHnd , #NPPM_ADDTOOLBARICON, FI.FuncItem(0)\cmdID, @LocalToolbaricons) ;
Heinz

Re: Problem adding icon to Notepad++

Posted: Mon Apr 01, 2013 5:09 pm
by IdeasVacuum
:mrgreen: