Kbase 22038: How To Change Placement of a Toggle-Box Label on the Screen
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/20/2001 |
|
SUMMARY:
By default, the standard Progress toggle-box widget has its label displayed on the right side. However, developers or end-users may wish to have a left-side label toggle-box widget instead. This Knowledge Base Solution shows you how to make use of the BS_LEFTTEXT Windows API constant to bring the check box's label text to the left.
SOLUTION:
This code example places a call to the Win32 API function,
SetWindowLongA, in order to accomplish the functionality. It also calls the InvalidateRect API to force a repaint of the Progress window after changing the side of the toggle-box label.
&SCOPED-DEFINE GWL_STYLE -16
&SCOPED-DEFINE BS_LEFTTEXT 32
DEFINE VARIABLE TOGGLE-1 AS LOGICAL INITIAL no
LABEL "Right-side label"
VIEW-AS TOGGLE-BOX
SIZE 21 BY .81 NO-UNDO.
DEFINE FRAME DEFAULT-FRAME
TOGGLE-1 AT ROW 1.95 COL 15
WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY
SIDE-LABELS NO-UNDERLINE THREE-D
AT COL 1 ROW 1
SIZE 47.2 BY 3.
ASSIGN
CURRENT-WINDOW:TITLE = "Left-side label toggle-box."
CURRENT-WINDOW:HEIGHT = 3
CURRENT-WINDOW:WIDTH = 47.2.
ON VALUE-CHANGED OF toggle-1 IN FRAME DEFAULT-FRAME
DO:
RUN changeToggleLabelSide(SELF:HWND,
IF SELF:LABEL BEGINS "R":U THEN
YES
ELSE
NO).
END.
MESSAGE "Click on the toggle-box to change its label side":U.
ENABLE ALL WITH FRAME DEFAULT-FRAME.
WAIT-FOR CLOSE OF THIS-PROCEDURE.
PROCEDURE changeToggleLabelSide:
DEFINE INPUT PARAMETER piHWND AS INTEGER NO-UNDO.
DEFINE INPUT PARAMETER plLeftLabel AS LOGICAL NO-UNDO.
DEFINE VARIABLE viStyles AS INTEGER NO-UNDO.
DEFINE VARIABLE viReturnvalue AS INTEGER NO-UNDO.
RUN GetWindowLongA (piHWND,
{&GWL_STYLE},
OUTPUT viStyles).
ASSIGN viStyles = viStyles + IF plLeftLabel THEN
{&BS_LEFTTEXT}
ELSE
((-1) * {&BS_LEFTTEXT}).
RUN SetWindowLongA (piHWND,
{&GWL_STYLE},
viStyles,
OUTPUT viStyles).
RUN InvalidateRect (piHWND,
0,
1,
OUTPUT viReturnvalue).
ASSIGN
toggle-1:LABEL IN FRAME default-frame = IF plLeftLabel THEN
"Left-side label":U
ELSE
"Right-side label":U.
END PROCEDURE.
PROCEDURE GetWindowLongA EXTERNAL "user32.dll":U:
DEFINE INPUT PARAMETER phwnd AS LONG NO-UNDO.
DEFINE INPUT PARAMETER cindex AS LONG NO-UNDO.
DEFINE RETURN PARAMETER currentlong AS LONG NO-UNDO.
END PROCEDURE.
PROCEDURE SetWindowLongA EXTERNAL "user32.dll":U:
DEFINE INPUT PARAMETER phwnd AS LONG NO-UNDO.
DEFINE INPUT PARAMETER cindex AS LONG NO-UNDO.
DEFINE INPUT PARAMETER newlong AS LONG NO-UNDO.
DEFINE RETURN PARAMETER oldlong AS LONG NO-UNDO.
END PROCEDURE.
PROCEDURE InvalidateRect EXTERNAL "user32.dll":U:
DEFINE INPUT PARAMETER HWND AS LONG NO-UNDO.
DEFINE INPUT PARAMETER lpRect AS LONG NO-UNDO.
DEFINE INPUT PARAMETER bErase AS LONG NO-UNDO.
DEFINE RETURN PARAMETER ReturnValue AS LONG NO-UNDO.
END PROCEDURE.
References to Written Documentation:
Progress Knowledge Base Solutions:
19504, "WIN32 API - How to Remove ScrollBars from a Window or Frame"
20708, "How To Force a Progress Window To Be Repainted on Entry"
21557, "How To Change the RESIZE Attr of a Window After Realizing It"