News:

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

WS_TABSTOP

Started by RuiLoureiro, August 12, 2008, 08:30:51 PM

Previous topic - Next topic

RuiLoureiro

Hi
    I m working with modal dialog boxes, and
    I found this 2 values in WINDOWS.INC:

                WS_TABSTOP         equ 10000h
                WS_MAXIMIZEBOX  equ 10000h

    And then when i use the style WS_TABSTOP the dialog box has
    a maximization button which i dont want.

    Are that 2 values correct ? WS_TABSTOP = 10000h ?

Thanks
Rui   

jj2007

They are correct. WS_TABSTOP is meant for controls, not for the dialog itself, so for Windows there is no ambiguity: You asked for a maximze box, and you got it ;-)

PBrennick

Rui,

I think you are asking why they both have the same values and is this a contradiction? The answer is no. The WS_MAXIMIZE is used by a dialog and the WS_TABSTOP is used by a control within the dialog so there is no problem.

If you do not want the WS_MAXIMIZE, use NOT WS_MAXIMIZE or just remove it from the list.
You can use something like the following to have no Maximize or Minimize boxes:


IDD_DLG1 DIALOGEX 0,0,190,219
CAPTION "ASCII Chart"
FONT 8,"MS Sans Serif",0,0,0
STYLE WS_POPUP|WS_VISIBLE|WS_CAPTION|WS_SYSMENU|DS_CENTER|DS_MODALFRAME
MENU IDM_MNU
BEGIN
  CONTROL "7-Bit ASCII Cponversion Chart:",1001,"Static",0x50000000,10,5,105,10,0x00000000
  CONTROL "", IDC_LIST1, "SysListView32", LVS_REPORT | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP,8,16,174,194,WS_EX_CLIENTEDGE
END

Code taken from the ASCIITable program. Notice the listview has WS_TABSTOP and it does not add a maximize box to the dialog.


-- Paul

[attachment deleted by admin]
The GeneSys Project is available from:
The Repository or My crappy website

RuiLoureiro

Hi all

jj2007,
           OK, i understood. Thanks for the reply

Paul,
           Thank you. Your example is cool.

Now, i have 1 problem to solve:

            How to change the color of a static control  ( LTEXT );

I attathed a prog.  example: Dialog3.asm and Dialog3.exe in Dialo3.zip and rsrc.zip.

The problem is this: the background color of the names "Name" and "Address" in
the dialog box should be the same as the background color of the window. But i couldnt set it.
It gives me white. There are something that im not understanding well

Can anyone help me
Thanks
Rui




[attachment deleted by admin]

MichaelW

There is more than one way to control the background color of a static control. This code returns a NULL_BRUSH in the WM_CTLCOLORSTATIC handler, which tells GDI not to modify the background. An alternative would be to return a brush of a color that matches the window background, and I think there are probably other ways to do it.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      hInstance dd 0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
DlgProc proc hDlg:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
    SWITCH uMsg
      CASE WM_CTLCOLORDLG

        invoke GetStockObject, WHITE_BRUSH

        ret     ; return the brush

      CASE WM_CTLCOLORSTATIC

        invoke SetTextColor, wParam, 0ff0000h
        invoke GetStockObject, NULL_BRUSH

        ret     ; return the brush

      CASE WM_CLOSE
        invoke EndDialog,hDlg,0
    ENDSW
    xor eax, eax
    ret
DlgProc endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    invoke GetModuleHandle, NULL
    mov hInstance, eax
    Dialog "Test", \
           "MS Sans Serif",10, \
           WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \
           1,0,0,120,90,1024
    DlgStatic "HELLO WORLD",SS_LEFT,32,35,52,10,100
    CallModalDialog hInstance,0,DlgProc,NULL
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

eschew obfuscation

PBrennick

Ruyi,
Michael's way is a way that I often use, especially for hyperlinks. But, the easiest way to do it is use an edit controol instead and set the ES_READONLY style. For some reason, that style accomplishes exactly what you want. You can set for no borders, etc, also.

-- Paul
The GeneSys Project is available from:
The Repository or My crappy website

RuiLoureiro

#6
Hi Michael,
               Thank you for your help and code. I ran it i saw what it does.
                But it doesnt solve the problem because the background is white and pushbuttons
                are green as the original color of the window . See it in Dialog4.zip. I want a green
                background color for the window. Thats the problem too.
                In any case, thanks  :U
