(抱歉,忘了贴内容^_^)<br>近几天我在研究Dephi动态创建窗口的方法,今天终于有了点眉目,现想和朋友<br>们探讨一下。<br><br>program APIWindow;<br><br>uses<br> Windows,<br> MMSystem,<br> Messages;<br><br>var<br> WinClass: TWndClassA;<br> Inst, Handle: Integer;<br> Msg: TMsg;<br> AppName: PChar;<br><br>{ 定义WindowProc过程 }<br>function WindowProc(hWnd, uMsg, wParam, lParam: Integer): Integer; stdcall;<br>var<br> hdc: Integer;<br> Rect: TRect;<br> ps: PAINTSTRUCT;<br>begin<br> case uMsg of<br> WM_CREATE : //在窗口建立时播放声音<br> PlaySound('TestSnd.wav', 0, SND_FILENAME + SND_ASYNC) ;<br> WM_PAINT :<br> begin //在窗口中央输入文字<br> hdc := BeginPaint (Handle, ps) ;<br> GetClientRect (Handle, Rect) ;<br> DrawText (hdc, 'Hello, Windows 95!', -1, Rect,<br> DT_SINGLELINE + DT_CENTER + DT_VCENTER) ;<br> EndPaint (Handle, ps) ;<br> end;<br> WM_DESTROY :<br> // PostQuitMessage(0) ; //这一句似乎不管用,要Halt才行<br> Halt; <br> end;<br><br> Result := DefWindowProc(hWnd, uMsg, wParam, lParam);<br>end;<br><br>begin<br> AppName := 'HelloWin';<br><br> { 初始化窗体类 }<br> Inst := hInstance;<br> with WinClass do<br> begin<br> style := CS_HREDRAW + CS_VREDRAW;<br> lpfnWndProc := @WindowProc;<br> hInstance := Inst;<br> hbrBackground := GetStockObject (WHITE_BRUSH);<br> lpszClassname := AppName;<br> hCursor := LoadCursor(0, IDC_ARROW);<br> end; <br> RegisterClass(WinClass); //注册窗体类<br><br> { 创建窗口 }<br> Handle := CreateWindow (AppName, // 窗体类名称<br> 'The Hello Program', // 窗体标题<br> WS_OVERLAPPEDWINDOW, // 窗体风格<br> CW_USEDEFAULT, // 初始化窗体X座标<br> CW_USEDEFAULT, // 初始化窗体Y座标<br> CW_USEDEFAULT, // 初始化窗体X尺寸<br> CW_USEDEFAULT, // 初始化窗体Y尺寸<br> 0, // 父窗体句柄<br> 0, // 窗体菜单句柄<br> Inst, // 程序实例(instance)句柄<br> nil) ; // 其它参数<br><br> ShowWindow(Handle, SW_SHOWNORMAL);<br> UpdateWindow(Handle);<br><br> { 消息循环 }<br> while(GetMessage(Msg, Handle, 0, 0)) do<br> begin<br> TranslateMessage(msg);<br> DispatchMessage(msg);<br> end; <br>end.<br><br>程序基本上是Charles Petzold的HelloWin.c例程的翻版,运行起来看上去<br>也一模一样,但是在编译时Delphi会报警告:“Constant expression<br>voilates subrange bounds”,这是为什么?还有一个不解,API函数中有<br>很多变量类型,如HWND、hInstance、hdc等,它们实际上是整数型的,但<br>和整数型的有什么区别?在定义函数时为什么不直接定义为Int、long等?<br>