Jump to content

How to insert cursors images in combobox


odaylton
 Share

Recommended Posts

I even understand that the Handle generated by _WinAPI_LoadCursor is not an Icon but how to display the image in the Combobox

Here is the listing and please tell me how to make the current user current cursorĀ image uncertainty

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
;dados de mouse
#include <WinAPIRes.au3>
;COMBO
#include <GuiComboBoxEx.au3>

Example()

Func Example()
    Local $hGUI, $hImage, $hCombo
    Local $idListview, $hImage
    Local $sWow64 = ""
    Local $Pasta="C:\WINDOWS\Cursors\3dgarro.cur"

    $hGUI = GUICreate("ImageList Mouse Icons", 400, 300)
    $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 394, 100)
    $idListview = GUICtrlCreateListView("", 2, 104, 394, 200, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
    GUISetState(@SW_SHOW)

    ; Load images
    $hImage = _GUIImageList_Create(16, 16)
    ;teste
    _GUIImageList_AddIcon($hImage, $Pasta)
    ;<<<<<<<<<<<<<<<<<<<<<this
    $hIcon= _WinAPI_CopyCursor(_WinAPI_LoadCursor(0,$IDC_HAND));32649 ; Hand cursor

        _GUIImageList_AddIcon($hImage, $hIcon);<<<<<<<<<<<<<<<<<< erro
    for $i=1 to 15
        $hIcon= _WinAPI_CopyCursor(_WinAPI_LoadCursor(0, $i));<<<<<<<<<<<<<<<<<
        _GUIImageList_AddIcon($hImage, $hIcon);<<<<<<<<<<<<
    Next
    _GUIImageList_AddIcon($hImage, $Pasta)
    _GUICtrlListView_SetImageList($idListview, $hImage, 1)
    _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Items", 120)

    ; Add items
    $a=StringSplit("testeIcone|HAND|APPSTARTING|ARROW|CROSS|HELP|IBEAM|ICON|NO|SIZE|SIZEALL|SIZENESW|SIZENS|SIZENWSE|SIZEWE|UPARROW|WAIT|testefim","|")
    For $i=1 to $a[0]
    _GUICtrlListView_AddItem($idListview, $a[$i], $i-1)
    _GUICtrlComboBoxEx_AddString($hCombo,  $a[$i], $i-1)
    Next

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

Note that only the initial image is uncertain because it comes from a file
And the one that would be the last enters as the second
And the background is black how to transform into transparent

imagem de cursor.bmp

Link to comment
Share on other sites

Something like this here?

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
;dados de mouse
#include <WinAPIRes.au3>
;COMBO
#include <GuiComboBoxEx.au3>

Example()

Func Example()
    Local $hGUI, $hImage, $hCombo
    Local $idListview, $hImage
    Local $sWow64 = ""
    Local $Pasta="C:\WINDOWS\Cursors\3dgarro.cur"

    $hGUI = GUICreate("ImageList Mouse Icons", 400, 300)
    $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 394, 100)
    $idListview = GUICtrlCreateListView("", 2, 104, 394, 200, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
    GUISetState(@SW_SHOW)

    ; Load images
    $hImage = _GUIImageList_Create(16, 16, 5)
    ;teste
    ;<<<<<<<<<<<<<<<<<<<<<this
    Local $aCursors[] = [ 32650, 32512, 32515, 32649, 32651, 32513, 32648, 32646, 32643, 32645, 32642, 32644, 32516, 32514 ]
    for $i=0 to UBound($aCursors) - 1
        $hIcon = _WinAPI_LoadCursor(0, $aCursors[$i])
        If $hIcon Then
            _GUIImageList_ReplaceIcon($hImage, -1, $hIcon)
            _WinAPI_DestroyIcon($hIcon)
        EndIf
    Next
    _GUICtrlListView_SetImageList($idListview, $hImage, 1)
    _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Items", 120)

    ; Add items
    $a=StringSplit("Standard arrow and small hourglass|Standard arrow|Crosshair|Hand|Arrow and question mark|I-beam|Slashed circle|Four-pointed arrow|Double-pointed arrow|Double-pointed arrow pointing|Double-pointed arrow|Double-pointed arrow|Vertical arrow|Hourglass","|")
    For $i=1 to $a[0]
    _GUICtrlListView_AddItem($idListview, $a[$i], $i-1)
    _GUICtrlComboBoxEx_AddString($hCombo,  $a[$i], $i-1)
    Next

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

Ā 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best! āœŒ
Her 'sikim hıyar' diyene bir avuƧ tuz alıp koşma!
ĀÆ\_(惄)_/ĀÆĀ  Ł©(ā—Ģ®Ģ®Ģƒā€¢Ģƒ)Ū¶ Ł©(-Ģ®Ģ®Ģƒ-Ģƒ)Ū¶ą«

Link to comment
Share on other sites

Many thanks for the prompt reply ...
What would be the nubs if it was not the masters.

It worked in part.
Images of icons are added ... ok
But in the Combobox after choosing item the mouse image does not appear

; Load images
    $hImage = _GUIImageList_Create(32, 32, 6);16,16,5) ;aumentei o icone e mudei o Image color depth


