The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: akalenuk on July 10, 2006, 03:27:29 PM

Title: SetText for a MessageBox
Post by: akalenuk on July 10, 2006, 03:27:29 PM
How can i changge text for a messagebox title? I tried the following:

      invoke MessageBox,0,ADDR buf,ADDR buf,0
      invoke GetActiveWindow
      push eax
      invoke dwtoa,eax,ADDR buf
      pop eax
      invoke SetWindowText,eax,ADDR buf

Also invoke GetLastActivePopup,0 instead of GetActiveWindow
All i get is an empty title bar.
Title: Re: SetText for a MessageBox
Post by: Casper on July 10, 2006, 05:26:52 PM
I think you should experiment with 'known' values, first.  set a text value in another buffer and use that to set as the title to the active window instead of using the value obtained from getting the name of the active window.  Does dwtoa zero terminate for example?  The answer is no so if the name of the active window is longer than the original value in buf you will have a problem or it will not display at all which is what is happening.  You should have a sufficient sized buffer and after the messagebox is displayed you should clear all locations to zero so dwtoa will work correctly.

Just my 3 cents (2 is not enough).
Paul
Title: Re: SetText for a MessageBox
Post by: Ratch on July 10, 2006, 06:01:34 PM
akalenuk ,

  I would think that you would want to change what is in the text of the MessageBox, not the title.  However, the following will do what you wnat.  Ratch

D EQU DWORD PTR
@ EQU OFFSET

.DATA?
BUF1 BYTE 20 DUP (?)

.CODE
START:
XOR EBP,EBP
INVOKE wsprintf,@ BUF1,TEXT('%9d',0),123456789
INVOKE MessageBox,EBP,TEXT('DISPLAY',0),@ BUF1,EBP

INVOKE wsprintf,@ BUF1,TEXT('%9d',0),987654321
INVOKE MessageBox,EBP,TEXT('DISPLAY',0),@ BUF1,EBP

INVOKE ExitProcess,0
END START

[attachment deleted by admin]
Title: Re: SetText for a MessageBox
Post by: Casper on July 10, 2006, 11:59:29 PM
Ratch,
Your example is not correct.  You are displaying two messageboxes where he wants to display just one but change the title.  There is a big difference.

Paul
Title: Re: SetText for a MessageBox
Post by: Ratch on July 11, 2006, 01:33:19 AM
Casper,

QuoteRatch,
Your example is not correct.  You are displaying two messageboxes where he wants to display just one but change the title.  There is a big difference.

     Unless I am missing something here, it is a difference without a distinction.  True there are two messageboxes, but not at the same time.  After the first messagebox disappears, the second appears with a different title in exactly the same place on the screen.  You need to specify more restrictive conditions on the way they appear before my code can be discounted as a solution.  Ratch
Title: Re: SetText for a MessageBox
Post by: akalenuk on July 11, 2006, 12:52:08 PM
Quote from: Casper on July 10, 2006, 05:26:52 PM
I think you should experiment with 'known' values, first. 
Good idea.
[a minute later]
Just tried this. Still nothing. Empty title.
Maybe i can't get messageboxes handler with these methods i use.
Title: Re: SetText for a MessageBox
Post by: akalenuk on July 11, 2006, 12:59:47 PM
Quote from: Ratch on July 10, 2006, 06:01:34 PM
I would think that you would want to change what is in the text of the MessageBox, not the title.  However, the following will do what you wnat.

Thanks, yet this is not exactly the same. Actually, it is not sufficient either the title or the content will be reset, but the main thing is to remain the same window with the same handler for future use, so any other application can use it for an output. I'm using a common dialog style window for now, but it takes a little more space, though all i need is to display only one number.


INVOKE wsprintf,@ BUF1,TEXT('%9d',0),123456789


And i couldn't make this to work. Where can i get TEXT macros?
Title: Re: SetText for a MessageBox
Post by: Casper on July 11, 2006, 01:28:12 PM
akalenuk,
Thank you for also pointing out to Ratch that he got lost somewhere.  I was sticking my neck out but your request was pretty 'obvious' to me.

About the text macros, just add the following line to your project...

include  \masm32\macros\macros.asm

