I have my executable using an icon file. However, I am trying to get the executable to use the icon in the tray and in the window title bar. This isnt' working. Here is my resource file ... If I can do it through code in my assembly file, or through the resource file, I don't care which way it is done, I guess that learning both would be nice? Ok, here is the resource file ...


1 ICON MOVEABLE PURE DISCARDABLE "html.ico"
2 ICON MOVEABLE PURE DISCARDABLE "html.ico"


The second icon would be the icon for the tray, window title etc ...

Here is my assembly file:




; httpd.asm

.586
.model flat, stdcall

; Case sensitive
option casemap :none

include kernel32.inc
include windows.inc
include user32.inc
include wsock32.inc
include ole32.inc
include shlwapi.inc
include wininet.inc
include advapi32.inc
include urlmon.inc
include shell32.inc
include gdi32.inc
include masm32.inc


includelib masm32.lib
includelib kernel32.lib
includelib user32.lib
includelib wsock32.lib
includelib ole32.lib
includelib shlwapi.lib
includelib wininet.lib
includelib advapi32.lib
includelib urlmon.lib
includelib shell32.lib
includelib gdi32.lib

WM_SHELLNOTIFY EQU WM_USER+5
IDI_TRAY EQU 0
IDM_RESTORE EQU 1000
IDM_EXIT EQU 1010

WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD


.CONST


; Message box for server initialization
MsgBoxCaption DB "HTTP Server",0
MsgBoxText DB "HTTP Server Successfully Started",0


.DATA


; Window/Icon Labels
ClassName DB "TrayIconWinClass",0
AppName  DB "HTTPD Settings",0
RestoreString DB "&Restore",0
SettingsString DB "Settings",0
ExitString DB "E&xit Program",0


; Registry Autokey Information
run_subkey DB "SOFTWARE\Microsoft\Windows\CurrentVersion\Run",0
run_name DB "Portable HTTP Server",0
run_path DB "C:\httpd.exe",0


.DATA?


hTemp DD ?
hInstance DD ?
hPopupMenu DD ?

note NOTIFYICONDATA <>


.CODE


; Notify user that the server has been initialized
httpd_started PROC
INVOKE MessageBox, NULL, ADDR MsgBoxText, ADDR MsgBoxCaption, MB_OK
RET
httpd_started ENDP


; Add Registry Entries for Autorun
WriteAutoStart PROC
INVOKE  RegCreateKeyEx, HKEY_CURRENT_USER, ADDR run_subkey, 0, 0, 0, KEY_WRITE, 0, ADDR hTemp, 0
CMP    EAX, ERROR_SUCCESS
JNE    @F
INVOKE  RegSetValueEx, , ADDR run_name, 0, REG_SZ, ADDR run_path, SIZEOF run_path
INVOKE  RegCloseKey,
@@:
RET
WriteAutoStart ENDP


; Settings Window
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
INVOKE LoadIcon,NULL,IDI_APPLICATION
MOV  wc.hIcon,eax
MOV  wc.hIconSm,eax
INVOKE LoadCursor,NULL,IDC_ARROW
MOV  wc.hCursor,eax
INVOKE RegisterClassEx, addr wc
INVOKE CreateWindowEx,
WS_EX_CLIENTEDGE,
ADDR ClassName,ADDR AppName,\
          WS_OVERLAPPED+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX+WS_MAXIMIZEBOX+WS_VISIBLE,CW_USEDEFAULT,\
          CW_USEDEFAULT,350,200,NULL,NULL,\
          hInst,NULL
