当主窗体创建的时候,窗体上的控件是什么时候建的啊?
1窗体创建的时候,窗体上的控件是什么时候建的啊?
2控件算不算窗体啊,要是算的话,他也应该注册窗体类并且创建的啊,这又是怎么完成的
[71 byte] By [
zhuyif] at [2008-1-9]
楼上的关于第2个问题的回答是错误的
1,窗口创建:function CreateWindow(lpClassName: PChar; lpWindowName: PChar;
dwStyle: DWORD; X, Y, nWidth, nHeight: Integer; hWndParent: HWND;
hMenu: HMENU; hInstance: HINST; lpParam: Pointer): HWND;
var
FPUCW: Word;
begin
FPUCW := Get8087CW;
Result := _CreateWindowEx(0, lpClassName, lpWindowName, dwStyle, X, Y,
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
Set8087CW(FPUCW);
end;
function CreateWindowA(lpClassName: PAnsiChar; lpWindowName: PAnsiChar;
dwStyle: DWORD; X, Y, nWidth, nHeight: Integer; hWndParent: HWND;
hMenu: HMENU; hInstance: HINST; lpParam: Pointer): HWND;
var
FPUCW: Word;
begin
FPUCW := Get8087CW;
Result := _CreateWindowExA(0, lpClassName, lpWindowName, dwStyle, X, Y,
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
Set8087CW(FPUCW);
end;
function CreateWindowW(lpClassName: PWideChar; lpWindowName: PWideChar;
dwStyle: DWORD; X, Y, nWidth, nHeight: Integer; hWndParent: HWND;
hMenu: HMENU; hInstance: HINST; lpParam: Pointer): HWND;
var
FPUCW: Word;
begin
FPUCW := Get8087CW;
Result := _CreateWindowExW(0, lpClassName, lpWindowName, dwStyle, X, Y,
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
Set8087CW(FPUCW);
end;
这些都是调用了系统的API函数来完成的,而窗口的控件则由Tcomponent类一层一层inherited Create(AOwner)下来的,直到完成指定的生成样板,
2、控件Tcontrol其实都是容器,类似于Form! 任何具有handle的控件其都能用来加载其它组件,只要将parent指定,这个结构类似于数据结构里数据链, 不过这里是对象链,对象包含了其指定的父类对象,将其断开父类对象的挂钩,挂靠到你指定的control中是完全可以的,回归C语言,form和control的原理还是一样的
procedure TApplication.CreateForm(InstanceClass: TComponentClass; var Reference);
var
Instance: TComponent;
begin
Instance := TComponent(InstanceClass.NewInstance);
TComponent(Reference) := Instance;
try
Instance.Create(Self);
except
TComponent(Reference) := nil;
raise;
end;
if (FMainForm = nil) and (Instance is TForm) then
begin
TForm(Instance).HandleNeeded;
FMainForm := TForm(Instance);
end;
end;
这里面TForm(Instance).HandleNeeded;这一句才完成窗口类的注册和主窗体的创建而
Instance.Create(Self);只完成窗口对象的建立,并无窗口类的注册和主窗体的创建。那依楼上说的:“窗口的控件则由Tcomponent类一层一层inherited Create(AOwner)下来的”,create 只建了对象.不知楼上明白我的意思没