AutoHotkey Community

It is currently May 27th, 2012, 7:13 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 29 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: January 24th, 2006, 10:04 pm 
Offline

Joined: February 12th, 2005, 8:31 pm
Posts: 82
One short question. ;)

Quote:
Menu_AssignBitmap( p_menu, p_item, p_bm_unchecked, p_unchecked_face, p_bm_checked=false, p_checked_face=false )

Did you forget to initialize "p_unchecked_face" with false or was it meant the way you wrote it above? I thought about:
Quote:
Menu_AssignBitmap( p_menu, p_item, p_bm_unchecked, p_unchecked_face=false, p_bm_checked=false, p_checked_face=false )

This would make assigning bitmaps easier when you just don't want to use a 'checked' bitmap or this LR_LOADTRANSPARENT feature. Assigning a picture would then just mean:
Code:
Menu_AssignBitmap("Tray", "1", item1.bmp)

Otherwise AHK keeps always saying you didn't pass enough parameters.

BTW. commented your script again. Don't know if it's of any use, but it makes copying from forum to your AHK scripts easier. :)

Code:
Menu_AssignBitmap(p_menu, p_item, p_bm_unchecked, p_unchecked_face=false, p_bm_checked=false, p_checked_face=false)
  {
    ; Thanks to shimanov for this function
    ; Details under http://www.autohotkey.com/forum/viewtopic.php?p=44577

    ; p_menu            = "MenuName" (e.g., Tray, etc.)
    ; p_item            = "MenuItemNumber" (e.g. 1, ...)
    ; p_bm_unchecked,
    ; p_bm_checked      = path to bitmap for unchecked 'n' checked menu entry/false
    ; p_unchecked_face,
    ; p_checked_face    = true/false (i.e., true = pixels with same color as
    ;                                 first pixel are transparent)

   
    static   menu_list, h_menuDummy
   
    If h_menuDummy=
    {
      menu_list = |
   
      ; Save current 'DetectHiddenWindows' mode to reset it later
      Old_DetectHiddenWindows := A_DetectHiddenWindows
      DetectHiddenWindows, on
     
      ; Retrieve scripts PID
      Process, Exist
      pid_this := ErrorLevel
     
      ; Create menuDummy and assign to Gui99
      Menu, menuDummy, Add
      Menu, menuDummy, DeleteAll
     
      Gui, 99:Menu, menuDummy
     
      ; Retrieve menu handle (menuDummy)
      h_menuDummy := DllCall( "GetMenu", "uint", WinExist( "ahk_class AutoHotkeyGUI ahk_pid " pid_this ) )
   
      ; Remove menu bar 'menuDummy'
      Gui, 99:Menu
     
      ; Reset 'DetectHiddenWindows' mode to old setting
      DetectHiddenWindows, %Old_DetectHiddenWindows%
    }
   
    ; Assign p_menu to menuDummy and retrieve menu handle
    If (! InStr(menu_list, "|" p_menu ",", false))
      {
        Menu, menuDummy, Add, :%p_menu%   
        menu_ix := DllCall( "GetMenuItemCount", "uint", h_menuDummy ) - 1
        menu_list = %menu_list%%p_menu%,%menu_ix%|
      }
    Else
      {
        menu_ix := InStr(menu_list, ",", false, InStr( menu_list, "|" p_menu ",", false)) + 1
        StringMid, menu_ix, menu_list, menu_ix, InStr(menu_list, "|", false, menu_ix) - menu_ix
      }
   
    h_menu := DllCall("GetSubMenu", "uint", h_menuDummy, "int", menu_ix)
   
    ; Load bitmap for unchecked menu entries
    If (p_bm_unchecked)
      {
        hbm_unchecked := DllCall( "LoadImage"
                                , "uint", 0
                                , "str", p_bm_unchecked
                                , "uint", 0                             ; IMAGE_BITMAP
                                , "int", 0
                                , "int", 0
                                , "uint", 0x10|(0x20*p_unchecked_face)) ; LR_LOADFROMFILE|LR_LOADTRANSPARENT
       
        If (ErrorLevel or ! hbm_unchecked)
          {
             MsgBox, [Menu_AssignBitmap: LoadImage: unchecked] failed: EL = %ErrorLevel%
             Return, false
          }
      }
   
    ; Load bitmap for checked menu entries
    If (p_bm_checked)
      {
        hbm_checked := DllCall( "LoadImage"
                              , "uint", 0
                              , "str", p_bm_checked
                              , "uint", 0                               ; IMAGE_BITMAP
                              , "int", 0
                              , "int", 0
                              , "uint", 0x10|(0x20*p_checked_face))     ; LR_LOADFROMFILE|LR_LOADTRANSPARENT
     
        If (ErrorLevel or ! hbm_checked)
          {
             MsgBox, [Menu_AssignBitmap: LoadImage: checked] failed: EL = %ErrorLevel%
             Return, false
          }
      }
   
    ; On success assign image to menu entry
    success := DllCall( "SetMenuItemBitmaps"
                      , "uint", h_menu
                      , "uint", p_item-1
                      , "uint", 0x400                                   ; MF_BYPOSITION
                      , "uint", hbm_unchecked
                      , "uint", hbm_checked )
                     
    If (ErrorLevel or ! success)
      {
        MsgBox, [Menu_AssignBitmap: SetMenuItemBitmaps] failed: EL = %ErrorLevel%
        Return, false
      }
   
    Return, true
  }

