?
Solved

Windows wont Shutdown when running my App

Posted on 2004-08-11
3
Medium Priority
?
305 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
[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
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 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