首页  编辑  

CreateDialog API

Tags: /超级猛料/API.Windows应用程序接口/窗口和控件相关/   Date Created:

program Project1;

uses windows;

const

 WM_CLOSE = $0010;

 SW_SHOW = $5;

type

 tagMSG = packed record

   hwnd: HWND;

   message: UINT;

   wParam: WPARAM;

   lParam: LPARAM;

   time: DWORD;

   pt: TPoint;

 end;

var

 h: hwnd;

 w: hwnd;

 bExit: boolean;

 aMessage: TMsg;

function DialogProc(h: hwnd; uMsg: UINT; wParam: wParam; lParam: LPARAM): DWORD; stdcall;

begin

 case umsg of

   wm_close:

     if MessageBox(h, 'Close this Window?', 'Confirm', MB_OKCANCEL+MB_ICONINFORMATION) = IDOK then

     begin

       DestroyWindow(h);

       bExit := True;

     end;

 else

   Result := 0;

 end;

end;

begin

 h := LoadLibrary('shell32.dll');

 bExit := False;

 if h = 0 then exit;

 w := CreateDialog(h, PAnsiChar(1007), 0, @DialogProc);

 FreeLibrary(h);

 if w=0 then exit;

 ShowWindow(W, SW_SHOW);

 while not bExit do

 begin

   GetMessage(aMessage, 0, 0, 0);

   TranslateMessage(amessage);

   DispatchMessage(aMessage);

 end;

end.

****************

procedure TForm1.Button2Click(Sender: TObject);

 function dlgpro(dlghandle:hwnd;dlgmsg:uint;dlgwp:wparam;dlglp:lparam):boolean;stdcall;

 var

   adc:hdc;

   arect:trect;

   agdiobj:hgdiobj;

   p:PAINTSTRUCT;

 begin

   case dlgmsg of

   wm_initdialog:

   begin

     result:=true;

   end;

   wm_paint:

   begin

     BeginPaint(dlghandle,p);

     agdiobj:=getstockobject(black_brush);

     fillrect(p.hdc,p.rcPaint,agdiobj);

     EndPaint(dlghandle,p);

   end;

   else

     Result:=0;

   end;

 end;

var

 ainstance,ret:thandle;

begin

 ainstance:=loadlibrary('comdlg32.dll');

 if ainstance <> 0 then begin

 ret:=createdialog(ainstance,MAKEINTRESOURCE(1547),application.handle,@dlgpro);

 if ret=0 then showmessage('Create dialog failed !');

 freelibrary(ainstance);

 end

 else showmessage('Load library failed !');

end;

Project1.dpr (4.2KB)
Script1.rc (3.5KB)
resource.h (0.8KB)