Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dialog control - add color border when focused
#1
Sorry again for this simple question.
I am looking for a way to give an interface element-border a different color (example: text-inputfield).
(see code below)

To summarize, I am just looking for a very simple way to change the border color of an interface element.
Or change the borderline/border color of the "Group, or multi-drag container", in that way I just place the around the interface-object(s)
(see code below)

Macro border_color_macro
Code:
Copy      Help
str controls = "3"
str e3Cha="Change bordercolor of this inputfield"
if(!ShowDialog("border_color" &border_color &controls)) ret

Function border_color
Code:
Copy      Help
;\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages


;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;3 Edit 0x54030080 0x200 28 46 154 14 "Change color of the inputfield border"
;4 Button 0x54020007 0x0 22 24 168 44 "Or change border-line/border-color of this element"
;END DIALOG
;DIALOG EDITOR: "" 0x2030307 "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#2
You will not find a simple way.
Can subclass the control and draw rectangle when it receives WM_NCPAINT.
Or create a hollow colored control and put it on top of the focused control, like in this example.
Or...

Function dialog_color_focus_rect
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3 4"
str e3 e4
if(!ShowDialog("dialog_color_focus_rect" &dialog_color_focus_rect &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;3 Edit 0x54030080 0x200 8 14 56 14 ""
;4 Edit 0x54030080 0x200 110 14 96 14 ""
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030508 "*" "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_DRAWITEM
,DT_SCFC_on_WM_DRAWITEM hDlg wParam lParam
,
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case [EN_SETFOCUS<<16|3,EN_SETFOCUS<<16|4]
,DT_ShowColorFocusControl hDlg
,
,case IDOK
,case IDCANCEL
ret 1
Function DT_ShowColorFocusControl
Code:
Copy      Help
;/dialog_color_focus_rect
function hDlg

;Call this from dialog procedure whenever focused control changed.

int borderWidth=1

;create static control that will be the focus rectangle
int hr=id(999 hDlg 1)
if(!hr) hr=CreateControl(0 "Static" 0 SS_OWNERDRAW 0 0 0 0 hDlg 999)
ShowWindow hr 0

;get rectangle of focused control and move our focus rect control there
int hf=GetFocus; if(!hf) ret
RECT r; GetWindowRect hf &r; MapWindowPoints 0 hDlg +&r 2
MoveWindow hr r.left r.top r.right-r.left r.bottom-r.top 0

;make our focus rect control hollow, to look like a rectangle with 1 pixel border
OffsetRect &r -r.left -r.top
int r1=CreateRectRgnIndirect(&r)
__GdiHandle r2; InflateRect &r -borderWidth -borderWidth; r2=CreateRectRgnIndirect(&r)
CombineRgn r1 r1 r2 RGN_DIFF
SetWindowRgn hr r1 0

BringWindowToTop hr
ShowWindow hr SW_SHOW
Function DT_SCFC_on_WM_DRAWITEM
Code:
Copy      Help
;/dialog_color_focus_rect
function hDlg wParam lParam

;Call this from dialog procedure on WM_DRAWITEM.
;Makes the focus rectangle blue.

int color=0xff0000 ;;blue

if(wParam!999) ret
__GdiHandle-- t_brush=CreateSolidBrush(color)
DRAWITEMSTRUCT& d=+lParam
RECT r; GetClientRect d.hWndItem &r
FillRect d.hDC &r t_brush
#3
Yes this was exactly what I was looking for, thank you!!!


Forum Jump:


Users browsing this thread: 2 Guest(s)