Jump to content

Problem with one kind of button


 Share

Recommended Posts

  • Moderators

daxstec,

That type of button is created with the $BS_SPLITBUTTON style, but it needs a deal more work before you get the menu to appear when you press the arrowed section - so I am not surprised that you cannot yet add such a control in Koda. ;)

This thread explains how to make such a button work. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

daxstec,

Glad I could help. :)

You know where we are if you run into difficulties - it is not the easiset control to use after 2 days! ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

daxstec,

where is "Thank you" button ?

We decided not to use them - you will soon learn who gives good advice. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hello,

after running a below source code I got http://imageshack.us/photo/my-images/89/unledglr.png/ I use Windows 7 and I am a bit confused because in the code I see a part responsible for 'a support' of an arrow. What is wrong ?

Thanks for the hint/answer !

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>

Global $hButton_1, $hButton_2

_Main()

Func _Main()
    Local $hGUI

    $hGUI = GUICreate("Buttons", 400, 400)

    $hButton_1 = GUICtrlCreateButton("Split Button 1", 10, 10, 120, 30, $BS_SPLITBUTTON)
    $hButton_2 = _GUICtrlButton_Create($hGUI, "Split Button 2", 10, 50, 120, 30, $BS_SPLITBUTTON)
    _GUICtrlButton_SetSplitInfo($hButton_2) ; puts icon to left

    GUISetState()

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $hButton_1
                ConsoleWrite("Button 1 pressed" & @CRLF)
        EndSwitch
    WEnd

    Exit

EndFunc   ;==>_Main

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)

    #forceref $hWnd, $Msg, $wParam

    Local $tNMBHOTITEM = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;dword dwFlags", $lParam)
    Local $nNotifyCode = DllStructGetData($tNMBHOTITEM, "Code")
    ;Local $nID = DllStructGetData($tNMBHOTITEM, "IDFrom")
    Local $hCtrl = DllStructGetData($tNMBHOTITEM, "hWndFrom")
    ;Local $dwFlags = DllStructGetData($tNMBHOTITEM, "dwFlags")

    Switch $nNotifyCode
        Case $BCN_DROPDOWN
            _Popup_Menu($hCtrl)
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY

Func _Popup_Menu($hCtrl)

    Local $hMenu
    Local Enum $idOpen = 1000, $idSave, $idInfo
    Local $sButton = "Button 1"
    If $hCtrl = $hButton_2 Then $sButton = "Button 2"
    $hMenu = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $idOpen)
    _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $idSave)
    _GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0)
    _GUICtrlMenu_InsertMenuItem($hMenu, 3, "Info", $idInfo)
    Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hCtrl, -1, -1, 1, 1, 2)
        Case $idOpen
            ConsoleWrite($sButton & " Open" & @CRLF)
        Case $idSave
            ConsoleWrite($sButton & " Save" & @CRLF)
        Case $idInfo
            ConsoleWrite($sButton & " Info" & @CRLF)
    EndSwitch
    _GUICtrlMenu_DestroyMenu($hMenu)

EndFunc   ;==>_Popup_Menu

; React on a button click
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

    #forceref $hWnd, $Msg

    Local $nNotifyCode = BitShift($wParam, 16)
    ;Local $nID = BitAND($wParam, 0x0000FFFF)
    Local $hCtrl = $lParam
    Local $sText = ""
    Switch $hCtrl
        Case $hButton_2
            Switch $nNotifyCode
                Case $BN_CLICKED
                    $sText = "Button 2 Clicked"
            EndSwitch
    EndSwitch

    If $sText <> "" Then ConsoleWrite($sText & @CRLF)

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_COMMAND
Link to comment
Share on other sites

  • Moderators

daxstec,

in the code I see a part responsible for 'a support' of an arrow

Where? :)

I see nothing at all in the code about "support". ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hCtrl, -1, -1, 1, 1, 2)
        Case $idOpen
            ConsoleWrite($sButton & " Open" & @CRLF)
        Case $idSave
            ConsoleWrite($sButton & " Save" & @CRLF)
        Case $idInfo
            ConsoleWrite($sButton & " Info" & @CRLF)
    EndSwitch

