News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Icon from shell32.dll to dialog form

Started by Mikl__, July 08, 2018, 02:08:20 AM

Previous topic - Next topic

Mikl__

Hi, all!
I know icon index in shell32.dll. How do extract that icon from the shell32.dll and display it on the dialog?

hutch--

Mikl__, I have not done this for years but from memory you need the resource ID and then use the normal API like LoadIcon.

Mikl__

I can extract any icon from any exe- or dll-file and display a path to exe- or dll-file and an icon index on the dialog, but I can not put the icon on the dialog
IDD_ICONDIALOGDEMO_DIALOG DIALOGEX 0, 0, 310, 70
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "IconDialogDemo"
FONT 8, "Tahoma"
BEGIN
    GROUPBOX        " Выбрана иконка ",IDC_STATIC_BORDER,4,7,299,52
    ICON            "",IDC_PIC_ICON,15,30,20,20
    EDITTEXT        IDC_TXT_ICONFILE,44,33,175,14,ES_AUTOHSCROLL | ES_LEFT
    EDITTEXT        IDC_TXT_ICONINDEX,224,33,36,12,ES_AUTOHSCROLL | ES_NUMBER
    CONTROL         "Spin1",IDC_SPN_ICONINDEX,"msctls_updown32",
                    UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_ARROWKEYS,256,32,
                    11,16
    PUSHBUTTON      "...",IDC_CMD_BROWSE,271,33,21,12
    LTEXT           "Имя файла, в котором находится иконка:",IDC_STATIC,44,21,175,8
    LTEXT           "Индекс иконки:",IDC_STATIC,224,21,53,8
END

HSE

Hi Mikl!!

Years I don't make a dialog, but... You are not declaring any iconICON_APP_32 ICON DISCARDABLE "../../ObjAsm32/Resources/Icons/OA32.ico"
Equations in Assembly: SmplMath

Vortex

Hi Mikl,

Is it about the DrawIcon function?

https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-drawicon

fearless

- https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-extracticona
- https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-extracticonexa


Mikl__

Hi, All!
It is partial solution of my problem
PickIconDlg function displays a dialog box that allows the user to choose an icon from the selection available embedded in a resource such as an executable or DLL file
. . . .
mov edx,offset pszIconPath
mov r9d,offset X
invoke PickIconDlg,0,,148   
        or      eax,eax
        jz      @f
mov r9d,offset dialog_procedure
and qword ptr [rsp+20h],0
invoke DialogBoxParam,IMAGE_BASE,IDD_ICONDIALOGDEMO_DIALOG,0
        . . .
dialog_procedure proc hDlg:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD
size_of_buffer equ 96
local buffer[size_of_buffer]:BYTE

mov hDlg,rcx

        cmp edx,WM_CLOSE
je wm_CLOSE
        cmp edx,WM_CLOSE
je wmCOMMAND
cmp edx,WM_INITDIALOG
jne wmBYE
wmINITDIALOG:lea ecx,buffer
mov edx,offset form
mov r8d,X
invoke wsprintf
lea r8d,buffer
        invoke SetDlgItemText,hDlg,IDC_TXT_ICONINDEX
lea r8d,offset pszIconPath
        invoke SetDlgItemTextW,hDlg,IDC_TXT_ICONFILE
mov ecx,offset pszIconPath
invoke LoadLibraryW
mov edx,X
inc edx
invoke LoadIcon,eax
invoke SendMessage,hDlg,WM_SETICON,ICON_BIG,eax
jmp wmBYE
wmCOMMAND:movzx eax,r8w ;movzx eax,word ptr wParam
or r9,r9 ;cmp lParam,0
jnz wmBYE
invoke SendMessage,,WM_CLOSE,0,0
jmp wmBYE
wm_CLOSE:invoke EndDialog,,0
wmBYE:  xor eax,eax
leave
retn
dialog_procedure endp
This is result of PickIconDlg function
It is what I get
But I want to get it

Mikl__

#7
An interim solution of the problem
asm-file . . . .
dialog_procedure proc hDlg:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD
size_of_buffer equ 96
local buffer[size_of_buffer]:BYTE

mov hDlg,rcx

        cmp edx,WM_CLOSE
je wm_CLOSE
        cmp edx,WM_CLOSE
je wmCOMMAND
        cmp edx,WM_PAINT
je wmPAINT
cmp edx,WM_INITDIALOG
jne wmBYE
wmINITDIALOG:lea ecx,buffer
mov edx,offset form
mov r8d,X
invoke wsprintf
lea r8d,buffer
        invoke SetDlgItemText,hDlg,IDC_TXT_ICONINDEX
