呵呵,Delphi中没有必要自己用CreateWindow或CreateWindowEx创建FORM呀,如果你要窗体,就用TForm,如果你不要窗体,只要窗口句柄,就用AllocHWnd()函数呀, 想你可能是要后者,可以看看Delphi的TTimer控件的源码,关键部分如下:constructor TTimer.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FEnabled := True;
FInterval := 1000;
FWindowHandle := AllocateHWnd(WndProc); //分配了一个窗口句柄
end;destructor TTimer.Destroy;
begin
FEnabled := False;
UpdateTimer;
DeallocateHWnd(FWindowHandle); //释放窗口句柄
inherited Destroy;
end;procedure TTimer.WndProc(var Msg: TMessage); //前面分配的窗口的窗口过程
begin
with Msg do
if Msg = WM_TIMER then
try
Timer;
except
Application.HandleException(Self);
end
else
Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam);
end;呵呵,不知你是这是要这个,一般有句柄就可以处理消息了,而它正好又没有实际的窗口界面!
如果你是要有界面的,直接建TForm的实例就行了!
begin
inherited Create(AOwner);
FEnabled := True;
FInterval := 1000;
FWindowHandle := AllocateHWnd(WndProc); //分配了一个窗口句柄
end;destructor TTimer.Destroy;
begin
FEnabled := False;
UpdateTimer;
DeallocateHWnd(FWindowHandle); //释放窗口句柄
inherited Destroy;
end;procedure TTimer.WndProc(var Msg: TMessage); //前面分配的窗口的窗口过程
begin
with Msg do
if Msg = WM_TIMER then
try
Timer;
except
Application.HandleException(Self);
end
else
Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam);
end;呵呵,不知你是这是要这个,一般有句柄就可以处理消息了,而它正好又没有实际的窗口界面!
如果你是要有界面的,直接建TForm的实例就行了!
begin
with Params do
FHandle := CreateWindowEx(ExStyle, WinClassName, Caption, Style,
X, Y, Width, Height, WndParent, 0, WindowClass.hInstance, Param);
end;
var
TempClass: TWndClass;
ClassRegistered: Boolean;
begin
UtilWindowClass.hInstance := HInstance;
ClassRegistered := GetClassInfo(HInstance, UtilWindowClass.lpszClassName,
TempClass);
if not ClassRegistered or (TempClass.lpfnWndProc <> @DefWindowProc) then
begin
if ClassRegistered then
Windows.UnregisterClass(UtilWindowClass.lpszClassName, HInstance);
Windows.RegisterClass(UtilWindowClass);
end;
Result := CreateWindowEx(WS_EX_TOOLWINDOW, UtilWindowClass.lpszClassName,
'', WS_POPUP {!0}, 0, 0, 0, 0, 0, 0, HInstance, nil);
if Assigned(Method) then
SetWindowLong(Result, GWL_WNDPROC, Longint(MakeObjectInstance(Method)));
end;
Windows, Messages;var
msg: Tmsg;
WinClass: TWndClassA;
hInst, hWindow, hButton, hStatic, hEdit, hFont: integer;procedure CheckPassword;
var
Text: PChar;
TextLength: Integer;
begin
TextLength:=GetWindowTextLength(hEdit);
if TextLength=8 then
begin
GetMem(Text, TextLength+1);
GetWindowText(hEdit, Text, TextLength+1);
if Text='Daubster' then MessageBox(hWindow,
'您输入的密码是正确的...'#9,
'密码验证',
MB_OK+MB_ICONINFORMATION);
freeMem(Text);
end
else
MessageBox(hWindow, '您输入的密码不是正确的...', '密码验证', MB_OK+MB_ICONSTOP);
SetFocus(hEdit);
end;function WindowProc(hWnd:HWND; uMsg:UINT;
wParam:WPARAM; lParam:LPARAM):LRESULT; stdcaLL;
begin
result:=DefWindowProc(hWnd, uMsg, wParam, lParam);
if uMsg=WM_DESTROY then Halt;
if (lParam=hButton) and (uMsg=WM_COMMAND) then CheckPassword;
end;begin
hInst:= hInstance;
with WinClass do
begin
style:= CS_CLASSDC or CS_PARENTDC;
lpfnWndProc:= @WindowProc;
hInstance:= hInst;
hbrBackground:= COLOR_BTNFACE+1;
lpszClassname:= 'DAUBSTER_SMALL_EXEFILE';
hCursor:= LoadCursor(0, IDC_ARROW);
end;
RegisterClass(WinClass); hWindow:=CreateWindowEx(WS_EX_WINDOWEDGE,
'DAUBSTER_SMALL_EXEFILE',
'小应用程序',
WS_VISIBLE or WS_SIZEBOX or WS_CAPTION or WS_SYSMENU,
200, 278, 305, 95, 0, 0, hInst, niL); hButton:=CreateWindow( 'Button',
'确定',
WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT,
215, 21, 65, 22, hWindow, 0, hInst, niL); hStatic:=Createwindow( 'Static',
'',
WS_VISIBLE or WS_CHILD or SS_LEFT,
16, 24, 75, 16, hWindow, 0, hInst, niL); hEdit:=CreateWindowEx( WS_EX_CLIENTEDGE,
'Edit',
'',
WS_CHILD or WS_VISIBLE or WS_BORDER or ES_PASSWORD,
85, 20, 121, 24, hWindow, 0, hInst, niL); hFont:=CreateFont( -11, 0, 0, 0, 400, 0, 0, 0,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH or FF_DONTCARE, 'Times New Roman');
if hFont <> 0 then
begin
SendMessage(hEdit, WM_SETFONT, hFont, 0);
SendMessage(hStatic, WM_SETFONT, hFont, 0);
SendMessage(hButton, WM_SETFONT, hFont, 0);
end; SetWindowText(hStatic, '请输入密码:');
SetFocus(hEdit); UpdateWindow(hWindow); while(GetMessage(msg, hWindow, 0, 0)) do
begin
TranslateMessage(msg);
DispatchMessage(msg);
end;
end.