forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Add bitmaps to Menu items; Menu check/uncheck !!
Goto page 1, 2  Next
 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced VDS 5 Source Code
View previous topic :: View next topic  
Author Message
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1054
Location: India

PostPosted: Tue Jul 15, 2003 6:49 am    Post subject: Add bitmaps to Menu items; Menu check/uncheck !! Reply with quote

This script illustrates some of the advanced things you can do with menu dialog element in VDS 5:
1. Setting bitmaps against each menu item.
2. Checking unchecking a menu item.
3. Toggle the menu bitmap depending on whether the menu item is ticked or not.
4. Disable a menu item.

Note that 2 and 4 are part of the new options available in VDS 5, while others use a system dll and windows API.

I have added a single menu heading in this example viz FILE.
The naming of menu items follows a Zero based naming order as below:
0 1 2 3 4 5 6 7 8
0 0
1 1
2 2
3 so on
4

This will help U when U R trying to retrieve a menu handle to apply bitmaps to it.
See the comments in the script source code for further details.

For this example to work you need 13x13 or 14x14 bitmaps in the same directory as the dsc/exe file.
EDIT:
You can download the whole package including the bitmaps needed here:
http://www.vdsworld.com/index.php?page=download&fileid=297


One can also resize the menu to use bigger bitmaps - if anyone is interested let me know.
I am not planning currently to that though Wink.

Code:

#-----------------------------------------------------------------------------#
#-Calling a Non-VDs dll  Add bitmaps to Menu by CodeScript--------------------#
#-Author: CodeScript----------------------------------------------------------#
#-Copyright: You can remove this info while Using this code in your app.------#
#------------but may be kind enough to add a word to documentation------------#
REM USE AT YOUR OWN RISK !!
REM MISTAKES MADE WHILE USING A NON VDS DLL MAY INVITE A VDS/SYSTEM CRASH.
REM SAVE YOUR WORK BEFORE RUNNING/DEBUGGING THIS SCRIPT.
  Title Add bitmaps to Menu by CodeScript
  DIALOG CREATE,Add bitmaps to Menu - CodeScript,-1,0,398,106,CLASS MYWIN,RESIZABLE
  DIALOG ADD,TEXT,TEXT1,10,90,240,16,Make Sure bitmaps are in the app directory !
  DIALOG ADD,MENU,File,&New|Ctrl+N,&Open|Ctrl+O,Save|Ctrl+S,-,Print Preview,Print|Ctrl+P,-,Confirm Exit,-,E&xit|Alt+F4
  DIALOG ADD,BUTTON,BUTTON1,36,134,124,32,Disable Save
  DIALOG ADD,BUTTON,BUTTON2,36,134,124,32,Enable Save
  DIALOG ADD,TEXT,TEXT2,72,80,240,16,After clicking this button have a look at the MENU !
  DIALOG SHOW
 IF @NULL(@regread(DEFAULT, MenuCtrl,Save))
  Dialog Disable,BUTTON2
  Dialog Hide,BUTTON2
 else
  Dialog Disable,BUTTON1
  Dialog Hide,BUTTON1
end
    LOADLIB USER32
