May 24, 2024, 01:36:20 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Icons for Menu items

Started by Andy, June 13, 2012, 05:30:38 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Hi,

It's really two questions:

1, The attached is an example of how to add images to a menu item (click on the 'History' item to see)

How can I amend this to add an image to a Popup menu item?

2, Does anyone know where I can get some good Windows / system icons / bitmaps that are free for commercial use?

Thanks,
Andy.


Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

As best I can tell context menus are COM objects.
The api DoContextMenuPopup appears to be the command that creates one.
I don't know how to do com objects so that's all I can say about it.

As for icons; I had that problem when trying to come up with icons for IWB+ and the new IDE.
I purchased Axialis IconWorkshop.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

did some more digging on the context menu and it appears there is a way to do it and doesn't involve COM objects.

create your popup(context) menu kinda like this with the low level commands:

hPopup = CreateMenu(1)
APPENDMENU(hPopup,"Color",MF_STRING,1)
APPENDMENU(hPopup,"Attributes",MF_STRING,2)

so now you have the handle to the menu you can add your images

then display your context menu with this command
SHOWCONTEXTMENU mywin, hPopup, @MOUSEX, @MOUSEY


This should work.

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

I'm not sure 100% but from my expirience with menu the best option for me is use
direct way trough win32 api ,and all things work as espected.
of course this require much coding ...

LarryMc

I decided to take a break from the IDE and work on your problem.
I modified your code and fixed several problems right off the bat.

1. Every LOADIMAGE has to have a corresponding DELETEIMAGE or the memory isn't freed.
   So 1st I had to get rid of all the END statements in the windows handler.  That's because the proper place for the DELETEIMAGE commands is right after the WAITUNTIL statement is executed.
   Since the DELETEIMAGE command needs a handle and you weren't saving both handles I changed the variable to an array.
  Then I added the proper DELETEIMAGE commands.
2. You had 2 CENTERWINDOW commands.  One right after the window was created and one in the handler.
   I removed the 1st one.  But when I ran the program the window wasn't centered.
   That's when I noticed that you had @IDINITDILAOG in a window handler - doesn't work in windows; only for dialogs.
   I changed it to @IDCREATE and the window centers correctly.
3. When creating a context menu like we need you have a choice of triggering the popup menu with the WM_CONTEXTMENU message or the @IDRBUTTONUP message.  The latter is better because the @MOUSEX, @MOUSEY constants will contain the proper values for positioning.  If you use WM_CONTEXTMENU message the popup will appear in the upper right client area unless you add extra code for the mouse position.
4. I added the code to the handler to create the contextmenu and to show it
5. I then added the code to show a contextmenu option was clicked.
6. Also declared the handler sub properly and added RETURN 0 to get rid of error messages on compile.

Const MF_STRING=0
'Set menu bitmaps in CB 13x13 in 256 colors,by Aurel

def hID:int
def hbmp[2]:int
def hMenu:int
def hSubmenu:int
CONST MF_BITMAP = 0x4
DECLARE "user32",GetMenu(hwnd AS INT),INT
DECLARE "user32",GetSubMenu(hMenu AS INT,nPos AS INT),INT
DECLARE "user32",GetMenuItemID(hMenu AS INT,nPos AS INT),INT
DECLARE "user32",GetMenuItemCount(hMenu AS INT),INT
DECLARE "user32",SetMenuItemBitmaps(hMenu AS INT,nPosition AS INT,wFlags AS INT,hBitmapUnchecked AS INT,hBitmapChecked AS INT),INT

DEF reasontitle,reasonwhy,reasonwhy2,reasonwhy3:string

CONST button_2 = 2
CONST static_71 = 71
CONST static_72 = 72
CONST static_73 = 73

Def win:window
OPENWINDOW win,250,120,520,230,@MINBOX|@MAXBOX|@SIZE|@TOPMOST,0,reasontitle,&reasonscreenhandler
floodfill win,1,1,rgb(100,100,100)

CONTROL win,@STATIC,reasonwhy,0,42,520,25,@CTEDITCENTER,STATIC_71
CONTROL win,@STATIC,reasonwhy2,0,64,520,25,@CTEDITCENTER,STATIC_72
CONTROL win,@STATIC,reasonwhy3,0,86,520,25,@CTEDITCENTER,STATIC_73
CONTROL win,@BUTTON,"OK",225,140,70,25,0x50800009,BUTTON_2

