The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Mark Jones on August 26, 2006, 07:54:54 PM

Title: Remove "app" icon from MessageBox?
Post by: Mark Jones on August 26, 2006, 07:54:54 PM
Hi, is it possible to remove the standard application icon from a MessageBox? i.e.,
(http://heliosstudios.net/temp/icon.png)
Title: Re: Remove "app" icon from MessageBox?
Post by: asmfan on August 26, 2006, 08:04:11 PM
Hi Mark, i think that the answer is in MessageBoxIndirect() function.
Title: Re: Remove "app" icon from MessageBox?
Post by: Mark Jones on August 26, 2006, 08:07:57 PM
Hi Asmfan, I tried this already without luck. MessageBoxIndirect lets us include a custom icon in the client area, but it still had the "app" icon in the title bar. Once, however, I made this title bar icon dissappear by accidentally providing a wrong size for the first member of the MSGBOXINDIRECT structure... but then nothing else would show. :wink
Title: Re: Remove "app" icon from MessageBox?
Post by: PBrennick on August 26, 2006, 09:22:15 PM
Mark the following program shows a MessageBox The without that icon and the second one will also remove the MessageBox in a certain period of time.  The program will empty the contents of the Recycle Bin.  Only tested with XP:


    .586                                ; create 32 bit code
    .model  flat, stdcall               ; 32 bit memory model
    option  casemap:none                ; Case sensitive

    include \masm32\include\windows.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\shell32.inc

    include \masm32\macros\macros.asm

    includelib  \masm32\lib\user32.lib
    includelib  \masm32\lib\kernel32.lib
    includelib  \masm32\lib\shell32.lib

.DATA

gc_Title db 'Housekeeping 101',0

.DATA?

ALIGN 4
ls_Instance HINSTANCE ?

.CODE

CleanRecycle proc
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    invoke  SHAddToRecentDocs, SHARD_PATH, 0
    invoke  SHEmptyRecycleBin, NULL, NULL, SHERB_NOCONFIRMATION+SHERB_NOPROGRESSUI+SHERB_NOSOUND
    ret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CleanRecycle endp
;
;
MBI_Timer Proc th_Wnd:HWND, tu_Msg:UINT, tu_EventId:UINT, tt_Time:DWORD
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;   Simulate pressing the OK button by sending a WM_QUIT message
    invoke  PostQuitMessage, 0
    ret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MBI_Timer EndP
;
;
ShowMsgBox Proc tc_Text:LPSTR, tn_IconID:DWORD, tn_TimeOut:DWORD
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Local   ls_MBP:MSGBOXPARAMS
    Local   lu_TimerId:UINT
    Local   ls_MSG:MSG

    mov     ls_MBP.cbSize, SizeOf MSGBOXPARAMS
    m2m     ls_MBP.hwndOwner, NULL
    m2m     ls_MBP.hInstance, ls_Instance
    m2m     ls_MBP.lpszText, tc_Text
    m2m     ls_MBP.lpszCaption, offset gc_Title
    m2m     ls_MBP.dwStyle, tn_IconID
    invoke  SetTimer, NULL, 0, tn_TimeOut, offset MBI_Timer
    mov     lu_TimerId, eax
    invoke  MessageBoxIndirect, Addr ls_MBP
    invoke  KillTimer, NULL, lu_TimerId
;   Remove WM_QUIT message, so the application doesn't quit
;   It is not really necessary but the program is better understood this way
    invoke  PeekMessage, addr ls_MSG, NULL, WM_QUIT, WM_QUIT, PM_REMOVE
    ret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ShowMsgBox EndP
;
;
Start:
    invoke GetModuleHandle, NULL
    mov ls_Instance, eax
    invoke  MessageBox, NULL, chr$("Empty the Recycle Bin?"), chr$("Housekeeping 101"), MB_YESNO or MB_ICONASTERISK
    .if eax==IDYES
      invoke  CleanRecycle
      fn ShowMsgBox, "Finished",MB_OK or MB_ICONINFORMATION, 3000
    .endif
    invoke  ExitProcess, NULL
;
;
    end     Start


Paul
Title: Re: Remove "app" icon from MessageBox?
Post by: BytePtr on August 27, 2006, 09:16:27 AM
Works fine in Windows 98SE.
Good work!
Title: Re: Remove "app" icon from MessageBox?
Post by: hutch-- on August 27, 2006, 09:34:52 AM
Paul,

Works fine on my win2k sp4.  :U
Title: Re: Remove "app" icon from MessageBox?
Post by: Vortex on August 27, 2006, 09:58:14 AM
Works fine on my Win Xp HE SP2 :U
Title: Re: Remove "app" icon from MessageBox?
Post by: Vortex on August 27, 2006, 10:24:56 AM
Hi Mark,

There is something that I didn't understand. By default, a normal message box doesn't display the standard application icon. ( Have a look at Iczelion's tutorial #2 for a quick example. ) I guess you are talking about dialog boxes?
Title: Re: Remove "app" icon from MessageBox?
Post by: PBrennick on August 27, 2006, 11:12:05 AM
Yes, Vortex,
You are correct and this can be seen by the first MessageBox in my posting.  It is displayed as a standard MessageBox.  I prefere using MessageBoxIndirect so neat things like timers can be used as is shown in the second one.  This is what asmfan recommended and he makes a valid, though brief, point.  As far as Mark talking about a DialogBox, since he mentions trying MessageBoxIndirect I would say no.

Thanks for the good reports on other systems.  I just tested it on ME, and it works well.  Attached is the project modified to assemble using GeneSys.

Paul


[attachment deleted by admin]
Title: Re: Remove "app" icon from MessageBox?
Post by: drizz on August 27, 2006, 02:39:43 PM
nobody knows???  :dazzled:

Mark, are you using:
invoke SetClassLong,hWnd,GCL_HICON,eax

replace it with:
invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eax

why does it happen?
your dialog class == #32770 (Dialog)
msg box class == #32770 (Dialog)
Title: Re: Remove "app" icon from MessageBox?
Post by: Mark Jones on August 29, 2006, 08:30:21 PM
Hi, no this is without any WndProc. Just compile code as GUI and call MessageBox, and it has this "app" icon. Do I have to FindWindow the MessageBox then SendMessage?
Title: Re: Remove "app" icon from MessageBox?
Post by: drizz on August 29, 2006, 10:27:10 PM
i can't recreate it, can you post your code (atleast the part that makes msgbox have icon)?

ML /c /coff /Cp /nologo /I"\MASM32\INCLUDE"
LINK /SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0 /LIBPATH:"\MASM32\LIB"
.586
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
.data
cap db "Windows Fade Demo",0
txt db "Coded by Mark Jones",0
.code
start:
invoke MessageBox,0,addr txt,addr cap,0
invoke ExitProcess,0
end start

EDIT: are you using MB_SYSTEMMODAL flag maybe?
Title: Re: Remove "app" icon from MessageBox?
Post by: Mark Jones on August 30, 2006, 01:11:28 AM
Quote from: drizz on August 29, 2006, 10:27:10 PM
EDIT: are you using MB_SYSTEMMODAL flag maybe?

Yes, MB_SYSTEMMODAL. (The "Windows Fade Demo..." was just an example I had handy, not the actual window in question.) Code as simple as:


include masm32rt.inc                    ; standard compile-time libs

.data
    szTitle          db "Test 123...",0
    szCaption        db "Rogue MessageBox App icon!",0

.code
    invoke MessageBox,0,addr szCaption,addr szTitle,\
                      MB_RETRYCANCEL+MB_SYSTEMMODAL


This app doesn't use a WndProc so it can run invisibly. It only shows the MessageBox if user intervention is required. Thanks for sticking with this. :wink
Title: Re: Remove "app" icon from MessageBox?
Post by: drizz on August 30, 2006, 02:35:15 AM
well..., if you must have always on top messagebox, and you cant live with the app icon showing...
i tried to make a workaround  :dazzled:, but it still involves window creation.
.686
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib

.data
cap db "Super Cool MessageBox",0
txt db "Coded by drizz",0

.code
MsgBoxAlwaysOnTopWithoutIcon proc uses ebx esi edi, lpText,lpCaption,dwStyle
LOCAL wc:WNDCLASSEX
xor esi,esi
invoke GetModuleHandle,esi
mov ebx,eax
mov edx,sizeof WNDCLASSEX
xor eax,eax
mov ecx,edx
lea edi,wc
rep stosb
mov wc.cbSize,edx
call @F
jmp DefWindowProc
@@: pop wc.lpfnWndProc
mov wc.hInstance,ebx
call @F
db "MsgBoxAlwaysOnTopWithoutIconClass",0
@@: pop edi
mov wc.lpszClassName,edi
invoke RegisterClassEx,addr wc
xor edx,edx
invoke CreateWindowEx,esi,edi,lpCaption,WS_POPUPWINDOW,edx,esi,edx,esi,edx,esi,ebx,esi
mov ebx,eax
invoke ShowWindow,ebx,SW_SHOW
invoke UpdateWindow,ebx
invoke SetWindowPos,ebx,HWND_TOPMOST,esi,esi,esi,esi,esi
invoke MessageBox,ebx,lpText,lpCaption,dwStyle
mov esi,eax
invoke DestroyWindow,ebx
invoke UnregisterClass,edi,wc.hInstance
mov eax,esi
ret
MsgBoxAlwaysOnTopWithoutIcon endp

start:
invoke MsgBoxAlwaysOnTopWithoutIcon,addr txt,addr cap,MB_OK
invoke ExitProcess,eax
end start

EDIT: let me just say that this func is for a program that will not have any windows/dialogs,
if you USE windows/dialogs all you have to do is set that window on top, use its handle in
messageboxA, and dont specify MB_SYSTEMMODAL!!!  :dazzled:

EDIT.2: added UnregisterClass
Title: Re: Remove "app" icon from MessageBox?
Post by: Mark Jones on August 30, 2006, 03:02:14 AM
Thanks Drizz! :U
Title: Re: Remove "app" icon from MessageBox?
Post by: asmfan on August 30, 2006, 07:26:53 PM
A few remarks by me

LOCAL wc:WNDCLASSEX
...
   mov edx,sizeof WNDCLASSEX
   mov ebx,eax
   mov ecx,edx
   lea edi,wc
   rep stosb

with what we fill the wc? xor eax,eax need to be there or at least xor al,al ;)
Title: Re: Remove "app" icon from MessageBox?
Post by: drizz on August 30, 2006, 07:33:11 PM
yes i realized that myself last night, but when i went to edit it, i remebered that al will always be zero!
but for clarity, yes you are right  :wink

i updated the code and added:
invoke UnregisterClass,edi,wc.hInstance