Author Topic: Icon from shell32.dll to dialog form  (Read 369 times)

Mikl__

  • Member
  • ****
  • Posts: 702
Icon from shell32.dll to dialog form
« on: July 08, 2018, 02:08:20 AM »
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--

  • Administrator
  • Member
  • ******
  • Posts: 5897
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Icon from shell32.dll to dialog form
« Reply #1 on: July 08, 2018, 02:49:58 AM »
Mikl__, I have not done this for years but from memory you need the resource ID and then use the normal API like LoadIcon.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Mikl__

  • Member
  • ****
  • Posts: 702
Re: Icon from shell32.dll to dialog form
« Reply #2 on: July 08, 2018, 03:20:31 AM »
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
Code: [Select]
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

  • Member
  • ****
  • Posts: 839
  • <AMD>< 7-32>
Re: Icon from shell32.dll to dialog form
« Reply #3 on: July 08, 2018, 04:17:44 AM »
Hi Mikl!!

Years I don't make a dialog, but... You are not declaring any icon
Code: [Select]
ICON_APP_32 ICON DISCARDABLE "../../ObjAsm32/Resources/Icons/OA32.ico"

Vortex

  • Member
  • *****
  • Posts: 1863
Re: Icon from shell32.dll to dialog form
« Reply #4 on: July 08, 2018, 04:54:32 AM »

fearless

  • Member
  • ***
  • Posts: 362
    • LetTheLightIn
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI

www.LetTheLight.in  My Github  Twitter

Mikl__

  • Member
  • ****
  • Posts: 702
Re: Icon from shell32.dll to dialog form
« Reply #6 on: July 08, 2018, 12:16:47 PM »
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
Code: [Select]
. . . .
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__

  • Member
  • ****
  • Posts: 702
Re: Icon from shell32.dll to dialog form
« Reply #7 on: July 08, 2018, 01:13:06 PM »
An interim solution of the problem
asm-file
Code: [Select]
. . . .
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-file
Code: [Select]
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        "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
« Last Edit: July 08, 2018, 05:00:37 PM by Mikl__ »

Mikl__

  • Member
  • ****
  • Posts: 702
Re: Icon from shell32.dll to dialog form
« Reply #8 on: July 08, 2018, 04:57:55 PM »
The previous code wrong displayed icons with an index greater than 53. This is the problem final solution
Code: [Select]
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

  • Member
  • *****
  • Posts: 8827
  • Assembler is fun ;-)
    • MasmBasic
Re: Icon from shell32.dll to dialog form
« Reply #9 on: July 08, 2018, 05:29:09 PM »
Another road for a standard Windows application:
Code: [Select]
  push 0
  invoke ExtractAssociatedIcon, 0, chr$("\Masm32\MasmBasic\icons\Eye.ico"), esp
  mov wc.hIcon, eax
  mov wc.hIconSm, eax
  pop edx

Mikl__

  • Member
  • ****
  • Posts: 702
Re: Icon from shell32.dll to dialog form
« Reply #10 on: July 08, 2018, 05:34:33 PM »
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

  • Member
  • *****
  • Posts: 8827
  • Assembler is fun ;-)
    • MasmBasic
Re: Icon from shell32.dll to dialog form
« Reply #11 on: July 08, 2018, 05:52:56 PM »
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__

  • Member
  • ****
  • Posts: 702
Re: Icon from shell32.dll to dialog form
« Reply #12 on: July 08, 2018, 06:13:31 PM »
Thanks, jj2007! I am continuing my experiments...

AW

  • Member
  • *****
  • Posts: 1562
  • Let's Make ASM Great Again!
Re: Icon from shell32.dll to dialog form
« Reply #13 on: July 09, 2018, 12:03:28 AM »
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__

  • Member
  • ****
  • Posts: 702
Re: Icon from shell32.dll to dialog form
« Reply #14 on: July 09, 2018, 12:27:46 AM »
Hi, AW!
Thank you