Solved

Windows wont Shutdown when running my App

Posted on 2004-08-11
3
253 Views
Last Modified: 2010-04-23
I have a slight problem - Windows wont shut down when its running my app.  The code which affects it is below, the only problem is the same line of code is what stops my app closing when the [X] is clicked, so i can place it in the systemtray.  Any info as to why this happens, or a workaround would be really helpful.

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    e.Cancel = True    '<---- Culprit (Wont Allow Windows to Shutdown)  
    HideToSysTray()
End Sub

As an afterthought could probably set e.Cancel = False, if it's possible to detect when windows wants to shutdown.

Jaz
0
Comment
Question by:jazduck
3 Comments
 
LVL 3

Author Comment

by:jazduck
ID: 11780406
Solved this one myself.  My afterthought was the way to go.

For any interested the code to detect a shutdown, and thus decide whether or not to close the app is as follows:

    Private Shared QueryShutdown As Integer = &H11
    Private Shared systemShutdown As Boolean = False

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = QueryShutdown Then
            systemShutdown = True
        End If
        MyBase.WndProc(m)
    End Sub

    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        If (systemShutdown) Then
            systemShutdown = False
            e.Cancel = False
        Else
            e.Cancel = True
            HideToSysTray()
        End If
    End Sub
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 11804841
User resolved; closed, 150 points refunded.

Netminder
Site Admin
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now