News:

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

Custom MessageBox Button Text

Started by dedndave, August 16, 2011, 11:16:09 PM

Previous topic - Next topic

dedndave


hutch--

Dave,

Its mainly a difference in how Ketil's resedit handles ID numbers. I have never used equates where resedit does not appear to have an option to directly work in ID numbers and always generates equates for each control.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

got it   :bg

well - i finally got a box with a button using DialogBoxIndirect   :lol

i must say that, of all the ms stuff i have seen, the template structures and arrays are the poorest in terms of organization
i am still a n00b, though - i am sure i will find something worse, eventually

on the plus side, it is easy to get a handle and examine the class structure members of example items
a good example is the button "shading" or "raised" effect
i can poke around in the guts of windows a little bit and see how they do it   :bg

hutch--

Dave,

Give this script a blast, it writes a simple dialog then starts the project in a new QE window.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

 :U

i am kinda new to dialogs - lol
thanks Hutch

dedndave

apparently, the gradient fill button is not a style or extended style
i guess it must be paiinted in
i saw someplace that it is supported with CommonControls 6.0 or better - what a coincidence   :P

ohhhhhh
you have to have a manifest file to get the gradient fill   :U

hutch--

Dave,

Here is another approach to creating a 3 button dialog that has user text control. The test piece is a normal resource dialog but the 3 button dialog is coded in memory and does not need a resource section so it can be put into a library module.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

thanks Hutch
that is a little more like what i am after

my current game plan is to create the box and buttons in the MsgBoxEx function
also, the function will play an optional sound and set the small icon in the title bar, if any
the hardest part of the whole thing will be figuring out sizes - lol

then, in the DlgProc, set all the text, similar to what you are doing
except this one has no resource file data at all
i haven't decided whether to set the large icon in the DlgProc or the function

i am using DialogBoxIndirectParam, and passing the address of a list of text pointers

the code is very small   :bg
and, now that i have a manifest file, i have the gradient buttons   :8)

here is a simple box with a button
;button

        push    0
        push    80h
        push    IDB_BTN1 or 0FFFF0000h
        push    0E0049h             ;size = 73 x 14
        push    170009h             ;pos = 9,23
        push    0                   ;extended style
        push    WS_CHILD or WS_VISIBLE or WS_TABSTOP ;BS_CENTER ;BS_PUSHLIKE ;BS_PUSHBUTTON

;dialog box

        push    0
        push    32h                 ;height = 50
        push    640000h             ;width = 100, y = DS_CENTER
        push    1                   ;x = DS_CENTER, cdit = 1
        push    0                   ;extended style
        push    WS_POPUP or WS_CAPTION or WS_SYSMENU or DS_CENTER or DS_MODALFRAME    ;WS_OVERLAPPED

        mov     edx,esp

        INVOKE  DialogBoxIndirectParam,hInstance,edx,edi,DlgProc,edi
        add     esp,52


the MsgBoxEx function will be based on that code
as i said, much of the code will be dedicated to figuring out how big to make everything
pixels aren't pixels, anymore - lol
everything is in "dialog template units"   ::)

as a maximum, i will give them:
optional/selectable sound
small icon in the title bar
large icon in the message area
a check box
up to 4 buttons
text in the title bar, message area, check box, and buttons

the form will be:
        INVOKE  MsgBoxEx,hWndOwner,lpszMessage,lpszCaption,lpStructure

there will be options, like selecting the default button, EscapeKey/Close alias, and so on

hutch--

The thing that makes message box replacements fun is the requirement to auto size the text display area to fit the size of the text, it means measuring the size of the provided message text and sizing both the dialog and the text display area to fit that text. It can be done but its no real joy to code.

Depending on how you create the basic window, it does not matter if you work in pixels or dialog units but if you are going to start resizing windows you will probably have to work in pixels.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

that is the hard part
in many ways, i want to mock the behaviour of MessageBox
some of it is pretty simple - some, not so much

i can use 1 of 2 approaches to get there
1) experiment with MessageBox and chart it's behaviour
2) disassemble MessageBox and mimic their sizing code

the later is probably more effort than i want to put in - lol
i can start with an enormous chunk of text and see what happens

the icon placement is straightforward
the button placement follows a simple rule, after message text is placed
button size is always the same, although the MessageBox function has a limited number of strings
i plan to expand this a little, so that the MessageBox sized button is the minimum,
but longer strings get a longer button - that is probably the only thing i want to change

i had thought of "auto-formatting" message text
i.e., if a large message string has no line-feeds, i could keep the box at a certain aspect ratio
we'll see how cold the water is when i get to that bridge   :P

dedndave

Hutch,
i did run across this handy little function that you might like...
SendDlgItemMessage

you don't have to retrieve and store all the control handles
you can send messages to the controls by referencing the dialog box handle and the control ID   :U

http://msdn.microsoft.com/en-us/library/ms645515%28v=VS.85%29.aspx

dedndave

i see that MS was careful to leave me room for improvements   :lol

(click on image for full-size)

hutch--

Dave,

SendDlgItemMessage() works OK but it does nothing better than GetDlgItem() placed in the handle position in SendMessage(). In a simple dialog you can use either to deal with the handles but with anything much more complex its worth the extra typing to get the handles for each control as you then have no effective limit on what you can do with them.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

ok - ran across a little bug
i want to see if it is specific to my machine, or a general XP bug   :bg

what's wrong with this picture...


attached is a test program that creates 8 boxes
when all 8 are closed, the program exits
you may have to try it a few times - i get different results each time
after running it a few times, i get all good buttons - lol
it may be that i am running them in threads and MessageBox does not like making so many at once

hutch--

Dave,

About the only difference I can see from running it is the message boxes with the icon are slightly taller as an icon is higher that a single line of text.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php