Hi Paul,
                Thanks for your help, too. I go to test your sugestion.
Rui
               EDIT: the rsrc file is in the previous post

[attachment deleted by admin]

RotateRight

Rui,

Try using a green brush when you register the class.

        invoke CreateSolidBrush,65280   ; 0x00bbggrr
        mov wc.hbrBackground,eax

RuiLoureiro

RotateRight,
                  It doesnt work. We dont register the class because it is a commom control.

I found this in Platform SDK -> User interface services -> windows controls -> Common controls

Common Control Messages
------------------------------------
«When a change is made to the system color settings, Windows sends a
WM_SYSCOLORCHANGE message to all top-level windows.
Your top-level window must forward the WM_SYSCOLORCHANGE message
to its common controls;
otherwise, the controls will not be notified of the color change.

Forwarding the message ensures that the colors used by your common controls
are consistent with those used by other user interface objects.

For example, a toolbar control uses the "3D Objects" color to draw its buttons.
If the user changes the 3D Objects color but the WM_SYSCOLORCHANGE message is not
forwarded to the toolbar
, the toolbar buttons will remain in their original color
(or even change to a combination of old and new colors) while the color of other buttons
in the system changes.»

But i dont understand how it works.
Rui

jj2007

You can always subclass the control and catch the background draw message, see this post for the basics.

PBrennick

Rui,

If you do not have any controls or graphics, etc. beneath the control that has the wrong color, just use the WS_EX_TRANSPARENT style and the color of the background under the control will show through. How about that? Remember to put it in the exStyle part.

-- Paul
The GeneSys Project is available from:
The Repository or My crappy website

MichaelW

Rui,

What colors do you want the dialog and the controls in it to have? I cannot tell from your code what you are trying to do. If you just want the normal dialog colors, there is no need to handle the WM_CTLCOLORDLG or WM_CTLCOLORSTATIC messages.

Also, your code as posted has errors that will keep it from running, at least under Windows 2000. For the main window, the call to RegisterClassEx is failing because your code does not initialize all the members of the WNDCLASSEX structure, and because the structure is LOCAL it initially contains garbage (under Windows 2000 and I think earlier versions). This problem can be corrected by setting all the members of the structure to zero at the start of the procedure:

invoke RtlZeroMemory, ADDR wc, sizeof WNDCLASSEX
eschew obfuscation

jj2007

Quote from: MichaelW on August 14, 2008, 03:57:53 AMbecause the structure is LOCAL it initially contains garbage (under Windows 2000 and I think earlier versions). This problem can be corrected by setting all the members of the structure to zero at the start of the procedure:

invoke RtlZeroMemory, ADDR wc, sizeof WNDCLASSEX


Under all Windows versions indeed, afaik. It would surprise me if Vista allocated a clean fresh stack to all programs - the prologue macro at least does not do the job for us ;-)

RuiLoureiro

Michael,
           Thanks for the reply.

         1. About problems on running Windows 2000. I tested it on my XP and it
            is to run on XP (only). But you have reason, people with 2000 may not run that
            example posted in the forum
           
         2. Usually i dont like to define data in .data? segment (i use only .data) and
            all local variables start with some initial value. I forgot it in that
            example in WNDCLASSEX struc. To correct it (to fix the bug) we need only to do

                            mov   wc.hIcon, NULL

            all other variables have an initial value


         3. The prog i posted is to show the problem about how to change the foreground
            and text colors in a modal dialog box. Thats the problem.
           
            How to do it when i want text color = Blue and window background= Green
            or
            when i want text color = Red and window bkg = default colour bkg
            etc.
           
            By default, on my XP the dialog wnd has a greenish bkg color and all
            other control colors are black (text color is black).
            i want to change text color  ( SetTextColor ) to another color.
           For example
            to the color i get with  (invoke GetSysColor, COLOR_BACKGROUND = Blue is
            what i see). But When i use SetTextColor to BLUE the backgroung of the
            text is white and the window backgrond is greenish. If i use
            SetBkColor to the color i get from GetSysColor, COLOR_WINDOW it
            does nothing.
           
          4. Where i saw information
             Platform SDK -> Development Guides -> Windows API -> Functions by category

            Control-Color Messages
            «
             Controls and the system can send control-color messages when they want
             the dialog box procedure to paint the background of a control
             or other window
             by using a specific brush and colors.

             This can be useful when applications override the default colors
             used in dialog boxes and their controls
