News:

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

Remove "app" icon from MessageBox?

Started by Mark Jones, August 26, 2006, 07:54:54 PM

Previous topic - Next topic

Mark Jones

Hi, is it possible to remove the standard application icon from a MessageBox? i.e.,
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

asmfan

Hi Mark, i think that the answer is in MessageBoxIndirect() function.
Russia is a weird place

Mark Jones

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
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

PBrennick

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
The GeneSys Project is available from:
The Repository or My crappy website

BytePtr

Works fine in Windows 98SE.
Good work!

hutch--

Paul,

Works fine on my win2k sp4.  :U
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Vortex


Vortex

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?

PBrennick

#8
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]
The GeneSys Project is available from:
The Repository or My crappy website

drizz

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)
The truth cannot be learned ... it can only be recognized.

Mark Jones

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?
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

drizz

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?
The truth cannot be learned ... it can only be recognized.

Mark Jones

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
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

drizz

#13
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
The truth cannot be learned ... it can only be recognized.

Mark Jones

"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08