Paul
Title: Re: SetText for a MessageBox
Post by: Ratch on July 11, 2006, 01:32:36 PM
 akalenuk,

    I still don't understand what you need.  If you want to another child window to change the MessageBox, just use the same owner handle as the parent window.  The MessageBox handler is internal to Windows.  Why is it important to not close the window?  Perhaps you want something like a listbox dialog box.  The Common Dialog Box windows are primaily used to manipulate files.  Is that what you want?  

    TEXT is a macro function.  Variations are found is many places on this board.  The code is shown below.  Ratch

TEXT MACRO P1:VARARG            ;inline code for BYTE string and implicit label
LOCAL L1
.DATA
L1 BYTE P1
.CODE
EXITM <OFFSET L1>
ENDM
Title: Re: SetText for a MessageBox
Post by: akalenuk on July 11, 2006, 03:47:19 PM
Quote from: Ratch on July 11, 2006, 01:32:36 PM
     I still don't understand what you need.  If you want to another child window to change the MessageBox, just use the same owner handle as the parent window.

Why not? I'll also try this. Thanks.

Quote from: Ratch on July 11, 2006, 01:32:36 PMThe MessageBox handler is internal to Windows.  Why is it important to not close the window?  Perhaps you want something like a listbox dialog box.  The Common Dialog Box windows are primaily used to manipulate files.  Is that what you want?

Actually, i want something on my desktop, by which several applications can show me a piece of their data. It is usefull to monitor their interactions. The easyest way to do so is to create any window, get it's handler and use "SetWindowText" from other applications. MessageBox is just an option to reduce the size of implementation. It is not that importrant, it is just i really like small executables  :bg
Title: Re: SetText for a MessageBox
Post by: akalenuk on July 11, 2006, 03:48:25 PM
Quote from: Casper on July 11, 2006, 01:28:12 PM
About the text macros, just add the following line to your project...

include  \masm32\macros\macros.asm

Allready found it, thanks.
Title: Re: SetText for a MessageBox
Post by: Ratch on July 11, 2006, 08:00:17 PM
akalenuk,

QuoteActually, i want something on my desktop, by which several applications can show me a piece of their data

     Ah, I understand more clearly now.  Ratch
Title: Re: SetText for a MessageBox
Post by: Will on July 12, 2006, 02:12:05 AM
I was trying to do this awhile back and iirc the messagebox is a dialog and I ended up using setdlgitemtext instead.  Not in a position to test now so I could be steering you in the wrong direction but it may be worth a look.
Title: Re: SetText for a MessageBox
Post by: zooba on July 12, 2006, 05:44:43 AM
I don't see how this could work. 'MessageBox' is a blocking call, ie. it doesn't return until the box is closed. If it belongs to another thread then it may be possible (I remember hijacking NET MESSAGE popups a few years ago) but you won't be able to do it to your own thread's one. Of course, if it belongs to you then you don't need to :wink

A precompiled dialog is probably your best option.

Cheers,

Zooba :U
Title: Re: SetText for a MessageBox
Post by: akalenuk on July 12, 2006, 01:13:54 PM
Quote from: Will on July 12, 2006, 02:12:05 AM
I was trying to do this awhile back and iirc the messagebox is a dialog and I ended up using setdlgitemtext instead.  Not in a position to test now so I could be steering you in the wrong direction but it may be worth a look.
It does nearly the same thing - posts a WM_SETTEXT to a dialog item's window. Well, i still should know its handler.
Title: Re: SetText for a MessageBox
Post by: akalenuk on July 12, 2006, 01:18:32 PM
Quote from: zooba on July 12, 2006, 05:44:43 AM
I don't see how this could work. 'MessageBox' is a blocking call, ie. it doesn't return until the box is closed.

! Sure! And i try to get a handler of a window after it is closed. That explains everything.

Quote from: zooba on July 12, 2006, 05:44:43 AM
A precompiled dialog is probably your best option.

But isn't it also a blocking call?
Title: Re: SetText for a MessageBox
Post by: zooba on July 13, 2006, 04:59:07 AM
Quote from: akalenuk on July 12, 2006, 01:18:32 PM
Quote from: zooba on July 12, 2006, 05:44:43 AM
A precompiled dialog is probably your best option.

But isn't it also a blocking call?

