2012-11-19 88 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屬性設置爲 的「按鈕」