Office-style menus

Share your advanced PureBasic knowledge/code with the community.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

that's really neat. thank you for this.

now, the good idea is to add icons support :)
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Post by eesau »

Updated the code in my first post (also put it between a single code-block for easier copy-pasting).

Added: Icon support! Add icons to menu items with:

Code: Select all

OfficeMenuSetIcon ( MenuID , ItemID , IconID )
Only native icons for now, will add support later for other image types. (See the "Tools"-menu for an example on how they look).

Added: Check marks. See "File"-menu for example.

Still to do:

- There's some slight flickering, I'll hopefully get rid of that by using memdc's.
- Fix code for Win98. Hard to do, since I don't have Win98 available right now, but I'll try anyway. The problems with the code and W98 is that previous Windows-versions had globally shared menu resources, which were very particular about what you did to them. W2K is probably the same. I'll see if I can find a fix though.
- Better icon support, different image formats and so on. Also, disabled icon states.
- Fix edit control (string gadget) context menus.
- Better coloring and color management.
- Slap the whole thing on a rebar, so we can get a menu identical to the ones in MS Office -products.

That's it for now, let me know if you find more bugs.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

This is getting better and better. Like the icons.

Doesn't seem to flicker on my system.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

On Vista the chr(9) stuff to put the keyboard shortcut on the right (right justified) just seems to do a regular tab. Haven't looked on anything other than Vista, maybe the same on others?
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Post by electrochrisso »

Great Work
Works great on my clunky old laptop under 98se but I get odd character next to some menu items, probably where the icons should go?. otherwise it works smoothly.
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Post by eesau »

electrochrisso wrote:Great Work
Works great on my clunky old laptop under 98se but I get odd character next to some menu items, probably where the icons should go?. otherwise it works smoothly.
What menu items exactly? Do you see any icons or checkmarks at all?
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Post by eesau »

Updated the code to include yet another hack to work around the system menu, hopefully the last one needed.
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

The Code seems not to Work on Windows 2000 (completely patched). I have a normal menu here without any Icon and some ASCII Codes in there....

Image
Tranquil
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

@Tranquil
change this line to If OSVersion ( ) => #PB_OS_Windows_98

Code: Select all

Procedure InitOffice ( Window ) 
    
   If OSVersion ( ) => #PB_OS_Windows_98 ; #PB_OS_Windows_XP 
    
      If Not GetProp_ ( WindowID ( Window ) , "OfficeMenuHook" ) 
         
         SetProp_ ( WindowID ( Window ) , "WindowProc" , SetWindowLong_ ( WindowID ( Window ) , #GWL_WNDPROC , @OfficeWindowCallback ( ) ) ) 
    
         SetProp_ ( WindowID ( Window ) , "OfficeMenuHook" , SetWindowsHookEx_ ( #WH_CALLWNDPROC , @OfficeHook ( ) , #Null , GetWindowThreadProcessId_ ( WindowID ( Window ) , #Null ) ) ) 
       
         ProcedureReturn #True 
       
      EndIf 

   EndIf 

   ProcedureReturn #Null 

EndProcedure
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Post by techjunkie »

Extremely super cool!! :D and very nice looking code! Great work!
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Post by eesau »

Added: Coloring that is system color-consistent and mimics Office about 99% accurately.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Brilliant, will be using this in the programs I write for work. Thanks. :D
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Post by eesau »

Oh, almost forgot. A big thanks to everyone for the nice comments :wink:
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

@eesau : again no run on Win98 :?:

Code: Select all

Procedure InitOffice ( Window ) 
    
   If OSVersion ( ) > #PB_OS_Windows_98 
    
      If Not GetProp_ ( WindowID ( Window ) , "OfficeMenuHook" ) 
         
         SetProp_ ( WindowID ( Window ) , "WindowProc" , SetWindowLong_ ( WindowID ( Window ) , #GWL_WNDPROC , @OfficeWindowCallback ( ) ) ) 
    
         SetProp_ ( WindowID ( Window ) , "OfficeMenuHook" , SetWindowsHookEx_ ( #WH_CALLWNDPROC , @OfficeHook ( ) , #Null , GetWindowThreadProcessId_ ( WindowID ( Window ) , #Null ) ) ) 
       
         ProcedureReturn #True 
       
      EndIf 

   EndIf 

   ProcedureReturn #Null 

EndProcedure 
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Post by eesau »

ABBKlaus wrote:@eesau : again no run on Win98 :?:

Code: Select all

If OSVersion ( ) > #PB_OS_Windows_98
Forgot to remove that :oops:

It *should* run on Win98, but I'll have to test some more.
Post Reply