I couldn't tell you. I personally prefer doing windows the 'old-fashioned' way - I'm not keen on using dialogs in resource files. However, basically all of the examples in the MASM32 package are based on dialog templates, so have a look at how those behave.

Cheers,

Zooba :U
Title: Re: SetText for a MessageBox
Post by: MichaelW on July 14, 2006, 01:56:41 AM
This is a mess, but it seems to work OK.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
        hInst     dd          0
        hWnd      dd          0
        hLst      dd          0
        wc        WNDCLASSEX  <>
        msg       MSG         <>
        className db          "message_window_class",0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    mov   hInst, rv(GetModuleHandle, NULL)
    mov   wc.cbSize,        sizeof WNDCLASSEX
    mov   wc.style,         CS_HREDRAW or CS_VREDRAW \
                              or CS_BYTEALIGNWINDOW
    mov   wc.lpfnWndProc,   OFFSET WndProc
    mov   wc.cbClsExtra,    NULL
    mov   wc.cbWndExtra,    NULL
    m2m   wc.hInstance,     hInst
    mov   wc.hbrBackground, rv(GetStockObject, WHITE_BRUSH)
    mov   wc.lpszMenuName,  NULL
    mov   wc.lpszClassName, OFFSET className
    mov   wc.hIcon,         rv(LoadIcon, NULL, IDI_APPLICATION)
    mov   wc.hCursor,       rv(LoadCursor, NULL, IDC_ARROW)
    mov   wc.hIconSm,       0
    invoke RegisterClassEx, ADDR wc
    invoke CreateWindowEx,  0,
                            ADDR className,
                            chr$("Message Window"),
                            WS_TILED or WS_SYSMENU or WS_MINIMIZEBOX,
                            0,0,300,200,
                            NULL, NULL,
                            hInst, NULL
    mov   hWnd, eax
    invoke ShowWindow, hWnd, SW_SHOWNORMAL
    invoke UpdateWindow, hWnd   
  msgLoop:
    invoke GetMessage, ADDR msg, NULL, 0, 0
    .IF (eax != 0)
        invoke TranslateMessage, ADDR msg
        invoke DispatchMessage, ADDR msg
        jmp   msgLoop
    .ENDIF
    exit msg.wParam
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
ListBox proc a:DWORD,b:DWORD,wd:DWORD,ht:DWORD,hParent:DWORD,ID:DWORD
    szText lstBox,"LISTBOX"
    invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR lstBox,0,
              WS_VSCROLL or WS_VISIBLE or \
              WS_BORDER or WS_CHILD or \
              LBS_HASSTRINGS or LBS_NOINTEGRALHEIGHT or \
              LBS_DISABLENOSCROLL,
              a,b,wd,ht,hParent,ID,hInst,NULL
    ret
ListBox endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
WndProc proc hWin:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
    .IF uMsg == WM_CREATE
        invoke ListBox, 0,0, 296, 175, hWin, 1000
        mov hLst, eax
    .ELSEIF uMsg == WM_DESTROY
        invoke PostQuitMessage, NULL
        return 0
    .ELSEIF uMsg == LB_ADDSTRING
        invoke SendMessage, hLst, uMsg, wParam, lParam
    .ENDIF
    invoke DefWindowProc, hWin, uMsg, wParam, lParam
    ret
WndProc endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
        hTarget dd 0
        str1 db "my other brother darryl",0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    invoke FindWindow, chr$("message_window_class"), chr$("Message Window")
    mov hTarget, eax
    .IF eax
        print "sending...",13,10
        invoke SendMessage, hTarget, LB_ADDSTRING, 0, ADDR str1
    .ENDIF
    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
Title: Re: SetText for a MessageBox
Post by: hutch-- on July 14, 2006, 02:32:19 AM
There is in fact another option with MASM32 and that is the in memory dialogs that are supported with a matching set of macros. It is an OS based technique that differs from RC compiled resources only in that it builds the interface and controls in code rather than using a dialog editor. they both use the system specified modal dialog message handler type callback to process messages and both system based techniques are reliable.

Fully coded windows are fine and you have more control over what they do but its more work to duplicate the functionality of a dialog where you also have to handle the keyboard for tab orders and similar.