I thought about eg. above code, I am right ? I want to obtain exactly sth like Posted Image do u have a working 'templete' for support of this button ? It will be great ! :)

Thanks for help !

Link to comment
Share on other sites

  • Moderators

daxstec,

But you already have a template to react to the button menu - it in the code that you posted! :)

Are you running the code in SciTE? If so, then you should see the menu selection appearing in the lower SciTE window courtesy of the ConsoleWrite lines. If you want something to happen in your script, then you need to replace those lines with some code your script can use. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

after one more time analysing of this script...I am a bit tired now, but I think you do not understand me, the problem is that after running script above I do NOT see a part http://imageshack.us/photo/my-images/801/unledhvq.png/. I see only two buttons with arrows (which I want to have) but after clicking on down arrow nothing happen, I dont see a list (popup). After analysing one more time this script in my opinion I should see this list (popup), right ? or not ?

Thanks !

Link to comment
Share on other sites

  • Moderators

daxstec,

I should see this list (popup), right ?

Yes, and I do see the popup menu when I click either button. If you are not seeing it then something is going very wrong. What OS are you running? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Windows 7 64 bit, I read that it works for Vista or Windows 7 so should work... all i can see is http://imageshack.us/f/846/unledlswo.png/

(for sure)

CTRL + A

CTRL + V

from SCiTE:

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>

Global $hButton_1, $hButton_2

_Main()

Func _Main()
    Local $hGUI

    $hGUI = GUICreate("Buttons", 400, 400)

    $hButton_1 = GUICtrlCreateButton("Split Button 1", 10, 10, 120, 30, $BS_SPLITBUTTON)
    $hButton_2 = _GUICtrlButton_Create($hGUI, "Split Button 2", 10, 50, 120, 30, $BS_SPLITBUTTON)
    _GUICtrlButton_SetSplitInfo($hButton_2) ; puts icon to left

    GUISetState()

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $hButton_1

                ConsoleWrite("Button 1 pressed" & @CRLF)
        EndSwitch
    WEnd

    Exit

EndFunc   ;==>_Main

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)

    #forceref $hWnd, $Msg, $wParam

    Local $tNMBHOTITEM = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;dword dwFlags", $lParam)
    Local $nNotifyCode = DllStructGetData($tNMBHOTITEM, "Code")
    Local $nID = DllStructGetData($tNMBHOTITEM, "IDFrom")
    Local $hCtrl = DllStructGetData($tNMBHOTITEM, "hWndFrom")
    Local $dwFlags = DllStructGetData($tNMBHOTITEM, "dwFlags")

    Switch $nNotifyCode
        Case $BCN_DROPDOWN
            _Popup_Menu($hCtrl)
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY

Func _Popup_Menu($hCtrl)

    Local $hMenu
    Local Enum $idOpen = 1000, $idSave, $idInfo
    Local $sButton = "Button 1"
    If $hCtrl = $hButton_2 Then $sButton = "Button 2"
    $hMenu = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $idOpen)
    _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $idSave)
    _GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0)
    _GUICtrlMenu_InsertMenuItem($hMenu, 3, "Info", $idInfo)
    Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hCtrl, -1, -1, 1, 1, 2)
        Case $idOpen
            ConsoleWrite($sButton & " Open" & @CRLF)
            MsgBox(0,"asd","asd")
        Case $idSave
            ConsoleWrite($sButton & " Save" & @CRLF)
        Case $idInfo
            ConsoleWrite($sButton & " Info" & @CRLF)
    EndSwitch
    _GUICtrlMenu_DestroyMenu($hMenu)

EndFunc   ;==>_Popup_Menu

; React on a button click
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

    #forceref $hWnd, $Msg

    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0x0000FFFF)
    Local $hCtrl = $lParam
    Local $sText = ""
    Switch $hCtrl
        Case $hButton_2
            Switch $nNotifyCode
                Case $BN_CLICKED
                    $sText = "Button 2 Clicked"
            EndSwitch
    EndSwitch

    If $sText <> "" Then ConsoleWrite($sText & @CRLF)

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_COMMAND