MOV  hwnd,eax
.while TRUE
INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg
.endw
MOV eax,msg.wParam
RET
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
; Set Icon File
.if uMsg==WM_INITDIALOG
INVOKE LoadIcon, hInstance, 2
INVOKE SendMessage, hWin, WM_SETICON, ICON_BIG or ICON_SMALL, eax
.endif
LOCAL pt:POINT
LOCAL rect:RECT
.if uMsg==WM_CREATE
INVOKE CreatePopupMenu
MOV hPopupMenu,eax
INVOKE AppendMenu,hPopupMenu,MF_STRING,IDM_RESTORE,addr RestoreString
INVOKE AppendMenu,hPopupMenu,MF_STRING,IDM_EXIT,addr ExitString
.elseif uMsg==WM_DESTROY
INVOKE DestroyMenu,hPopupMenu
INVOKE PostQuitMessage,NULL
.elseif uMsg==WM_SIZE
.if wParam==SIZE_MINIMIZED
MOV note.cbSize,sizeof NOTIFYICONDATA
PUSH hWnd
POP note.hwnd
MOV note.uID,IDI_TRAY
MOV note.uFlags,NIF_ICON+NIF_MESSAGE+NIF_TIP
MOV note.uCallbackMessage,WM_SHELLNOTIFY
INVOKE LoadIcon,NULL,IDI_WINLOGO
MOV note.hIcon,eax
INVOKE lstrcpy,addr note.szTip,addr AppName
INVOKE ShowWindow,hWnd,SW_HIDE
INVOKE Shell_NotifyIcon,NIM_ADD,addr note
.endif
.elseif uMsg==WM_COMMAND
.if lParam==0
INVOKE Shell_NotifyIcon,NIM_DELETE,addr note
MOV eax,wParam
.if ax==IDM_RESTORE
INVOKE ShowWindow,hWnd,SW_RESTORE
.else
INVOKE DestroyWindow,hWnd
.endif
.endif
.elseif uMsg==WM_SHELLNOTIFY
.if wParam==IDI_TRAY
.if lParam==WM_RBUTTONDOWN
INVOKE GetCursorPos,addr pt
INVOKE SetForegroundWindow,hWnd
INVOKE TrackPopupMenu,hPopupMenu,TPM_RIGHTALIGN or TPM_RIGHTBUTTON,pt.x,pt.y,NULL,hWnd,NULL
INVOKE PostMessage,hWnd,WM_NULL,0,0
.elseif lParam==WM_LBUTTONDBLCLK
INVOKE SendMessage,hWnd,WM_COMMAND,IDM_RESTORE,0
.endif
.endif
.else
INVOKE DefWindowProc,hWnd,uMsg,wParam,lParam
RET
.endif
XOR eax,eax
RET
WndProc endp

execute:
CALL WriteAutoStart
CALL httpd_started
INVOKE GetModuleHandle, NULL
MOV    hInstance, EAX
INVOKE WinMain, hInstance, NULL, NULL, SW_SHOWDEFAULT
INVOKE ExitProcess, EAX
END execute



Here are my errors:



Assembling: httpd.asm
httpd.asm(144) : error A2006: undefined symbol : hWin
httpd.asm(144) : error A2114: INVOKE argument type mismatch : argument : 1
httpd.asm(146) : error A2012: PROC, MACRO, or macro repeat directive must preced
e LOCAL
httpd.asm(147) : error A2012: PROC, MACRO, or macro repeat directive must preced
e LOCAL
httpd.asm(183) : error A2006: undefined symbol : pt
httpd.asm(183) : error A2114: INVOKE argument type mismatch : argument : 1
httpd.asm(185) : error A2006: undefined symbol : pt
httpd.asm(185) : error A2114: INVOKE argument type mismatch : argument : 4
httpd.asm(185) : error A2114: INVOKE argument type mismatch : argument : 3
POLINK: fatal error: File not found: 'httpd.obj'.



Thanks in advance, I know that it is a lot of code, but I figured to include all of it just incase something that I have no clue about affects something else ...

Regards,

p0wder.
Posted on 2006-07-19 15:48:28 by p0wder
icons:

invoke LoadIcon, hInstance, 1
mov wc.hIcon, eax
mov wc.hIconSm, eax


Also you don't need to include the same icon resource twice.

As for the errors (which are pretty self explanatory btw):

hWin should be hWnd and all occurrences of Local variables should precede any instructions in the procedure (make "Local.." to be the first thing in the procedure).

Posted on 2006-07-19 16:23:42 by arafel
That still does not cause the tray icon to load. Only the window title icon.
Posted on 2006-07-20 07:48:13 by p0wder
Did you minimize your app? The trayicon does not show unless you minimize the application.
Posted on 2006-07-20 09:00:57 by JimmyClif
No I forgot to minimize and ended up looking at the imaginary icon file in the tray :P///
Yea, I minimized and all that I see is the generic .exe icon sitting in the tray.
Posted on 2006-07-20 17:24:41 by p0wder
p0wder,

Use something like this at WM_CREATE  to make TrayIcon to appear.


mov TrayIcon.cbSize, sizeof NOTIFYICONDATA
push hWnd
pop TrayIcon.hwnd
mov TrayIcon.uID, 0
mov TrayIcon.uFlags, NIF_ICON + NIF_TIP
invoke LoadIcon, hInstance, IDI_ICON1
mov TrayIcon.hIcon, eax
invoke lstrcpy, ADDR TrayIcon.szTip, CTEXT("InfoTip text here")
invoke Shell_NotifyIcon, NIM_ADD, ADDR TrayIcon


And put this to WM_DESTROY


invoke Shell_NotifyIcon, NIM_DELETE, ADDR TrayIcon
Posted on 2006-07-20 17:37:46 by SamiP
Works great, thanks!
Posted on 2006-07-21 11:08:59 by p0wder