Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dialog control - add color border when focused
#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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)