I do not know what is wrong :)

Edited by daxstec
Link to comment
Share on other sites

On Windows7/32bit I see also the popup menu.

daxstec, here is an alternative, if you use XP (or up): Ward's GUICtrlMenuEx:

Example of usage (Ward's):

; ===============================================================================================================================
; GUICtrlMenuEx UDF Example
; Purpose: Demonstrate The Usage Of GUICtrlMenuEx UDF
; Author:  Ward
; ===============================================================================================================================

#Include "GUICtrlMenuEx.au3"

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

Example1()
Example2()
Example3()
Example4()

Func Example1()
 Example("Example1", Default, 24, 24, 24, 24, "Basic Example")
EndFunc

Func Example2()

 Example("Example2", Default, 16, 36, 48, 64, "Differet Icon Size")
EndFunc

Func Example3()
 Example("Example3", True, 24, 24, 24, 24, "Force Use Callback (2K/XP Default)")
EndFunc

Func Example4()
 Example("Example4", False, 24, 24, 24, 24, "Force Not Use Callback (Vista/Win7 Default)")
EndFunc

Func Example($Title, $UseCallback, $Size1, $Size2, $Size3, $Size4, $Text)

 _GUICtrlMenuEx_Startup($UseCallback)

 Local $Icon1 = _WinAPI_ShellExtractIcons("C:\Windows\system32\shell32.dll", 0, $Size1, $Size1)
 Local $Icon2 = _WinAPI_ShellExtractIcons("C:\Windows\system32\shell32.dll", 1, $Size2, $Size2)
 Local $Icon3 = _WinAPI_ShellExtractIcons("C:\Windows\system32\shell32.dll", 2, $Size3, $Size3)
 Local $Icon4 = _WinAPI_ShellExtractIcons("C:\Windows\system32\shell32.dll", 3, $Size4, $Size4)
 Local $Icon5 = _WinAPI_ShellExtractIcons("C:\Windows\system32\shell32.dll", 7, 64, 64)

 Local $GUI = GUICreate($Title, 600)

 Local $SubMenu = _GUICtrlMenu_CreatePopup()
 _GUICtrlMenuEx_AddMenuItem($SubMenu, "Test Menu Item 1", 1001, $Icon1)
 _GUICtrlMenuEx_AddMenuItem($SubMenu, "Test Menu Item 2", 1002, $Icon2)
 _GUICtrlMenuEx_AddMenuBar($SubMenu)
 _GUICtrlMenuEx_AddMenuItem($SubMenu, "Test Menu Item 3", 1003, $Icon3)

 _GUICtrlMenuEx_InsertMenuItem($SubMenu, 1, "Test Menu Item Insertion", 1004, $Icon4)
 _GUICtrlMenuEx_InsertMenuBar($SubMenu, 1)

 Local $MainMenu = _GUICtrlMenu_CreateMenu()
 _GUICtrlMenu_AddMenuItem($MainMenu, $Text, 0, $SubMenu)
 _GUICtrlMenuEx_SetItemIcon($MainMenu, 0, $Icon5)
 _GUICtrlMenu_SetMenu($GUI, $MainMenu)

 GUISetState()

 _WinAPI_DestroyIcon($Icon1)
 _WinAPI_DestroyIcon($Icon2)
 _WinAPI_DestroyIcon($Icon3)
 _WinAPI_DestroyIcon($Icon4)
 _WinAPI_DestroyIcon($Icon5)

 While 1
  Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   GUISetState(@SW_HIDE)
   _GUICtrlMenuEx_DestroyMenu($SubMenu) ; Release the image resource used by GUICtrlMenuEx
   _GUICtrlMenuEx_DestroyMenu($MainMenu) ; Release the image resource used by GUICtrlMenuEx
   ExitLoop

  Case $GUI_EVENT_SECONDARYUP
   _GUICtrlMenu_TrackPopupMenu($SubMenu, $GUI)

  EndSwitch
 WEnd
EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
 Local $Code =_WinAPI_HiWord($wParam)
 If $Code = 0 Then ; Menu Command
  Local $MenuID = _WinAPI_LoWord($wParam)
  ConsoleWrite("MenuID " & $MenuID & @CRLF)
 EndIf
EndFunc

Func _WinAPI_ShellExtractIcons($Icon, $Index, $Width, $Height)
 Local $Ret = DllCall('shell32.dll', 'int', 'SHExtractIconsW', 'wstr', $Icon, 'int', $Index, 'int', $Width, 'int', $Height, 'ptr*', 0, 'ptr*', 0, 'int', 1, 'int', 0)
 If @Error Or $Ret[0] = 0 Or $Ret[5] = Ptr(0) Then Return SetError(1, 0, 0)
 Return $Ret[5]
EndFunc

GUICtrlMenuEx.au3

; ===============================================================================================================================
; GUICtrlMenuEx UDF
; Purpose: Icon Support For Standard GuiMenu UDF
; Author:  Ward
; ===============================================================================================================================

#Include-once
#Include <GUIConstants.au3>
#Include <GuiMenu.au3>
#Include <WindowsConstants.au3>

; ===============================================================================================================================
; Functions List:
; _GUICtrlMenuEx_Startup($UseCallBack = Default)
; _GUICtrlMenuEx_SetItemIcon($Menu, $Item, $Icon, $ByPos = True)
; _GUICtrlMenuEx_AddMenuItem($Menu, $Text, $CmdID = 0, $Icon = 0, $SubMenu = 0)
; _GUICtrlMenuEx_InsertMenuItem($Menu, $Index, $Text, $CmdID = 0, $Icon = 0, $SubMenu = 0)
; _GUICtrlMenuEx_AddMenuBar($Menu)
; _GUICtrlMenuEx_InsertMenuBar($Menu, $Index)
; _GUICtrlMenuEx_DeleteMenu($Menu, $Item, $ByPos = True)
; _GUICtrlMenuEx_DestroyMenu($Menu)
; ===============================================================================================================================

Global $__g_GUICtrlMenuEx_UseCallback

Func _GUICtrlMenuEx_Startup($UseCallback = Default)
 If IsKeyword($UseCallback) Then
  Switch @OSVersion
  Case "WIN_2008R2", "WIN_7", "WIN_2008", "WIN_VISTA"
   $UseCallback = False

  Case Else
   $UseCallback = True
  EndSwitch
 EndIf

 If $UseCallback Then
  GUIRegisterMsg($WM_DRAWITEM, "__GUICtrlMenuEx_WM_DRAWITEM")
  GUIRegisterMsg($WM_MEASUREITEM, "__GUICtrlMenuEx_WM_MEASUREITEM")
 Else
  GUIRegisterMsg($WM_DRAWITEM, "")
  GUIRegisterMsg($WM_MEASUREITEM, "")
 EndIf
 $__g_GUICtrlMenuEx_UseCallback = $UseCallback
EndFunc

Func _GUICtrlMenuEx_SetItemIcon($Menu, $Item, $Icon, $ByPos = True)
 If $Icon Then
  If $__g_GUICtrlMenuEx_UseCallback Then
   $Icon = _WinAPI_CopyIcon($Icon)
   Local $MENUITEMINFO = _GUICtrlMenu_GetItemInfo($Menu, $Item, $ByPos)
   DllStructSetData($MENUITEMINFO, "Mask", $MIIM_BITMAP)
   DllStructSetData($MENUITEMINFO, "BmpItem", -1) ; HBMMENU_CALLBACK
   _GUICtrlMenu_SetItemInfo($Menu, $Item, $MENUITEMINFO, $ByPos)
   _GUICtrlMenu_SetItemData($Menu, $Item, $Icon)
  Else
   Local $Bitmap = __GUICtrlMenuEx_CreateBitmapFromIcon($Icon)
   _GUICtrlMenu_SetItemBmp($Menu, $Item, $Bitmap, $ByPos)
  EndIf
  Return True
 EndIf
 Return False
EndFunc

Func _GUICtrlMenuEx_AddMenuItem($Menu, $Text, $CmdID = 0, $Icon = 0, $SubMenu = 0)
 Local $Index = _GUICtrlMenu_AddMenuItem($Menu, $Text, $CmdID, $SubMenu)
 _GUICtrlMenuEx_SetItemIcon($Menu, $Index, $Icon)
 Return $Index
EndFunc

Func _GUICtrlMenuEx_InsertMenuItem($Menu, $Index, $Text, $CmdID = 0, $Icon = 0, $SubMenu = 0)
 If _GUICtrlMenu_InsertMenuItem($Menu, $Index, $Text, $CmdID, $SubMenu) Then
  If _GUICtrlMenuEx_SetItemIcon($Menu, $Index, $Icon) Then Return True
 EndIf
 Return False
EndFunc

Func _GUICtrlMenuEx_AddMenuBar($Menu)
 Local $Item = _GUICtrlMenu_AddMenuItem($Menu, "")
 _GUICtrlMenu_SetItemType($Menu, $Item, $MFT_SEPARATOR)
EndFunc

Func _GUICtrlMenuEx_InsertMenuBar($Menu, $Index)
 If _GUICtrlMenu_InsertMenuItem($Menu, $Index, "") Then
  _GUICtrlMenu_SetItemType($Menu, $Index, $MFT_SEPARATOR)
  Return True
 EndIf
 Return False
EndFunc

Func _GUICtrlMenuEx_DeleteMenu($Menu, $Item, $ByPos = True)
 If $__g_GUICtrlMenuEx_UseCallback Then
  Local $Icon = _GUICtrlMenu_GetItemData($Menu, $Item, $ByPos)
  _WinAPI_DestroyIcon($Icon)
 Else
  Local $Bitmap = _GUICtrlMenu_GetItemBmp($Menu, $Item, $ByPos)
  _WinAPI_DeleteObject($Bitmap)
 EndIf
 Return _GUICtrlMenu_DeleteMenu($Menu, $Item, $ByPos)
EndFunc

Func _GUICtrlMenuEx_DestroyMenu($Menu)
 Local $Count = _GUICtrlMenu_GetItemCount($Menu)
 For $i = 1 To $Count
  _GUICtrlMenuEx_DeleteMenu($Menu, 0)
 Next
 Return _GUICtrlMenu_DestroyMenu($Menu)
EndFunc

Func __GUICtrlMenuEx_WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam)
 If $__g_GUICtrlMenuEx_UseCallback Then
  Local $MeasureItem = DllStructCreate('UINT CtlType;UINT CtlID;UINT itemID;UINT itemWidth;UINT itemHeight;ULONG_PTR itemData', $lParam)
  If DllStructGetData($MeasureItem, "CtlType") = 1 Then ; ODT_MENU = 1
   Local $Icon =  DllStructGetData($MeasureItem, "itemData")
   If $Icon Then
    Local $Size = __GUICtrlMenuEx_GetIconSize($Icon)
    DllStructSetData($MeasureItem, "itemWidth", $Size[0])
    DllStructSetData($MeasureItem, "itemHeight", $Size[1])
    Return TRUE
   EndIf
  EndIf
 EndIf
 Return 0