_________________
Cheers
BBCodeWriterToDo-ListCopyPassage


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2006, 10:22 pm 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
AGermanUser wrote:
Did you forget to initialize "p_unchecked_face" with false or was it meant the way you wrote it above?


I decided to require explicit specification of one set of bitmap parameters, so that users would not forget they exist -- I could go either way on this one.

Quote:
commented your script again


Thanks. It is useful, and helpful, to those who desire to understand the internals of the code; however, it is unnecessary for those who simply want to use the function.

I intend to leave the code as posted...

to mitigate the ire of those who would count lines.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2006, 7:05 pm 
Offline

Joined: February 24th, 2005, 8:45 am
Posts: 278
Very nice function. Thanks for sharing it. I really am in need of Assigning bitmaps to my MIGHTY BIG ALL IN ONE MENU.. :lol: Now here are my questions and problems:

First of all, does this function really assign an image as a context menu image or it just replaces the "check mark"(Tick) to the bitmap (I am guessing this because of the true and false parameters of the function.) And if it does... is this possible to PROPERLY assign a bitmap/ico to a menu?.

and second.. i used it with my script:
Code:
....................
Menu, movies_control, Add, Smallville, :smallville
............
Menu, Main, Add, Movies-Tv Serials Control, :movies_control
Menu_AssignBitmap( "movies_control", 1, "smallville_sec.bmp", false )
..........
your function goes here

When i run it for the first time, it works perfect:

Image

but when i run it again without closing the script it says:

Image
and the menu is shown but the img does not appear.

and the last problem is that when i try to add an image to a main menu(can be seen in the image as Folder Control, Program Control etc) it shows the same error.. here's the code:
Code:
.............
Menu, Main, Add
Menu, Main, Add, -=EXIT=-, Exit
..........
Menu_AssignBitmap( "Main", 6, "movies.bmp", false )
.........


so can someone please answer my questions..
Thanks again

_________________
My small "thanks" to AHK in shape of these dedicated 3d images
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2006, 7:58 pm 
Don't know if I can help you, but I used this function in my AHK CopyPassage script within the context menu. And it works like a charm.

Concerning your problem I guess it may be because of a changed menu handler or PID of your GUI. But this is a very rough guess. I may be completely wrong.
Maybe you have to post your complete code/script in order to help you.