%H = @strdel(@WINEXISTS(#MYWIN),1,1)
 IF %H
REM  First load all the bitmaps into memory and get their handles:
      %A = @lib(user32,LoadImageA,INT:,0,new.bmp,0,0,0,$10)
      %B = @lib(user32,LoadImageA,INT:,0,open.bmp,0,0,0,$10)
      %C = @lib(user32,LoadImageA,INT:,0,save.bmp,0,0,0,$10)
      %D = @lib(user32,LoadImageA,INT:,0,preview.bmp,0,0,0,$10)
      %E = @lib(user32,LoadImageA,INT:,0,print.bmp,0,0,0,$10)
      %F = @lib(user32,LoadImageA,INT:,0,yes.bmp,0,0,0,$10)
      %G = @lib(user32,LoadImageA,INT:,0,no.bmp,0,0,0,$10)
REM GET THE HANDLE TO THE MENU BAR OF THE DIALOG
      %I = @lib(user32,GetMenu,INT:,%H)
REM  NOW GET THE HANDLE OF THE FIRST MENU OF THE DIALOG ie "FILE"
REM IT WILL BE ZERO'th ITEM - ZERO BASED NAMING 
      %K = @lib(user32,GetSubMenu,INT:,%I,0)
REM NOW START APPLYING THE BITMAPS FROM THE ZERO'th ITEM OF FILE
      %J = @lib(user32,SetMenuItemBitmaps,BOOL:,%K,0,$400,%A,%A)
      %J = @lib(user32,SetMenuItemBitmaps,BOOL:,%K,1,$400,%B,%B)
      %J = @lib(user32,SetMenuItemBitmaps,BOOL:,%K,2,$400,%C,%C)
REM REMEMBER !! EVEN SEPERATORS ARE COUNTED AS A MENU ITEM     
      %J = @lib(user32,SetMenuItemBitmaps,BOOL:,%K,4,$400,%D,%D)
      %J = @lib(user32,SetMenuItemBitmaps,BOOL:,%K,5,$400,%E,%E)
REM REMEMBER !! EVEN SEPERATORS ARE COUNTED AS A MENU ITEM       
      %J = @lib(user32,SetMenuItemBitmaps,BOOL:,%K,7,$400,%F,%G)
      %J = @lib(user32,DrawMenuBar,INT:,%H)
      FREELIB USER32
      ELSE
   ERROR -1
  end


:evloop
Wait event
goto @EVENT()

:RESIZE
goto EVLOOP

:NewMenu
goto EVLOOP

:OpenMenu
goto EVLOOP


:SaveMenu
INFO Add code to save your document !
goto EVLOOP

:BUTTON1BUTTON
REGISTRY WRITE, DEFAULT, MenuCtrl,Save, X
  Dialog Disable,BUTTON1
  Dialog Hide,BUTTON1
  Dialog Enable,BUTTON2
  Dialog show,BUTTON2
goto EVLOOP

:BUTTON2BUTTON
REGISTRY WRITE, DEFAULT, MenuCtrl,Save,
  Dialog Disable,BUTTON2
  Dialog Hide,BUTTON2
  Dialog Enable,BUTTON1
  Dialog show,BUTTON1
goto EVLOOP

:Print PreviewMenu
goto EVLOOP

:PrintMenu
goto EVLOOP

:Confirm ExitMenu
REM READ VDS 5 HELP ON MENU DIALOG ELEMENT
REM IF U DON'T UNDERSTAND CHECKING MENU ITEMS
REM AND DISABLING MENU ITEMS !
IF @NOT(@NULL(@regread(DEFAULT,,Confirm Exit)))
 REGISTRY WRITE, DEFAULT, ,Confirm Exit,
 ELSE
 REGISTRY WRITE, DEFAULT, ,Confirm Exit,1
 END
goto Evloop


:CLOSE
:ExitMenu
IF @NULL(@regread(DEFAULT,,Confirm Exit))
 %Q = @ASK(Are sure you want to Quit?@CR()@CR()To avoid seeing this message:@CR()Goto File->Confirm Exit and uncheck it !")")
 IF @EQUAL(%Q,1)
  exit
  else
  goto EVLOOP
  end
  ELSE
  EXIT
END


_______________________________________________________________________________________

_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension


Last edited by CodeScript on Thu Jul 31, 2003 6:24 pm; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Tue Jul 15, 2003 9:33 am    Post subject: Reply with quote

This is really cool! For the ones who want to use this in their applications, you can include the bitmap files within the EXE itself. Just extract them, and you can use them. Smile

Btw. CodeScript, how do you make a UUEncoded file?

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1054
Location: India

PostPosted: Tue Jul 15, 2003 10:25 am    Post subject: Reply with quote

Skit3000 wrote:
This is really cool! For the ones who want to use this in their applications, you can include the bitmap files within the EXE itself. Just extract them, and you can use them. Smile

Btw. CodeScript, how do you make a UUEncoded file?


I haven't figured out the problem as to why the bmps compiled into the exe dont work with this (I have pointed out to the resource name and also specified the hinst parameter and omited the LR_LOADFROMFILE from fuLoad correctly.Rolling Eyes

The only thing i didnt try was to load the image by ordinal using the MAKEINTRESOURCE macro. If U want U can try it. Smile

One can place the bmp's in a seperate directory like res etc to avoid clutter.

As for UUEncoding there are a lot of free UUEncoderrs/MIME encoders available on the net. U could simply use winzip also Smile .
BTW could U extract the images out of the UUE ?

_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Tue Jul 15, 2003 10:52 am    Post subject: Reply with quote

Yes, I could extract them. I think it's a handy way to place images etc. on this forum! Smile

Btw. I tried to make a sub-routine for your script which is easier in use. The only downside is that only 7 menu items can be used, because VDS doesn't pass any more variables to the script... Crying or Very sad

Code:
#define command,Menu

  DIALOG CREATE,My Program,-1,0,240,160,,CLASS MYWIN
  Menu Add,File,New|Ctrl+N|new.bmp,Open|Ctrl+O|open.bmp,-,Print Preview||preview.bmp,Print|Ctrl+P|print.bmp,Exit|Alt+F4
  Menu Add,Nothing here,a||new.bmp,b||open.bmp,c||preview.bmp,d||no.bmp,e||yes.bmp
  Menu Add,Help?!,a||test.bmp,b||open.bmp
  DIALOG SHOW

:Evloop
wait event
goto @event()

:Close
exit

rem You can save the unbeneath code into another file, so you can include it.

:Menu
%%itemcounter =
if @equal(%%menucounter,)
  %%menucounter = 0
  else
  %%menucounter = @succ(%%menucounter)
  end
 
if @equal(%1,Add)
 
  parse "%%name_1;%%hotkey_1",%3
  parse "%%name_2;%%hotkey_2",%4
  parse "%%name_3;%%hotkey_3",%5
  parse "%%name_4;%%hotkey_4",%6
  parse "%%name_5;%%hotkey_5",%7
  parse "%%name_6;%%hotkey_6",%8
  parse "%%name_7;%%hotkey_7",%9

if @equal(%4,)
  dialog add,menu,%2,%%name_1|%%hotkey_1
  elsif @equal(%5,)
  dialog add,menu,%2,%%name_1|%%hotkey_1,%%name_2|%%hotkey_2
  elsif @equal(%6,)
  dialog add,menu,%2,%%name_1|%%hotkey_1,%%name_2|%%hotkey_2,%%name_3|%%hotkey_3
  elsif @equal(%7,)
  dialog add,menu,%2,%%name_1|%%hotkey_1,%%name_2|%%hotkey_2,%%name_3|%%hotkey_3,%%name_4|%%hotkey_4
  elsif @equal(%8,)
  dialog add,menu,%2,%%name_1|%%hotkey_1,%%name_2|%%hotkey_2,%%name_3|%%hotkey_3,%%name_4|%%hotkey_4,%%name_5|%%hotkey_5
  elsif @equal(%9,)
  dialog add,menu,%2,%%name_1|%%hotkey_1,%%name_2|%%hotkey_2,%%name_3|%%hotkey_3,%%name_4|%%hotkey_4,%%name_5|%%hotkey_5,%%name_6|%%hotkey_6
  else
  dialog add,menu,%2,%%name_1|%%hotkey_1,%%name_2|%%hotkey_2,%%name_3|%%hotkey_3,%%name_4|%%hotkey_4,%%name_5|%%hotkey_5,%%name_6|%%hotkey_6,%%name_7|%%hotkey_7
  end

shift

  %%windowidentifier = @strdel(@winexists(@dlgtext()),1,1)
  IF %%windowidentifier
    repeat

      if @equal(%%itemcounter,)
        %%itemcounter = 0
        else
        %%itemcounter = @succ(%%itemcounter)
        end
     
      parse "%%name;%%hotkey;%%bitmap",%2

      if @unequal(%%bitmap,)

        loadlib user32
        REM  First load all the bitmaps into memory and get their handles:
        %A = @lib(user32,LoadImageA,INT:,0,%%bitmap,0,0,0,$10)
        REM GET THE HANDLE TO THE MENU BAR OF THE DIALOG
        %I = @lib(user32,GetMenu,INT:,%%windowidentifier)
        REM  NOW GET THE HANDLE OF THE FIRST MENU OF THE DIALOG ie "FILE"
        REM IT WILL BE ZERO'th ITEM - ZERO BASED NAMING 
        %K = @lib(user32,GetSubMenu,INT:,%I,%%menucounter)
        REM NOW START APPLYING THE BITMAPS FROM THE ZERO'th ITEM OF FILE
        %J = @lib(user32,SetMenuItemBitmaps,BOOL:,%K,%%itemcounter,$400,%A,%A)
        %J = @lib(user32,DrawMenuBar,INT:,%%windowidentifier)
        freelib user32
        end
                 
      shift
     
    until @equal(%2,)
   
    else
    error -1
    end
end

exit


Edit1: Changed some little bugs...

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!


Last edited by Skit3000 on Tue Jul 15, 2003 11:54 am; edited 1 time in total
Back to top
View user's profile Send private message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Tue Jul 15, 2003 11:52 am    Post subject: Reply with quote

Very excellent example! Thumbs Up Very Happy Very Happy
_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1054
Location: India

PostPosted: Tue Jul 15, 2003 1:15 pm    Post subject: Reply with quote

Hi Skit
It's nice to use an include as U did so that the user need not have to write the part to call the dll etc.
OK i think the 7 item limit can be probably overcome by using global variables or better still making a subroutine for using the same varables again and again - load into a string/ list using a seperator and parse - something like that - U R an expert in this area !

I would like to suggest to U that U can load user32.dll at the begining of the include portion just at the :Menu label and Unload it after all the bitmaps are set ie
Code:
until @equal(%2,)
just before unloading the dll call this :
Code:
%J = @lib(user32,DrawMenuBar,INT:,%%windowidentifier)
No need to call the dll repeatedly. Also you need to redraw the menu only once so that all the bitmaps U set R displayed.

This will avoid repeated load / unload and thereby trashing the dll Wink and also speed up the loading.

_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Tue Jul 15, 2003 2:02 pm    Post subject: Reply with quote

Thanks for the tip, I'll look into that. Now I will explain why that 7 item limit is there...

Menu Add,File,New|Ctrl+N|new.bmp,Open|Ctrl+O|open.bmp,-,Print Preview||preview.bmp,Print|Ctrl+P|print.bmp,Exit|Alt+F4

The first two variables (%1 and %2) are used for creating the menu. So only %3-%9 is left. Because you have to make a menu in once, and there cannot be any more parameter, you can only create a menu with 7 (9-2) items... I tried looping but that way the comma's which has to seperate the items won't work.

I hope the above text is understandable... Embarassed Wink

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Tue Jul 15, 2003 2:30 pm    Post subject: Reply with quote

Skit3000 wrote:
Thanks for the tip, I'll look into that. Now I will explain why that 7 item limit is there...

Menu Add,File,New|Ctrl+N|new.bmp,Open|Ctrl+O|open.bmp,-,Print Preview||preview.bmp,Print|Ctrl+P|print.bmp,Exit|Alt+F4

The first two variables (%1 and %2) are used for creating the menu. So only %3-%9 is left. Because you have to make a menu in once, and there cannot be any more parameter, you can only create a menu with 7 (9-2) items... I tried looping but that way the comma's which has to seperate the items won't work.

I hope the above text is understandable... Embarassed Wink


Skit,
Why don't you just do this replace the commas with carriage returns
Code:

[b]Menu Add,File,New|Ctrl+N|new.bmp@cr()Open|Ctrl+O|open.bmp@cr()-@cr()Print Preview||preview.bmp@cr()Print|Ctrl+P|print.bmp@cr()Exit|Alt+F4[/b]


Then in the body of your sub-routine/command/function just assign %3 to a VDS list and then parse the items?

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Tue Jul 15, 2003 3:05 pm    Post subject: Reply with quote

I want it to be VDS syntax. I thought about your way as well, but that's only confusing... Embarassed
_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
Tommy
Admin Team


Joined: 16 Nov 2002
Posts: 737
Location: The Netherlands

PostPosted: Tue Jul 15, 2003 3:51 pm    Post subject: Reply with quote

Skit, although I haven't looked very deeply into your code yet, wouldn't using the SHIFT
command resolve the problem with the limited number of parameter variables?

Skit3000 wrote:
Thanks for the tip, I'll look into that. Now I will explain why that 7 item limit is there...

Menu Add,File,New|Ctrl+N|new.bmp,Open|Ctrl+O|open.bmp,-,Print Preview||preview.bmp,Print|Ctrl+P|print.bmp,Exit|Alt+F4

The first two variables (%1 and %2) are used for creating the menu. So only %3-%9 is left. Because you have to make a menu in once, and there cannot be any more parameter, you can only create a menu with 7 (9-2) items... I tried looping but that way the comma's which has to seperate the items won't work.

I hope the above text is understandable... Embarassed Wink
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Wed Jul 16, 2003 10:09 am    Post subject: Reply with quote

No, I can't, look at this example:

Code:
%1 = a
%2 = b
%3 = c
%4 = d
%5 = e
%6 = f
%7 = g
%8 = h
%9 = i

repeat
  dialog add,menu,File,%1
  shift
until @equal(%1,)


You have to make a dialog yourself. After that you'll see why this doesn't work...

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1054
Location: India

PostPosted: Wed Jul 16, 2003 2:49 pm    Post subject: Reply with quote

I am not good at subroutines - never tried one Sad
But Skit

Another shortcoming with the subroutine U can try to overcome additionally is placing two bitamps per menu item based on whether it is checked or not. An user who is adding bitmaps to his menu would probably also like to add this functionality of different bitmaps for check and uncheck state of the menu item that is available in the script I wrote.

_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Wed Jul 16, 2003 2:55 pm    Post subject: Reply with quote

That will be the next thing to make... Wink
_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
X-Tools
Valued Contributor
Valued Contributor


Joined: 20 Sep 2001
Posts: 296
Location: Germany

PostPosted: Tue Aug 19, 2003 8:22 am    Post subject: Reply with quote

Hi,

does somebody know how to hide and show a menu using api ?
I am trying to replace the ssmenu.dll in my app with api codes.
I found all api's, but not show and hide.

Bye, Fabian
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Tue Aug 19, 2003 2:22 pm    Post subject: Reply with quote

X-Tools wrote:
Hi,

does somebody know how to hide and show a menu using api ?
I am trying to replace the ssmenu.dll in my app with api codes.
I found all api's, but not show and hide.

Bye, Fabian


Hi X-Tools,
I have an example that is part of the Gadget software package that will show you how to hide a menu. The script that plays with menus is the 3Bars.dsc script.
Basicly you would use the function RemoveMenu to hide the menu. RemoveMenu just hides the menu the menu handle and menu is still in memory and is not removed from memory it just removes it from the view of the dialog. To show that menu again you would have to use either InsertMenu or ModifyMenu which will let you put it back in the same spot or a new location.

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced VDS 5 Source Code All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum




Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group