T
TTreeNodes.GetC
Unregistered / Unconfirmed
GUEST, unregistred user!
下面这段代码能运行,但是却有提[blue]示'Constant expression violates subrange bounds'[/blue]<br>Button1的Click事件中不能创建新窗体,大家可以试试!<br>请大家帮忙!<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br>var<br> HWindow:HWND;<br>{$R *.DFM}<br><br>function RegisterClassEx:Boolean;<br>var<br> WindowClassEx:TWndClassEx;<br>begin<br> with WindowClassEx do<br> begin<br> cbSize:=SizeOf(TWndClassEx);<br> Style:=CS_HREDRAW or CS_VREDRAW;<br> lpfnWndProc:=@DefWindowProc;<br> cbClsExtra:=0;<br> cbWndExtra:=0;<br> hInstance:=hInstance;<br> hIcon:=LoadIcon(0,IDI_APPLICATION);<br> hCursor:=LoadCursor(0,IDC_WAIT);<br> hbrBackground:=COLOR_WINDOW;<br> lpszMenuName:=Nil;<br> lpszClassName:='TestClass';<br> hIconSm:=0;<br> end;<br> Result:=Windows.RegisterClassEx(WindowClassEx)<>0;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> if not RegisterClassEx then<br> begin<br> ShowMessage('RegisterClassEx failed');<br> Exit;<br> end;<br> hWindow:=CreateWindowEx(WS_EX_CLIENTEDGE or WS_EX_CONTEXTHELP,<br> 'TestClass',<br> 'APIWindow',<br> WS_OVERLAPPEDWINDOW and not WS_MAXIMIZEBOX and not WS_MINIMIZEBOX,<br> CW_USEDEFAULT,<br> CW_USEDEFAULT,<br> CW_USEDEFAULT,<br> CW_USEDEFAULT,<br> 0,<br> 0,<br> hInstance,<br> nil);<br> if hWindow<>0 then<br> begin<br> ShowWindow(hWindow,SW_SHOWNORMAL);<br> UpdateWindow(hWindow);<br> end<br> else<br> begin<br> ShowMessage('CreateWindow failed');<br> Exit;<br> end; <br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> DestroyWindow(hWindow);<br> Windows.UnregisterClass('TestClass',hInstance);<br>end;<br><br>end.