News:

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

Remove Gui

Started by p0wder, July 28, 2006, 05:44:02 PM

Previous topic - Next topic

p0wder

I am trying to remove the window [not just make it invisible, but remove the code] from the example which i am using. I just want to execute the program, then have it immediately minimize and sit in the tray. any pointers on where to start?


; 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


Mark Jones

INVOKE CreateWindowEx creates a window (or control.)

Nowhere is it stated that a Win32 application MUST create a window... however, if the application is going to sit in the system tray it should probably have a WndProc so that the WM_CLOSE message can be intercepted.

What have you tried so far?
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

p0wder

This is what I have so far, but it just runs in the background, how do i get it into the tray, ... also, what else can i remove?


; 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,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


Mark Jones

Take a look at \masm32\icztutes\tute23, that almost does what you want. When the main window is minimized, the only thing visible is the tray icon. Now just make the window default minimized... :wink
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

hutch--

There is an old trick that used to work fine, If you need a WndProc type function, you need a window to point messages at it but you can easily create a window that is not visible on the screen by using negative co-ordinates for the top XY. It will still show on your Alt+Tab list but it does not get displayed. If you can imagine it, starting with the XY co-ordinates at -1000 it places the window about 1 metre above and to the left of your monitor.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Mark Jones

Hutch, is that a valid programming method? :lol

I recall some apps in earlier versions of windows which would get moved off the screen this way, sometimes this cause serious problems. Eventually I found a freeware app called "discover window" which would find these and bring them back on-screen.

Here's another hint about Icz tute 23: swap "WS_SOMETHING" with "WS_MINIMIZE" and the app will default to starting in the systray. :U
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

hutch--

Mark,

The method was always very reliable. You could solve the problem of a finder app, just detect the top XY and move it back again and if the finder persisted, keep changing the window title so it has to enumerate all the windows each time. A systray icon is an OK method but you can get tired of too many items on the systray.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

PBrennick

Hutch,
Quote from: hutch-- on July 29, 2006, 03:57:04 AM
A systray icon is an OK method but you can get tired of too many items on the systray.
That is certainly the way that I feel, I've got miine down to 9 items, 6 are hidden.  Which brings up another point.  Why work so hard to create an app that runs in the System Tray when, chances are, it will just be hidden.  What is the point?

Paul
The GeneSys Project is available from:
The Repository or My crappy website