flat assembler
Message board for the users of flat assembler.

Index > Windows > Icon Trouble

Author
Thread Post new topic Reply to topic
calpol2004



Joined: 16 Dec 2004
Posts: 110
calpol2004
ive so far managed to give my application an icon, i have a dialog as my main window how can i make the icon appear in the top left corner of the dialog box?
Post 03 Jan 2006, 18:20
View user's profile Send private message MSN Messenger Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2
mov eax,[uMsg]
cmp eax,WM_INITDIALOG
jne @WM_COMMAND_MINIMIZED
invoke LoadIcon,[hInstance],IDI_ICON
invoke SendMessage,[hWin],WM_SETICON,TRUE,eax
Post 03 Jan 2006, 18:31
View user's profile Send private message Reply with quote
calpol2004



Joined: 16 Dec 2004
Posts: 110
calpol2004
hmm i tried ure code except i got errors with the compare and jump. i left them out and this happened:

1.the title of window was shifted to right as if the icon was there
2.there is no icon!


Description:
Filesize: 10.12 KB
Viewed: 2141 Time(s)

messenger.JPG


Post 03 Jan 2006, 18:45
View user's profile Send private message MSN Messenger Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2
Did you define IDI_ICON???? to something????

If so, post your code and executable. I will fix the problem for you
Post 04 Jan 2006, 00:21
View user's profile Send private message Reply with quote
calpol2004



Joined: 16 Dec 2004
Posts: 110
calpol2004
ok here my code . i have assigned an icon to ID_ICON as it the icon of the application when viewed in a folder, but it doesnt appear in top left corner of the dialog.

Code:
format PE GUI 4.0
entry start

include '..\..\include\win32a.inc'

ID_ICON     =   1
ID_USERNAME = 100
ID_MESSAGE  = 101
ID_SEND     = 102
ID_CLEAR    = 103

section '.data?' data readable writeable

   flags       dd ?
   message     dd ?
   length      rd 1
   sender      rd 21
   username    rd 21
   path        dd "send",0
   open        dd "open",0
   net         dd "net",0

section '.code' code readable executable

  start:
        invoke  GetModuleHandle,0
        invoke  DialogBoxParam,eax,37,HWND_DESKTOP,DialogProc,0
        or      eax,eax
        jz      exit
  exit:
        invoke  ExitProcess,0

proc DialogProc hwnddlg,msg,wparam,lparam
        push    ebx esi edi
        cmp     [msg],WM_INITDIALOG
        je      wminitdialog
        cmp     [msg],WM_COMMAND
        je      wmcommand
        cmp     [msg],WM_CLOSE
        je      wmclose
        xor     eax,eax
        jmp     finish
  wminitdialog:
        invoke  SetWindowPos,[hwnddlg],HWND_TOPMOST,0,0,0,0,SWP_NOMOVE+SWP_NOSIZE
        invoke  GetModuleHandle,0
        invoke  LoadIcon,eax,ID_ICON
        mov     eax,[msg]
        invoke  SendMessage,[hwnddlg],WM_SETICON,ICON_SMALL,eax
        jmp     processed
  wmcommand:
        mov     eax,[wparam]
        and     eax,0FFFFh
        cmp     eax,ID_SEND
        je      send
        cmp     eax,ID_CLEAR
        je      clear
        jmp     processed
        send:
                invoke GetUserName,sender,length+20
                invoke GetDlgItemText,[hwnddlg],ID_USERNAME,username,length+20
                invoke GetDlgItemText,[hwnddlg],ID_MESSAGE,message,length+449

                ;concenate strings here

                invoke ShellExecute,[hwnddlg],open,net,path,0,SW_HIDE
                invoke MessageBox,[hwnddlg],path,message,MB_OK
                jmp    processed
        clear:
                invoke SetDlgItemText,[hwnddlg],ID_USERNAME,""
                invoke SetDlgItemText,[hwnddlg],ID_MESSAGE,""
        jmp     processed
  wmclose:
        invoke  EndDialog,[hwnddlg],0
  processed:
        mov     eax,1
  finish:
        pop     edi esi ebx
        ret