lea r8d,offset pszIconPath
        invoke SetDlgItemTextW,hDlg,IDC_TXT_ICONFILE
mov ecx,offset pszIconPath
invoke LoadLibraryW
mov edx,X
inc edx
invoke LoadIcon,eax
mov hIcon,rax
invoke SendMessage,hDlg,WM_SETICON,ICON_BIG,eax
jmp wmBYE
wmPAINT:invoke GetDC
invoke DrawIcon,eax,20,50,hIcon
jmp wmBYE
wmCOMMAND:movzx eax,r8w ;movzx eax,word ptr wParam
or r9,r9 ;cmp lParam,0
jnz wmBYE
invoke SendMessage,,WM_CLOSE,0,0
jmp wmBYE
wm_CLOSE:invoke EndDialog,,0
wmBYE:  xor eax,eax
leave
retn
dialog_procedure endp
rc-fileIDD_ICONDIALOGDEMO_DIALOG DIALOGEX 0, 0, 310, 70
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "IconDialogDemo"
FONT 8, "Tahoma"
BEGIN
    GROUPBOX        "Icon Selection",IDC_STATIC_BORDER,4,7,299,52
    EDITTEXT        IDC_TXT_ICONFILE,44,33,175,14,ES_AUTOHSCROLL | ES_LEFT
    EDITTEXT        IDC_TXT_ICONINDEX,224,33,36,12,ES_AUTOHSCROLL | ES_NUMBER
    CONTROL         "Spin1",IDC_SPN_ICONINDEX,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_ARROWKEYS,256,32,11,16
    PUSHBUTTON      "...",IDC_CMD_BROWSE,271,33,21,12
    LTEXT           "Icon Library File Name:",IDC_STATIC,44,21,175,8
    LTEXT           "Icon Index:",IDC_STATIC,224,21,53,8
END

Mikl__

The previous code wrong displayed icons with an index greater than 53. This is the problem final solution dialog_procedure proc hDlg:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD
size_of_buffer equ 96
local buffer[size_of_buffer]:BYTE
local phiconLarge:qword
local phiconSmall:qword

mov hDlg,rcx

        cmp edx,WM_CLOSE
je wm_CLOSE
        cmp edx,WM_CLOSE
je wmCOMMAND
        cmp edx,WM_PAINT
je wmPAINT
cmp edx,WM_INITDIALOG
jne wmBYE
wmINITDIALOG:lea ecx,buffer
mov edx,offset form
mov r8d,X
invoke wsprintf
lea r8d,buffer
        invoke SetDlgItemText,hDlg,IDC_TXT_ICONINDEX
lea r8d,offset pszIconPath
        invoke SetDlgItemTextW,hDlg,IDC_TXT_ICONFILE
mov ecx,offset pszIconPath
mov edx,X
lea r8d,phiconLarge
lea r9d,phiconSmall
mov qword ptr [rsp+20h],1
        invoke ExtractIconExW
mov rax,phiconLarge
mov hIcon,rax
invoke SendMessage,hDlg,WM_SETICON,ICON_BIG,eax
jmp wmBYE
wmPAINT:invoke GetDC
invoke DrawIcon,eax,20,50,hIcon
jmp wmBYE
wmCOMMAND:;movzx eax,r8w ;movzx eax,word ptr wParam
or r9,r9 ;cmp lParam,0
jnz wmBYE
invoke SendMessage,,WM_CLOSE,0,0
jmp wmBYE
wm_CLOSE:invoke EndDialog,,0
wmBYE:  xor eax,eax
leave
retn
dialog_procedure endp
Special thanks to Vortex and fearless

jj2007

Another road for a standard Windows application:  push 0
  invoke ExtractAssociatedIcon, 0, chr$("\Masm32\MasmBasic\icons\Eye.ico"), esp
  mov wc.hIcon, eax
  mov wc.hIconSm, eax
  pop edx

Mikl__

Thank you jj2007!
I didn't know about ExtractAssociatedIcon... or "I not knew about ExtractAssociatedIcon" or "I haven't known about ExtractAssociatedIcon" How is more correct? 27 shades of temporary forms, I can go crazy

jj2007

I didn't know, either :P

It is lousily documented at MSDN. Inter alia, they don't mention that
- you can use a *.ico file instead of an executable,
- you can use zero as the module handle, and
- you must use zero for the lpiIcon WORD. But it works just fine.

Mikl__

Thanks, jj2007! I am continuing my experiments...

aw27

What you are trying to do is draw an icon to a picture control.
Although this is relatively easy (you must actually use DrawIcon or something similar), I am leaving this to you and will post instead a variation which is to change a button icon to some shell32.dll icon.
Source and exe attached:

Mikl__