.NET Rebar Control Error
-
I have created my own Rebar Control and I am having issues on Windows 2000 machines. When creating the handle it throws an Win32Exception with the error "Invalid window class name". It works fine on Windows XP machines. The following is my CreateHandle method and CreateParams property. Any ideas? protected override void CreateHandle() { if (!RecreatingHandle) { // Initialize Cool Bar Common Control INITCOMMONCONTROLSEX initCommonControls = new INITCOMMONCONTROLSEX(); // I set Size field in constructor initCommonControls.Flags = InitCommonClasses.COOL_CLASSES | InitCommonClasses.BAR_CLASSES; SafeInterop.InitCommonControlsEx(initCommonControls); } base.CreateHandle(); // <-- Exception thrown here } protected override CreateParams CreateParams { [SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.UnmanagedCode)] get { CreateParams createParams = base.CreateParams; createParams.ClassName = Interop.REBARCLASSNAME; createParams.Style |= (int)(CommonControlStyles.NORESIZE | CommonControlStyles.NODIVIDER | CommonControlStyles.NOPARENTALIGN); if (_Borders) { createParams.Style |= (int)RebarStyles.BANDBORDERS; createParams.Style |= (int)(RebarStyles.VARHEIGHT | RebarStyles.AUTOSIZE); return createParams; } } }
-
I have created my own Rebar Control and I am having issues on Windows 2000 machines. When creating the handle it throws an Win32Exception with the error "Invalid window class name". It works fine on Windows XP machines. The following is my CreateHandle method and CreateParams property. Any ideas? protected override void CreateHandle() { if (!RecreatingHandle) { // Initialize Cool Bar Common Control INITCOMMONCONTROLSEX initCommonControls = new INITCOMMONCONTROLSEX(); // I set Size field in constructor initCommonControls.Flags = InitCommonClasses.COOL_CLASSES | InitCommonClasses.BAR_CLASSES; SafeInterop.InitCommonControlsEx(initCommonControls); } base.CreateHandle(); // <-- Exception thrown here } protected override CreateParams CreateParams { [SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.UnmanagedCode)] get { CreateParams createParams = base.CreateParams; createParams.ClassName = Interop.REBARCLASSNAME; createParams.Style |= (int)(CommonControlStyles.NORESIZE | CommonControlStyles.NODIVIDER | CommonControlStyles.NOPARENTALIGN); if (_Borders) { createParams.Style |= (int)RebarStyles.BANDBORDERS; createParams.Style |= (int)(RebarStyles.VARHEIGHT | RebarStyles.AUTOSIZE); return createParams; } } }
You must make sure that your window class is registered using
RegisterClass(Ex)
API.InitCommonControls
does this for classes defined in the common controls library, but any custom classes must be registered by you.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
You must make sure that your window class is registered using
RegisterClass(Ex)
API.InitCommonControls
does this for classes defined in the common controls library, but any custom classes must be registered by you.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
I found out what is was. The INITCOMMONCONTROLSEX structure had the size and flags fields the wrong way, so the call to InitCommonControlsEx was failing. It's just weird that it worked fine Windows XP, sometimes is really bad for developing on, because it hides errors.