Code:
#Compile Exe #Dim All #Register None #Include "Win32Api.INC" %DlgColor = &HC08040 '****************************** '* pbLabel * '****************************** Global pbLabel_Default_ForeColor As Long, pbLabel_Default_BackColor As Long %pbLabel_Frame = 4 Function Register_pbLabel As Long Local wc As WNDCLASS Local szClassName As Asciiz * 8 szClassName = "pbLabel" wc.lpfnWndProc = CodePtr(pbLabelProc) wc.hInstance = GetModuleHandle(ByVal 0&) wc.hCursor = LoadCursor(ByVal 0&, ByVal %IDC_ARROW) wc.hBrBackGround = GetStockObject(%NULL_BRUSH) wc.lpszClassName = VarPtr(szClassName) wc.cbWndExtra = 8 Function = RegisterClass(wc) End Function %pbLabel_ForeColor = 0 %pbLabel_BackColor = 4 Function pbLabelProc (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Dim i As Long, j As Long, jj As Long, k As Long, kk As Long Dim hMemDC As Long, hMemBmp As Long, pBits As Long Ptr Dim Clr As Long Static hFont As Long Dim bmi As BITMAPINFO, bm As BITMAP, ps As PAINTSTRUCT, rc As Rect Select Case wMsg Case %WM_CREATE ' Defaults SetWindowLong hWnd, %pbLabel_ForeColor, pbLabel_Default_ForeColor SetWindowLong hWnd, %pbLabel_BackColor, pbLabel_Default_BackColor Case %WM_SETFONT hFont = wParam Case %WM_SETTEXT Function = DefWindowProc(hWnd, wMsg, wParam, lParam) InvalidateRect hWnd, ByVal 0, 0 UpdateWindow hWnd Exit Function Case %WM_PAINT Dim MyClr(2) As Long MyClr(0) = MakLng(&H0300, 2) MyClr(1) = GetWindowLong (hWnd, %pbLabel_ForeColor) MyClr(2) = GetWindowLong (hWnd, %pbLabel_BackColor) MyClr(0) = CreatePalette (ByVal VarPtr(MyClr(0))) BeginPaint hWnd, ps SelectPalette ps.hDC, MyClr(0), %False RealizePalette ps.hDC GetClientRect hWnd, rc hMemDC = CreateCompatibleDC(ps.hDC) bmi.bmiHeader.biSize = SizeOf(bmi.bmiHeader) bmi.bmiHeader.biWidth = rc.nRight - rc.nLeft bmi.bmiHeader.biHeight = rc.nBottom - rc.nTop bmi.bmiHeader.biPlanes = 1 bmi.bmiHeader.biBitCount = 32 bmi.bmiHeader.biCompression = %BI_RGB hMemBmp = CreateDIBSection(hMemDC, bmi, %DIB_RGB_COLORS, 0, 0, 0) GlobalLock hMemBmp: SelectObject hMemDC, hMemBmp GetObject hMemBmp, SizeOf(bm), bm pBits = bm.bmBits i = GetWindowLong (hWnd, %pbLabel_BackColor) j = (i And &H00FF0000): Shift Right j, 16 k = (i And &H0000FF00): Shift Right k, 8 i = (i And &HFF) Clr = Rgb(j, k, i) For j = rc.nBottom - 1 To rc.nTop Step - 1 For k = rc.nLeft To rc.nRight - 1 @pBits = Clr: pBits = pBits + 4 Next Next SetBkMode hMemDC, %OPAQUE SetBkColor hMemDC, GetWindowLong (hWnd, %pbLabel_BackColor) SetTextColor hMemDC, GetWindowLong (hWnd, %pbLabel_ForeColor) SelectObject hMemDC, hFont Dim Txt As Asciiz * 100, sz As SIZEL GetWindowText hWnd, Txt, SizeOf(Txt) i = GetWindowLong(hWnd, %GWL_STYLE) If (i And %SS_RIGHT) = %SS_RIGHT Then j = %SS_RIGHT Else _ If (i And %SS_CENTER) = %SS_CENTER Then j = %SS_CENTER Else _ j = %SS_LEFT GetTextExtentPoint32 hMemDC, Txt, Len(Txt), sz GetClientRect hWnd, rc If (i And %pbLabel_FRAME) = %pbLabel_FRAME Then Select Case j Case %SS_CENTER: sz.cx = Max(0, (rc.nRight - rc.nLeft - sz.cx) \ 2) Case %SS_LEFT: sz.cx = Min(0.05 * (rc.nRight - rc.nLeft), rc.nRight - rc.nLeft - sz.cx) Case %SS_RIGHT: sz.cx = Max(0, 0.95 * (rc.nRight - rc.nLeft) - sz.cx) End Select pBits = bm.bmBits i = GetWindowLong (hWnd, %pbLabel_ForeColor) j = (i And &H00FF0000): Shift Right j, 16 k = (i And &H0000FF00): Shift Right k, 8 i = (i And &HFF) Clr = Rgb(j, k, i) If sz.cy = 0 Then GetTextExtentPoint32 hMemDC, " ", 1, sz For j = rc.nBottom - 1 To rc.nTop Step - 1 For k = rc.nLeft To rc.nRight - 1 If j >= (rc.nTop + sz.cy / 2) Then If (k = rc.nLeft) Or (k = (rc.nRight - 1)) Or _ (j = rc.nBottom - 1) Or (j = rc.nTop + sz.cy / 2) Then @pBits = Clr End If pBits = pBits + 4 Next Next sz.cy = 0 Else Select Case j Case %SS_CENTER: sz.cx = Max(0, (rc.nRight - rc.nLeft - sz.cx) \ 2) Case %SS_LEFT: sz.cx = 0 Case %SS_RIGHT: sz.cx = Max(0, (rc.nRight - rc.nLeft - sz.cx)) End Select sz.cy = Max(0, (rc.nBottom - rc.nTop - sz.cy) \ 2) End If TextOut hMemDC, rc.nLeft + sz.cx, rc.nTop + sz.cy, Txt, Len(Txt) BitBlt ps.hDC, 0, 0, rc.nRight, rc.nBottom, hMemDC, 0, 0, %SRCCOPY EndPaint hWnd, ps DeleteDC hMemDC DeleteObject hMemBmp DeleteObject MyClr(0) Exit Function End Select Function = DefWindowProc(hWnd, wMsg, wParam, lParam) End Function CallBack Function DlgProc Dim hFontC10 As Static Long, hDC As Long, i As Long Select Case CbMsg Case %WM_DESTROY DeleteObject hFontC10 Case %WM_INITDIALOG Register_pbLabel pbLabel_Default_ForeColor = %WHITE pbLabel_Default_BackColor = %DlgColor hDC = GetDC(%HWND_DESKTOP) i = GetDeviceCaps(hDC, %LOGPIXELSY) ReleaseDC %HWND_DESKTOP, hDC hFontC10 = CreateFont(0 - MulDiv(10, i, 72), 0, 0, 0, %FW_NORMAL, 0, 0, 0, _ %RUSSIAN_CHARSET, %OUT_TT_PRECIS, %CLIP_DEFAULT_PRECIS, _ %DEFAULT_QUALITY, %FF_DONTCARE, "Courier New") Control Add "pbLabel", CbHndl, 101, "Frame", 220, 10, 180, 110, %WS_CHILD Or %WS_VISIBLE Or %pbLabel_FRAME Or %SS_CENTER Or %WS_CLIPSIBLINGS ' <============== Control Add "pbLabel", CbHndl, 103, "Label-103", 10, 10, 200, 10, %WS_CHILD Or %WS_VISIBLE Control Add TextBox, CbHndl, 104, "TextBox-102", 10, 22, 200, 14 Control Add "pbLabel", CbHndl, 105, "Label-105", 230, 54, 160, 10, %WS_CHILD Or %WS_VISIBLE Control Add TextBox, CbHndl, 106, "TextBox-106", 230, 66, 160, 14 Control Add "pbLabel", CbHndl, 107, "Label-107", 230, 82, 160, 10, %WS_CHILD Or %WS_VISIBLE Control Add TextBox, CbHndl, 108, "TextBox-108", 230, 94, 160, 14 Control Add Button, CbHndl, 109, "Button", 320, 135, 80, 15 For i = 1 To 9 Control Send CbHndl, 100 + i, %WM_SETFONT, hFontC10, 1 Next ' Setwindowpos GetDlgItem(CbHndl, 101), GetDlgItem(CbHndl, 109), 0, 0, 0, 0, _ ' %SWP_NOSIZE Or %SWP_NOMOVE Or %SWP_NOACTIVATE ' Aldo's suggestion End Select End Function Function PbMain Local hDlg As Long Dialog New 0, "", ,, 410, 200, %WS_CAPTION Or %WS_SYSMENU Or %WS_CLIPCHILDREN To hDlg Dialog Show Modal hDlg Call DlgProc End Function
E-MAIL: [email protected]
Leave a comment: