I am trying to remove the window in my applicaton, Not really interested in GUI developement except for the tray icon. I want my application to load and immediately be in the tray with the tray icon. Thats it. Not main window, as the win432 gui progamming is a bit new to me, I dont even know where to start ...




; httpd.asm
; Portable HTTP Daemon

; -- -----------------------------------------

.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_EXIT EQU 1010
IDM_MYIP EQU 3
IDM_SETTINGS EQU 4
IDM_ABOUT EQU 5

; Web Server Port Number to bind to
MYPORT EQU 80

; -------------------------------------------

; Various Prototypes
WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WSAStartup PROTO wVersionRequested:DWORD, lpWSAData:DWORD
WSACleanup PROTO
OpenHomepage PROTO
OpenSettings PROTO
About PROTO
CreateXML PROTO

; -------------------------------------------

.CONST

; -------------------------------------------

; XML Configuration File Prototype
szXMLData DB "<?xml version='1.0' encoding='utf-8' ?>",0
DB "<HTTPD>",0
DB "<configuration>",0
DB "<config key='Port'>80</config>",0
DB "<config key='RegistryEnabled'>0</config>",0
DB "</configuration>",0
DB "</HTTPD>",0,0

szCaption DB " HTTP Server",0
szBoxText DB " HTTP Server Successfully Started",0
szURL DB "http://www.murderdesign.com",0
szXMLConf DB "Configuration.xml",0

.DATA?

; -------------------------------------------

; Networking stuff
wsaData WSADATA <?>
sockAddr sockaddr_in <?>

; -------------------------------------------

; WSAData Error Infobox test
szBox DB ?

; -------------------------------------------

; Various Handles
hTemp DD ?
hInstance DD ?
hPopupMenu DD ?

note NOTIFYICONDATA <>
iconData NOTIFYICONDATA <?>

.DATA

; Temporary Buffer
bTemp DB 512 DUP(0)

szClassName DB "TrayIconWinClass",0
szAppName DB "HTTPD Settings",0
szIP DB "My IP",0
szSettings DB "Settings",0
szAbout DB "About",0
szExit DB "Exit",0
szWebSettings DB "http://localhost/?settings",0
szSubkey DB "SOFTWARE\Microsoft\Windows\CurrentVersion\Run",0
szName DB "Portable HTTP Server",0
szPath DB "C:\httpd.exe",0

; -------------------------------------------

.CODE

; -------------------------------------------

; Waits until connected to Internet
WaitUntilConnected PROC
INVOKE InternetGetConnectedState, 0, 0
CMP EAX, 0
JZ @F
@@:
INVOKE Sleep, 2000
JMP @B
RET
WaitUntilConnected ENDP

; -------------------------------------------

; Notify user that the server has been initialized
About PROC
; gethostbyname
INVOKE MessageBox, NULL, ADDR szBoxText, ADDR szCaption, MB_OK
RET
About ENDP

; -------------------------------------------

; Notify user that the server has been initialized
MyIP PROC
; gethostbyname
INVOKE MessageBox, NULL, ADDR szBoxText, ADDR szCaption, MB_OK
RET
MyIP ENDP

; -------------------------------------------

; Add Registry Entries for Autorun
WriteAutoStart PROC
INVOKE  RegCreateKeyEx, HKEY_CURRENT_USER, ADDR szSubkey, 0, 0, 0, KEY_WRITE, 0, ADDR hTemp, 0
CMP    EAX, ERROR_SUCCESS
JNE    @F
INVOKE  RegSetValueEx, , ADDR szName, 0, REG_SZ, ADDR szPath, SIZEOF szPath
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 szClassName
; Set Windows title icon
INVOKE LoadIcon, hInstance, 2
MOV  wc.hIcon, EAX
MOV  wc.hIconSm, EAX
MOV  note.hIcon, EAX
INVOKE LoadCursor, NULL, IDC_ARROW
MOV  wc.hCursor, EAX
INVOKE RegisterClassEx, ADDR wc
INVOKE CreateWindowEx,
WS_EX_CLIENTEDGE,
ADDR szClassName,ADDR szAppName,\
          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
LOCAL pt:POINT
LOCAL rect:RECT
; Program was just launched
.IF uMsg == WM_CREATE
; Create PopUp menu for right clicking
INVOKE CreatePopupMenu
MOV hPopupMenu, EAX
; Add menu items to the popup
INVOKE AppendMenu, hPopupMenu, MF_STRING, IDM_MYIP, ADDR szIP
INVOKE AppendMenu, hPopupMenu, MF_SEPARATOR, NULL, NULL
INVOKE AppendMenu, hPopupMenu, MF_GRAYED, IDM_ABOUT, ADDR szAbout
INVOKE AppendMenu, hPopupMenu, MF_SEPARATOR, NULL, NULL
INVOKE AppendMenu, hPopupMenu, MF_GRAYED, IDM_SETTINGS, ADDR szSettings
INVOKE AppendMenu, hPopupMenu, MF_SEPARATOR, NULL, NULL
INVOKE AppendMenu, hPopupMenu, MF_STRING, IDM_EXIT, ADDR szExit
; Destroy popup menu
.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, hInstance, 2
MOV note.hIcon, EAX
INVOKE lstrcpy, ADDR note.szTip, ADDR szAppName
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_MYIP
INVOKE MyIP
.ELSEIF AX == IDM_SETTINGS
INVOKE OpenSettings
.ELSEIF AX == IDM_ABOUT
INVOKE About
.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_MYIP, 0
.ENDIF
.ENDIF
.ELSE
INVOKE DefWindowProc, hWnd, uMsg, wParam, lParam
RET
.ENDIF
; EAX = 0
XOR EAX, EAX
RET
WndProc ENDP

