Simple way to start a static Application

ImDaFrEaK

Well-known member
Joined
Jan 7, 2006
Messages
416
Location
California
Programming Experience
5-10
I am looking for a simple way to start a static application. Basically I don't want there to be any windows and I don't want it to be a windows service. In time I do want the application to open windows ect but not initionally. I have over come this in an awkward route and I imagine I will get the response why? I just want to learn how a Windows Form can run as an application and wait statically for Windows Messages that's all. Thanks :)
 
Your not going to be able to do this in VB.Net. As VB.Net needs a startup object, namely a form. This is possible however in C++. I'm guessing that you have over come this by hiding the main window?

VB.NET:
I just want to learn how a Windows Form can run as an application and wait statically for Windows Messages that's all.

Not sure what you mean by this as that is what a window will do. It will idle until a message is posted in it's message queue.
 
My apologies; I meant not to sound as if I was waiting for a Windows type Window message but a static program to wait for a message from Windows OS. Anyways, yes you are right. This is what a window does but it also does so much more than I need. Mostly, I don't need to see the window at all. I want it to run much like a service for individual users. For now I am content with just completely hiding the window with every property I can b/c what I want is working great.
There is and must be a way to do this with vb.net b/c the windows form does it. If the Form does it then I need to know how the form was written. It may require some API wrapping and message hooking but I know it's possible. Do I want to waste that much time figuring it out. Not at all. I'll use a nothing window, lol.
 
I'm still not sure exactly what you want but here is some info to consider that may help if you are going to try.


A 'sub main' in vb.net is nothing like an actual 'WinMain' for an app much of the complexity is hidden by the framework and vb.net. In an actual SubMain certain parameters will be passed to the procedure i.e hInstance, prevInstance and some others that relate to command line arguments. It is here that the application message loop is set up using

GetMessage()
TranslateMessage
DispatchMessage // It is here that the message is sent to the WindowProcedure ((WndProc) in VB.Net)) assigned to that window when the class was registered.

An application won't exit until GetMessage returns false. However because this is hidden by the simplicity of vb.net you cannot affect this sub routine. As far as i can see it just won't be possible to do this with VB.Net because you can't get down 'low enough' Without a window in VB.Net GetMessage will always return false unless you are creating a service.
 
If you turn off application framework in Application settings you can choose a different startup object, for example a Sub Main in a module. Look also into other Application class members, like the different Run method versions. I don't think you will get any windows messages without a window, though, but you can run a thread and monitor stuff and show a form when needed, much like a Console application.
 
I am looking for a simple way to start a static application. Basically I don't want there to be any windows and I don't want it to be a windows service. In time I do want the application to open windows ect but not initionally. I have over come this in an awkward route and I imagine I will get the response why? I just want to learn how a Windows Form can run as an application and wait statically for Windows Messages that's all. Thanks :)

VBN can still use a Sub Main() to start, so long as you disable the application framework (which does former vb6 things like Single Instance Application)

Go into project properties, to the page where you select which form is your startup object, and remove the tickbox from "Enable App Framework"

You can now choose a sub main for you app.

Note that to process windows messages without a window is a contradiction; a bit like asking how to drive to the shops if you dont own a car. Windows have windows message queues and thats how they process messages. No window. No messages.

You you will need at least one window, which can be opened offscreen or created with visible = false

VB.NET:
Form f = new Form()
f.Visible = false
Application.Run(f) 'starts message processing on f, ensurting you app wont quit until f is close()d

heres what my "sub main" looks like in C# (my normal dev env):
VB.NET:
    static void Main()
    {
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      Application.Run(new MainForm());
    }
  }
}

theres no reason you cant do this in vb BUT if "enable app FW" is ticked, you cannot choose a Sub Main() to be the startup thing of your app
 
Windows have windows message queues and thats how they process messages. No window. No messages

No, they dont. An application has a message queue. Windows process the messges they are sent from the applications message loop given the Window Procedure that is defined at the time the class is registered.

And whilst VB.Net App's can have a Sub Main it isn't 'real' entry point for that application. No application can start without being passed a Module handle by the OS.
 
Back
Top