btw. I predefine the third parameter in the function definition as false so that I mustn't enter a third parameter all the time.
_________________
Cheers
AGU a.k.a AGermanUser
Image


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 18th, 2006, 6:50 am 
Offline

Joined: February 24th, 2005, 8:45 am
Posts: 278
AGU wrote:
I guess it may be because of a changed menu handler or PID of your GUI


Sorry i forgot to tell .. in my script i dont have a GUI... just a MENU... maybe thats the reason?

AGU wrote:
but I used this function in my AHK CopyPassage script within the context menu. And it works like a charm.


Can you please send the only part of ur script which adds the bitmaps to menu's (Along the line which adds that specific menu)... and have u tried to add a bitmap to a Menu that has got more Submenu's? (Take a look at my posted image)

_________________
My small "thanks" to AHK in shape of these dedicated 3d images
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 18th, 2006, 1:10 pm 
Quote:
Can you please send the only part of ur script which adds the bitmaps to menu's (Along the line which adds that specific menu).


Definition des Kontextmenüs
Code:
; Create custom context menu
Menu, Context, Add, Open URL, CallUrl
Menu, Context, Add
Menu, Context, Add, Edit Note, EditNote
Menu, Context, Add, Delete Note, DeleteNote
Menu, Context, NoStandard

Menu_AssignBitmap("Context", "1", url_bmp)
Menu_AssignBitmap("Context", "3", edit_bmp)
Menu_AssignBitmap("Context", "4", delete_bmp)


Mit diesem Label wird das Menü aufgerufen
Code:
GuiContextMenu:
  RowSelected := LV_GetCount("S")
 
  If (A_GuiEvent = "RightClick" AND RowSelected)
    {
      Menu, Context, Show
    }
Return


Die Funktion "Menu_AssignBitmap" die ich verwende findest du hier:
http://www.autohotkey.net/~AGermanUser/ ... ctions.ahk
Quote:
.. and have u tried to add a bitmap to a Menu that has got more Submenu's? (Take a look at my posted image)
Nope, sorry. Haven't tried that yet.

Cheers
AGU


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2006, 8:26 am 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
sosaited wrote:
Very nice function.


Thanks.

Quote:
does this function really assign an image as a context menu image


Yes.

Quote:
replaces the "check mark"(Tick) to the bitmap (I am guessing this because of the true and false parameters of the function.)


Each menu item has an associated "checked" state. Hence:

shimanov wrote:
p_bm_unchecked,
p_bm_checked = path to bitmap/false
p_unchecked_face,
p_checked_face = true/false (i.e., true = pixels with same color as first pixel are transparent)


Note:

MSDN wrote:
If both parameters are NULL, the system displays the default check-mark bitmap when the item is selected, and removes the bitmap when the item is not selected.


Quote:
When i run it for the first time, it works perfect
...
but when i run it again without closing the script it says [error]


Do you use "Menu, <Delete|DeleteAll>" in your script? If so, then the problem is that the function caches the menu handles associated with previously defined menus, and does not account for deleted menus.

Quote:
try to add an image
...
Menu_AssignBitmap( "Main", 6, "movies.bmp", false )


Item #6 refers to a separator line. Try:

Code:
Menu_AssignBitmap( "Main", 11, "movies.bmp", false )


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2006, 9:04 pm 
Offline

Joined: February 24th, 2005, 8:45 am
Posts: 278
shimanov wrote:
Do you use "Menu, <Delete|DeleteAll>" in your script

Yes I do.
shimanov wrote:
If so, then the problem is that the function caches the menu handles associated with previously defined menus, and does not account for deleted menus.

I edited your function a little bit so just before it finishes, it DELETE's all Variable's.. Here's what i got:
If i add this at the end of your function: (i.e Delet all the variables)
Code:
   hbm_checked =
   success =
   hbm_unchecked =
   p_bm_unchecked =
   h_menu =
   p_item =
   p_bm_checked =
   h_menuDummy =
   menu_ix =
   menu_list =
   p_menu =
   p_unchecked_face =
   p_bm_checked =
   p_checked_face =

