News:

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

SetText for a MessageBox

Started by akalenuk, July 10, 2006, 03:27:29 PM

Previous topic - Next topic

akalenuk

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.

Casper

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

Ratch

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]

Casper

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

Ratch

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

akalenuk

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.

akalenuk

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?

Casper

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

Ratch

 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

akalenuk

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

akalenuk

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.

Ratch

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

Will

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.

zooba

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

akalenuk

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.