; -------------------------------------------

; Open Browser to software homepage
OpenHomepage PROC
INVOKE ShellExecute, NULL, NULL, ADDR szURL, NULL, NULL, SW_SHOWNORMAL
INVOKE ExitProcess, NULL
OpenHomepage ENDP

; -------------------------------------------

; Open Browser to software homepage
OpenSettings PROC
INVOKE ShellExecute, NULL, NULL, ADDR szWebSettings, NULL, NULL, SW_SHOWNORMAL
INVOKE ExitProcess, NULL
OpenSettings ENDP

; -------------------------------------------

; Initialize Web Server
HTTPD PROC
; Start Winsock
INVOKE WSAStartup, 0002h, ADDR wsaData
; Test if winsock started by seeing if there was an error value in EAX
TEST EAX, EAX
JZ startupSucceeded
; Error handling code goes below
INVOKE MessageBox, NULL, ADDR szBox, ADDR szCaption, MB_OK
startupSucceeded:
; check lower byte of wVersion (major version number)
CMP BYTE PTR , 2
JAE versionOK
; Error: version < 2
; Winsock still has to be cleaned up though:
JMP doCleanup
RET
versionOK:
; Call winsock functions here
RET
doCleanup:
INVOKE WSACleanup
TEST EAX, EAX
JZ cleanupSucceeded
; Error Handling Code goes below
cleanupSucceeded:
RET
HTTPD ENDP

; -------------------------------------------

; Create XML Configuration File
CreateXML PROC
; Local Variables
LOCAL hXMLConf :DWORD ; File Handle
LOCAL fSize :DWORD ; File Size
LOCAL BWRTN :DWORD ; Bytes Written
LOCAL hMem :DWORD ; Memory Handle
; Create XML Configuration File
INVOKE CreateFile,ADDR szXMLConf,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_ARCHIVE,
NULL
; Place the XML File Handle in hXMLConf
MOV hXMLConf, EAX
; Get The XML Configuration File Size
INVOKE GetFileSize, hXMLConf, NULL
MOV fSize, EAX
SUB fSize, 1
; Allocate enough memory for the file
INVOKE GlobalAlloc, GMEM_FIXED, fSize
MOV hMem, EAX
INVOKE ReadFile, hXMLConf, hMem, fSize, ADDR BWRTN, NULL
INVOKE MessageBox, 0, hMem, ADDR szCaption, 0
; Close The File Handle
INVOKE CloseHandle, hXMLConf
; Free the Allocated Memory
INVOKE GlobalFree, hMem
RET
CreateXML ENDP

; -------------------------------------------

Execute:
; Get this programs handle
INVOKE GetModuleHandle, NULL
MOV hInstance, EAX
INVOKE WinMain, hInstance, NULL, NULL, SW_SHOWDEFAULT
INVOKE ExitProcess, EAX
END Execute

; -------------------------------------------




Posted on 2006-07-28 10:32:07 by p0wder
Well, you could remove the WS_VISIBLE flag from your main window and do the Shell_NotifyIcon in the WM_CREATE handler.
Posted on 2006-07-28 11:15:10 by JimmyClif
Also, please consider using "attach file" for snippets as long as this instead of posting inline :)
Posted on 2006-07-28 12:15:49 by f0dder
But what am I looking for exactly to remove this? which parts of the code ... i dont even want to get involved with a gui. i am building a web server, which is administered via a web based interface, so i dont even want the code there .. just confusing while i try to learn ... thanks in advance
Posted on 2006-07-28 12:42:15 by p0wder
Well, obviously you need a window (although not necessarily a visible one) since you want a tray icon. You have a CreateWindowEx call for this. For this call, WS_VISIBLE is specified as one of the flags; remove this flag.
Posted on 2006-07-28 12:45:26 by f0dder
Also, have another look at this piece of your code:


INVOKE GetFileSize, hXMLConf, NULL
MOV fSize, EAX
SUB fSize, 1
; Allocate enough memory for the file
INVOKE GlobalAlloc, GMEM_FIXED, fSize
MOV hMem, EAX
INVOKE ReadFile, hXMLConf, hMem, fSize, ADDR BWRTN, NULL


So you have the Size of the File. You deduct 1 from it and then you read less than the file is long into that exact same size of Memory? That is asking for trouble. It is possible that one day the 0 terminator of the File gets cut off, and the last byte in you buffer will be a char and upon scanning for the end your app crashes.

Posted on 2006-07-28 13:16:28 by JimmyClif
I already pointed out those errors in another thread :)
Posted on 2006-07-28 13:22:02 by f0dder
Didn't see that thread. Good job.

Won't hurt pointing them out again as they're still not fixed though :lol:
Posted on 2006-07-28 13:37:50 by JimmyClif

Didn't see that thread. Good job.

Won't hurt pointing them out again as they're still not fixed though :lol:

Yup - hence the link... and good that you pointed it out too, the more the merrier ^_^
Posted on 2006-07-28 13:40:21 by f0dder