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
FOS-BretAsked:
Who is Participating?
 
käµfm³d 👽Commented:
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 :)
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
    <DllImport("coredll.dll")> _
    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

Open in new window

0
 
käµfm³d 👽Commented:
Have you tried Me.Hide() in the form load event?
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Hide()
End Sub

Open in new window

0
 
FOS-BretAuthor Commented:
I have tried that, but when I do that, I can't get the app to come back to the front (with ALT-TAB).

There's a minimize button and it works perfectly. I just want to do what it does, but programatically.

Thanks,
Bret
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
deepu chandranCommented:
hi,
Please fin the MSDN link already discussed,
http://social.msdn.microsoft.com/Forums/en-US/netfxcompact/thread/777da0d8-2930-46d1-b452-591b766b5d86

In that link there is an OpenNetCF solution can try out.

Regards

Deepu
0
 
FOS-BretAuthor Commented:
I'm sorry for the delay in responding. I was called away from work for several days. My laptop died while I was away, so I'm now waiting for a restore to get my code back. I should have it tomorrow or the next day and I'll try the suggestions out a that time.

Thanks,
Bret
0
 
käµfm³d 👽Commented:
No worries  :)
0
 
FOS-BretAuthor Commented:
This worked great and it was first. Thanks very much.
Bret
0
 
käµfm³d 👽Commented:
NP. Glad to help :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.