EndFunc

Func __GUICtrlMenuEx_WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
 If $__g_GUICtrlMenuEx_UseCallback Then
  Local $DrawItem = DllStructCreate('UINT CtlType;UINT CtlID;UINT itemID;UINT itemAction;UINT itemState;HWND hwndItem;HWND hDC;INT rcItem[4];ULONG_PTR itemData', $lParam)
  If DllStructGetData($DrawItem, "CtlType") = 1 Then ; ODT_MENU = 1
   Local $Icon =  DllStructGetData($DrawItem, "itemData")
   If $Icon Then
    Local $hDC = DllStructGetData($DrawItem, "hDC")
    Local $Left = DllStructGetData($DrawItem, "rcItem", 1)
    Local $Top = DllStructGetData($DrawItem, "rcItem", 2)
    _WinAPI_DrawIconEx($hDC, $Left / 2, $Top, $Icon, 0, 0, 0, 0, 3)
   EndIf
   Return TRUE
  EndIf
 EndIf
 Return 0
EndFunc

Func __GUICtrlMenuEx_GetIconSize($Icon)
 Local Const $tagBITMAP = "LONG bmType;LONG bmWidth;LONG bmHeight;LONG bmWidthBytes;WORD bmPlanes;WORD bmBitsPixel;ptr bmBits"
 Local $IconInfo = _WinAPI_GetIconInfo($Icon)

 Local $BITMAP = DllStructCreate($tagBITMAP)
 _WinAPI_GetObject($IconInfo[5], DllStructGetSize($BITMAP), DllStructGetPtr($BITMAP))

 Local $Width = DllStructGetData($BITMAP, "bmWidth")
 Local $Height = DllStructGetData($BITMAP, "bmHeight")

 _WinAPI_DeleteObject($IconInfo[4])
 _WinAPI_DeleteObject($IconInfo[5])

 Local $Ret[2] = [$Width, $Height]
 Return $Ret