endp

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',user,'USER32.DLL',shell,'SHELL32.DLL',advapi,'ADVAPI32.DLL'
  import kernel,GetModuleHandle,'GetModuleHandleA',ExitProcess,'ExitProcess'
  import user,DialogBoxParam,'DialogBoxParamA',GetDlgItemText,'GetDlgItemTextA',\
  SetDlgItemText,'SetDlgItemTextA',MessageBox,'MessageBoxA',EndDialog,'EndDialog',\
  SetWindowPos,'SetWindowPos',SendMessage,'SendMessageA',LoadIcon,'LoadIconA'
  import shell,ShellExecute,'ShellExecuteA'
  import advapi,GetUserName,'GetUserNameA'
  

section '.rsrc' resource data readable
  directory RT_DIALOG,dialogs,RT_ICON,icons,RT_GROUP_ICON,group_icons
  resource icons,1,LANG_NEUTRAL,icon_data
  resource group_icons,17,LANG_NEUTRAL,main_icon
  icon main_icon,icon_data,'icon.ico'
  resource dialogs,37,LANG_ENGLISH+SUBLANG_DEFAULT,messager
  dialog messager,'Messenger',340,280,180,55,DS_MODALFRAME+DS_CENTER+WS_POPUP+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX
  dialogitem 'EDIT','Insert Username Here',ID_USERNAME,2,5,121,15,WS_VISIBLE+WS_BORDER+WS_TABSTOP
  dialogitem 'EDIT','Insert Message Here',ID_MESSAGE,2,25,121,15,WS_VISIBLE+WS_BORDER+WS_TABSTOP+ES_AUTOHSCROLL
  dialogitem 'BUTTON','Send',ID_SEND,125,5,52,15,WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON
  dialogitem 'BUTTON','Clear',ID_CLEAR,125,25,52,15,WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON
  dialogitem 'STATIC','Created By Callum Lamb',-1,54,46,100,9,WS_VISIBLE
enddialog

    


Description:
Download
Filename: messenger.zip
Filesize: 10.32 KB
Downloaded: 61 Time(s)

Post 04 Jan 2006, 11:54
View user's profile Send private message MSN Messenger Reply with quote
calpol2004



Joined: 16 Dec 2004
Posts: 110
calpol2004
i accidentally pressed new thread instead of reply so it took me a while to realise and put here where it shud be Embarassed . but heres my code i have assigned an icon to ID_ICON ne ways heres my source see if u can see any problems.

Code:
format PE GUI 4.0 
entry start 

include '..\..\include\win32a.inc' 

ID_ICON     =   1 
ID_USERNAME = 100 
ID_MESSAGE  = 101 
ID_SEND     = 102 
ID_CLEAR    = 103 

section '.data?' data readable writeable 

   flags       dd ? 
   message     dd ? 
   length      rd 1 
   sender      rd 21 
   username    rd 21 
   path        dd "send",0 
   open        dd "open",0 
   net         dd "net",0 

section '.code' code readable executable 

  start: 
        invoke  GetModuleHandle,0 
        invoke  DialogBoxParam,eax,37,HWND_DESKTOP,DialogProc,0 
        or      eax,eax 
        jz      exit 
  exit: 
        invoke  ExitProcess,0 

proc DialogProc hwnddlg,msg,wparam,lparam 
        push    ebx esi edi 
        cmp     [msg],WM_INITDIALOG 
        je      wminitdialog 
        cmp     [msg],WM_COMMAND 
        je      wmcommand 
        cmp     [msg],WM_CLOSE 
        je      wmclose 
        xor     eax,eax 
        jmp     finish 
  wminitdialog: 
        invoke  SetWindowPos,[hwnddlg],HWND_TOPMOST,0,0,0,0,SWP_NOMOVE+SWP_NOSIZE 
        invoke  GetModuleHandle,0 
        invoke  LoadIcon,eax,ID_ICON 
        mov     eax,[msg] 
        invoke  SendMessage,[hwnddlg],WM_SETICON,ICON_SMALL,eax 
        jmp     processed 
  wmcommand: 
        mov     eax,[wparam] 
        and     eax,0FFFFh 
        cmp     eax,ID_SEND 
        je      send 
        cmp     eax,ID_CLEAR 
        je      clear 
        jmp     processed 
        send: 
                invoke GetUserName,sender,length+20 
                invoke GetDlgItemText,[hwnddlg],ID_USERNAME,username,length+20 
                invoke GetDlgItemText,[hwnddlg],ID_MESSAGE,message,length+449 

                ;concenate strings here 

                invoke ShellExecute,[hwnddlg],open,net,path,0,SW_HIDE 
                invoke MessageBox,[hwnddlg],path,message,MB_OK 
                jmp    processed 
        clear: 
                invoke SetDlgItemText,[hwnddlg],ID_USERNAME,"" 
                invoke SetDlgItemText,[hwnddlg],ID_MESSAGE,"" 
        jmp     processed 
  wmclose: 
        invoke  EndDialog,[hwnddlg],0 
  processed: 
        mov     eax,1 
  finish: 
        pop     edi esi ebx 
        ret 
