关于往别的程序的pagecontrol里增加tabsheet的问题,感兴趣的请留步?(50分)

  • 主题发起人 主题发起人 jacklin
  • 开始时间 开始时间
J

jacklin

Unregistered / Unconfirmed
GUEST, unregistred user!
相信大家对许多显卡驱动程序有印象,安装完后在控制面板里的"显示"里会出现自己的Tabsheet,这在delphi里如何实现?
 
我想你必须有把握对"别的程序"中的结构很清楚吧,如果清楚就不难了.不过显<br>卡设置中的界面是通过API实现的,那有一个通用的接口.
 
我一直记得huizhang说的'可以用createwindow api 和消息传递给其它windows程<br>序加wincontrl类控件'试了几次没有实现。<br>你说的加入显示中和此问题关系不是太大吧,它一定不是用这方法,用的是windows<br>中提供的接口,不是注册表就是ini。
 
barton兄,假设"别的程序"是自己写的程序,那当然就清楚程序结构了。那么如何<br>实现我所说的要求呢?<br>另外,您老兄能否说一下显卡设置中通用的API接口,俺对这很感兴趣!<br><br>*这个问题50分实在太少了,大家请原谅:jacklin刚刚白手起家,家底只有二百来<br>分,实在无法支付巨额赏金。<br><br>
 
其实我也曾想过这个问题.我把我应用程序中的所有设置集中到一起想做到<br>控制面板中,如果直接用我想是可以的.只是最近比较忙没有试.<br>这个问题可以反过来想:你的应用程序中的Form被一个PageControl调用可能<br>就比较好想了,不过这可能需要将Form做到DLL或COM中.当然,作Form调用或<br>作TabSheet调用都是调用这个DLL或COM.显示卡的设置也应该是这个思想,<br>...当然这只是猜测:-)<br>过两天我发个DEMO你看看.
 
