programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: colored buttons

From: Virgil Stamps <vstamps_at_houston.rr.com>
Date: Mon, 6 Jun 2005 07:52:52 -0500

About 1-2 years ago I received help on color buttons myself. I wanted
pushbuttons that would indicate state by color. Rather than trim this down
and leave something out, here is the source for a modal window.
Virgil
\ relay1.f
DIALOG Relay1_Setup-TEMPLATE
[MODAL " Relay Group 1 State, Sense and Test" 8 12 168 172
 (FONT 12, MS Sans Serif) ]
 [LTEXT " Out Sense" -1 110 4 50 12 ]
 [RTEXT " Standby" -1 4 20 102 12 ]
 [RTEXT " Calib.in Progress" -1 4 36 102 12 ]
 [RTEXT " System Fail" -1 4 52 102 12 ]
 [RTEXT " Come Read" -1 4 68 102 12 ]
 [RTEXT " Local Lockout" -1 4 84 102 12 ]
 [RTEXT " Calibration Confirm" -1 4 100 102 12 ]
 [RTEXT " Validation Confirm" -1 4 116 102 12 ]
 [RTEXT " Process Confirm" -1 4 132 102 12 ]

 [DRAWNBUTTON " " 116 114 20 10 10 ] \ r16 Standby
Status
 [DRAWNBUTTON " " 117 114 36 10 10 ] \ r17 Calibration
in Progress
 [DRAWNBUTTON " " 118 114 52 10 10 ] \ r18 System Fail
Status Out
 [DRAWNBUTTON " " 119 114 68 10 10 ] \ r19 Come Read
Status Out
 [DRAWNBUTTON " " 121 114 84 10 10 ] \ r21 Local Lockout
Status
 [DRAWNBUTTON " " 132 114 100 10 10 ] \ r32 Calibration
Confirm Status Out
 [DRAWNBUTTON " " 133 114 116 10 10 ] \ r33 Validation
Confirm Status Out
 [DRAWNBUTTON " " 145 114 132 10 10 ] \ r45 Process
Confirm

 [DRAWNBUTTON " " 148 134 20 10 10 ] \ r48 Standby
Status Sense
 [DRAWNBUTTON " " 149 134 36 10 10 ] \ r49 Calibration
in Progress Sense
 [DRAWNBUTTON " " 150 134 52 10 10 ] \ r50 System Fail
Status Out Sense
 [DRAWNBUTTON " " 151 134 68 10 10 ] \ r51 Come Read
Status Out Sense
 [DRAWNBUTTON " " 153 134 84 10 10 ] \ r53 Local Lockout
Status Sense
 [DRAWNBUTTON " " 164 134 100 10 10 ] \ r64 Calibration
Confirm Status Out Sense
 [DRAWNBUTTON " " 165 134 116 10 10 ] \ r65 Validation
Confirm Status Out Sense
 [DRAWNBUTTON " " 177 134 132 10 10 ] \ r77 Process
Confirm sense

 [DEFPUSHBUTTON " Exit" 1 114 148 40 12 ]

END-DIALOG
0 VALUE BRUSH2

: KILLBRUSH2 ( -- )
   BRUSH2 IF BRUSH2 DeleteObject DROP 0 TO BRUSH2 THEN ;

: Mode_State2 ( flag -- color )
    IF GREEN
    ELSE BLACK
    THEN ;
: Sense_State2 ( flag -- color ) IF LIGHT-BLUE ELSE LIGHT-GRAY THEN ;

: BUTTONBRUSH2 ( -- hbrush ) KILLBRUSH2
   LPARAM GetDlgCtrlID CASE
  116 OF DOA. @R16 Mode_State2 ENDOF \ Standby Status
  117 OF DOA. @R17 Mode_State2 ENDOF \ Calibration in Progress
  118 OF DOA. @R18 Mode_State2 ENDOF \ System Fail Status Out
  119 OF DOA. @R19 Mode_State2 ENDOF \ Come Read Status Out
  121 OF DOA. @R21 Mode_State2 ENDOF \ Local Lockout Status
  132 OF DOA. @R32 Mode_State2 ENDOF \ Calibration Confirm Status Out
  133 OF DOA. @R33 Mode_State2 ENDOF \ Validation Confirm Status Out
  145 OF DOA. @R45 Mode_State2 ENDOF \ r45 Process Confirm

  148 OF DOA. @R48 Sense_State2 ENDOF \ Standby Status Sense
  149 OF DOA. @R49 Sense_State2 ENDOF \ Calibration in Progress Sense
  150 OF DOA. @R50 Sense_State2 ENDOF \ System Fail Status Out Sense
  151 OF DOA. @R51 Sense_State2 ENDOF \ Come Read Status Out Sense
  153 OF DOA. @R53 Sense_State2 ENDOF \ Local Lockout Status Sense
  164 OF DOA. @R64 Sense_State2 ENDOF \ Calibration Confirm Status Out
Sense
  165 OF DOA. @R65 Sense_State2 ENDOF \ Validation Confirm Status Out