EndFunc

Func __GUICtrlMenuEx_CreateBitmapFromIcon($Icon)
 Switch @OSVersion
 Case "WIN_2008R2", "WIN_7", "WIN_2008", "WIN_VISTA"
  Return __GUICtrlMenuEx_CreateBitmapFromIcon_Vista($Icon)

 Case Else
  Return __GUICtrlMenuEx_CreateBitmapFromIcon_XP($Icon)
 EndSwitch
EndFunc

Func __GUICtrlMenuEx_CreateBitmapFromIcon_XP($Icon)
 Local $Size = __GUICtrlMenuEx_GetIconSize($Icon)
 Local $DC = _WinAPI_GetDC(0)
 Local $DestDC = _WinAPI_CreateCompatibleDC($DC)
 Local $Bitmap = _WinAPI_CreateSolidBitmap(0, _WinAPI_GetSysColor($COLOR_MENU), $Size[0], $Size[1])
 Local $OldBitmap = _WinAPI_SelectObject($DestDC, $Bitmap)
 If $OldBitmap > 0 Then
  _WinAPI_DrawIconEx($DestDC, 0, 0, $Icon, 0, 0, 0, 0, 3) ; $DI_NORMAL = 3
  _WinAPI_SelectObject($DestDC, $OldBitmap)
 EndIf
 _WinAPI_ReleaseDC(0, $DC)
 _WinAPI_DeleteDC($DestDC)
 Return $Bitmap
