2012-11-19 55 views
0

我得到Win32Exception - 生成代码中的“类已经存在”。相同的代码在我的演示项目中没有问题。什么可能是一个问题?Win32Exception - 类已经存在

Private Class MyClientWindow 
    Inherits NativeWindow 

    Public Sub New(ByVal parent As Form) 

     Dim cp As CreateParams = New CreateParams() 

     ' Fill in the CreateParams details. 
     cp.Caption = "Parent Static Window" 
     cp.ClassName = "Static" 

     ' Set the position on the form 
     cp.X = 0 
     cp.Y = 0 
     cp.Height = 0 
     cp.Width = 0 

     ' Specify the form as the parent. 
     cp.Parent = parent.Handle 

     ' Create as a child of the specified parent 
     cp.Style = WS_CHILD Or WS_VISIBLE 

     ' Create the actual window 
     Me.CreateHandle(cp) 
    End Sub 

End Class 

System.ComponentModel.Win32Exception was unhandled by user code. 
ErrorCode=-2147467259,  
Message=Class already exists, 
NativeErrorCode=1410, 
StackTrace: 
at System.Windows.Forms.NativeWindow.WindowClass.RegisterClass() 
at System.Windows.Forms.NativeWindow.WindowClass.Create(String className, Int32 classStyle) 
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp) 
+1

如果你改变了类名,会发生什么? – jdigital

+0

是的,大写classname使它工作 – walter

回答

0

从“静态”更改类名称为“静态”的接缝工作。我发现在该讲话中CreateParams.ClassName Property

从标准Button控件派生,这className属性设置为 的“按钮”