Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# RegisterClassEx/WNDCLASSEX problem

Posted on 2008-10-30
1
Medium Priority
?
1,263 Views
Last Modified: 2013-12-17
Hello all,

I am having trouble registering a new window class in C# using RegisterClassEx.  My application already heavily uses the WinAPI via pInvoke (i.e. DllImport statements) for other functions, and that part isn't the problem, I don't think (but am open to the possibility.)

Basically, when I call CreateWindowEx, it fails with error 1407, which basically says that my class name is undefined (which I agree with.)  I simply can't seem to figure out the WNDCLASSEX structure and how to use it in C#.  Could anyone please post and/or send me C# sample code that will successfully register a new window class (named, for example's sake "sample_window") that will allow a call to CreateWindowEx similar to the following to succeed??

            IntPtr myNewSampleWindowHWND = CreateWindowEx(WS_EX_TOPMOST, "sample_window", "", WS_VISIBLE, 0, 0, 500, 500, this.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

My goal is to create a blank (in the sense of WinAPI programming) topmost window that I can get a Graphics object from and draw a rectangle on.  Other than what I specifically draw, I would like the window to be completely "blank" (A.K.A  no menu or title bar, etc.)  I only want what I draw to be displayed.  Ultimately, the app should be able to destroy the window using something like:

DestroyWindow(myNewSampleWindowHWND)

Does that make sense?  I know how to do this in VC++, but am trying to stick to C# for code-management purposes.  I have tried and tried to no avail to get this to work in C#, and I could really use some help.

Thanks so much!!!
Kendell
(points awarded to all on-subject responders)
0
Comment
Question by:kwelch007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
kwelch007 earned 0 total points
ID: 22848068
It turns out that, for my purposes at least, I was able to create a topmost/"transparent" window using the VS2008 wizard.  I created a Form, set its FormBorderStyle to "none", set its TopMost property to "true", and set both its BackColor and TransparencyKey values to the same color.  It then became useable for my purposes.

It seems to me that nobody on the web has published any working code using API calls to RegisterClassEx and CreateWindowEx (including the WNDCLASSEX structure.)  I can still think of a lot of reasons that someone might need to use RegisterClassEx and CreateWindowEx directly from C#, and I hope this thread continues.

I would also note that the .NET "NativeWindow()" function might be useful, but I had trouble with the MSDN sample code conflicting with another class I was using, and came across my solution before pursuing the problem.

Thanks anyway!
Kendell
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question