EndFunc

Func __GUICtrlMenuEx_CreateBitmapFromIcon_Vista($Icon)
 Local Const $AC_SRC_OVER = 0x00
 Local Const $AC_SRC_ALPHA = 0x01
 Local Const $BPPF_ERASE = 0x01
 Local Enum  $BPBF_COMPATIBLEBITMAP, $BPBF_DIB, $BPBF_TOPDOWNDIB, $BPBF_TOPDOWNMONODIB

 Local $Size = __GUICtrlMenuEx_GetIconSize($Icon)
    Local $DestDC = _WinAPI_CreateCompatibleDC(0)
 Local $Bitmap = __GUICtrlMenuEx_Create32BitHBITMAP($DestDC, $Size)
 Local $OldBitmap = _WinAPI_SelectObject($DestDC, $Bitmap)
    If $OldBitmap > 0 Then
  Local $BlendFunction = DllStructCreate("BYTE BlendOp; BYTE BlendFlags; BYTE SourceConstantAlpha; BYTE AlphaFormat")
  DllStructSetData($BlendFunction, 1, $AC_SRC_OVER)
  DllStructSetData($BlendFunction, 2, 0)
  DllStructSetData($BlendFunction, 3, 255)
  DllStructSetData($BlendFunction, 4, $AC_SRC_ALPHA)

  Local $PaintParams = DllStructCreate("DWORD Size; DWORD Flags; ptr Exclude, ptr BlendFunction")
  DllStructSetData($PaintParams, "Size", DllStructGetSize($PaintParams))
  DllStructSetData($PaintParams, "Flags", $BPPF_ERASE)
  DllStructSetData($PaintParams, "BlendFunction", DllStructGetPtr($BlendFunction))

  Local $Rect = DllStructCreate($tagRECT)
  DllStructSetData($Rect, "Right", $Size[0])
  DllStructSetData($Rect, "Bottom", $Size[1])

  Local $PaintBuffer = __GUICtrlMenuEx_BeginBufferedPaint($DestDC, DllStructGetPtr($Rect), $BPBF_DIB, DllStructGetPtr($PaintParams))
  If Not @Error And $PaintBuffer[0] Then
   If _WinAPI_DrawIconEx($PaintBuffer[1], 0, 0, $Icon, 0, 0, 0, 0, 3) Then ; $DI_NORMAL = 3
    __GUICtrlMenuEx_ConvertBufferToPARGB32($PaintBuffer[0], $DestDC, $Icon, $Size)
   EndIf
   __GUICtrlMenuEx_EndBufferedPaint($PaintBuffer[0], True)
  EndIf
  _WinAPI_SelectObject($DestDC, $OldBitmap)
    EndIf
    _WinAPI_DeleteDC($DestDC)
    Return $Bitmap
