home *** CD-ROM | disk | FTP | other *** search
- {$define RETAIL_VERSION}
- {!define Win32}
- {***************************************************************************
- Source File Name : ExDlgs
- Autor : Mario M. Westphal
- Erstellt am : 14.07.1992
-
- Compiler : Borland Pascal for Windows 1.x
- Betriebssystem : DOS 5.0, Windows 3.x
- Compiler-Schalter : -
-
- Bemerkungen : -
-
- Beschreibung : Unit fⁿr erweiterte Dialogelemente und allgemeine
- Routinen.
- Diese Unit deklariert benutzerdefinierte
- Nachrichten ab wm_User+300;
-
- Revisionen : 1.00 14.10.1992 created (MW)
- 07.04.1993 revisited (MW)
-
- ****************************************************************************}
- {$M 8192,8192}
- {$A+,B-,D+,F-,G+,I+,L+,N-,R+,S+,V+,W-,X+,Q+}
-
- {$IFDEF RETAIL_VERSION}
- {$D-,L-,S-,R-,Q-,I-}
- {$ENDIF}
-
- Unit ExDlg;
-
- interface
-
- uses
- WinTypes,
- WinProcs,
- WinDos,
- Objects,
- Strings,
- OWindows,
- ODialogs,
- SysTools;
-
- const
- WMOFFSET = 300; { Start der Meldungen dieser Unit }
- wm_PBarCanceled = wm_User+WMOFFSET;
-
- type
- PPBarDialog = ^TPBarDialog;
- TPBarDialog = object(TWindow)
-
- MaxValue : Real; { Maximalwert }
- ActValue : Integer; { Aktueller Wert }
- BarBrush : HBrush; { Balkenfarbe }
- pnShadow : HPen; { Schatten }
- HasButton: Boolean; { Schalter ? }
- PBtn : PButton; { Schalter }
- CharPt : TPoint; { Zeichenbreite- und H÷he des Systemfonts }
- rcBar : TRect; { Rechteck des Balkens }
- hbmBar : HBitmap; { Ausgabe-Bitmap }
-
- constructor Init (AParent : PWindowsObject;
- ATitle : PChar;
- AMax : Real;
- Button : Boolean);
- destructor Done; virtual;
- function CanClose : Boolean; virtual;
-
- procedure SetupWindow; virtual;
- procedure SetColors; virtual;
-
- function GetClassName: PChar; virtual;
- procedure GetWindowClass(var AWndClass: TWndClass); virtual;
- procedure DrawBar (DC: HDC);
- procedure Paint(PaintDC: HDC; var PaintInfo: TPaintStruct); virtual;
- procedure SetPos(CurValue: Real);
- procedure WMKeyDown (var Msg: TMessage);
- virtual wm_First or wm_KeyDown;
- procedure Cancel (var Msg: TMessage);
- virtual id_First or ID_ABORT;
- end;
-
- type
- PMsgWindow = ^TMsgWindow;
- TMsgWindow = object(TWindow)
- Message : PChar; { Angezeigter Text }
- CharPt : TPoint; { Zeichenbreite- und H÷he des Systemfonts }
- rcText : TRect; { Das den Text umgebende Rechteck }
- constructor Init (AParent: PWindowsObject; ATitle: PChar);
- destructor Done; virtual;
- function CanClose : Boolean; virtual;
- function GetClassName: PChar; virtual;
- procedure GetWindowClass(var AWndClass: TWndClass); virtual;
- procedure Paint(PaintDC: HDC; var PaintInfo: TPaintStruct); virtual;
- procedure SetText (MsgStr: PChar);
- end;
-
-
- const
- { Modi fⁿr den CtrDialog }
- CTRDLG_SYSTEM = 1; { Ausrichtung bezⁿglich des Bildschirms }
- CTRDLG_PARENT = 2; { Ausrichtung bezⁿglich des Parent-Windows }
-
- { Zentrierte Dialoge }
- type
- PCtrDialog = ^TCtrDialog;
- TCtrDialog = object(TDialog)
- CtrMode : Byte;
- constructor Init(AParent: PWindowsObject; AName: PChar; AMode: Byte);
- procedure SetupWindow; virtual;
- function GetClassName: PChar; virtual;
- procedure GetWindowClass(var AWndClass: TWndClass); virtual;
- end;
-
-
- {* Allgemeines *}
-
- function ChangeMenu (Wnd: HWnd; Position, Flags: Word;
- NewStr: PChar) : Bool;
-
- function ChangeSysMenu (Wnd: HWnd; Position, Flags: Word;
- NewStr: PChar) : Bool;
-
-
- implementation
-
- {----------------------------------------------------------
- ─ndert das Menu mit dem Handle "Menu" mit der Command-ID
- Position auf Flags. Wird fⁿr NewStr ein Leerstring
- ⁿbergeben, wird der alte Menⁿname beibehalten, ansonsten
- wird er auf NewStr geΣndert.
- }
- function ChangeMenu (Wnd: HWnd; Position, Flags: Word;
- NewStr: PChar) : Bool;
- var
- s : array[0..50] of Char;
- Menu : HMenu;
- begin
- Menu := GetMenu(Wnd);
- GetMenuString(Menu, Position, s, 50, MF_BYCOMMAND);
- if NewStr[0] = #0 then
- ChangeMenu := ModifyMenu(Menu, Position, Flags, Position, s)
- else
- ChangeMenu := ModifyMenu(Menu, Position, Flags, Position, NewStr);
- end;
-
- {----------------------------------------------------------
- Wie ChangeMenu, arbeitet aber mit dem System-Menⁿ des
- angegebenen Fensters.
- }
- function ChangeSysMenu (Wnd: HWnd; Position, Flags: Word;
- NewStr: PChar) : Bool;
- var
- s : array[0..50] of Char;
- Menu : HMenu;
- begin
- Menu := GetSystemMenu(Wnd,false);
- GetMenuString(Menu, Position, s, 50, MF_BYCOMMAND);
- if NewStr[0] = #0 then
- ChangeSysMenu := ModifyMenu(Menu, Position, Flags, Position, s)
- else
- ChangeSysMenu := ModifyMenu(Menu, Position, Flags, Position, NewStr);
- end;
-
-
- {**********************************************************}
- { TPBarDialog }
- { }
- { Erzeugt einen Dialog mit einem optionalen Schalter. In }
- { diesem Dialog wird ein Prozentbalken angezeigt der vom }
- { Parent neu gesetzt werden kann. Der Dialog ist bezⁿglich }
- { des Parent zentriert. }
- { Drⁿckt der Anwender den Schalter, wird eine entsprechende}
- { Nachricht an den Parent gesendet. }
- {**********************************************************}
- constructor TPBarDialog.Init (AParent : PWindowsObject;
- ATitle : PChar;
- AMax : Real;
- Button : Boolean);
- var
- R : TRect;
- tm : TTextMetric;
- DC : HDC;
- x,y : Integer;
- w,h : Integer;
- s : array[0..50] of Char;
-
- begin
- Inherited Init(AParent,ATitle);
- Attr.Style := ws_Visible or ws_Popup or ws_Caption or ws_Border;
-
- DC := CreateIC('DISPLAY',nil,nil,nil);
- GetTextMetrics(DC,tm);
- DeleteDC(DC);
- CharPt.y := tm.tmHeight;
- CharPt.x := tm.tmAveCharWidth;
-
- GetWindowRect(Parent^.HWindow,R);
- Attr.W := GetSystemMetrics(SM_CXSCREEN) div 10 * 4;
- Attr.H := 3*CharPt.x+2*CharPt.y+GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CYBORDER);
- Attr.X := R.Left+(R.Right-R.Left) div 2 - Attr.W div 2;
-
- { Pens und Brushes anlegen }
- SetColors;
-
- MaxValue := AMax;
- ActValue := 0;
- HasButton := Button;
-
- { Rechteck for den Balken berechnen }
- rcBar.Left := 2*CharPt.x;
- rcBar.Right := Attr.W-2*CharPt.x;
- rcBar.Top := 2*CharPt.x;
- rcBar.Bottom := rcBar.Top+CharPt.y+CharPt.x;
-
- if HasButton then
- begin
- StrCopy(s,'Abbrechen');
- w := (StrLen(s)+4)*CharPt.x;
- h := CharPt.y+ CharPt.y div 4*3;
- x := Attr.W div 2 - w div 2;
- y := rcBar.Bottom+2*CharPt.x;
- New(pBtn,Init(@Self,ID_ABORT,s,x,y,w,h,true));
- inc(Attr.H,rcBar.Bottom);
- end
- else
- begin
- h := 0;
- PBtn := NIL;
- end;
-
- Attr.Y := R.Top+(R.Bottom-R.Top) div 2 - Attr.H div 2;
- end;
-
- {----------------------------------------------------------
- Erzeugt eine kompatible Bitmap von der Gr÷▀e des
- Balkens. In diese Bitmap werden alle Ausgaben des
- des Balkens von DrawBar gemacht.
- }
- procedure TPBarDialog.SetupWindow;
- var
- DC : HDC;
- rcTemp : TRect;
- begin
- Inherited SetupWindow;
- DC := GetDC(HWindow);
- rcTemp := rcBar;
- OffsetRect(rcTemp,-rcBar.Left,-rcBar.Top);
- hbmBar := CreateCompatibleBitmap(DC,rcTemp.Right,rcTemp.Bottom);
- ReleaseDC(HWindow,DC);
- end;
-
- {----------------------------------------------------------
- }
- destructor TPBarDialog.Done;
- begin
- DeleteObject(hbmBar);
- DeleteObject(BarBrush);
- DeleteObject(pnShadow);
- Inherited Done;
- end;
-
- {----------------------------------------------------------
- Wenn der Anwender das Fenster ⁿber das Systemmenⁿ
- schlie▀t, wird geprⁿft, ob das Fenster ⁿber einen
- Button verfⁿgt. Wenn ja, wird die "Button gedrⁿckt"
- Botschaft gesendet. Ansonsten wird immer false
- geliefert.
- }
- function TPBarDialog.CanClose : Boolean;
- begin
- CanClose := false;
- end;
-
- {----------------------------------------------------------
- }
- procedure TPBarDialog.SetColors;
- var
- IC : HDC;
- begin
- IC := CreateIC('DISPLAY',nil,nil,nil);
- pnShadow := CreatePen(PS_SOLID,1,GetNearestColor(IC,RGB(85,85,85)));
- BarBrush := CreateSolidBrush(GetNearestColor(IC,RGB(0,0,255)));
- DeleteDC(IC);
- end;
-
- {----------------------------------------------------------
- Neue Fenster-Klasse definieren.
- }
- function TPBarDialog.GetClassName: PChar;
- begin
- GetClassName := 'MWINDICATOR';
- end;
-
- {----------------------------------------------------------
- }
- procedure TPBarDialog.GetWindowClass(var AWndClass: TWndClass);
- var IC : HDC;
- begin
- Inherited GetWindowClass(AWndClass);
- IC := CreateIC('DISPLAY',nil,nil,nil);
- AWndClass.hBrBackground := CreateSolidBrush(GetNearestColor(IC,RGB(193,193,193)));
- AWndClass.Style := AWndClass.Style or cs_SaveBits;
- DeleteDC(IC);
- end;
-
- {----------------------------------------------------------
- Zeichnet den Prozentbalken neu und gibt die Prozentzahl
- in der Mitte des Balkens aus.
- }
- procedure TPBarDialog.DrawBar (DC: HDC);
- var
- OldBrush : HBrush;
- R : TRect;
- Size : Integer;
- MadeDC : Boolean;
- OldPen : HPen;
- rcTemp : TRect;
- MemDC : HDC;
- hbmOld : HBitmap;
- PercStr : array[0..4] of Char;
-
- begin
- if DC = 0 then
- begin
- DC := GetDC(HWindow);
- MadeDC := true;
- end
- else
- MadeDC := false;
-
- { Rechteck des Balkens an den Nullpunkt verschieben (Bitmap-Ursprung) }
- rcTemp := rcBar;
- OffsetRect(rcTemp,-rcBar.Left,-rcBar.Top);
-
- { Die Bitmap in einen Memory Device Context selektieren. In diesen wird gezeichnet. }
- MemDC := CreateCompatibleDC(DC);
- hbmOld := SelectObject(MemDC,hbmBar);
-
- { Rahmen zeichnen }
- OldPen := SelectObject(MemDC,GetStockObject(WHITE_PEN));
- OldBrush := SelectObject(MemDC,GetClassWord(HWindow,GCW_HBRBACKGROUND));
- with rcTemp do begin
- Rectangle(MemDC,Left,Top,Right,Bottom);
- SelectObject(MemDC,pnShadow);
- MoveTo(MemDC,Succ(Left),Pred(Bottom));
- LineTo(MemDC,Pred(Right),Pred(Bottom));
- LineTo(MemDC,Pred(Right),Top);
- end;
-
- SetBkMode(MemDC,TRANSPARENT);
-
- { Balken einzeichnen }
- SelectObject(MemDC,GetStockObject(NULL_PEN));
- SelectObject(MemDC,BarBrush);
- R := rcTemp;
- OffsetRect(R,1,1);
- dec(R.Bottom,1);
- Size := Round((rcTemp.Right-R.Left-1) / 100 * ActValue);
-
- R.Right := r.Left+Size;
- with R do Rectangle(MemDC,Left,Top,Right,Bottom);
-
- { Neuen Text schreiben }
- SetTextColor(MemDC,RGB(255,255,255));
- wvsprintf(PercStr,'%u%%',ActValue);
-
- DrawText(MemDC,PercStr,-1,rcTemp,DT_CENTER or DT_NOCLIP or DT_VCENTER or DT_SINGLELINE);
-
- BitBlt(DC,rcBar.Left,rcBar.Top,rcBar.Right,rcBar.Bottom,MemDC,0,0,SRCCOPY);
-
- SelectObject(MemDC,hbmOld);
- SelectObject(MemDC,OldPen);
- SelectObject(MemDC,OldBrush);
- DeleteDC(MemDC);
- if MadeDC then ReleaseDC(HWindow,DC);
- end;
-
- {----------------------------------------------------------
- Bearbeitet WM_PAINT-Nachrichten. Ruft DrawBar auf, um den
- Balken neu zu zeichnen.
- }
- procedure TPBarDialog.Paint(PaintDC: HDC; var PaintInfo: TPaintStruct);
- begin
- Inherited Paint(PaintDC,PaintInfo);
- if not IsIconic(HWindow) then DrawBar(PaintDC);
- end;
-
- {----------------------------------------------------------
- Setzt einen neuen Prozentwert.
- }
- procedure TPBarDialog.SetPos(CurValue: Real);
- var
- ActSave : Integer;
- begin
- ActSave := ActValue;
- ActValue := Round(CurValue / (MaxValue / 100));
- if ActValue <= ActSave then exit;
- if (ActValue >= 0) and (ActValue <= 100) then
- begin
- DrawBar(0);
- end;
- end;
-
- {----------------------------------------------------------
- }
- procedure TPBarDialog.WMKeyDown (var Msg: TMessage);
- begin
- if HasButton then
- begin
- if Msg.wParam = VK_ESCAPE then SendMessage(HWindow,wm_Command,ID_ABORT,pBtn^.HWindow);
- end;
- DefWndProc(Msg);
- end;
-
- {----------------------------------------------------------
- Wird aufgerufen, wenn der Halt-Button gedrⁿckt wird.
- *******
- ACHTUNG: Entfernt NICHT den Dialog. Dies mu▀ von der
- ******* Funktion erledigt werden, die den Dialog erzeugt
- hat. Sendet die Nachricht wm_PBarCanceled an das
- erzeugende Fenster.
- }
- procedure TPBarDialog.Cancel (var Msg: TMessage);
- begin
- PostMessage(Parent^.HWindow, wm_PBarCanceled, 0, 0);
- end;
-
-
- {**********************************************************}
- { TMessageWindow }
- { }
- { Erzeugt ein Fenster mit einem grauen Hintergrund auf das }
- { eine beliebige Textausgabe gemacht werden kann. Der Text }
- { wird automatisch zentriert und das Fenster in seiner }
- { Gr÷▀e an den Text angepassst. Das Fenster ist bezⁿglich }
- { des Parents zentriert. }
- {**********************************************************}
-
- {----------------------------------------------------------
- }
- constructor TMsgWindow.Init (AParent: PWindowsObject; ATitle: PChar);
- var
- R : TRect;
- DC : HDC;
- tm : TTextMetric;
- begin
- Inherited Init (AParent, ATitle);
- Attr.Style := ws_Popup or ws_Border or ws_Visible or ws_Caption;
- Message := Nil;
-
- DC := CreateIC('DISPLAY',nil,nil,nil);
- GetTextMetrics(DC,tm);
- DeleteDC(DC);
-
- CharPt.y := tm.tmHeight + tm.tmExternalLeading;
- CharPt.x := tm.tmAveCharWidth;
- rcText.Left := 0;
- rcText.Top := 0;
- rcText.Right := GetSystemMetrics(SM_CXSCREEN) div 10 * 4;
- rcText.Bottom := 0;
-
- InflateRect(rcText,2*CharPt.y,2*CharPt.y);
- OffsetRect(rcText,Abs(rcText.Left),Abs(rcText.Top));
- end;
-
- {----------------------------------------------------------
- }
- destructor TMsgWindow.Done;
- begin
- if Message <> Nil then StrDispose(Message);
- Inherited Done;
- end;
-
- {----------------------------------------------------------
- Sorgt dafⁿr, da▀ der Anwender das Fenster nicht ⁿber
- <Alt>-<F4> schlie▀en kann. Das Fenster kann nur vom
- ⁿbergeordneten Fenster geschlossen werden.
- }
- function TMsgWindow.CanClose : Boolean;
- begin
- CanClose := false;
- end;
-
- {----------------------------------------------------------
- }
- function TMsgWindow.GetClassName: PChar;
- begin
- GetClassName := 'MWMSGWINDOW';
- end;
-
- {----------------------------------------------------------
- }
- procedure TMsgWindow.GetWindowClass(var AWndClass: TWndClass);
- var IC : HDC;
- begin
- Inherited GetWindowClass(AWndClass);
- IC := CreateIC('DISPLAY',nil,nil,nil);
- AWndClass.hBrBackground := CreateSolidBrush(GetNearestColor(IC,RGB(193,193,193)));
- DeleteDC(IC);
- AWndClass.Style := AWndClass.Style or cs_SaveBits;
- end;
-
- {----------------------------------------------------------
- }
- procedure TMsgWindow.Paint(PaintDC: HDC; var PaintInfo: TPaintStruct);
- var R : TRect;
- begin
- Inherited Paint(PaintDC,PaintInfo);
- GetClientRect(HWindow,R);
- InflateRect(R,-2*CharPt.x,-CharPt.y);
- SetBkColor(PaintDC,GetNearestColor(PaintDC,RGB(193,193,193)));
- DrawText(PaintDC,Message,-1,R,DT_CENTER or DT_NOCLIP or DT_WORDBREAK);
- end;
-
- {----------------------------------------------------------
- }
- procedure TMsgWindow.SetText(MsgStr: PChar);
- var
- R : TRect;
- DC : HDC;
- x,y,w,h : Integer;
- begin
- if Message <> Nil then StrDispose(Message);
- Message := StrNew(MsgStr);
-
- rcText.Left := 0;
- rcText.Top := 0;
- rcText.Right := GetSystemMetrics(SM_CXSCREEN) div 10 * 4;
- rcText.Bottom := 0;
-
- DC := GetDC(HWindow);
- DrawText(DC,Message,-1,rcText,DT_CALCRECT or DT_CENTER or DT_NOCLIP or DT_WORDBREAK);
- rcText.Right := Max(rcText.Right,GetSystemMetrics(SM_CXSCREEN) div 10*4);
- ReleaseDC(HWindow,DC);
-
- InflateRect(rcText,2*CharPt.x,1*CharPt.y);
- OffsetRect(rcText,Abs(rcText.Left),Abs(rcText.Top));
-
- { for saventy! }
- if Parent <> NIL then
- GetWindowRect(Parent^.HWindow,R)
- else
- GetWindowRect(GetDesktopWindow,R);
-
- W := rcText.Right+2*GetSystemMetrics(SM_CXBORDER);
- H := rcText.Bottom+GetSystemMetrics(SM_CYCAPTION) + 2*GetSystemMetrics(SM_CYBORDER);
- X := R.Left+(R.Right-R.Left) div 2 - W div 2;
- Y := R.Top+(R.Bottom-R.Top) div 2 - H div 2;
-
- SetWindowPos(HWindow,0,x,y,w,h,swp_NoZOrder);
- InvalidateRect(HWindow,nil,true);
- UpdateWindow(HWindow);
- end;
-
- {***********************************************************}
- { TCtrDialog - Zentrierter Dialog }
- { }
- { Wie TDialog, allerdings wird der Dialog automatisch auf }
- { dem Bildschirm zentiert. }
- { }
- {***********************************************************}
-
- {----------------------------------------------------------
- Initialisiert einen zentrierten Dialog.
- Parameter wie bei TDialog.
- Mode definiert, ob der Dialog bezⁿglich des Bildschirms
- ausgerichtet werden soll, oder bezⁿglich des Parents.
- }
- constructor TCtrDialog.Init(AParent: PWindowsObject; AName: PChar; AMode: Byte);
- begin
- Inherited Init(AParent,AName);
- CtrMode := AMode;
- end;
-
- {----------------------------------------------------------
- }
- procedure TCtrDialog.SetupWindow;
- var
- r,r2 : TRect;
- x,y : Integer;
- begin
- Inherited SetupWindow;
- GetWindowRect(HWindow,r);
- OffsetRect(r,-r.Left,-r.Top);
- if CtrMode = CTRDLG_SYSTEM then
- begin
- SetWindowPos(HWindow,0,(GetSystemMetrics(sm_CXScreen) - R.Right) div 2,
- (GetSystemMetrics(sm_CYScreen) - R.Bottom) div 2,0,0,swp_NoSize or swp_NoZOrder);
- end
- else
- begin
- { for saventy }
- if Parent <> NIL then
- GetWindowRect(Parent^.HWindow,r2)
- else
- GetWindowRect(GetDesktopWindow,r2);
- x := (R2.Right-R2.Left)-R.Right;
- if x > 0 then
- x := R2.Left + x div 2
- else
- x := (GetSystemMetrics(sm_CXScreen) - R.Right) div 2;
- y := (R2.Bottom-R2.Top)-R.Bottom;
- if y > 0 then
- y := R2.Top+y div 2
- else
- y := (GetSystemMetrics(sm_CYScreen) - R.Bottom) div 2;
- SetWindowPos(HWindow,0,x,y,0,0,swp_NoSize or swp_NoZOrder);
- end;
- end; { SetupWindow }
-
- {----------------------------------------------------------
- }
- function TCtrDialog.GetClassName: PChar;
- begin
- GetClassName := 'MWCTRDIALOG';
- end;
-
- {----------------------------------------------------------
- }
- procedure TCtrDialog.GetWindowClass(var AWndClass: TWndClass);
- begin
- Inherited GetWindowClass(AWndClass);
- end;
-
- END.