这个问题我已经搞定。^_^<br><br>条件:1.要添加的Form(权且叫子窗体)需按指定格式做:所有的<br>&nbsp; 内容都用若干个GroupBox容器装上(当然也可以改用Panel或其<br>&nbsp; 它的容器),按钮加上1-4的Tag值(当然你也可以自己改成其它<br>&nbsp; 数)。<br>&nbsp; &nbsp; &nbsp; 2.做一个空的Form(权且叫父窗体),放上一个PageControl<br>&nbsp; (Left和Top一定要设置好,其它属性随便),命名为pcGlobal。<br><br>其余的你看以下代码:<br><br>type<br>&nbsp; TSubForm = class(TObject)<br>&nbsp; private<br>&nbsp; &nbsp; FTabSheet: TTabSheet;<br>&nbsp; &nbsp; FActive: Boolean;<br>&nbsp; &nbsp; FBoxes, FButtons: TList;<br>&nbsp; &nbsp; FForm: TForm;<br>&nbsp; &nbsp; FPageControl: TPageCOntrol;<br>&nbsp; &nbsp; procedure SetActive(Value: Boolean);<br>&nbsp; protected<br>&nbsp; public<br>&nbsp; &nbsp; constructor Create(AForm: TForm; APageControl: TPageControl);<br>&nbsp; &nbsp; destructor Destroy; override;<br>&nbsp; &nbsp; property Active: Boolean read FActive write SetActive;<br>&nbsp; end;<br><br>&nbsp; TfmOption = class(TForm)<br>&nbsp; &nbsp; pcGlobal: TPageControl;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormDestroy(Sender: TObject);<br>&nbsp; &nbsp; procedure FormActivate(Sender: TObject);<br>&nbsp; &nbsp; procedure pcGlobalChange(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; Forms: TList;<br>&nbsp; &nbsp; FIndex: Integer;<br>&nbsp; &nbsp; procedure SetIndex(Value: Integer);<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; &nbsp; procedure AddForm(AForm: TForm);<br>&nbsp; &nbsp; property FormIndex: Integer read FIndex write SetIndex;<br>&nbsp; end;<br><br>var<br>&nbsp; fmOption: TfmOption;<br><br>function TestOption: Boolean;<br><br>implementation<br><br>{$R *.DFM}<br><br>function TestOption: Boolean;<br>begin<br>&nbsp; fmOption := TfmOption.Create(nil);<br>&nbsp; fmSub1 := TfmSub1.Create(nil); &nbsp;//创建第一个子窗体实例<br>&nbsp; fmSub2 := TfmSub2.Create(nil); &nbsp;//创建第二个子窗体实例<br>&nbsp; ...<br>&nbsp; with fmOption do<br>&nbsp; try<br>&nbsp; &nbsp; AddForm(fmSub1); &nbsp;//加入第一个窗体的实例<br>&nbsp; &nbsp; AddForm(fmSub2); &nbsp;//加入第一个窗体的实例<br>&nbsp; &nbsp; ...<br>&nbsp; &nbsp; Result := ShowModal = mrOK;<br>&nbsp; finally<br>&nbsp; &nbsp; Free;<br>&nbsp; &nbsp; fmSub1.Free; &nbsp; &nbsp; &nbsp;//如果不是本过程创建就不必释放<br>&nbsp; &nbsp; fmSub2.Free; &nbsp; &nbsp; &nbsp;//如果不是本过程创建就不必释放<br>&nbsp; &nbsp; ...<br>&nbsp; end;<br>end;<br><br>// TSubForm 对象<br><br>constructor TSubForm.Create(AForm: TForm; APageControl: TPageControl);<br>var<br>&nbsp; I, W, H: Integer;<br>begin<br>&nbsp; FForm := AForm;<br>&nbsp; FPageControl := APageControl;<br>&nbsp; FBoxes := TList.Create;<br>&nbsp; FButtons := TList.Create;<br>&nbsp; FTabSheet := TTabSheet.Create(FPageControl.Parent);<br>&nbsp; FTabSheet.PageControl := FPageControl;<br>&nbsp; FTabSheet.Caption := AForm.Caption;<br>&nbsp; for I := 0 to AForm.ComponentCount - 1 do begin<br>&nbsp; &nbsp; if AForm.Components is TGroupBox then begin<br>&nbsp; &nbsp; &nbsp; //当然这里暂时只处理TGroupBox<br>&nbsp; &nbsp; &nbsp; TGroupBox(AForm.Components).Parent := FTabSheet;<br>&nbsp; &nbsp; &nbsp; FBoxes.Add(AForm.Components);<br>&nbsp; &nbsp; &nbsp; W := TGroupBox(AForm.Components).Left<br>&nbsp; &nbsp; &nbsp; &nbsp; + TGroupBox(AForm.Components).Width + 14;<br>&nbsp; &nbsp; &nbsp; H := TGroupBox(AForm.Components).Top<br>&nbsp; &nbsp; &nbsp; &nbsp; + TGroupBox(AForm.Components).Height + 36;<br>&nbsp; &nbsp; &nbsp; if FPageControl.Height &lt; H then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; FPageControl.Height := H;<br>&nbsp; &nbsp; &nbsp; &nbsp; FPageControl.Parent.Height := H + 75;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; if FPageControl.Width &nbsp;&lt; W then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; FPageControl.Width &nbsp;:= W;<br>&nbsp; &nbsp; &nbsp; &nbsp; FPageControl.Parent.Width &nbsp;:= W + 21;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end else if AForm.Components is TButton then<br>&nbsp; &nbsp; //按钮在这里处理<br>&nbsp; &nbsp; if AForm.Components.Tag &gt; 0 then<br>&nbsp; &nbsp; with TButton(AForm.Components) do begin<br>&nbsp; &nbsp; &nbsp; Parent := FPageControl.Parent;<br>&nbsp; &nbsp; &nbsp; Visible := False;<br>&nbsp; &nbsp; &nbsp; FButtons.Add(AForm.Components);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>destructor TSubForm.Destroy;<br>var<br>&nbsp; I: Integer;<br>begin<br>&nbsp; //啊哈!借东西要还,要不然下次没得借的说!<br>&nbsp; for I := 0 to FButtons.Count - 1 do<br>&nbsp; &nbsp; TWinControl(FButtons).Parent := FForm;<br>&nbsp; for I := 0 to FBoxes.Count - 1 do<br>&nbsp; &nbsp; TGroupBox(FBoxes).Parent := FForm;<br>&nbsp; FBoxes.Free;<br>&nbsp; FButtons.Free;<br>&nbsp; inherited Destroy;<br>end;<br><br>procedure TSubForm.SetActive(Value: Boolean);<br>var<br>&nbsp; I: Integer;<br>begin<br>&nbsp; //根据Tag的指引,在最适当的地方显示按钮<br>&nbsp; if FActive = Value then Exit;<br>&nbsp; FActive := Value;<br>&nbsp; for I := 0 to FButtons.Count - 1 do begin<br>&nbsp; &nbsp; case TButton(FButtons).Tag of<br>&nbsp; &nbsp; &nbsp; 1: TButton(FButtons).Left := FPageControl.Width - 305;<br>&nbsp; &nbsp; &nbsp; 2: TButton(FButtons).Left := FPageControl.Width - 201;<br>&nbsp; &nbsp; &nbsp; 3: TButton(FButtons).Left := FPageControl.Width - 97;<br>&nbsp; &nbsp; &nbsp; 4: TButton(FButtons).Left := FPageControl.Width - 409;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; TButton(FButtons).Top := FPageControl.Height + 14;<br>&nbsp; &nbsp; TButton(FButtons).Visible := FActive;<br>&nbsp; end;<br>end;<br><br>//TfmOption 对象<br><br>procedure TfmOption.SetIndex(Value: Integer);<br>begin<br>&nbsp; //激活相应的"虚窗体"<br>&nbsp; if FIndex = Value then Exit;<br>&nbsp; if FIndex &gt;= 0 then TSubForm(Forms[FIndex]).Active := False;<br>&nbsp; FIndex := Value;<br>&nbsp; TSubForm(Forms[FIndex]).Active := True;<br>end;<br><br>procedure TfmOption.AddForm(AForm: TForm);<br>var<br>&nbsp; ASubForm: TSubForm;<br>begin<br>&nbsp; ASubForm := TSubForm.Create(AForm, pcGlobal);<br>&nbsp; Forms.Add(ASubForm);<br>&nbsp; Position := poScreenCenter;<br>end;<br><br>procedure TfmOption.FormCreate(Sender: TObject);<br>begin<br>&nbsp; Forms := TList.Create;<br>&nbsp; FIndex := - 1;<br>end;<br><br>procedure TfmOption.FormDestroy(Sender: TObject);<br>begin<br>&nbsp; while Forms.Count &gt; 0 do begin<br>&nbsp; &nbsp; TSubForm(Forms[Forms.Count - 1]).Free;<br>&nbsp; &nbsp; Forms.Delete(Forms.Count - 1);<br>&nbsp; end;<br>&nbsp; Forms.Free;<br>end;<br><br>procedure TfmOption.FormActivate(Sender: TObject);<br>begin<br>&nbsp; pcGlobal.ActivePage := pcGlobal.Pages[0];<br>&nbsp; SetIndex(0);<br>end;<br><br>procedure TfmOption.pcGlobalChange(Sender: TObject);<br>begin<br>&nbsp; FormIndex := pcGlobal.ActivePage.TabIndex;<br>end;<br><br>end.
 
barton:<br>能不能再讲讲使用的方法,比如我想把上面的Form加到"显示"属性页中,<br>该如何操作.(我想还必须在注册表中加些东西吧?)
 
barton要实现的效果叫做"属性页".<br>windows提供的接口应该是COM的接口吧.<br>自己实现IPropertyPage接口就可以了.<br><br>在MSDN里查property page关键字吧.<br>
 
控制别的程序可能不好玩.用COM可能不行.因为显示属性页属于系统控制的全<br>局实例,而COM只是一个接口.如果通过接口实现只可能定义一个特殊的消息来<br>驱动.我想你的思路可能有问题:不是显示卡驱动程序调用系统的FORM,而是系<br>统程序调用显示卡驱动程序的FORM?
 
接受答案了.
 
后退
顶部