Question : Start app minimized in vb.net (2005) Compact Framework

Hey All,

I've found a few examples for this, but I can't get any of them to work and/or I don't understand them. I have a small compact framework vb.net (2005) app that's running on a Windows CE 5.0 device. I want to start the application minimized, but of course that's not an option in the WindowState property of the form.

Can someone walk me through doing this?

Thanks,
Bret

Answer : Start app minimized in vb.net (2005) Compact Framework

Ok. The best I could come up with is to put the "Minimize" code on a timer (because just calling the code from Form_Load didn't seem to work). It's not ideal to your situation, but it does work. This was tested on my Win Mobile 6.0 pocket pc and one of the CE 5.0 emulators in VS.

I tried to give meaningful comments, but if you don't understand any part of it, please feel free to ask :)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
Imports System.Runtime.InteropServices

Public Class Form1
    ' Per documentation, Delegates in WinMobile must derive
    '  from EventHandler
    Private sw As New EventHandler(AddressOf DelegateFunction)

    ' Constant - Instructs ShowWindow() to minimize
    Private Const SW_MINIMIZED As Integer = 6

    ' Interop function call = Used to access the native
    '    function ShowWindow, which is used to minimize the form
     _
    Public Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Create a new thread so that Form_Load can return
        Dim minimizeThread As New System.Threading.Thread(AddressOf MinimizeFormAfterSleep)

        ' Execute the thread
        minimizeThread.Start()
    End Sub

    Private Sub MinimizeFormAfterSleep()
        ' Pseudo-timer
        System.Threading.Thread.Sleep(4000)  ' Change 4000 (4 seconds) to a time more fitting to your needs

        ' Call the delegate that runs the minimize code
        Me.Invoke(sw, Me, EventArgs.Empty)
    End Sub

    Private Sub DelegateFunction(ByVal sender As Object, ByVal e As EventArgs)
        ' Execute the minimize code
        ShowWindow(Me.Handle, SW_MINIMIZED)
    End Sub

End Class
Random Solutions  
 
programming4us programming4us