home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / dtx9302 / fillbar / fbdll.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-03-02  |  11.2 KB  |  427 lines

  1. {$A+,B-,D+,E-,F-,G+,I+,K+,N-,O-,P-,Q-,R-,S+,T-,V+,W+,X+,Y-}
  2. (*========================================================*)
  3. (*                        FBDLL.PAS                       *)
  4. (*         (C) 1993 Andreas Siegmund & DMV-Verlag         *)
  5. (*                                                        *)
  6. (* DLL, die Fillbars in Dialogboxen zur Verfⁿgung stellt. *)
  7. (* Compiler: Turbo Pascal für Windows, Borland Pascal 7.0 *)
  8. (*========================================================*)
  9.  
  10. LIBRARY FillBar;
  11.  
  12. {$R FBDLL.RES}
  13.  
  14. USES
  15.   WinTypes, WinProcs, Strings, CustCntl,
  16. {$IFDEF VER70} OWindows, Objects; {$ELSE} WObjects; {$ENDIF}
  17.  
  18. CONST
  19.   ofBitmap1 =  2;
  20.   ofBitmap2 =  4;
  21.   ofColor   =  6;
  22.   ofFillBar = 10;
  23.   ofFont    = 12;
  24.   ofValue   = 14;
  25.   ofSize    = 16;
  26.  
  27. CONST
  28.   FillBarHeight        = 21;
  29.   fbm_NewValue  : WORD = 0;
  30.  
  31. TYPE
  32.   pParamRec = ^tParamRec;
  33.   tParamRec = RECORD
  34.     CtlStyle: tHandle;
  35.     IdToStr : tIdToStr;
  36.     StrToId : tStrToId;
  37.   END;
  38.  
  39. PROCEDURE SetFillBarValue(Dlg: hWND; aId: INTEGER;
  40.                           NewValue: INTEGER); EXPORT;
  41. BEGIN
  42.   SendDlgItemMessage(Dlg, aId, fbm_NewValue, NewValue, 0);
  43. END;
  44.  
  45. FUNCTION FillBarMsg(hWindow: hWND; Message: WORD;
  46.                     wParam: WORD; lParam: LONGINT): LONGINT;
  47.                     EXPORT;
  48. VAR
  49.   Bitmap      : hBitmap;
  50.   PaintStruct : tPaintStruct;
  51.  
  52. FUNCTION GetBitmap1: hBitmap;
  53. BEGIN
  54.   GetBitmap1 := GetWindowWord(hWindow, ofBitmap1);
  55. END;
  56.  
  57. FUNCTION GetBitmap2: hBitmap;
  58. BEGIN
  59.   GetBitmap2 := GetWindowWord(hWindow, ofBitmap2);
  60. END;
  61.  
  62. FUNCTION GetColor: tColorRef;
  63. BEGIN
  64.   GetColor := GetWindowLong(hWindow, ofColor);
  65. END;
  66.  
  67. PROCEDURE SetColor(t: tColorRef);
  68. BEGIN
  69.   SetWindowLong(hWindow, ofColor, t);
  70. END;
  71.  
  72. FUNCTION GetFillBar: hBitmap;
  73. BEGIN
  74.   GetFillBar := GetWindowWord(hWindow, ofFillBar);
  75. END;
  76.  
  77. PROCEDURE SetFillBar(b: hBitmap);
  78. BEGIN
  79.   SetWindowWord(hWindow, ofFillBar, b);
  80. END;
  81.  
  82. FUNCTION GetFont: hFont;
  83. BEGIN
  84.   GetFont := GetWindowWord(hWindow, ofFont);
  85. END;
  86.  
  87. PROCEDURE SetFont(Font: hFont);
  88. BEGIN
  89.   SetWindowWord(hWindow, ofFont, Font);
  90. END;
  91.  
  92. FUNCTION GetValue: WORD;
  93. BEGIN
  94.   GetValue := GetWindowWord(hWindow, ofValue);
  95. END;
  96.  
  97. PROCEDURE SetValue(w: WORD);
  98. BEGIN
  99.   SetWindowWord(hWindow, ofValue, w);
  100. END;
  101.  
  102. PROCEDURE Paint(DC: hDC);
  103. VAR
  104.   ClientRect: tRect;
  105.   MemDC     : hDC;
  106.   Bitmap    : hBitmap;
  107. BEGIN
  108.   GetClientRect(hWindow, ClientRect);
  109.   WITH ClientRect DO BEGIN
  110.     Bitmap := GetFillBar;
  111.     MemDC  := CreateCompatibleDC(DC);
  112.     SelectObject(MemDC, Bitmap);
  113.     BitBlt(DC, 0, 0, Right, Bottom, MemDC, 0, 0, SrcCopy);
  114.     DeleteObject(MemDC);
  115.   END;
  116. END;
  117.  
  118. PROCEDURE Repaint;
  119. VAR
  120.   DC : hDC;
  121. BEGIN
  122.   DC := GetDC(hWindow);
  123.   Paint(DC);
  124.   ReleaseDC(hWindow, DC);
  125. END;
  126.  
  127. PROCEDURE SetNewValue(aValue: INTEGER);
  128. VAR
  129.   DC        : hDC;
  130.   MemDC     : hDC;
  131.   BitmapDC  : hDC;
  132.   Handle    : hBitmap;
  133.   ClientRect: tRect;
  134.   r         : REAL;
  135.   FillLen   : INTEGER;
  136.   s         : ARRAY[0..6] OF CHAR;
  137. BEGIN
  138.   IF aValue IN [0..100] THEN BEGIN
  139.     SetValue(aValue);
  140.     DC := GetDC(hWindow);
  141.     GetClientRect(hWindow, ClientRect);
  142.     WITH ClientRect DO BEGIN
  143.       r := (Right / 100) * aValue;
  144.       FillLen := Round(r);
  145.       MemDC := CreateCompatibleDC(DC);
  146.       BitmapDC := CreateCompatibleDC(DC);
  147.       Handle := GetFillBar;
  148.       IF Handle <> 0 THEN DeleteObject(Handle);
  149.       Handle := CreateCompatibleBitmap(DC, Right,
  150.                                        FillBarHeight);
  151.       SetFillBar(Handle);
  152.       SelectObject(BitmapDC, Handle);
  153.  
  154.       (* ====== Grundgerⁿst des Fillbar erstellen ====== *)
  155.       SelectObject(MemDC, GetBitmap1);
  156.       BitBlt(BitmapDC, 0, 0, 4, FillBarHeight,
  157.              MemDC, 0, 0, SrcCopy);
  158.       StretchBlt(BitmapDC, 4, 0, Right - 8, FillBarHeight,
  159.                  MemDC, 4, 0, 20, FillBarHeight, SrcCopy);
  160.       BitBlt(BitmapDC, Right-4, 0, 4, FillBarHeight, MemDC,
  161.              60, 0, SrcCopy);
  162.  
  163.       (* ====== Fⁿllgrad erstellen falls Wert > 0 ======= *)
  164.       IF aValue <> 0 THEN BEGIN
  165.         SelectObject(MemDC, GetBitmap2);
  166.         BitBlt(BitmapDC, 0, 0, 2, FillBarHeight,
  167.                MemDC, 0, 0, SrcCopy);
  168.         StretchBlt(BitmapDC, 2, 0, FillLen-7, FillBarHeight,
  169.                    MemDC, 3, 0, 20, FillBarHeight, SrcCopy);
  170.         BitBlt(BitmapDC, FillLen - 5, 0, 5, FillBarHeight,
  171.                MemDC, 59, 0, SrcCopy);
  172.       END;
  173.       (* ================= Text ausgeben ================ *)
  174.       IF GetColor <> RGB(255, 255, 255) THEN BEGIN
  175.         SelectObject(BitmapDC, GetFont);
  176.         Str(aValue, s);
  177.         StrCat(s, ' %');
  178.         SetTextColor(BitmapDC, GetColor);
  179.         SetTextAlign(BitmapDC, ta_Center);
  180.         SetBkMode(BitmapDC, Transparent);
  181.         TextOut(BitmapDC, Right DIV 2, 4, s, StrLen(s));
  182.       END;
  183.       DeleteObject(BitmapDC);
  184.       DeleteObject(MemDC);
  185.     END;
  186.     ReleaseDC(hWindow, DC);
  187.   END;
  188. END;
  189.  
  190. FUNCTION ChooseColor(Style: LONGINT): tColorRef;
  191. BEGIN
  192.   CASE Style OF
  193.     0 : ChooseColor := RGB(  0,   0, 255);
  194.     1 : ChooseColor := RGB(128,   0,   0);
  195.     2 : ChooseColor := RGB(  0,   0,   0);
  196.     3 : ChooseColor := RGB(  0, 128,   0);
  197.     4 : ChooseColor := RGB(  0, 255, 255);
  198.     5 : ChooseColor := RGB(255, 255, 255);
  199.   END;
  200. END;
  201.  
  202. FUNCTION CreateSmallFont: hFont;
  203. VAR
  204.   Font   : hFont;
  205.   LogFont: tLogFont;
  206. BEGIN
  207.   Font := GetStockObject(ANSI_VAR_FONT);
  208.   GetObject(Font, SizeOf(LogFont), @LogFont);
  209.   LogFont.lfWeight := 700;
  210.   Font := CreateFontIndirect(LogFont);
  211.   CreateSmallFont := Font;
  212. END;
  213.  
  214. BEGIN
  215.   FillBarMsg := 0;
  216.   IF Message = fbm_NewValue THEN
  217.   BEGIN
  218.     SetNewValue(wParam);
  219.     Repaint;
  220.   END ELSE
  221.   CASE Message OF
  222.     wm_Create:
  223.       BEGIN
  224.         Bitmap := LoadBitmap(hInstance, pChar(100));
  225.         SetWindowWord(hWindow, ofBitmap1, Bitmap);
  226.         Bitmap := LoadBitmap(hInstance, pChar(200));
  227.         SetWindowWord(hWindow, ofBitmap2, Bitmap);
  228.         WITH pCreateStruct(lParam)^ DO
  229.           SetColor(ChooseColor(Style));
  230.         SetFillBar(0);
  231.         SetFont(CreateSmallFont);
  232.         SetNewValue(0);
  233.       END;
  234.     wm_Paint:
  235.       BEGIN
  236.         BeginPaint(hWindow, PaintStruct);
  237.         Paint(PaintStruct.hDC);
  238.         EndPaint(hWindow, PaintStruct);
  239.       END;
  240.     wm_NCHitTest: FillBarMsg := -1;
  241.     wm_Destroy: 
  242.       BEGIN
  243.         FillBarMsg := DefWindowProc(hWindow, Message,
  244.                                     wParam, lParam);
  245.         DeleteObject(GetBitmap1);
  246.         DeleteObject(GetBitmap2);
  247.         DeleteObject(GetFillBar);
  248.         DeleteObject(GetFont);
  249.       END;
  250.   ELSE
  251.     FillBarMsg := DefWindowProc(hWindow, Message,
  252.       wParam, lParam);
  253.   END;
  254. END;
  255.  
  256. (* ==================== Info-Methoden =================== *)
  257.  
  258. FUNCTION FillBarInfo: tHandle; EXPORT;
  259. VAR
  260.   hInfo: tHandle;
  261.   Info : pRWCtlInfo;
  262. BEGIN
  263.   hInfo := GlobalAlloc(gMem_Share OR gMem_ZeroInit,
  264.     SizeOf(tRWCtlInfo));
  265.   IF hInfo <> 0 THEN BEGIN
  266.     Info := GlobalLock(hInfo);
  267.     WITH Info^ DO BEGIN
  268.       wVersion := 100;
  269.       wCtlTypes := 1;
  270.       StrCopy(szClass, 'ASFillBar');
  271.       StrCopy(szTitle, 'AS - Custom Controls');
  272.       WITH ctType[0] DO BEGIN
  273.         wWidth := 263 OR $8000;
  274.         wHeight := FillBarHeight OR $8000;
  275.         StrCopy(szDescr, 'FillBar');
  276.         dwStyle := ws_Child;
  277.         hToolBit := 0;
  278.         hDropCurs := 0;
  279.       END;
  280.     END;
  281.     GlobalUnlock(hInfo);
  282.   END;
  283.   FillBarInfo := hInfo;
  284. END;
  285.  
  286. FUNCTION FillBarStyleDlg(hWindow: hWND; Message: WORD;
  287.          wParam: WORD; lParam: LONGINT): LONGINT; EXPORT;
  288. CONST
  289.   Prop = 'Prop';
  290. VAR
  291.   hRec : tHandle;
  292.   Rec  : pParamRec;
  293.   Style: pCtlStyle;
  294.   s    : ARRAY[0..265] OF CHAR;
  295.   Radio: INTEGER;
  296.   I    : INTEGER;
  297. BEGIN
  298.   CASE Message OF
  299.     wm_InitDialog:
  300.       BEGIN
  301.         hRec := LoWord(lParam);
  302.         Rec := GlobalLock(hRec);
  303.         Style := GlobalLock(Rec^.CtlStyle);
  304.         SetProp(hWindow, Prop, hRec);
  305.         WITH Rec^, Style^ DO BEGIN
  306.           IdToStr(wID, s, SizeOf(s));
  307.           SetDlgItemText(hWindow, 100, s);
  308.  
  309.           CheckRadioButton(hWindow, 110, 115,
  310.             110+dwStyle);
  311.         END;
  312.         GlobalUnlock(Rec^.CtlStyle);
  313.         GlobalUnlock(hRec);
  314.       END;
  315.     wm_Destroy:
  316.         RemoveProp(hWindow, Prop);
  317.     wm_Command:
  318.       CASE wParam OF
  319.         idCancel: EndDialog(hWindow, 0);
  320.         idOk:
  321.           BEGIN
  322.             hRec := GetProp(hWindow, Prop);
  323.             Rec := GlobalLock(hRec);
  324.             Style := GlobalLock(Rec^.CtlStyle);
  325.             WITH Rec^, Style^ DO BEGIN
  326.               GetDlgItemText(hWindow, 100, s,
  327.                 SizeOf(s));
  328.               wID := StrToId(s);
  329.               Radio := 110;
  330.               FOR I := 110 TO 115 DO
  331.                 IF IsDlgButtonChecked(hWindow, I) <> 0 THEN
  332.                   Radio := I;
  333.               dwStyle := Radio-110;
  334.             END;
  335.             GlobalUnlock(Rec^.CtlStyle);
  336.             GlobalUnlock(hRec);
  337.             EndDialog(hWindow, 1);
  338.           END;
  339.         ELSE FillBarStyleDlg := 0;
  340.         END;
  341.     ELSE FillBarStyleDlg := 0;
  342.   END;
  343. END;
  344.  
  345. FUNCTION FillBarStyle(hWindow: hWND; CtlStyle: tHandle;
  346.          StrToId: tStrToId; IdToStr: tIdToStr): Bool;
  347.          EXPORT;
  348. VAR
  349.   hRec  : tHandle;
  350.   Rec   : pParamRec;
  351.   hFocus: hWND;
  352. BEGIN
  353.   FillBarStyle := FALSE;
  354.   hRec := GlobalAlloc(gMem_Share, SizeOf(tParamRec));
  355.   IF hRec <> 0 THEN BEGIN
  356.     Rec := GlobalLock(hRec);
  357.     Rec^.IdToStr := IdToStr;
  358.     Rec^.StrToId := StrToId;
  359.     Rec^.CtlStyle := CtlStyle;
  360.     GlobalUnlock(hRec);
  361.     hFocus := GetFocus;
  362.     FillBarStyle := Bool(DialogBoxParam(hInstance,
  363.                          MakeIntResource(100), hWindow,
  364.                          @FillBarStyleDlg, hRec));
  365.     IF hFocus <> 0 THEN SetFocus(hFocus);
  366.     GlobalFree(hRec);
  367.   END;
  368. END;
  369.  
  370. FUNCTION FillBarFlags(Style: LONGINT; Buff: pChar;
  371.                       BuffLength: WORD): WORD; EXPORT;
  372. BEGIN
  373.   StrCopy(Buff, '');
  374. END;
  375.  
  376. FUNCTION ListClasses(szAppName: pChar; wVersion: WORD;
  377.              fnLoad: tLoad; fnEdit: tEdit): tHandle; EXPORT;
  378. VAR
  379.   hClasses: tHandle;
  380.   Classes : pCtlClassList;
  381. BEGIN
  382.   hClasses := GlobalAlloc(gMem_Share OR gMem_ZeroInit,
  383.               SizeOf(INTEGER) + SizeOf(TRWCtlClass));
  384.   IF hClasses <> 0 THEN BEGIN
  385.     Classes := GlobalLock(hClasses);
  386.     WITH Classes^ DO BEGIN
  387.       nClasses  := 1;
  388.       WITH Classes[0] DO BEGIN
  389.         fnInfo  := FillBarInfo;
  390.         fnStyle := FillBarStyle;
  391.         fnFlags := FillBarFlags;
  392.       END;
  393.     END;
  394.     GlobalUnlock(hClasses);
  395.   END;
  396.   ListClasses := hClasses;
  397. END;
  398.  
  399. EXPORTS
  400.   FillBarMsg      INDEX 1,
  401.   ListClasses     INDEX 2,
  402.   SetFillBarValue INDEX 3;
  403.  
  404. VAR
  405.   Class : tWndClass;
  406.  
  407. BEGIN
  408.   WITH Class DO BEGIN
  409.     lpszClassName := 'ASFillBar';
  410.     hCursor       := LoadCursor(0, idc_Arrow);
  411.     lpszMenuName  := NIL;
  412.     Style         := cs_HRedraw OR cs_VRedraw OR cs_DblClks
  413.                                 OR cs_GlobalClass;
  414.     lpfnWndProc   := tFarProc(@FillBarMsg);
  415.     hInstance     := SYSTEM.hInstance;
  416.     hIcon         := 0;
  417.     cbWndExtra    := ofSize;
  418.     cbClsExtra    := 0;
  419.     hbrBackGround := 0;
  420.   END;
  421.   RegisterClass(Class);
  422.   fbm_NewValue := RegisterWindowMessage('FillBar_NewValue');
  423. END.
  424.  
  425. (*========================================================*)
  426. (*                      Ende von FBDLL.PAS                *)
  427.