'create menu
BEGINMENU win
MENUTITLE "&File"
MENUITEM "Quit",0,5000
MENUTITLE "Safety"
BEGINPOPUP "Safety settings"
MENUITEM "Add additional safety for " ,0,5001
MENUITEM "Remove additional safety for " ,0,5002
ENDPOPUP
MENUTITLE "History"
MENUITEM "Delete History",0,5003
MENUITEM "Show History",0,5009
MENUTITLE "Home"
MENUITEM "Set Home page",0,5004
MENUTITLE "Internet"
BEGINPOPUP "Internet connection"
MENUITEM "Disable  Internet",0,5005
MENUITEM "Enable  Internet",0,5006
ENDPOPUP
ENDMENU

AddPic2Menu()

WAITUNTIL win = 0
if hbmp[0] then DELETEIMAGE hbmp[0],@IMGBITMAP
if hbmp[1] then DELETEIMAGE hbmp[1],@IMGBITMAP
END

SUB reasonscreenhandler(),int
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW win
/* Initialize any controls here */
CASE @IDCLOSEWINDOW
CLOSEWINDOW win
      case @IDCHAR             
            Key = @CODE
            'Esc
            IF Key=27
CLOSEWINDOW win
            ENDIF
            'Enter
            IF key=13
CLOSEWINDOW win
            ENDIF
CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_2 'OK
IF @NOTIFYCODE = 0
                  CLOSEWINDOW win
ENDIF
ENDSELECT
CASE @IDRBUTTONUP
uint hPopup = CreateMenu(1)
APPENDMENU(hPopup,"Color",MF_STRING,1001)
hID = GetMenuItemID(hPopup,0)
SetMenuItemBitmaps(hPopup,hID,MF_BITMAP,hbmp[0],hbmp[0])
APPENDMENU(hPopup,"Attributes",MF_STRING,1002)
hID = GetMenuItemID(hPopup,1)
SetMenuItemBitmaps(hPopup,hID,MF_BITMAP,hbmp[1],hbmp[1])
SHOWCONTEXTMENU win, hPopup, @MOUSEX, @MOUSEY
CASE @IDMENUPICK
SELECT @MENUNUM
CASE 1001
messagebox win,"Color selected","right-click",0
CASE 1002
messagebox win,"Attributes selected","right-click",0
CASE 5000
CLOSEWINDOW win
ENDSELECT
ENDSELECT
RETURN 0
ENDSUB


Sub AddPic2Menu
'First get the menuhandle of your app
hMenu = GetMenu(win.hwnd)
'Then get the handle of the first submenu
hSubmenu = GetSubMenu(hMenu,2) 
     
hID = GetMenuItemID(hSubmenu,0) : 'Get the menu Id of the first entry
hbmp[0] = LOADIMAGE (GETSTARTPATH + "test2.bmp",@IMGBITMAP)
SetMenuItemBitmaps(hMenu,hID,MF_BITMAP,hbmp[0],hbmp[0])

hID = GetMenuItemID(hSubmenu,1)   
hbmp[1] = LOADIMAGE (GETSTARTPATH + "test.bmp",@IMGBITMAP)
SetMenuItemBitmaps(hMenu,hID,MF_BITMAP,hbmp[1],hbmp[1])
Return 0
ENDSUB

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Thanks Aurel & Larry.

Thanks for taking time out to look into this!

I am now in the process of making some bitmaps to suit my project.

When I have finished the bitmaps I will post them here - they may not be very professional but they may be some use to someone.

Thanks again!!

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Robert34

Thanks for the code to add bitmaps to menu items. This is cool.

I would like to know if it is possible to add Tool Tips to menu items?

Thanks,
Robert

LarryMc

Quote from: Robert34 on June 14, 2012, 10:17:13 AM
Thanks for the code to add bitmaps to menu items. This is cool.

I would like to know if it is possible to add Tool Tips to menu items?

Thanks,
Robert
The answer is yes.  There are numerous places on the web that show how.
Problem is the examples are in some form of C; and I'm not smart enough to convert it.
A good example is here