endp 

section '.idata' import data readable writeable 

  library kernel,'KERNEL32.DLL',user,'USER32.DLL',shell,'SHELL32.DLL',advapi,'ADVAPI32.DLL' 
  import kernel,GetModuleHandle,'GetModuleHandleA',ExitProcess,'ExitProcess' 
  import user,DialogBoxParam,'DialogBoxParamA',GetDlgItemText,'GetDlgItemTextA',\ 
  SetDlgItemText,'SetDlgItemTextA',MessageBox,'MessageBoxA',EndDialog,'EndDialog',\ 
  SetWindowPos,'SetWindowPos',SendMessage,'SendMessageA',LoadIcon,'LoadIconA' 
  import shell,ShellExecute,'ShellExecuteA' 
  import advapi,GetUserName,'GetUserNameA' 
   

section '.rsrc' resource data readable 
  directory RT_DIALOG,dialogs,RT_ICON,icons,RT_GROUP_ICON,group_icons 
  resource icons,1,LANG_NEUTRAL,icon_data 
  resource group_icons,17,LANG_NEUTRAL,main_icon 
  icon main_icon,icon_data,'icon.ico' 
  resource dialogs,37,LANG_ENGLISH+SUBLANG_DEFAULT,messager 
  dialog messager,'Messenger',340,280,180,55,DS_MODALFRAME+DS_CENTER+WS_POPUP+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX 
  dialogitem 'EDIT','Insert Username Here',ID_USERNAME,2,5,121,15,WS_VISIBLE+WS_BORDER+WS_TABSTOP 
  dialogitem 'EDIT','Insert Message Here',ID_MESSAGE,2,25,121,15,WS_VISIBLE+WS_BORDER+WS_TABSTOP+ES_AUTOHSCROLL 
  dialogitem 'BUTTON','Send',ID_SEND,125,5,52,15,WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON 
  dialogitem 'BUTTON','Clear',ID_CLEAR,125,25,52,15,WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON 
  dialogitem 'STATIC','Created By Callum Lamb',-1,54,46,100,9,WS_VISIBLE 
enddialog 

    


and heres the whole package:


Description:
Download
Filename: messenger.zip
Filesize: 10.32 KB
Downloaded: 58 Time(s)

Post 04 Jan 2006, 14:05
View user's profile Send private message MSN Messenger Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
Code:
        invoke  GetModuleHandle,0
        invoke  LoadIcon,eax,ID_ICON
        mov     eax,[msg]
        invoke  SendMessage,[hwnddlg],WM_SETICON,ICON_SMALL,eax    


1. First of all. What does this "mov eax, [msg]" do here in the middle of other code? The point here is not to overwrite eax. Delete that line
2. Afaik, you pass RT_GROUP_ICON id to LoadIcon API not RT_ICON itself. Try "invoke LoadIcon, eax, 17"
Post 04 Jan 2006, 15:56
View user's profile Send private message Visit poster's website Reply with quote
calpol2004



Joined: 16 Dec 2004
Posts: 110
calpol2004
wow thx, works great, however im havin problems with the actual icons. it always assigns the first icon in the icon file to the top left corner (small 16x16) and the same in a winxp folder (supposed to be large 48x48) and also on desktop (32x32). say if i set my icon to a 16x16 or have 16x16 first in the icon file, small icons will be ok but 32x32 and 48x48 look weird as they show a rather enlarged pixelated icon even though i have 32x32 and 48x48 versions inside the icon files, and vice versa how can i make the application recognise all the icons in the icon file and display them appropriately instead of setting one icon for everything?
Post 04 Jan 2006, 18:06
View user's profile Send private message MSN Messenger Reply with quote
farrier



