Author Topic: Message-only window  (Read 957 times)

Vortex

  • Member
  • *****
  • Posts: 1851
Message-only window
« on: February 24, 2017, 06:13:43 AM »
Here is a small message-only window example. The windowless application sets a timer and displays a message box after 5 seconds.

Code: [Select]
include     MessageOnlyWnd.inc

.data

ClassName   db 'Message',0
message     db 'Click OK to terminate the application',0
title1      db 'Message-only window',0

.data?

wc          WNDCLASSEX <?>
msg         MSG <?>
hInstance   dq ?

.code

start:

    sub     rsp,12*8+8

    invoke  GetModuleHandle,0
    mov     hInstance,rax

    mov     wc.cbSize,SIZEOF WNDCLASSEX
    lea     rcx,WndProc
    mov     wc.lpfnWndProc,rcx
    mov     wc.hInstance,rax
    lea     rcx,ClassName
    mov     wc.lpszClassName,rcx

    invoke  RegisterClassEx,ADDR wc

    xor     rax,rax
   
    invoke  CreateWindowEx,0,ADDR ClassName,0,\
            0,rax,rax,rax,rax,\
            HWND_MESSAGE,rax,hInstance,rax

    .WHILEtrue

        invoke  GetMessage,ADDR msg,NULL,0,0
       
        .BREAKIFeq rax,0

        invoke  TranslateMessage,ADDR msg
        invoke  DispatchMessage,ADDR msg

    .ENDW
   
    invoke  ExitProcess,0


WndProc PROC hWnd:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD

    sub     rsp,4*8

    .ifeq rdx,WM_CREATE

        invoke  SetTimer,rcx,ID_TIMER,5000,ADDR TimerProc
           
    .elseifeq  rdx,WM_DESTROY

        invoke  PostQuitMessage,NULL

    .else

        invoke  DefWindowProc,rcx,rdx,r8,r9     
        ret
       
    .endif
   
    xor     rax,rax
    ret

WndProc ENDP


TimerProc PROC hWnd:QWORD,uMsg:QWORD,idEvent:QWORD,dwTime:QWORD
   
    sub     rsp,4*8
    mov     hWnd,rcx

    invoke  KillTimer,rcx,ID_TIMER
    invoke  MessageBox,0,ADDR message,ADDR title1,MB_OK

    invoke  SendMessage,hWnd,WM_DESTROY,0,0
    ret

TimerProc ENDP

END

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5847
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Message-only window
« Reply #1 on: February 24, 2017, 09:22:01 AM »
Works fine here in my Win 10 64.  :t
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin: