![]() |
Re: [Artikel] Den ExitCode eines Dialogfensters nutzen
Zitat:
Ich glaube es ist einfacher wenn ich ein Beispiel dazu schreibe, aber im Moment fehlt mir die Zeit dazu... |
Re: [Artikel] Den ExitCode eines Dialogfensters nutzen
Ach so, dann ist alles klar, denn dann kennt auch das Hauptprogramm die Struktur, da man ja die Unit des Dialoges vorher im Hauptprogramm einbinden muss. Ich werde es heute Abend mal probieren.
|
Re: [Artikel] Den ExitCode eines Dialogfensters nutzen
Also diese Window Properties klingen ja wirklich nicht schlecht.
Derzeit speichere/lese ich meinen Zeiger per SetWindowLong und GetWindowLong im UserBereich ... sollte ich da auch besser umsteigen, oder ist dieses auch OK? Klar, der Vorteil bei den Properties wäre natürlich, daß da über 'nem Namen und nicht mit 'ner "Nummer" auf die Daten zugegriffen werden kann. |
Re: [Artikel] Den ExitCode eines Dialogfensters nutzen
Hier das angekündigte Beispiel (schnell runtergeschrieben, statt eines Ressourcenskriptes habe ich DialogBoxIndirect verwendet (einfach um das Beispiel auf den Quellcode zu beschränken))
Delphi-Quellcode:
Der Aufruf sieht dann etwa so aus:
unit FooDlg;
interface {$MINENUMSIZE 4} uses Windows; type {$IFDEF UNICODE} TextString = System.WideString; {$ELSE !UNICODE} TextString = System.AnsiString; {$ENDIF UNICODE} type TFooModalResult = ( foomrNone, foomrOk, foomrCancel ); type TFooDialogParam = record Parent: HWND; // in Text : TextString; // in/out end; type TFooDialog = class private FText: TextString; public class function ShowModal(var AParam: TFooDialogParam): TFooModalResult; end; implementation {$EXTENDEDSYNTAX ON} uses Messages; const FooDialogTemplate: packed record Dialog: packed record Header : TDlgTemplate; Menu : array [0..0] of WideChar; WndClass: array [0..0] of WideChar; Title : array [0..3] of WideChar; Points : Word; Weight : Word; Italic : Byte; Charset : Byte; FontFace: array [0..12] of WideChar; end; __align0: Word; Edit: packed record Header : TDlgItemTemplate; WndClass : array [0..1] of WideChar; Title : array [0..0] of WideChar; ExtraCount: Word; end; __align1: Word; ButtonOk: packed record Header : TDlgItemTemplate; WndClass : array [0..1] of WideChar; Title : array [0..3] of WideChar; ExtraCount: Word; end; ButtonCancel: packed record Header : TDlgItemTemplate; WndClass : array [0..1] of WideChar; Title : array [0..7] of WideChar; ExtraCount: Word; end; end = ( Dialog: ( Header: ( style : WS_VISIBLE or WS_POPUP or WS_CAPTION or WS_SYSMENU or DS_MODALFRAME or DS_SETFONT or DS_CENTER; dwExtendedStyle: 0; cdit : 3; x : 0; y : 0; cx : 4 + 100 + 4; cy : 4 + 60 + 2 + 12 + 4 ); Menu : (#0); WndClass: (#0); Title : ('F', 'o', 'o', #0); Points : 8; Weight : FW_NORMAL; Italic : Ord(False); Charset : DEFAULT_CHARSET; FontFace: ('M', 'S', ' ', 'S', 'h', 'e', 'l', 'l', ' ', 'D', 'l', 'g', #0) ); Edit: ( Header: ( style : WS_VISIBLE or WS_CHILD or WS_TABSTOP or ES_MULTILINE or ES_WANTRETURN or WS_VSCROLL or WS_HSCROLL or ES_AUTOVSCROLL or ES_AUTOHSCROLL; dwExtendedStyle: 0; x : 4; y : 4; cx : 100; cy : 60; id : 100 ); WndClass : (#$FFFF, #$0081); Title : (#0); ExtraCount: 0 ); ButtonOk: ( Header: ( style : WS_VISIBLE or WS_CHILD or WS_TABSTOP or BS_DEFPUSHBUTTON; dwExtendedStyle: 0; x : 4 + 100 - 38 - 2 - 38; y : 4 + 60 + 2; cx : 38; cy : 12; id : ID_OK; ); WndClass : (#$FFFF, #$0080); Title : ('&', 'O', 'K', #0); ExtraCount: 0 ); ButtonCancel: ( Header: ( style : WS_VISIBLE or WS_CHILD or WS_TABSTOP or BS_PUSHBUTTON; dwExtendedStyle: 0; x : 4 + 100 - 38; y : 4 + 60 + 2; cx : 38; cy : 12; id : ID_CANCEL; ); WndClass : (#$FFFF, #$0080); Title : ('&', 'C', 'a', 'n', 'c', 'e', 'l', #0); ExtraCount: 0; ) ); function FooDialogProc(ADlg: HWND; AMsg: UINT; WParam: WPARAM; LParam: LPARAM): Integer stdcall; const PropName = 'Instance'; var PropInst: TFooDialog; EditText: HWND; begin Result := Ord(True); case AMsg of WM_INITDIALOG: begin PropInst := TFooDialog(LParam); SetProp(ADlg, PropName, THandle(PropInst)); if Assigned(PropInst) then begin EditText := GetDlgItem(ADlg, FooDialogTemplate.Edit.Header.id); if EditText <> 0 then SetWindowText(EditText, PChar(PropInst.FText)); end; end; WM_NCDESTROY: RemoveProp(ADlg, PropName); WM_CLOSE: EndDialog(ADlg, Integer(foomrNone)); WM_COMMAND: case HiWord(WParam) of BN_CLICKED: begin case LoWord(WParam) of ID_OK: begin PropInst := TFooDialog(GetProp(ADlg, PropName)); if Assigned(PropInst) then begin EditText := GetDlgItem(ADlg, FooDialogTemplate.Edit.Header.id); if EditText <> 0 then begin SetLength(PropInst.FText, GetWindowTextLength(EditText) + 1); SetLength(PropInst.FText, GetWindowText(EditText, PChar(PropInst.FText), Length(PropInst.FText))); end; end; end; end; EndDialog(ADlg, LoWord(WParam)); end; else Result := Ord(False); end; else Result := Ord(False); end; end; class function TFooDialog.ShowModal(var AParam: TFooDialogParam): TFooModalResult; var FooDialog: TFooDialog; begin FooDialog := TFooDialog.Create(); try FooDialog.FText := AParam.Text; Result := TFooModalResult( DialogBoxIndirectParam(HInstance, FooDialogTemplate.Dialog.Header, AParam.Parent, TFNDlgProc(@FooDialogProc), Integer(FooDialog))); AParam.Text := FooDialog.FText; finally FooDialog.Free(); end; end; end.
Delphi-Quellcode:
var
Param: TFooDialogParam; begin Param.Parent := ParentHandle; Param.Text := 'Foo'#13#10'Bar'; case TFooDialog.ShowModal(Param) of foomrOk: MessageBox(Param.Parent, PChar(Param.Text), '[OK]', MB_OK); foomrCancel: MessageBox(Param.Parent, PChar(Param.Text), '[Cancel]', MB_OK); else MessageBox(Param.Parent, PChar(Param.Text), 'Dialog closed', MB_OK); end; end; |
Re: [Artikel] Den ExitCode eines Dialogfensters nutzen
Ui. Da muss ich erstmal gucken, wo du die Daten ablegst und wie du sie wieder hervorzauberst. ;)
|
Re: [Artikel] Den ExitCode eines Dialogfensters nutzen
Zitat:
|
Re: [Artikel] Den ExitCode eines Dialogfensters nutzen
Das mit der Klasse verkompliziert das eigentlich mehr.
|
Re: [Artikel] Den ExitCode eines Dialogfensters nutzen
Zitat:
|
Re: [Artikel] Den ExitCode eines Dialogfensters nutzen
So gerade ausprobiert: Einen Dialog kann man auch einfach mit EndDialog schließen. man muss also kein WM_CLOSE shcicken und dann auf WM_CLOSE reagieren. Somit kommt meine Methode auch ohne eine globale Variable in der Unit für den zweiten Dialog aus. :P Nur die Struktur muss global in der Unit sein.
Ich glaube, dabei bleibe ich auch. Nicos Methode ist mir doch etwas zu kompliziert muss ich ehrlich sagen. :? |
Re: [Artikel] Den ExitCode eines Dialogfensters nutzen
Zitat:
Ich finde den Missbrauch des Exit-Codes bedenklicher als mein dahingeschludertes Beispiel :) |
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:40 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz