快近来抢分啊!(100分)

  • 主题发起人 主题发起人 TTreeNodes.GetC
  • 开始时间 开始时间
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>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button2Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br>var<br>&nbsp; HWindow:HWND;<br>{$R *.DFM}<br><br>function RegisterClassEx:Boolean;<br>var<br>&nbsp; WindowClassEx:TWndClassEx;<br>begin<br>&nbsp; with WindowClassEx do<br>&nbsp; begin<br>&nbsp; &nbsp; cbSize:=SizeOf(TWndClassEx);<br>&nbsp; &nbsp; Style:=CS_HREDRAW or CS_VREDRAW;<br>&nbsp; &nbsp; lpfnWndProc:=@DefWindowProc;<br>&nbsp; &nbsp; cbClsExtra:=0;<br>&nbsp; &nbsp; cbWndExtra:=0;<br>&nbsp; &nbsp; hInstance:=hInstance;<br>&nbsp; &nbsp; hIcon:=LoadIcon(0,IDI_APPLICATION);<br>&nbsp; &nbsp; hCursor:=LoadCursor(0,IDC_WAIT);<br>&nbsp; &nbsp; hbrBackground:=COLOR_WINDOW;<br>&nbsp; &nbsp; lpszMenuName:=Nil;<br>&nbsp; &nbsp; lpszClassName:='TestClass';<br>&nbsp; &nbsp; hIconSm:=0;<br>&nbsp; end;<br>&nbsp; Result:=Windows.RegisterClassEx(WindowClassEx)&lt;&gt;0;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; if not RegisterClassEx then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage('RegisterClassEx failed');<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br>&nbsp; hWindow:=CreateWindowEx(WS_EX_CLIENTEDGE or WS_EX_CONTEXTHELP,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'TestClass',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'APIWindow',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WS_OVERLAPPEDWINDOW and not WS_MAXIMIZEBOX and not WS_MINIMIZEBOX,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hInstance,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nil);<br>&nbsp; if hWindow&lt;&gt;0 then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowWindow(hWindow,SW_SHOWNORMAL);<br>&nbsp; &nbsp; UpdateWindow(hWindow);<br>&nbsp; end<br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage('CreateWindow failed');<br>&nbsp; &nbsp; Exit;<br>&nbsp; end; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; DestroyWindow(hWindow);<br>&nbsp; Windows.UnregisterClass('TestClass',hInstance);<br>end;<br><br>end.
 
难道就没有人知道吗?<br>富翁都消失了吗?<br>还是徒有虚名啊?[:(][:(][?]
 
看来论坛上的人只能回答一些简单的问题,[:(!][:(!][^][^]<br>真是可悲
 
首先、发问请用能概括问题的标题,否则高手是不屑理会的。<br>其次、谁也没有义务为你回答问题<br>再次、此问题只是一些最简单的低级错误,没有难度<br>第四、解决方法如下:<br>function RegisterClassEx:Boolean;<br>var<br>&nbsp; WindowClassEx:TWndClassEx;<br>&nbsp; Inst: Integer;<br>begin<br>&nbsp; Inst := hInstance;<br>&nbsp; //建议一开始给WindowClassEx赋初值(清零)<br>&nbsp; FillChar(WindowClassEx, SizeOf(TWndClassEx), 0);<br>&nbsp; with WindowClassEx do<br>&nbsp; begin<br>&nbsp; &nbsp; cbSize:=SizeOf(TWndClassEx);<br>&nbsp; &nbsp; Style:=CS_HREDRAW or CS_VREDRAW;<br>&nbsp; &nbsp; lpfnWndProc:=@DefWindowProc;<br>&nbsp; &nbsp; cbClsExtra:=0;<br>&nbsp; &nbsp; cbWndExtra:=0;<br>&nbsp; &nbsp; hInstance:=inst;//这里写hInstance := hInstance你想让Delphi怎么帮你处理??<br>&nbsp; &nbsp; hIcon:=LoadIcon(0,IDI_APPLICATION);<br>&nbsp; &nbsp; hCursor:=LoadCursor(0,IDC_WAIT);<br>&nbsp; &nbsp; hbrBackground:=COLOR_WINDOW;<br>&nbsp; &nbsp; lpszMenuName:=Nil;<br>&nbsp; &nbsp; lpszClassName:='TestClass';<br>&nbsp; &nbsp; hIconSm:=0;<br>&nbsp; end;<br>&nbsp; Result:=Windows.RegisterClassEx(WindowClassEx)&lt;&gt;0;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; if not RegisterClassEx then<br>&nbsp; &nbsp; RaiseLastOSError;<br><br>&nbsp; hWindow:=CreateWindowEx(WS_EX_CLIENTEDGE or WS_EX_CONTEXTHELP,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'TestClass',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'APIWindow',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WS_OVERLAPPEDWINDOW and not WS_MAXIMIZEBOX and not WS_MINIMIZEBOX,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hInstance,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nil);<br>&nbsp; if hWindow&lt;&gt;0 then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowWindow(hWindow,SW_SHOWNORMAL);<br>&nbsp; &nbsp; UpdateWindow(hWindow);<br>&nbsp; end<br>&nbsp; else<br>&nbsp; &nbsp; RaiseLastOSError;<br>end;<br>第五、出现警告的原因是CreateWindowEx里那几个参数是有符号32位整数,而<br>&nbsp; &nbsp; &nbsp; CW_USEDEFAULT是DWORD,即无符号32位整数!
 
多谢高手了!
 
后退
顶部