Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Transparent Text Background over progress bar
#1
Hi All,

It would be cool to have progress bar fill in over text. I know settings of "Static text transparent background" from http://www.quickmacros.com/forum/showthr...p?tid=3980. But there seems to be z-order issue. When update of progress bar occurs, it moves in front of text. Any tricks to keep the text on top of the progress bar?
Thanks, S

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

;note: static control: remove WS_CLIPSIBLINGS style, and add WS_EX_TRANSPARENT.

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 46 18 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;4 Static 0x50000201 0x20 2 4 42 10 "TEXT"
;3 msctls_progress32 0x54000000 0x4 0 0 46 18 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030605 "" "" "" ""


if(!ShowDialog("Dialog4" &Dialog4)) ret

ret
;messages

int hpb=id(3 hDlg)
int step= 1        
int range=6
sel message
,case WM_INITDIALOG
,,__Font-- f
,,f.Create("Courier New" 22 1)
,,f.SetDialogFont(hDlg "4")
,,SendMessage hpb PBM_SETRANGE 1 range<<16
,,SetTimer hDlg 1 1 0
,,int+ rangecounter
,case WM_DESTROY
,case WM_TIMER
,,out rangecounter
,,SendMessage hpb PBM_SETPOS rangecounter 0
,,Zorder id(4 hDlg) HWND_TOPMOST
,,rangecounter = rangecounter+1
,,if rangecounter > range
,,,KillTimer hDlg 1
,case WM_CTLCOLORSTATIC
,sel GetWinId(lParam)
,,case 4
,,SetBkMode wParam TRANSPARENT
,,ret GetStockObject(NULL_BRUSH) ;;transparent brush
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#2
Function Dialog4567
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 46 18 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 msctls_progress32 0x54000000 0x4 0 0 46 18 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030605 "" "" "" ""


if(!ShowDialog("" &Dialog4567)) ret

ret
;messages

int hpb=id(3 hDlg)
int step= 1
int range=6
sel message
,case WM_INITDIALOG
,,__Font-- f
,,f.Create("Courier New" 22 1)
,,SetWindowSubclass hpb &subclass_progress_bar_text 1 &f
,,SendMessage hpb PBM_SETRANGE 1 range<<16
,,SetTimer hDlg 1 1 0
,,int-- rangecounter
,case WM_DESTROY
,case WM_TIMER
,,out rangecounter
,,SendMessage hpb PBM_SETPOS rangecounter 0
,,rangecounter = rangecounter+1
,,if rangecounter > range
,,,KillTimer hDlg 1
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

Function subclass_progress_bar_text
Code:
Copy      Help
;/
function# hWnd message wParam lParam uIdSubclass dwRefData

;This function can be used with SetWindowSubclass as window procedure.
;<help>SetWindowSubclass</help> is the recommended way to subclass windows. Easier and safer than SetWindowLong.

;OutWinMsg message wParam lParam ;;uncomment to see received messages

int R=DefSubclassProc(hWnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hWnd &subclass_progress_bar_text uIdSubclass)
,
,case WM_PAINT
,int dc=GetDC(hWnd)
,int k=SaveDC(dc)
,__Font& f=+dwRefData
,SelectObject(dc f)
,SetBkMode dc TRANSPARENT
,SetTextColor dc 0xFF0000
,TextOutW dc 0 0 L"TEST" 4
,RestoreDC dc k
,ReleaseDC hWnd dc

ret R
#3
Thanks so much! Completely works as written. But how do I center text. It is starting from upper left. Only looks good if the width of text and size of progress bar are exactly same. Is it possible to center the text. If exceedingly complicated, not worth it...only if easy for you!,
Thanks so much as always, S
#4
Instead of TextOut[W] use DrawText[Ex][W] with flag DT_CENTER. Reference in MSDN Library.
#5
thanks!,
S
#6
Looked here http://msdn.microsoft.com/en-us/library/...s.85).aspx

tried to do it like this based on above and dll user32 [DrawTextA]#DrawText hdc $lpchText cchText RECT*lprc format:

Code:
Copy      Help
,RECT r; DpiGetWindowRect dc &r ;;push button
,lpstr s = "TEST"
,DrawText dc s -1 &r  DT_CENTER

but text remains invisible.

not sure what you mean by [Ex] and [W] in DrawText[Ex][W]

Thanks, S

Quote:int DrawText(
_In_ HDC hDC,
_Inout_ LPCTSTR lpchText,
_In_ int nCount,
_Inout_ LPRECT lpRect,
_In_ UINT uFormat
);

Parameters
hDC [in]
A handle to the device context.
lpchText [in, out]
A pointer to the string that specifies the text to be drawn. If the nCount parameter is -1, the string must be null-terminated.
If uFormat includes DT_MODIFYSTRING, the function could add up to four additional characters to this string. The buffer containing the string should be large enough to accommodate these extra characters.
nCount [in]
The length, in characters, of the string. If nCount is -1, then the lpchText parameter is assumed to be a pointer to a null-terminated string and DrawText computes the character count automatically.
lpRect [in, out]
A pointer to a RECT structure that contains the rectangle (in logical coordinates) in which the text is to be formatted.
uFormat [in]
The method of formatting the text. This parameter can be one or more of the following values.
Value Meaning
DT_CENTER
Centers text horizontally in the rectangle.


Forum Jump:


Users browsing this thread: 1 Guest(s)