Joined: 26 Aug 2004
Posts: 274
Location: North Central Mississippi
farrier
calpol2004,

The following works for me with an app that has a dialog as the main window:


Code:
WindowsDir              rb      MAX_PATH

        invoke  GetModuleFileName, NULL, WindowsDir, MAX_PATH
                        ;Retrieve fully qualified exe name
        invoke  ExtractIcon, [gWnd], WindowsDir, 0
                        ;gets handle to icon from exe
        mov             [icon_hand], eax
        push    eax
        invoke  SendMessage, [gWnd], WM_SETICON, ICON_SMALL, eax
        pop             eax
        invoke  SendMessage, [gWnd], WM_SETICON, ICON_BIG, eax
    


hth,

farrier

_________________
Some Assembly Required
It's a good day to code!
U.S.Constitution; Bill of Rights; Amendment 1:
... the right of the people peaceably to assemble, ...
The code is dark, and full of errors!
Post 04 Jan 2006, 20:57
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
farrier: Maybe it works, but it's very unclean solution. I wouldn't involve SHELL32.DLL (ie. ExtractIcon API) at all. It's better to search for an error in previous code.

I already did this and answered in another thread. EAX is overwritten after calling for icon handle. Also bad resource id is passed
Post 04 Jan 2006, 21:31
View user's profile Send private message Visit poster's website Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2
Code:
format PE GUI 4.0 
entry start 

include '..\..\include\win32a.inc' 

ID_ICON     =   1 
ID_MAINDLG = 37
ID_USERNAME = 100 
ID_MESSAGE  = 101 
ID_SEND     = 102 
ID_CLEAR    = 103 

____MACRO_______________

macro @GetModuleHandle

{
          mov eax,dword [fs:18h]   ; API : GetModuleHandleA
          mov eax,dword [ds:eax+30h]  ;---------------
          mov eax,dword [ds:eax+8h]  ;--------------------

}


section '.data?' data readable writeable 

   flags       dd ? 
   message     dd ?
  hInstance  dd ? 
   length      rd 1 
   sender      rd 21 
   username    rd 21 
   path        dd "send",0 
   open        dd "open",0 
   net         dd "net",0 

section '.code' code readable executable 

  start: 
        @GetModuleHandle
        mov [hInstance],eax 
        invoke  DialogBoxParam,eax,ID_MAINDLG ,HWND_DESKTOP,DialogProc,0 
        test      eax,eax 
        jz      exit 
  exit: 
        invoke  ExitProcess,0 

proc DialogProc hwnddlg,msg,wparam,lparam 
        push    ebx esi edi 
        cmp     [msg],WM_INITDIALOG 
        je      wminitdialog 
        cmp     [msg],WM_COMMAND 
        je      wmcommand 
        cmp     [msg],WM_CLOSE 
        je      wmclose 
        xor     eax,eax 
        jmp     finish 
  wminitdialog: 
        invoke  SetWindowPos,[hwnddlg],HWND_TOPMOST,0,0,0,0,SWP_NOMOVE+SWP_NOSIZE 
        invoke  LoadIcon,[hInstance],ID_ICON 
        invoke  SendMessage,[hwnddlg],WM_SETICON,ICON_SMALL,eax 
        jmp     processed 
  wmcommand: 
        mov     eax,[wparam] 
        and     eax,0FFFFh 
        cmp     eax,ID_SEND 
        je      send 
        cmp     eax,ID_CLEAR 
        je      clear 
        jmp     processed 
        send: 
                invoke GetUserName,sender,length+20 
                invoke GetDlgItemText,[hwnddlg],ID_USERNAME,username,length+20 
                invoke GetDlgItemText,[hwnddlg],ID_MESSAGE,message,length+449 

                ;concenate strings here 

                invoke ShellExecute,[hwnddlg],open,net,path,0,SW_HIDE 
                invoke MessageBox,[hwnddlg],path,message,MB_OK 
                jmp    processed 
        clear: 
                invoke SetDlgItemText,[hwnddlg],ID_USERNAME,"" 
                invoke SetDlgItemText,[hwnddlg],ID_MESSAGE,"" 
        jmp     processed 
  wmclose: 
        invoke  EndDialog,[hwnddlg],0 
  processed: 
        mov     eax,1 
  finish: 
        pop     edi esi ebx 
        ret 
