|
-
Jul 20th, 2007, 12:22 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Create a formless app?
I want to create an application that has/needs no form or controls. When launched, it would show an icon in the tray area & run some code at certain intervals using a timer control. Can someone explain how to make an app with no form, as I have never done that before. I can handle the timer & notify icon part, I just need help with the form (or lack of). Thanks...
-
Jul 20th, 2007, 12:34 PM
#2
Re: Create a formless app?
Just have your startup object as a Module with Sub Main.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 20th, 2007, 12:36 PM
#3
Re: Create a formless app?
Here is a little example of RobDogg's solution to get you started.
http://www.codeproject.com/useritems/NotifyChecker.asp
Good luck.
-
Jul 20th, 2007, 12:37 PM
#4
Re: Create a formless app?
It is pretty easy, you just have to account for some things that generally are taken for granted because the windows form does it for you.
You need to manually create everything, manually hook up event handlers, and manually dispose of the objects when the app closes. The trick is to also call Application.Run() to create a message loop. Otherwise the exe would run and close right away.
Here are the steps:
1) Create a new Windows Forms application, and delete the default Form1 that is added by Visual Studio
2) Add a module to the project
3) Paste code from below into module
4) Go into project properties and uncheck "Enable Appliction Framework" and change "Startup Object" to "Sub Main"
5) Add an icon to the resources section of your project properties (the one I used in my example code was called inet.ico, just change the code to match your icon name
Code:
Module Module1
Private MyNotifyIcon As NotifyIcon 'ICON IN SYSTEM TRAY COMPONENT
Private MyContextMenu As ContextMenu 'CONTEXT MENU WHEN ITEM IS CLICKED ON
Private MyTimer As Timer
Public Sub Main()
'CREATE INSTANCES OF OBJECTS WE NEED
MyNotifyIcon = New NotifyIcon
MyContextMenu = New ContextMenu
MyTimer = New Timer
MyNotifyIcon.Icon = My.Resources.inet 'SET AN ICON (ICON IS A RESOURCE IN THE PROJECT)
MyNotifyIcon.Visible = True 'SET VISIBLE
'ADD CAPTIONS AND EVENT HANDLERS FOR ITEMS IN CONTEXT MENU
MyContextMenu.MenuItems.Add("Show Messagebox", AddressOf ShowMessagebox)
MyContextMenu.MenuItems.Add("Exit", AddressOf ExitApplication)
MyNotifyIcon.ContextMenu = MyContextMenu 'ASSIGN CONTEXT MENU TO ICON
'SETUP TIMER
MyTimer = New Timer
MyTimer.Interval = 10000 '10 seconds
MyTimer.Start()
AddHandler MyTimer.Tick, AddressOf Timer_Tick
'CREATE A MESSAGE LOOP WITH NO FORM, OTHERWISE THE APPLICATION WOULD EXIT RIGHT AWAY
Application.Run()
End Sub
'DELEGATE SUB TO EXIT APPLICATION
Private Sub ExitApplication(ByVal sender As Object, ByVal e As EventArgs)
'CLEAN UP YOUR OBJECTS
MyTimer.Stop()
MyTimer.Dispose()
MyContextMenu.Dispose()
MyNotifyIcon.Dispose()
'EXIT APPLICATION LOOP
Application.Exit()
End Sub
'DELEGATE SUB TO SHOW MESSAGEBOX
Private Sub ShowMessagebox(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show("Hello World")
End Sub
'DELEGATE TO HANDLE TIMER TICKING
Private Sub Timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
MyTimer.Stop()
MessageBox.Show("Timer Ticked")
MyTimer.Start()
End Sub
End Module
-
Jul 20th, 2007, 02:37 PM
#5
Re: Create a formless app?
Unless you really need to have the tray icon or need to interact with the current user in other ways, you might want to consider writing this app as a Windows Service. This would insure that it would always be running as long as the computer was turned on. As a regular app, you would have to depend on someone being logged in for your app to run.
-
Jul 20th, 2007, 03:06 PM
#6
Thread Starter
Frenzied Member
Re: Create a formless app?
Thanks guys. I will try your suggestions...
-
Jul 23rd, 2007, 10:01 AM
#7
Thread Starter
Frenzied Member
Re: Create a formless app?
I have ran across another method to make a formless app. It involves setting the WindowState property to Minimized & the ShowInTaskbar property to False. So, essentially, there is a form, but it is never shown. Is this an acceptable way to go "formless", or are the methods mentioned above the better way to do it?
-
Jul 23rd, 2007, 10:03 AM
#8
Re: Create a formless app?
you are making unused and unneeded resources by doing it that way.
It will work, and it could make your life a bit easier because you can use the form to add components like timers and use the GUI of Visual Studio to setup properties and such, but I still would recommend the method I posted above, as it only creates resources for exactly what you need.
-
Jul 23rd, 2007, 01:55 PM
#9
Re: Create a formless app?
You can still use timers and stuff without forms.
-
Jul 23rd, 2007, 03:00 PM
#10
Thread Starter
Frenzied Member
Re: Create a formless app?
kleinma ... is there an event to capture when I click on a NotifyIcon BalloonTip? Thanks...
-
Jul 23rd, 2007, 03:05 PM
#11
Re: Create a formless app?
-
Jul 23rd, 2007, 03:49 PM
#12
Re: Create a formless app?
 Originally Posted by nbrege
kleinma ... is there an event to capture when I click on a NotifyIcon BalloonTip? Thanks...
yes you just need to hook it up to a subroutine manually. If you look at my sample code above, I do that very thing with the timer and its tick event.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|