because the results are weird (at least for me) i am sending screenshots
The First "Run" works great:
Image
The Second run works "weird" :) : (The submenu "Arrow" Disappears but the Image is shown)
Image

And then, I added another Bitmap to the MAIN menu (by applying your suggested method : Menu_AssignBitmap( "Main", 11, "movies.bmp", false ) )
First run (with bitmaps assigned to both Menu item's): (Bitmap assigned to only one ITEM, Submenu's working)

Image

Surprisingly, Its second RUN gave error!:
Image

but after i clicked OK, the menu was displayed like this: (ALL SUBMENU's gone.. even the one's that had nothing to do with the Menu_AssignBitmap Function)
Image

and the cycle keeps repeating (in the case of Bitmaps assigned to both Menu Items) after second Run....

Now i am stuck.. i have no idea what is going on with this script, and my luck :lol: .. but i am sure as you are an expert shimanov and experienced in API .. and DllCall.. you can help me..

IF you need, Here are the files of my iMenu Script:
AHK Script File
Fav.ini (File required by script)
Movies.bmp
smallville_sec.bmp

Thanks

_________________
My small "thanks" to AHK in shape of these dedicated 3d images
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 23rd, 2006, 12:55 am 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
Sorry, at present, I don't have time to characterize or analyze AHk's menu command behavior.

So, here is a quick fix:

change:
Code:
MButton::
...
Menu, open_sub, Add, %v_currentname1%, open
}

> if menu_Main_init=
> {
> menu_Main_init := true

Menu, Main, Add, %A_Space%%A_Space%%A_Space%%A_Space%%A_Space%%A_Space%%A_Space%%A_Space%%A_Space%AESAM(Alpha v1.6), Info


change:
Code:
MButton::
...
Menu_AssignBitmap( "Main", "11", "movies.bmp", false )

> }

Menu, Main, Show


remove:
Code:
MButton::
...
> GetKeyState, v_mbuttonstate, MButton
> If v_mbuttonstate = U
>    Menu, Main, DeleteAll


Report this post
Top
 Profile  
Reply with quote  
 Post subject: update: 2006.03.22
PostPosted: March 23rd, 2006, 5:18 am 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
shimanov wrote:
Sorry, at present, I don't have time to characterize or analyze AHk's menu command behavior.


Never mind. It wasn't really a bug, but it was annoying. And I can appreciate the need for dynamic menu creation.

changes:
    * function prototype: p_unchecked_face=false (Thanks AGU)
    * support dynamically created menus (Thanks sosaited)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 24th, 2006, 11:26 am 
Offline

Joined: November 18th, 2005, 11:18 pm
Posts: 25
Location: Germany
...and how can I use my .ICO files for menus ?
At the moment this is working with .BMP files only.

_________________
greets Grendel


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 24th, 2006, 10:21 pm 
Offline

Joined: February 24th, 2005, 8:45 am
Posts: 278
Thanks alot shimanov.. it works without any problems now...

_________________
My small "thanks" to AHK in shape of these dedicated 3d images
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2006, 10:42 pm 
First off excellent work shimanov!!!

But im having a bit of trouble... I created a script that creates pictures under my startbutton that have custom menus that have applications in them. I use the attach bitmap function and it works great!...except that the pictures seem to be shifted or not fit. They are 16*16 so i would assume they would fit. Anyone know why this happens?

Image

view the code (note this will be a script that i post as soon as i work out the bugs, so you can use it, but be warned! there are bugs)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2006, 6:02 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
Anonymous wrote:
I use the attach bitmap function and it works great!...except that the pictures seem to be shifted or not fit. They are 16*16 so i would assume they would fit. Anyone know why this happens?

The pic looks ok to me... The alignment is likely due to the method used to add images. The images are added as custom checkmarks for menu items. The images are not automatically sized to fit AFAIK...


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 29 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Stigg and 22 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group