endp 

section '.idata' import data readable writeable 

  library kernel,'KERNEL32.DLL',user,'USER32.DLL',shell,'SHELL32.DLL',advapi,'ADVAPI32.DLL' 
  import kernel,GetModuleHandle,'GetModuleHandleA',ExitProcess,'ExitProcess' 
  import user,DialogBoxParam,'DialogBoxParamA',GetDlgItemText,'GetDlgItemTextA',\ 
  SetDlgItemText,'SetDlgItemTextA',MessageBox,'MessageBoxA',EndDialog,'EndDialog',\ 
  SetWindowPos,'SetWindowPos',SendMessage,'SendMessageA',LoadIcon,'LoadIconA' 
  import shell,ShellExecute,'ShellExecuteA' 
  import advapi,GetUserName,'GetUserNameA' 
   

section '.rsrc' resource data readable 
  directory RT_DIALOG,dialogs,RT_ICON,icons,RT_GROUP_ICON,group_icons 
  resource icons,1,LANG_NEUTRAL,icon_data 
  resource group_icons,17,LANG_NEUTRAL,main_icon 
  icon main_icon,icon_data,'icon.ico' 
  resource dialogs,37,LANG_ENGLISH+SUBLANG_DEFAULT,messager 
  dialog messager,'Messenger',340,280,180,55,DS_MODALFRAME+DS_CENTER+WS_POPUP+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX 
  dialogitem 'EDIT','Insert Username Here',ID_USERNAME,2,5,121,15,WS_VISIBLE+WS_BORDER+WS_TABSTOP 
  dialogitem 'EDIT','Insert Message Here',ID_MESSAGE,2,25,121,15,WS_VISIBLE+WS_BORDER+WS_TABSTOP+ES_AUTOHSCROLL 
  dialogitem 'BUTTON','Send',ID_SEND,125,5,52,15,WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON 
  dialogitem 'BUTTON','Clear',ID_CLEAR,125,25,52,15,WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON 
  dialogitem 'STATIC','Created By Callum Lamb',-1,54,46,100,9,WS_VISIBLE 
enddialog    
Post 05 Jan 2006, 04:40
View user's profile Send private message Reply with quote
farrier



Joined: 26 Aug 2004
Posts: 274
Location: North Central Mississippi
farrier
calpol2004,

You can use the "unclean" solution I gave you in "the other" thread using the ExtractIcon function, where you can specify which icon you wish to extract.

I've never been referred to as "unclean" before; I guess I'll have to have a talk with my Rabbi/Imam Shocked

hth,

farrier

_________________
Some Assembly Required
It's a good day to code!
U.S.Constitution; Bill of Rights; Amendment 1:
... the right of the people peaceably to assemble, ...
The code is dark, and full of errors!
Post 05 Jan 2006, 13:33
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
farrier wrote:
I've never been referred to as "unclean" before;
And I have never refer to you as "unclean". It was the solution you presented that I was judging.

farrier wrote:
You can use the "unclean" solution I gave you in "the other" thread using the ExtractIcon function, where you can specify which icon you wish to extract.
Yes, it is true. But doing so, you go around. The file is already loaded and all we need is to get the handle to icon. Your code is pointing to your own file to let it open once again and search in that new memory place. It is not needed and IMHO worse solution. The only difference is that using LoadIcon one must pass RT_GROUP_ICON id and in ExtractIcon one passes RT_ICON.
Post 05 Jan 2006, 19:18
View user's profile Send private message Visit poster's website Reply with quote
farrier



Joined: 26 Aug 2004
Posts: 274
Location: North Central Mississippi
farrier
Reverend,

Alright, now he has two ways of accomplishing the same thing.

I was kidding!

farrier

_________________
Some Assembly Required
It's a good day to code!
U.S.Constitution; Bill of Rights; Amendment 1:
... the right of the people peaceably to assemble, ...
The code is dark, and full of errors!
Post 05 Jan 2006, 20:28
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.