Note that I increased the size of the icon and changed (Image color depth) to display the icon when the item is selected, since it was disappearing when selected.
I tried changing the background color but it did not work

mouse em combo.JPG

Link to comment
Share on other sites

This code

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
;dados de mouse
#include <WinAPIRes.au3>
;COMBO
#include <GuiComboBoxEx.au3>

Example()

Func Example()
    Local $hGUI, $hImage, $hCombo
    Local $idListview, $hImage
    Local $sWow64 = ""
    Local $Pasta="C:\WINDOWS\Cursors\3dgarro.cur"

    $hGUI = GUICreate("ImageList Mouse Icons", 400, 310)
    $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 394, 200)
    $idListview = GUICtrlCreateListView("", 2, 50, 394, 250, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
    GUISetState(@SW_SHOW)

    ; Load images
    $hImage = _GUIImageList_Create(32, 32, 5, 5);16,16,5) ;aumentei o icone e mudei o Image color depth
    ;teste
    ;<<<<<<<<<<<<<<<<<<<<<this
    Local $aCursors[] = [ 32650, 32512, 32515, 32649, 32651, 32513, 32648, 32646, 32643, 32645, 32642, 32644, 32516, 32514 ]
    for $i=0 to UBound($aCursors) - 1
        $hIcon = _WinAPI_LoadCursor(0, $aCursors[$i])
        If $hIcon Then
            _GUIImageList_ReplaceIcon($hImage, -1, $hIcon)
            _WinAPI_DestroyIcon($hIcon)
        EndIf
    Next
    _GUICtrlListView_SetImageList($idListview, $hImage, 1)
    _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Items", 120)

    ; Add items
    $a=StringSplit("Standard arrow and small hourglass|Standard arrow|Crosshair|Hand|Arrow and question mark|I-beam|Slashed circle|Four-pointed arrow|Double-pointed arrow|Double-pointed arrow pointing|Double-pointed arrow|Double-pointed arrow|Vertical arrow|Hourglass","|")
    For $i=1 to $a[0]
    _GUICtrlListView_AddItem($idListview, $a[$i], $i-1)
    _GUICtrlComboBoxEx_AddString($hCombo,  $a[$i], $i-1, $i-1)
    Next

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

looks like this in my Win7 VM

Combo_Icon.png
Ā 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best! āœŒ
Her 'sikim hıyar' diyene bir avuƧ tuz alıp koşma!
ĀÆ\_(惄)_/ĀÆĀ  Ł©(ā—Ģ®Ģ®Ģƒā€¢Ģƒ)Ū¶ Ł©(-Ģ®Ģ®Ģƒ-Ģƒ)Ū¶ą«

Link to comment
Share on other sites

I did not imagine that a simple problem could cause so many changes.

I noticed the subtle changes from the previous code and again this is a genius thing.

But notice the icons of Cross and Iben, they are invisible because they are white and without any contour.

I again changed the _GUIImageList_Create (32, 32, 6, 2) function where the black background did display the invisible lines with white background.