Sense
  177 OF DOA. @R77 Sense_State2 ENDOF \ r77 Process Confirm sense

   ENDCASE CreateSolidBrush DUP TO BRUSH2 ;

: REFRESH_Relay1_STATUS ;

0 VALUE DOACRC10
: REFRESH-Relay1-REGISTERS ( -- )
   DOACRC10 DOA LAST-DOA CRC DROP DUP TO DOACRC10 = NOT
   IF REFRESH_Relay1_STATUS
       HWND 0 0 InvalidateRect DROP
   THEN
 ;

: Relay1-CLOSE ( -- res ) KILLBRUSH2
     Relay1_Setup-TEMPLATE CELL- OFF HWND DestroyWindow 0
   1 KillTimer DROP 0 ;

: Relay1-INIT ( -- ) FALSE TO DOACRC10 #Rly1 TO Schedule
   HWND 1 500 0 SetTimer DROP
    0 TO BRUSH2 ;

: ButtonSend2 ( id n -) ?Access
    IF -Bool 5 XMIT
    ELSE DROP DROP PleaseLogOn
    THEN ;

[SWITCH Relay1_Setup-COMMANDS DROP ( wparam -- )
   IDOK RUN: #Idle TO Schedule HWND 0 EndDialog ;
    116 RUN: DOA. R16 DOA. @R16 ButtonSend2 ; \ Sample/Cal Flow Block
    117 RUN: DOA. R17 DOA. @R17 ButtonSend2 ; \ Strm 1 sel
    118 RUN: DOA. R18 DOA. @R18 ButtonSend2 ; \ val 1 sel
    119 RUN: DOA. R19 DOA. @R19 ButtonSend2 ; \ cal 1 sel
    120 RUN: DOA. R20 DOA. @R20 ButtonSend2 ; \ Strm 2 sel
    121 RUN: DOA. R21 DOA. @R21 ButtonSend2 ; \ val 2 sel
    132 RUN: DOA. R32 DOA. @R32 ButtonSend2 ; \ cal 2 sel
    133 RUN: DOA. R33 DOA. @R33 ButtonSend2 ; \ inj sel
    145 RUN: DOA. R45 DOA. @R45 ButtonSend2 ; \ Process Confirm

    148 RUN: DOA. R48 DOA. @R48 ButtonSend2 ; \ Sample/Cal Flow Block
sense
    149 RUN: DOA. R49 DOA. @R49 ButtonSend2 ; \ Strm 1 sel sense
    150 RUN: DOA. R50 DOA. @R50 ButtonSend2 ; \ val 1 sel sense
    151 RUN: DOA. R51 DOA. @R51 ButtonSend2 ; \ cal 1 sel sense
    152 RUN: DOA. R52 DOA. @R52 ButtonSend2 ; \ Strm 2 sel sense
    153 RUN: DOA. R53 DOA. @R53 ButtonSend2 ; \ val 2 sel sense
    164 RUN: DOA. R64 DOA. @R64 ButtonSend2 ; \ cal 2 sel sense
    165 RUN: DOA. R65 DOA. @R65 ButtonSend2 ; \ inj sel sense
    177 RUN: DOA. R77 DOA. @R77 ButtonSend2 ; \ Process Confirm sense
SWITCH]

[SWITCH Relay1_Setup-MESSAGES ZERO ( msg -- res )
   WM_INITDIALOG RUN: Relay1-INIT -1 ;
   WM_CLOSE RUNS Relay1-CLOSE
   WM_COMMAND RUN: WPARAM LOWORD Relay1_Setup-COMMANDS ;
   WM_TIMER RUN: REFRESH-Relay1-REGISTERS 0 ;
   WM_CTLCOLORBTN RUN: ( -- hbrush ) BUTTONBRUSH2 ;

SWITCH]

:NONAME ( -- res ) MSG LOWORD Relay1_Setup-MESSAGES ; 4 CB:
Relay1_Setup-CALLBACK

: Relay1_Setup ( hwnd -- res )
   HINST Relay1_Setup-TEMPLATE ROT Relay1_Setup-CALLBACK 0
DialogBoxIndirectParam ;

-----Original Message-----
From: sftalk-bounce_at_forth.com [mailto:sftalk-bounce_at_forth.com] On Behalf Of
wheath_at_comcast.net
Sent: Sunday, June 05, 2005 10:28 AM
To: sftalk_at_forth.com
Subject: [sftalk] Re: colored buttons

I have investigated this problem extensively, and as far as I could find
out, in windows this is very difficult. The WM_CTLCOLORBTN message sent to
the dialog does NOT work as advertised and the button always gets painted
back to its original windows default color. I have tried invalidating the
button rectangle,
painting over the rectangle etc and all fail.
Possibly one could "subclass" the button and change its color.
The "Official" way is the create your own [DRAWNBUTTON
button. However, then you have to handle ALL of the messages sent to the
button, outline it, color it, change the clicked and unclicked appearance,
change the focus rectangle, etc yourself.
---------------------------------------------------------------------

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Mon Jun 06 2005 - 05:50:46 PDT

This archive was generated by hypermail 2.2.0 : Thu Dec 04 2008 - 03:04:20 PST