Blogs
在VC中实现控件容器
Submitted by gougou on Sat, 2005-06-04 10:28在VC6中设计器不提供类似Delphi,.Net中的容器的控件Panel组件,因此做复杂界面的时候比较麻烦,为了模拟容器控件的效果,我们可以通过创建一个无边框的Dialog,将其停靠到主界面上来仿真。代码示意如下。
BOOL CDivideSettingDetail::OnInitDialog()
{
CCommDlg::OnInitDialog();
CWnd* pWnd = GetDlgItem( IDC_TRAIN );
CRect rect;
pWnd->GetWindowRect( &rect );
ScreenToClient( &rect );
InitTrainDetail();
TrainDetail.Create(IDD_015_1, this);
TrainDetail.ShowWindow( WS_VISIBLE | WS_CHILD );
TrainDetail.SetWindowPos( pWnd, 0, rect.top, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER );
TrainDetail.ShowWindow(SW_SHOW);
上面的IDC_TRAIN是一个用来定位的控件,设计时将它设置为不可见即可
Html Help 2注册工具
Submitted by gougou on Tue, 2005-05-03 17:16VS.Net 中的帮助是基于Html Help 2的格式的,它不像Chm那样,一个文件就可以直接运行,必须经过一些繁琐的注册步骤才行,微软提供的注册模块是基于MSI的,非常不好用。
我写了一个安装HtmlHelp2的工具,两种运行模式,一种是GUI的,一种是命令行的,支持Merge Topic和Plugin两种注册方式,可以同时支持多个target,包括VS.Net2003/2002和Delphi8/Delphi2005等。
最新版本是1.2---更新日期是2005/06/05
下载:http://www.sharpplus.com/downloads/RegH212.zip
Windows的一个焦点控制问题
Submitted by gougou on Mon, 2005-05-02 16:34将一个相对于基本路径的相对路径转化为绝对路径
Submitted by gougou on Sun, 2005-04-24 17:17Delphi中没有提供将一个相对于基本路径的相对路径转化为绝对路径的函数,我迫不得已自己写了一个。
function GetAbsolutePath(BasePath, RelativePath:string):string;
implementation
uses ComObj, ComConst, dialogs;
function PathCombine(lpszDest: PChar; const lpszDir, lpszFile: PChar):
PChar; stdcall; external 'shlwapi.dll' name 'PathCombineA';
function PathCombineA(lpszDest: PAnsiChar; const lpszDir, lpszFile:
PAnsiChar): PAnsiChar; stdcall; external 'shlwapi.dll';
function PathCombineW(lpszDest: PWideChar; const lpszDir, lpszFile:
PWideChar): PWideChar; stdcall; external 'shlwapi.dll';
function GetAbsolutePath(BasePath, RelativePath:string):string;
var
Dest:array [0..MAX_PATH] of char;
begin
FillChar(Dest,MAX_PATH+1,0);
PathCombine(Dest,PChar(BasePath), PChar(RelativePath));
Result:=string(Dest);
end;
TStringGrid的糟糕设计
Submitted by gougou on Wed, 2005-04-13 13:13最近在给客户作一个更加强大的类似于TStringGrid的支持多种自定义编辑器的网格控件,结果发现TStringGrid的设计是比较糟糕的,它所使用的原位编辑器的虚方法只能是从TInputEdit派生,而TInplaceEdit又是从TMaskEdit派生出来的,这样的结果就是如果要从TStringGrid派生新组件的话,无法通过重载CreateEditor来支持其他的编辑器控件,虽然Grids单元中Borland也做了一些其他的原位编辑器,但是实现的非常生硬。另外TStringGrid中很多重要的方法没有声明为虚方法,甚至没有放在Protected部分,导致扩展性极差,看了一些其他的商业的网格控件,好多作者直接放弃了扩展TStringGrid的想法,直接从TCustomControl来重新做的。
发布ActionList For WinForm
Submitted by gougou on Tue, 2005-04-12 08:53WinForm中没有提供类似于VCL中的ActionList组件,我写了一个ActionList For WinForm的组件,大家有兴趣的可以用用,提提意见。
特性
- 支持VS2003,Delphi2005的IDE中组件集成,HtmlHelp2的帮助集成。
- 提供了一个方便的Action绑定组件设计器,提供了对于MenuItem,Toolbar Button和标准按钮的集成
- 几乎没有侵入性,无须修改原有组件代码,就可以很容易的扩展支持其他的界面组件。
- 内置了EditCopyAction,EditCutAction,EditClearAction,EditPasteAction, EditSelectAllAction, EditUndoAction, WindowCloseAction, WindowArrangeAction,WindowCascadeAction,WindowMinimizeAllAction,WindowTileHorizontalAction,WindowTileHorizontalAction, WindowTileVerticalAction等十几个预定义的Action。
下载:
调用集合属性编辑器
Submitted by gougou on Mon, 2005-04-11 17:32TDBGrid的组件编辑器双击后会调出Columns的属性编辑器,这要调用未公开的ColnEdit中的方法ShowCollectionEditorClass方法来实现,代码示意如下
uses ColnEdit,...;
....
procedure TSAGComponentEditor.ExecuteVerb(Index: Integer);
begin
case Index of
0://Show Column Editor;
begin
ShowCollectionEditorClass(Designer, TCollectionEditor, Component,
TSAGrid(Component).GridColumns, 'GridColumns', [coAdd, coDelete, coMove]);
end;
end;
end;
衡量软件质量的一个标准
Submitted by gougou on Mon, 2005-04-04 22:52以前写程序时,不太注意细节,编译后代码总也一些警告和提示,一直也没太在意,前两天写的程序提交给用户测试,结果用户发现所有的快捷键都不好使了,检查才发现一个从基类派生的方法没有声明为Override,其实代码在编译时对静态方法覆盖了虚方法报过警告,但我给忽视了。有了这个教训,我把所有的警告都给修正了。以后一定要注意看似不起眼的警告同软件的质量也息息相关。
编写GUI和控制台双模式程序
Submitted by gougou on Sun, 2005-03-27 20:46uses
SysUtils,
Windows,
Forms,
CMain in 'CMain.pas' {FormMain},
H2Reg in 'H2Reg.pas',
WbemScripting_TLB in '..\..\Imports\WbemScripting_TLB.pas';
{$R *.res}
begin
if ParamCount = 0 then
begin
Application.Initialize;
Application.CreateForm(TFormMain, FormMain);
Application.Run;
end
else
begin
AllocConsole;
try
Writeln('Usage:RegH2 -help');
Writeln('Please Enter to terminate...');