EndFunc

Func __GUICtrlMenuEx_ConvertBufferToPARGB32($BufferedPaint, $hDC, $Icon, $Size)
 Local $Row
 Local $ARGBPtr = __GUICtrlMenuEx_GetBufferedPaintBits($BufferedPaint, $Row)
 Local $ARGB = DllStructCreate("dword[" & ($Size[0] * $Size[1]) & "]", $ARGBPtr)
 If Not __GUICtrlMenuEx_HasAlpha($ARGB, $Size, $Row) Then
  Local $IconInfo = _WinAPI_GetIconInfo($Icon)
  If $IconInfo[4] Then
   __GUICtrlMenuEx_ConvertToPARGB32($hDC, $ARGB, $IconInfo[4], $Size, $Row)
  EndIf
  _WinAPI_DeleteObject($IconInfo[4])
  _WinAPI_DeleteObject($IconInfo[5])
 EndIf
EndFunc

Func __GUICtrlMenuEx_HasAlpha($ARGB, $SizeImage, $Row)
 Local $Delta = $Row - $SizeImage[0]
 Local $Pos = 1

 For $y = $SizeImage[1] To 1 Step -1
  For $x = $SizeImage[0] To 1 Step -1
   If BitAND(DllStructGetData($ARGB, 1, $Pos), 0xFF000000) Then
    Return True
   EndIf
   $Pos += 1
  Next
  $Pos += $Delta
 Next
 Return False
EndFunc

Func __GUICtrlMenuEx_ConvertToPARGB32($hDC, ByRef $ARGB, $hBmp, $Size, $Row)
 Local $BITMAPINFO = DllStructCreate($tagBITMAPINFO)
 DllStructSetData($BITMAPINFO, "Size", DllStructGetSize($BITMAPINFO))
 DllStructSetData($BITMAPINFO, "Planes", 1)
 DllStructSetData($BITMAPINFO, "Compression", 0) ; BI_RGB
 DllStructSetData($BITMAPINFO, "Width", $Size[0])
 DllStructSetData($BITMAPINFO, "Height", $Size[1])
 DllStructSetData($BITMAPINFO, "BitCount", 32)

 Local $ARGBMask = DllStructCreate("dword[" & ($Size[0] * $Size[1]) & "]")
 If _WinAPI_GetDIBits($hDC, $hBmp, 0, $Size[1], DllStructGetPtr($ARGBMask), DllStructGetPtr($BITMAPINFO), 0) = $Size[1] Then
  Local $Delta = $Row - $Size[0]
  Local $Pos = 1

  For $y = $Size[1] To 1 Step -1
   For $X = $Size[0] To 1 Step -1
    If DllStructGetData($ARGBMask, 1, $Pos) Then
     DllStructSetData($ARGB, 1, 0, $Pos)
    Else
     DllStructSetData($ARGB, 1, BitOR(DllStructGetData($ARGB, 1, $Pos), 0xFF000000), $Pos)
    EndIf
    $Pos += 1
   Next
  Next
 EndIf
