[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Invisible window

Posted on 2006-06-07
Medium Priority
Last Modified: 2011-09-20
How can I create window with valid handle without showing it?
My problem is that I have form with some object in it, which should be initialized with form handle. When form is just created, in constructor, handle is invalid. Handle is created only when form is shown first time. Form.CreateHandle Method shows the form, so I cannot use it.
Currently I make initialization when form is shown first time, and this is not nice. I need a way to create invisible form with valid window handle.

Environment: C# 2005, Windows Forms.
Question by:AlexFM
  • 3
  • 2

Assisted Solution

God_Ares earned 1000 total points
ID: 16851076
What kind of component?

Will the object accept a intptr.null (well you understand what I'm aiming at)...

On the other hand you have to ask yourself Why does it need a handle,..? Maybe it needs to read Windows Messages for some reason.. I'm sure it woudn't be there if it wasn't nessesary.

Creating a window on the fly is possible (consider making it a borderless window with size 1,1 and location 0,0). You can even do this with a new form..

But I think your current solutuin (creating it on form_load right?) is a good one, with the infromation you gave to us.



LVL 48

Author Comment

ID: 16851233
This is my own class written in C++, it requires window handle for initialization. And this is really necessary :)
My current solution is working, but I don't like it. For example, initialization can fail, and I hide this window immediately. In this case window is shown for a short time and disappears.
There should be way to do this. In Win32 programming this is very simple - just create window without WS_VISIBLE style.
LVL 96

Accepted Solution

Bob Learned earned 1000 total points
ID: 16851356

I override the CreateParams to set window styles for controls.  Here is an example for a form:

Creating Mirrored Windows Forms and Controls

protected override CreateParams CreateParams
        CreateParams CP = base.CreateParams;
        if (! base.DesignMode)
        return CP;

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 48

Author Comment

ID: 16851632
Sorry, TheLearnedOne, I don't see how this helps. Maybe you posted in wrong question by mistake?  :-)
LVL 96

Expert Comment

by:Bob Learned
ID: 16851739

You said, "just create window without WS_VISIBLE style."

And I showed a way of getting at the window parameters to remove the WS_VISIBLE style property.

LVL 48

Author Comment

ID: 16851867
OK, now I see, thank you.
I have a lot of other problems using .NET window handle in C++ code, because .NET can change window handle on the fly when window is hidden and shown again. I need to change algorithm completely, keep form reference and extract handle dynamically when necessary - a lot of changes, but at least I learned something.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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 summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month18 days, 15 hours left to enroll

834 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