Solved

Windows wont Shutdown when running my App

Posted on 2004-08-11
3
277 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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