News:

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

Custom MessageBox using MessageBoxIndirect

Started by Peterpan, January 05, 2005, 01:11:03 PM

Previous topic - Next topic

Peterpan

Hi all,

I'm not sure where I should post this. Anyway, I'd like to share this with anyone who likes a custom messagebox without creating your own Dialog :bg
This function has a timeout capability (taken from MSDN example)

MsgBoxIn.asm

    .586
    .model flat, stdcall
    option casemap :none   ; case sensitive

; #############################

   include \masm32\include\windows.inc
   include \masm32\include\user32.inc
   include \masm32\include\kernel32.inc
   include \masm32\include\winmm.inc
   include \masm32\macros\macros.asm

   includelib \masm32\lib\user32.lib
   includelib \masm32\lib\kernel32.lib
   includelib \masm32\lib\winmm.lib

; #############################
   ; *** Procedure/Function Prototype

   ShowMsgBox PROTO :LPSTR, :BOOL, :DWORD, :BOOL, :DWORD

; #############################

.Const
   gc_Title       db 'MessageBoxIndirect',0
   gc_WaveFile    db 'DING_WAVE',0
   gc_WaveType    db 'WAVE',0


.Data?
ALIGN 4
   gh_Instance HINSTANCE ?


; #############################
.Code
ALIGN 4

Start:
   invoke GetModuleHandle, NULL
   mov gh_Instance, eax

  fn ShowMsgBox, "Default - Error Icon...3 sec", FALSE, \
     MB_ICONERROR or MB_ABORTRETRYIGNORE, FALSE, 3000
   fn ShowMsgBox, "Icon ID# 100 - with sound...3 sec", TRUE, 100, TRUE, 3000
   fn ShowMsgBox, "Icon ID# 100 - no sound. Click button to finish", TRUE, 100, FALSE, 0

   exit

; #############################

MBI_Timer Proc th_Wnd:HWND, tu_Msg:UINT, tu_EventId:UINT, tt_Time:DWORD
   invoke PostQuitMessage, 0
   ret
MBI_Timer EndP

; #############################

ShowMsgBox Proc tc_Text:LPSTR, tb_UserIcon:BOOL, tn_IconID:DWORD, \
      tb_UseSound:BOOL, 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, gh_Instance
   m2m ls_MBP.lpszText, tc_Text
   m2m ls_MBP.lpszCaption, offset gc_Title
   .If ( tb_UserIcon )
      m2m ls_MBP.dwStyle, MB_USERICON
      m2m ls_MBP.lpszIcon, tn_IconID
   .else
      m2m ls_MBP.dwStyle, tn_IconID
   .endif

   .If ( tb_UseSound && tb_UserIcon )
      invoke FindResource, gh_Instance, addr gc_WaveFile, addr gc_WaveType
      .If ( eax )
         invoke LoadResource, gh_Instance, eax
         invoke LockResource, eax
         invoke PlaySound, eax, NULL, SND_ASYNC + SND_MEMORY
      .endif
   .endif

   .If ( tn_TimeOut )
      invoke SetTimer, NULL, 0, tn_TimeOut, offset MBI_Timer
      mov lu_TimerId, eax

      push ebx
      invoke MessageBoxIndirect, Addr ls_MBP
      mov ebx, eax   ; save return value to ebx
      invoke KillTimer, NULL, lu_TimerId

      ; Remove WM_QUIT message, so the application doesn't quit
      invoke PeekMessage, addr ls_MSG, NULL, WM_QUIT, WM_QUIT, PM_REMOVE

      .If ( eax )       ; is timeout ?
         mov eax, 0     ; return 0
      .else
         mov eax, ebx   ; else, return original value
      .endif

      pop ebx

   .else
      invoke MessageBoxIndirect, Addr ls_MBP
   .endif

   ret
ShowMsgBox EndP

; #############################

End Start


MsgBoxIn.RC

; From Windows folder
DING_WAVE WAVE DISCARDABLE "Ding.WAV"

; replace with your own icon
100 ICON MOVEABLE PURE LOADONCALL DISCARDABLE "Info.ICO"


Regards

Vortex


Peterpan

#2
The "Ding.wav" is from windows\media folder. I think it is installed with any version of windows (??). If you don't have it in your windows folder, you can use any wave file you want to. For "Info.ico" I forgot where I got it. It's from the internet. Just replace it with your own icon. You can use any kind of icon for it  :U

Is it okay for me to attached those file here?  I mean is it ok to distribute the file ?

pbrennick

#3
There is no need to post that wave file, everyone has a copy of it.  BTW:  I like your MessageBox example, very nice..and useful.
Paul

Peterpan

pbrennick,

Quote from: pbrennick on January 13, 2005, 05:21:07 PM
There is no need to post that wave file, everyone has a copy of it. BTW:  I like your MessageBox example, very nice..and useful.

I'm sorry for replying so late. I'm kind of busy for few days and haven't got a time to login :'(
Anyway, that's what I thought. I think it comes with all windows version. I'm glad you like it though  :U