10.08.08 13:58
С помощью Интернета вытрудил вот такой код:
program WAPIDialogs;
uses
Windows,
Messages;
var
MainHandle:HWND;
Msg:TMsg;
{$R *.res}
{$R Window.res}
procedure OnIdle;
begin
//Кусок кода, ускипано
end;
procedure DoDeInit(Handle:HWND);
begin
DestroyWindow(Handle);
PostQuitMessage(0);
end;
procedure DoInit(Handle:HWND);
begin
ShowWindow(Handle,SW_MAXIMIZE);
end;
function DlgProc(Handle:HWND; Msg:UINT; WP:WPARAM; LP:LPARAM):BOOL; stdcall;
begin
Result:=False;
case Msg of
WM_INITDIALOG: DoInit(Handle);
WM_CLOSE: DoDeInit(Handle);
WM_COMMAND:
case WP of
IDCANCEL:
begin
ShowWindow(Handle,SW_MINIMIZE); EndDialog(Handle,0);
end;
end; //case WP
end; //case Msg
end; //DlgProc
begin
MainHandle:=CreateDialog(HInstance,'MAIN',0,@DlgProc);
if MainHandle<>0 then
while True do
if PeekMessage(Msg,MainHandle,0,0,PM_REMOVE) then
begin
if Msg.message=WM_NULL then Break;
if not(IsDialogMessage(MainHandle,Msg)) then
begin
TranslateMessage(Msg); DispatchMessage(Msg);
end
end
else
OnIdle;
end.
В принципе, это работает, но не нравится, что приходится отлавливать WM_NULL. Без этого приложение прячет окно и повисает в while'е.
Использование диалогов из ресурсов - это, можно сказать, "условие задачи".
Код
program WAPIDialogs;
uses
Windows,
Messages;
var
MainHandle:HWND;
Msg:TMsg;
{$R *.res}
{$R Window.res}
procedure OnIdle;
begin
//Кусок кода, ускипано
end;
procedure DoDeInit(Handle:HWND);
begin
DestroyWindow(Handle);
PostQuitMessage(0);
end;
procedure DoInit(Handle:HWND);
begin
ShowWindow(Handle,SW_MAXIMIZE);
end;
function DlgProc(Handle:HWND; Msg:UINT; WP:WPARAM; LP:LPARAM):BOOL; stdcall;
begin
Result:=False;
case Msg of
WM_INITDIALOG: DoInit(Handle);
WM_CLOSE: DoDeInit(Handle);
WM_COMMAND:
case WP of
IDCANCEL:
begin
ShowWindow(Handle,SW_MINIMIZE); EndDialog(Handle,0);
end;
end; //case WP
end; //case Msg
end; //DlgProc
begin
MainHandle:=CreateDialog(HInstance,'MAIN',0,@DlgProc);
if MainHandle<>0 then
while True do
if PeekMessage(Msg,MainHandle,0,0,PM_REMOVE) then
begin
if Msg.message=WM_NULL then Break;
if not(IsDialogMessage(MainHandle,Msg)) then
begin
TranslateMessage(Msg); DispatchMessage(Msg);
end
end
else
OnIdle;
end.
В принципе, это работает, но не нравится, что приходится отлавливать WM_NULL. Без этого приложение прячет окно и повисает в while'е.
Использование диалогов из ресурсов - это, можно сказать, "условие задачи".
Отредактировано: 10.08.08 14:00