News:

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

Read only EditBox text color

Started by statis, September 25, 2011, 07:25:56 PM

Previous topic - Next topic

statis

Hello,

I search to have many text colors in my readonly EditBox's on dialogBox.
I have 4 ReadOnlyEditBox's and i do testing values and text does comming red if value isn't good.
I have tested WM_CTLCOLORSTATIC but 4 all's are red and if minimize dialogbox when windows is restaured all's (>4)OnlyReadEditBox text's are red.


Have you solution ?
Thanks

dedndave

offhand, it sounds like bad values

the values are in COLORREF form...
http://msdn.microsoft.com/en-us/library/aa923096.aspx

so, red would be 0FFh
green would be 0FF00h
and blue would be 0FF0000h

qWord

While handling WM_CTLCOLORSTATIC, you must filter the request by comparing the sender (lParam) with the handle (or the ID) of the control, that displays the invalid value.
FPU in a trice: SmplMath
It's that simple!

MichaelW

This works for me:

;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================

IDC_EDIT1 equ 1001
IDC_EDIT2 equ 1002
IDC_EDIT3 equ 1003

;==============================================================================
    .data
        hInstance dd 0
        hwndEdit1 dd 0
        hwndEdit2 dd 0
        hwndEdit3 dd 0
    .code
;==============================================================================

DlgProc proc hwndDlg:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD

    SWITCH uMsg

        CASE WM_INITDIALOG

            invoke GetDlgItem, hwndDlg, IDC_EDIT1
            mov hwndEdit1, eax

            invoke GetDlgItem, hwndDlg, IDC_EDIT2
            mov hwndEdit2, eax

            invoke GetDlgItem, hwndDlg, IDC_EDIT3
            mov hwndEdit3, eax

            invoke SetDlgItemText, hwndDlg, IDC_EDIT1, chr$("ABC.XYZabc.xyz")

            invoke SetDlgItemText, hwndDlg, IDC_EDIT2, chr$("ABC.XYZabc.xyz")

            invoke SetDlgItemText, hwndDlg, IDC_EDIT3, chr$("ABC.XYZabc.xyz")

            ;--------------------------------------------------------
            ; Cannot remove highlight by sending EM_SETSEL directly
            ; from WM_INITDIALOG handler:
            ;
            ;     http://support.microsoft.com/kb/96674
            ;
            ;--------------------------------------------------------

            invoke SetFocus, hwndEdit1
            invoke PostMessage, hwndEdit1, EM_SETSEL ,0 , 0

        CASE WM_CTLCOLORSTATIC

            SWITCH lParam

                CASE hwndEdit1

                    invoke SetTextColor, wParam, 0ffh

                CASE hwndEdit2

                    invoke SetTextColor, wParam, 0ff00h

                CASE hwndEdit3

                    invoke SetTextColor, wParam, 0ff0000h

            ENDSW

            invoke GetStockObject, WHITE_BRUSH

            ret

        CASE WM_COMMAND

            SWITCH wParam

                CASE IDCANCEL

                    invoke EndDialog, hwndDlg, 0

            ENDSW

        CASE WM_CLOSE

            invoke EndDialog, hwndDlg, 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 WS_MINIMIZEBOX or DS_CENTER, \
           3,0,0,100,100,1024

    DlgEdit WS_BORDER or ES_MULTILINE or ES_WANTRETURN or \
            WS_VSCROLL or ES_AUTOVSCROLL or ES_READONLY, \
            5,5,87,20,IDC_EDIT1

    DlgEdit WS_BORDER or ES_MULTILINE or ES_WANTRETURN or \
            WS_VSCROLL or ES_AUTOVSCROLL or ES_READONLY, \
            5,32,87,20,IDC_EDIT2

    DlgEdit WS_BORDER or ES_MULTILINE or ES_WANTRETURN or \
            WS_VSCROLL or ES_AUTOVSCROLL or ES_READONLY, \
            5,59,87,20,IDC_EDIT3

    CallModalDialog hInstance,0,DlgProc,NULL

    exit
;==============================================================================
end start


Edit: There is a problem with tab-key navigation leaving the text highlighted, and I can see no easy way around this.
eschew obfuscation

dedndave

i used WS_GROUP and WS_TABSTOP to get the tab key to work
and - the edit boxes are now multi-line, as you requested   :bg

    invoke GetModuleHandle, NULL
    mov   hInstance, eax

    Dialog "Test", \
           "MS Sans Serif",10, \
           WS_OVERLAPPED or WS_SYSMENU or WS_MINIMIZEBOX or DS_CENTER or WS_CLIPCHILDREN, \
           3,0,0,100,100,1024

    DlgEdit WS_BORDER or ES_MULTILINE or ES_WANTRETURN or \
            WS_VSCROLL or ES_AUTOVSCROLL or ES_READONLY or WS_GROUP or WS_TABSTOP, \
            5,5,87,20,IDC_EDIT1

    DlgEdit WS_BORDER or ES_MULTILINE or ES_WANTRETURN or \
            WS_VSCROLL or ES_AUTOVSCROLL or ES_READONLY or WS_TABSTOP, \
            5,32,87,20,IDC_EDIT2

    DlgEdit WS_BORDER or ES_MULTILINE or ES_WANTRETURN or \
            WS_VSCROLL or ES_AUTOVSCROLL or ES_READONLY or WS_TABSTOP, \
            5,59,87,20,IDC_EDIT3

    CallModalDialog hInstance,0,DlgProc,NULL

    exit


i also added WS_CLIPCHILDREN to the main dialog out of "general practice" - lol

statis

Thanks +++,

I do change colors before and after action

code extract:
.if eax==hIDE_EDIT0
  .if hcolor0==0
    invoke SetTextColor, wParam, 0h
  .elseif hcolor0==1
    invoke SetTextColor, wParam, 0ffh
  .endif
.elseif eax==hIDE_EDIT1
  .if hcolor1==0
    invoke SetTextColor, wParam, 0h
  .elseif hcolor1==1
    invoke SetTextColor, wParam, 0ffh
  .endif
.endif
;
;change0 action after text sending
mov hcolor0,1
invoke SendMessage,hWnd,WM_CTLCOLORSTATIC,0,0
;
;change1 action after text sending
mov hcolor1,1
invoke SendMessage,hWnd,WM_CTLCOLORSTATIC,0,0

i have more tried with invoke SendMessage,hWnd,WM_CTLCOLORSTATIC,0,hIDE_EDIT0 (and hIDE_EDIT1)
to write text color is ok
to change isn't
If  i minimized/restaured window colors are updated with my choice hcolor edit take color

Do you have solution to update color ?

PS for me TAB with WS_GROUP and WS_TABSTOP doesn't work

statis

Solved with :
invoke RedrawWindow,hWnd,NULL,NULL,RDW_INVALIDATE or RDW_UPDATENOW or RDW_ERASE , after change hcolorx

thanks more

dedndave

maybe this will help

QuoteA 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.

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.

http://msdn.microsoft.com/en-us/library/windows/desktop/bb787524%28v=vs.85%29.aspx

PBrennick

... subclassing is my thought same as I do with my about boxes ...

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