.

            Following are the control-color messages,
            which have replaced the WM_CTLCOLOR message.

            WM_CTLCOLORBTN
            WM_CTLCOLORDLG
            WM_CTLCOLOREDIT
            WM_CTLCOLORLISTBOX
            WM_CTLCOLORSCROLLBAR
            WM_CTLCOLORSTATIC

            A control sends a control-color message to the dialog box procedure just before
            it paints its own background.
             
            The message allows the procedure to specify which brush to use and
            to set the background and foreground colors
.
            The procedure specifies a brush by returning the brush handle.
           
            To set the background and foreground colors,
            the procedure uses the SetBkColor and SetTextColor functions with
            the control's display device context.
             
            The control-color message passes a handle to the display device context
            to the procedure in the message's wParam parameter

            ...
            In any case, when a dialog box procedure does not process a control-color message,
            the system uses a brush with the default window color to paint the background
            for all controls and windows except scroll bars.
           
            An application can retrieve the default window color by passing the COLOR_WINDOW
            value to the GetSysColor
function.
            While the background is painted, the foreground color for the
            display device context is set to the default text color (COLOR_WINDOWTEXT)
            »
            «
            WM_CTLCOLORSTATIC Notification

            A static control, or an edit control that is read-only or disabled,
            sends the WM_CTLCOLORSTATIC message to its parent window when the control
            is about to be drawn.
            By responding to this message, the parent window can use
            the specified device context handle
            to set the text and background colors of the static control.

            A window receives this message through its WindowProc function.

            WM_CTLCOLORSTATIC

            WPARAM wParam
            LPARAM lParam;

            wParam = Handle to the device context for the static control window.
            lParam = Handle to the static control.

            Return Value: If an application processes this message,
            the return value is a handle to a brush that the system uses
            to paint the background of the static control.
            »
            ;...................................

Michael,
            It seems to be easy.
            I tried to use this information. But i am doing something wrong
            or i misunderstood something ...and, at last, it doesnt work

Rui

MichaelW

Microsoft could have done a better job on the WM_CTLCOLORSTATIC documentation, and it should have included a working example.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      hInstance dd 0
      hBrush    dd 0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
DlgProc proc hDlg:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    SWITCH uMsg

      CASE WM_INITDIALOG

        invoke CreateSolidBrush, 0ff00h
        mov hBrush, eax

      CASE WM_CTLCOLORDLG

        ;------------------------------------------
        ; Comment this out for default background.
        ;------------------------------------------

        return hBrush

      CASE WM_CTLCOLORSTATIC

        ;----------------------------------------------
        ; The default message handling will ignore the
        ; text color setting if no brush is returned.
        ;----------------------------------------------

        ;--------------------------------
        ; Blue text on green background.
        ;--------------------------------

        invoke SetTextColor, wParam, 0ff0000h
        invoke SetBkColor, wParam, 0ff00h
        invoke GetStockObject, NULL_BRUSH
        ret

        ;invoke SetTextColor, wParam, 0ff0000h
        ;invoke SetBkMode, wParam, TRANSPARENT
        ;return hBrush

        ;invoke SetTextColor, wParam, 0ff0000h
        ;invoke SetBkMode, wParam, TRANSPARENT
        ;invoke GetStockObject, NULL_BRUSH
        ;ret

        ;---------------------------------
        ; Red text on default background.
        ;---------------------------------

        ;invoke SetTextColor, wParam, 0ffh
        ;invoke SetBkMode, wParam, TRANSPARENT
        ;invoke GetStockObject, NULL_BRUSH
        ;ret

      CASE WM_CLOSE

        invoke DeleteObject, hBrush
        invoke EndDialog,hDlg,0

    ENDSW
    xor eax, eax
    ret
DlgProc endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    invoke GetModuleHandle, NULL
    mov hInstance, eax
    Dialog "Test", \
           "MS Sans Serif",10, \
           WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \
           1,0,0,120,90,1024
    DlgStatic "HELLO WORLD",SS_LEFT,32,35,52,10,100
    CallModalDialog hInstance,0,DlgProc,NULL
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


Also, are you aware that I posted an example that displays a list of the system colors here.

eschew obfuscation