News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

adding icons

Started by Telefunken, July 16, 2006, 09:26:52 PM

Previous topic - Next topic

p0wder

Well, that does work - but only with the window title. I am still dealing with it not working in the tray ... i just see the generic executable icon in the tray now.

However, the code [posted above, but not working ... includes a SendMessage call, which I understand the API sendmessage, but not what this does]    

This code is what generates the error, but i think that this is what will help with the tray icon .. any ideas?


; Set Icon File
.if uMsg==WM_INITDIALOG
INVOKE LoadIcon, hInstance, 2
INVOKE SendMessage, hWin, WM_SETICON, ICON_BIG OR ICON_SMALL, EAX
.endif


-p0wder.

zooba

Same deal as what Mark said for the tray icon:

Quote INVOKE LoadIcon,NULL,IDI_WINLOGO
MOV note.hIcon,eax

Load your own icon here rather than a system one.

Also, the SendMessage line will be failing because it has hWin as a parameter, which is not defined. It should probably be hWnd.

Cheers,

Zooba :U

p0wder


Hmm, maybe I am retarded, but this is what I have so far, and it still does not work, but no errors ... The window title icon works, but the tray icon is still a generic .exe files icon.


WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
MOV   wc.cbSize, SIZEOF WNDCLASSEX
MOV   wc.style, CS_HREDRAW OR CS_VREDRAW OR CS_DBLCLKS
MOV   wc.lpfnWndProc, OFFSET WndProc
MOV   wc.cbClsExtra, NULL
MOV   wc.cbWndExtra, NULL
PUSH  hInst
POP   wc.hInstance
MOV   wc.hbrBackground,COLOR_APPWORKSPACE
MOV   wc.lpszMenuName, NULL
MOV   wc.lpszClassName, OFFSET ClassName
;Set Tray Icon
INVOKE LoadIcon,NULL,IDI_WINLOGO
MOV note.hIcon,eax
; Set Windows title icon
INVOKE LoadIcon, hInstance, 2
MOV   wc.hIcon, EAX
MOV   wc.hIconSm, EAX

Mark Jones

Quote from: p0wder on July 20, 2006, 12:39:50 PM
Well, that does work - but only with the window title. I am still dealing with it not working in the tray ... i just see the generic executable icon in the tray now.

You are welcome. :toothy
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

p0wder

Thanks Mark! any Ideas why the icon does not show up in the tray though?

Mark Jones

Hmm, I seem to recall some added steps necessary for tray-icon manipulation. Try tinkering with this (IDI_ICON is resource 100 in rsrc.rc):


    WM_TRAY     equ WM_USER+120
    IDI_TRAY    equ 245
.data?
    iconData    NOTIFYICONDATA<?>
.code

WndProc proc hwnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
    mov eax,uMsg

    .if (eax==WM_TRAY)                          ; tray icon handler
        .if (wParam==IDI_TRAY)
            .if (lParam==WM_LBUTTONUP)          ; left button
                ; left button click
            .elseif (lParam==WM_RBUTTONUP)      ; right button
                ; right button click
            .endif
        .endif

    .elseif (eax==WM_CREATE)                    ; setup tray structures
        push edi                                ; use edi as NOTIFYICONDATA
        lea edi,iconData
        assume edi:ptr NOTIFYICONDATA
        mov [edi].cbSize,sizeof NOTIFYICONDATA
        mov eax,hwnd
        mov [edi].hwnd,eax
        mov [edi].uID,IDI_TRAY
        mov [edi].uFlags,NIF_ICON or NIF_MESSAGE or NIF_TIP
        mov [edi].uCallbackMessage,WM_TRAY
        invoke LoadIcon,hInstance,100           ; tray icon
        mov [edi].hIcon,eax
        invoke lstrcpy,addr [edi].szTip,addr AppTip
        invoke Shell_NotifyIcon,NIM_ADD,edi     ; load it
        assume edi:nothing
        pop edi                                 ; restore edi when done

    .elseif (eax==WM_DESTROY)
        invoke Shell_NotifyIcon,NIM_DELETE,addr iconData
        invoke PostQuitMessage,0

    .else                                       ; else default handler
        invoke DefWindowProc,hwnd,uMsg,wParam,lParam
        ret
       
    .endif
    xor eax,eax                                 ; always return zero here
    ret
WndProc endp
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

p0wder

hm, thats not even going to the tray now, but i am going to keep playing with it. someone had once told me that a recource file could use an icon with just a few adjustments for the tray, exe in explorer and the window title. going to try and figure it out :P

PBrennick



This is the way to do it.

In the rc file ...

4000 ICON "na.ico"


In the asm file ...

    .IF uMsg == WM_CREATE

      mov    hIconRW, rv(LoadImage,hInstance,1000,IMAGE_ICON,16,16,NULL)
      mov    hIconRead, rv(LoadImage,hInstance,2000,IMAGE_ICON,0,0,NULL)
      mov    hIconWrite, rv(LoadImage,hInstance,3000,IMAGE_ICON,0,0,NULL)
      mov    hIconNA, rv(LoadImage,hInstance,4000,IMAGE_ICON,0,0,NULL)
     
      mov    hPopupMenu, rv(CreatePopupMenu)

      Invoke AppendMenu, hPopupMenu, MF_STRING, IDM_EXIT, chr$("Exit")

      mov    nid.cbSize, SIZEOF NOTIFYICONDATA
      m2m    nid.hwnd, hWin
      mov    nid.uID, IDI_TASKBARICON
      mov    nid.uFlags, NIF_ICON+NIF_MESSAGE+NIF_TIP
      mov    nid.uCallbackMessage, WM_CALLBACK
      m2m    nid.hIcon, hIconNA
      Invoke lstrcpy, ADDR nid.szTip, ADDR windowName

      Invoke Shell_NotifyIcon, NIM_ADD, ADDR nid


lLook carefully at the nid structure.
Paul
The GeneSys Project is available from:
The Repository or My crappy website

zooba

Quote from: p0wder on July 20, 2006, 02:26:29 PM

;Set Tray Icon
INVOKE LoadIcon,NULL,IDI_WINLOGO
MOV note.hIcon,eax
; Set Windows title icon
INVOKE LoadIcon, hInstance, 2
MOV   wc.hIcon, EAX
MOV   wc.hIconSm, EAX


That's because you still haven't changed the code I pointed out before. Try this instead of the code above:


; Set Windows title icon
INVOKE LoadIcon, hInstance, 2
MOV   wc.hIcon, EAX
MOV   wc.hIconSm, EAX
MOV   note.hIcon,EAX


This will set all the icon parameters to the same icon, rather than setting one to the generic icon.

p0wder

Thanks! Works like a charm.