Could it be that with your experience it would be possible to change the black color to a blue background at least for a better look ....

Ā 

Another issue:

For a better visualization I adopted as a pad the 32x32 size that seems to be the normal one of the cursor and with that I thought by well increase the font for size 14.

GUISetFont (14,400,0, "Arial")

Behold, the combobox did not accept it.

Not even using GUICtrlSetFont ($ hCombo, 14, 400, 0, "Arial")

So I snoozed the _GUICtrlComboBoxEx_Create function and noticed that it uses:

_WinAPI_SetFont ($ hCombo, _WinAPI_GetStockObject ($ __ COMBOBOXCONSTANT_DEFAULT_GUI_FONT))

In your code and thanks to the link:

How to change font of ComboBoxEx

I solved the mystery by unscrambling a font of size 30 in pixels to have the desired look

Here are the latest changes:

Ā 

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
;dados de mouse
#include <WinAPIRes.au3>
;COMBO
#include <GuiComboBoxEx.au3>
;Fonts
#include <FontConstants.au3>

Example()

Func Example()
    Local $hGUI, $hImage, $hCombo, $hFont
    Local $idListview, $hImage
    Local $sWow64 = ""
    Local $Pasta = "C:\WINDOWS\Cursors\3dgarro.cur"

    $hGUI = GUICreate("ImageList Mouse Icons", 500, 310)

    GUISetFont(14, 400, 0, "Arial");<<<<<<<<<<this does not work for _GUICtrlComboBoxEx_Create

    $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 494, 200)
    ;GUICtrlSetFont($hCombo, 14, 400, 0, "Arial");<<<<<<<<<<It does not work
    ;
    ;Create a handle to a font object
    $hFont = _WinAPI_CreateFont(30, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial')
    ;Pass the handle to _WinAPI_SetFont
    _WinAPI_SetFont($hCombo, $hFont)

    $idListview = GUICtrlCreateListView("", 2, 50, 494, 250, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
    GUISetState(@SW_SHOW)

    ; Load images
    $hImage = _GUIImageList_Create(32, 32, 6, 2) ;32,32,5,5) ;  ;<<<<<<<<<<<<<<<<<<<<<this
    Local $aCursors[] = [32650, 32512, 32515, 32649, 32651, 32513, 32648, 32646, 32643, 32645, 32642, 32644, 32516, 32514]
    For $i = 0 To UBound($aCursors) - 1
        $hIcon = _WinAPI_LoadCursor(0, $aCursors[$i])
        If $hIcon Then
            _GUIImageList_ReplaceIcon($hImage, -1, $hIcon)
            _WinAPI_DestroyIcon($hIcon)
        EndIf
    Next

    _GUICtrlListView_SetImageList($idListview, $hImage, 1)
    _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Icons - Mouses", 350)


    ; Add items
    $a = StringSplit("Standard arrow and small hourglass|Standard arrow|Crosshair|Hand|Arrow and question mark|I-beam|Slashed circle|Four-pointed arrow|Double-pointed arrow|Double-pointed arrow pointing|Double-pointed arrow|Double-pointed arrow|Vertical arrow|Hourglass", "|")
    For $i = 1 To $a[0]
        _GUICtrlListView_AddItem($idListview, $a[$i], $i - 1)
        _GUICtrlComboBoxEx_AddString($hCombo, $a[$i], $i - 1, $i - 1);<<<<<<<<<<<<<<<<<<<<this is just for geniuses
    Next

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

I suggest that this source detail can be corrected or exemplified within the autoit help

Ā 

I look forward to the new genius idea to partially solve the background color problem.

Preferably using GetSysColor

Ā 

Link to comment
Share on other sites

Here the version to change the background color

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
;dados de mouse
#include <WinAPIRes.au3>
;COMBO
#include <GuiComboBoxEx.au3>
;Fonts
#include <FontConstants.au3>
;background color
#include <GDIPlus.au3>

Example()

Func Example()
    Local $hGUI, $hImage, $hCombo, $hFont
    Local $idListview, $hImage
    Local $sWow64 = ""
    Local $Pasta = "C:\WINDOWS\Cursors\3dgarro.cur"

    $hGUI = GUICreate("ImageList Mouse Icons", 500, 310)

    GUISetFont(14, 400, 0, "Arial");<<<<<<<<<<this does not work for _GUICtrlComboBoxEx_Create

    $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 494, 200)
    ;GUICtrlSetFont($hCombo, 14, 400, 0, "Arial");<<<<<<<<<<It does not work
    ;
    ;Create a handle to a font object
    $hFont = _WinAPI_CreateFont(30, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial')
    ;Pass the handle to _WinAPI_SetFont
    _WinAPI_SetFont($hCombo, $hFont)

    $idListview = GUICtrlCreateListView("", 2, 50, 494, 250, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
    GUISetState(@SW_SHOW)

    _GDIPlus_Startup()
    ; Load images
    Local $iW = 32, $iH = 32, $iBgColor1 = 0xFFE0E0, $iBgColor2 = BitShift(BitAND(0xFF, $iBgColor1), -16) + BitAND(0xFF00, $iBgColor1) + BitShift(BitAND(0xFF0000, $iBgColor1), 16)
    $hImage = _GUIImageList_Create($iW, $iH, 5) ;32,32,5,5) ;  ;<<<<<<<<<<<<<<<<<<<<<this
    Local $aCursors[] = [32650, 32512, 32515, 32649, 32651, 32513, 32648, 32646, 32643, 32645, 32642, 32644, 32516, 32514]
    $hBmp = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp)
    _GUIImageList_SetBkColor ( $hImage, $iBgColor1) ;BGR
    For $i = 0 To UBound($aCursors) - 1
        $hIcon = _WinAPI_LoadCursor(0, $aCursors[$i])
        If $hIcon Then
            Switch $aCursors[$i]
                Case 32513, 32515
                    _GUIImageList_ReplaceIcon($hImage, -1, $hIcon)
                Case Else
                    $hImg = _GDIPlus_BitmapCreateFromHICON32($hIcon) ;convert the cursor to a bmp
                    _GDIPlus_GraphicsClear($hGfx, 0xFF000000 + $iBgColor2) ;ARGB
                    _GDIPlus_GraphicsDrawImageRect($hGfx, $hImg, 0, 0, $iW, $iH)
                    $hIconNew = _GDIPlus_HICONCreateFromBitmap($hBmp)
                    _GUIImageList_ReplaceIcon($hImage, -1, $hIconNew)
                    _WinAPI_DestroyIcon($hIconNew)
                    _GDIPlus_ImageDispose($hImg)
            EndSwitch
            _WinAPI_DestroyIcon($hIcon)
        EndIf
    Next
    _GDIPlus_GraphicsDispose($hGfx)
    _GDIPlus_ImageDispose($hBmp)

    _GUICtrlListView_SetImageList($idListview, $hImage, 1)
    _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Icons - Mouses", 350)


    ; Add items
    $a = StringSplit("Standard arrow and small hourglass|Standard arrow|Crosshair|Hand|Arrow and question mark|I-beam|Slashed circle|Four-pointed arrow|Double-pointed arrow|Double-pointed arrow pointing|Double-pointed arrow|Double-pointed arrow|Vertical arrow|Hourglass", "|")
    For $i = 1 To $a[0]
        _GUICtrlListView_AddItem($idListview, $a[$i], $i - 1)
        _GUICtrlComboBoxEx_AddString($hCombo, $a[$i], $i - 1, $i - 1);<<<<<<<<<<<<<<<<<<<<this is just for geniuses
    Next

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

Also for those two cursors (standard arrow and I-beam).

Edited by UEZ
Update

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best! āœŒ
Her 'sikim hıyar' diyene bir avuƧ tuz alıp koşma!
ĀÆ\_(惄)_/ĀÆĀ  Ł©(ā—Ģ®Ģ®Ģƒā€¢Ģƒ)Ū¶ Ł©(-Ģ®Ģ®Ģƒ-Ģƒ)Ū¶ą«

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

×
×
  • Create New...