EndFunc

Func __GUICtrlMenuEx_Create32BitHBITMAP($hDC, $Size, $ppvBits = 0)
 Local $BITMAPINFO = DllStructCreate($tagBITMAPINFO)
 DllStructSetData($BITMAPINFO, "Size", DllStructGetSize($BITMAPINFO))
 DllStructSetData($BITMAPINFO, "Planes", 1)
 DllStructSetData($BITMAPINFO, "Compression", 0) ; BI_RGB
 DllStructSetData($BITMAPINFO, "Width", $Size[0])
 DllStructSetData($BITMAPINFO, "Height", $Size[1])
 DllStructSetData($BITMAPINFO, "BitCount", 32)
 Return __GUICtrlMenuEx_CreateDIBSection($hDC, DllStructGetPtr($BITMAPINFO), 0, $ppvBits, 0, 0)
EndFunc

Func __GUICtrlMenuEx_CreateDIBSection($hDC, $pbmi, $iUsage, $ppvBits, $hSection, $dwOffset)
 Local $Ret = DllCall("gdi32.dll", "hwnd", "CreateDIBSection", "hwnd", $hDC, "ptr", $pbmi, "uint", $iUsage, "ptr", $ppvBits, "hwnd", $hSection, "dword", $dwOffset)
 Return $Ret[0]
EndFunc

Func __GUICtrlMenuEx_BeginBufferedPaint($hdcTarget, $prcTarget, $dwFormat, $pPaintParams)
 Local $Ret = DllCall("UxTheme.dll", "hwnd", "BeginBufferedPaint", "hwnd", $hdcTarget, "ptr", $prcTarget, "dword", $dwFormat, "ptr", $pPaintParams, "hwnd*", 0)
 If Not @Error Then
  Local $Array[2] = [$Ret[0], $Ret[5]]
  Return $Array
 EndIf
 Return SetError(1, 0, 0)
EndFunc

Func __GUICtrlMenuEx_EndBufferedPaint($BufferedPaint, $UpdateTarget = True)
 Local $Ret = DllCall("UxTheme.dll", "hwnd", "EndBufferedPaint", "hwnd", $BufferedPaint, "int", $UpdateTarget)
 If Not @Error Then
  Return $Ret[0]
 EndIf
 Return SetError(1, 0, 0)
EndFunc

Func __GUICtrlMenuEx_GetBufferedPaintBits($BufferedPaint, ByRef $Row)
 Local $Ret = DllCall("UxTheme.dll", "int", "GetBufferedPaintBits", "hwnd", $BufferedPaint, "ptr*", 0, "int*", 0)
 If Not @Error Then
  $Row = $Ret[3]
  Return $Ret[2]
 EndIf
 Return SetError(1, 0, 0)
EndFunc

[EDIT] Here is a printscreen of the gui, after running your script from the previous post: http://imageshack.us/photo/my-images/534/cmenu.jpg/

Edited by taietel
Link to comment
Share on other sites

I do not know what is wrong ;)

It works in x86 so it's the structure that's bad. I don't know the correct one (Yashied is the expert :)) but a temporary fix is to use x86 AutoIt.

Add:

#AutoIt3Wrapper_UseX64=n

At the top of your script. You're gonna need to install SciTE4AutoIt3 if you don't have it already.

Link to comment
Share on other sites

@AdmiralManHairAlkex Thank you very much ! ! ! Now it works fine ! It is no problem to add one line to the code provided I know what exactly write and I know thanks to AdmiralManHairAlkex ! !

Thanks one more time, I was not sure that I am tired and it is my fault but I thought that it will be an issue of 74 bit.

Thanks ! !

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...