And here is a header file for a menu tooltip class which looks pretty straight forward.

Maybe someone with the time and skills will convert it for us.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Deleting / hiding a loaded bitmap from a window.

I have (thanks to everybody) now got a windows with 5 buttons on it, and 5 nice bitmaps next to the corresponding buttons.

Now, when you click on button number 3, the program hides buttons 1 & 2.

How can I hide / delete the 2 bitmaps that are next to buttons 1 & 2 when these buttons are hidden?


Can that be done?

When I have finished creating these bitmaps (up to 35 at the moment), would any one like them? (free for any use) and if so where can I post them on here?

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

Attached is the best I could come up with.
It requires that you have a blank image the same color as your window background.
Zip includes an exe file and my testing icons.

As for the icons you have created we can put them in the user offering section.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Thanks Larry,

Will give it a go,

And will post bitmaps / icons when done!

Thanks,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

The example posted above was based on the use of the LOADIMAGE,SHOWIMAGE, and DELETEIMAGE commands along with a blank image.

If you used bitmap images and STATIC controls to hold the images you don't need the blank image.
And you can show/hide the image just like any other control/window with the SHOWWINDOW command

Attached has exe and testing bitmaps.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Thanks Larry,

Have tried both ways, decided to go with the buttons_icon example and load a bitmap with the same background color to mask the bitmap.

I have one problem though, the attached browser_test2 example loads an icon called "site2.ico", it appears as a little grey icon in the urldlg window - But when the window is minimized to the taskbar and then restored on to screen the icon is "lost"?

Any ideas why / how to stop it?

Sorry to be a pain!

Thanks again,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

Quote from: andy1966 on June 17, 2012, 03:58:54 AM
I have one problem though, the attached browser_test2 example loads an icon called "site2.ico", it appears as a little grey icon in the urldlg window - But when the window is minimized to the taskbar and then restored on to screen the icon is "lost"?

Any ideas why / how to stop it?
Two ways that I know of to fix it.
1. Make it a static control like the images you wanted to disappear.

If you want/need to stick with the SHOWIMAGE way then modify the urlhandler to look like this:
SELECT @CLASS
   case @IDPAINT                                                 '<- added line
      SHOWIMAGE (*p.urldlg, icontwo, @IMGSCALABLE,250,38,16,16)  '<- added line
   CASE @IDCONTROL
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Thanks Larry,

Tried every which way before your suggestion!

Stuck with your suggestion and it works great!

Anyone know why CASE @IDPAINT makes the difference?

Anyway, thanks again.

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

Quote from: andy1966 on June 18, 2012, 05:18:48 AM
Anyone know why CASE @IDPAINT makes the difference?
Here's my story and I'm sticking to it till someone says I'm full of BS.

The SHOWIMAGE command draws the image from memory directly to the parent window's Device Context.
If the DC is erased and then redrawn there is no entity associated with the window that is storing the handle to the bitmap stored in memory and redrawing it for you..
Anytime there is any reason to redraw a window the WM_PAINT (@IDPAINT) message is sent to the window.  Unless you are doing ownerdrawn windows we don't usually have to worry with it.

When you create a static control you are actually creating a special window that has a place to store the bitmap handle and its internal WM_PAINT handler is programmed to redraw the bitmap for you.
(In my button and chart libraries I'm doing the WM_PAINT message handling from scratch.)

Like I said, that's my story and I'm sticking to it.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Hi,

Thanks all for your help,

I have posted some bitmaps in the "user offerings" section if anyone wants them.

Might not be the best first attempt but at least they are free if you can use them!

Thanks,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

Thanks for posting the bitmaps.
Can I ask why you picked a 'non-standard' size of 13x13 instead of the 'normal' 16x16 used in the toolbars?
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Hi Larry,

Simply because Aurel said he thought it was the best size.

Will do some more bitmaps soon, if you would like I will do them 16x16

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

Hey, I was just curious about the size choice.
It doesn't matter to me because I make my own.
I was just thinking in terms of dual purpose bitmaps (menus and toolbars)
The images I use in my menus for the new IDE are 16x16.

The point is you make them for your use the way you like them then if anyone wants to use them that is purely their choice.

I just like the idea you are sharing.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Always want to share no problem!
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.