以下代码类型的工作,它是从TJvOpenDialog派生的,它给了我一些如何做到的提示:
type TMyOpenDialog = class(TJvOpenDialog) private procedure Setposition; protected procedure DoFolderChange; overrIDe; procedure WndProc(var Msg: TMessage); overrIDe; end;procedure TMyOpenDialog.Setposition;beginvar Monitor: TMonitor; ParentControl: TWinControl; Res: LongBool;begin if (Assigned(Owner)) and (Owner is TWinControl) then ParentControl := (Owner as TWinControl) else if Application.MainForm <> nil then ParentControl := Application.MainForm else begin // this code was already in TJvOpenDialog Monitor := Screen.Monitors[0]; Res := SetwindowPos(ParentWnd,Monitor.left + ((Monitor.WIDth - WIDth) div 2),Monitor.top + ((Monitor.Height - Height) div 3),WIDth,Height,SWP_NOACTIVATE or SWP_NOZORDER); exit; // => end; // this is new Res := SetwindowPos(GetParent(Handle),ParentControl.left + ((ParentControl.WIDth - WIDth) div 2),ParentControl.top + ((ParentControl.Height - Height) div 3),SWP_NOACTIVATE or SWP_NOZORDER);end;procedure TMyOpenDialog.DoFolderChangebegin inherited DoFolderChange; // call inherited first,it sets the dialog style etc. Setposition;end;procedure TMyOpenDialog.WndProc(var Msg: TMessage);begin case Msg.Msg of WM_ENTERIDLE: begin // This has never been called in my tests,but since TJVOpenDialog // does it I figured there may be some fringe case which requires // Setposition being called from here. inherited; // call inherited first,it sets the dialog style etc. Setposition; exit; end; end; inherited;end;
“有点工作”意味着第一次打开对话框时,它会以所有者表单为中心显示.但是,如果我然后关闭对话框,移动窗口并再次打开对话框,SetwindowPos似乎没有任何效果,即使它确实返回true.对话框在第一次打开的位置打开.
这是在windows XP上运行的Delphi 2007,目标框也运行windows XP.
解决方法 TJvOpenDialog是topenDialog的后代,因此您应该在VCL居中对话后运行您的展示位置调用. VCL在响应CDN_INITDONE通知时执行此 *** 作.响应WM_SHOWWINDOW消息太早了,在我的测试中,窗口过程从不接收WM_ENTERIDLE消息.uses commdlg;[...]procedure TJvOpenDialog.DoFolderChange;begin inherited DoFolderChange; // Setposition; // shouldn't be needing this,only place the dialog onceend;procedure TJvOpenDialog.WndProc(var Msg: TMessage);begin case Msg.Msg of WM_NOTIFY: begin if POFNotify(Msg.LParam)^.hdr.code = CDN_INITDONE then begin inherited; // VCL centers the dialog here Setposition; // we don't like it ;) Exit; end; end; inherited;end;
要么,
procedure TJvOpenDialog.WndProc(var Msg: TMessage);begin case Msg.Msg of WM_NOTIFY: if POFNotify(Msg.LParam)^.hdr.code = CDN_INITDONE then Exit; end; inherited;end;
有了 *** 作系统所说的对话框,它实际上是有意义的.
总结以上是内存溢出为你收集整理的delphi – 如何定位TOpenDialog全部内容,希望文章能够帮你解决delphi – 如何定位TOpenDialog所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)