Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,086 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,550 people online right now. Registration is fast and FREE... Join Now!




need help with running application wile invisible

3 Pages V  1 2 3 >  
Reply to this topicStart new topic

need help with running application wile invisible

narmer93
24 Aug, 2008 - 01:34 PM
Post #1

D.I.C Head
**

Joined: 13 Mar, 2008
Posts: 239



Thanked: 1 times
My Contributions
i need help with this
this code halfly works
vb
Public Class Form1

Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.S Then
Me.Visible = True'this part doesn't work'
ElseIf e.KeyCode = Keys.H Then
Me.Visible = False'this part works'
End If
End Sub
End Class

how can i press a key and make the form visible or other thing if the form is not in the focus mode?
the above code works only if the form is in focus mode
how can i make it work if it is not in the focus mode or running in the form of a tray icon?
i can it be something like the task manager ,i press ctrl +alt+del and it opens,
how can i make something like that if it is running in the form of a tray icon can be visible by clicking on it or by pressing a combination of buttons?

and this code also desn't work
vb
Public Class Form1

Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.S And e.KeyCode = Keys.D Then
Me.Hide()
End If
End Sub
End Class

it works if it was only one key pressed but more than one ley nothing happens
any explanations or ideas or beter ways?

This post has been edited by narmer93: 24 Aug, 2008 - 01:45 PM
User is offlineProfile CardPM
+Quote Post

gbertoli3
RE: Need Help With Running Application Wile Invisible
24 Aug, 2008 - 03:31 PM
Post #2

DIC at Heart + Code
Group Icon

Joined: 23 Jun, 2008
Posts: 1,046



Thanked: 17 times
Dream Kudos: 950
My Contributions
Your trying to show the form when it is no longer accepting data.
Let me explain.

If a form is hidden, it can't run the code you are trying to tell it to do. Thus making it unreachable code.
User is online!Profile CardPM
+Quote Post

narmer93
RE: Need Help With Running Application Wile Invisible
24 Aug, 2008 - 03:43 PM
Post #3

D.I.C Head
**

Joined: 13 Mar, 2008
Posts: 239



Thanked: 1 times
My Contributions
if the application can't be run if it is not in focus mode ,so how does the task manager work,or
i have a prog called tuneup utilites ,there is a memory optimizer in it ,when i press ctrl+alt+o,it runs the optimizer in the tray icon
how can i make something like that then?


and why doesn't multiple buttons work? as in the second code?

if the application can't be run if it is not in focus mode ,so how does the task manager work,or
i have a prog called tuneup utilites ,there is a memory optimizer in it ,when i press ctrl+alt+o,it runs the optimizer in the tray icon
how can i make something like that then?


and why doesn't multiple buttons work? as in the second code?
User is offlineProfile CardPM
+Quote Post

Damage
RE: Need Help With Running Application Wile Invisible
24 Aug, 2008 - 09:34 PM
Post #4

D.I.C Addict
Group Icon

Joined: 5 Jun, 2008
Posts: 738



Thanked: 7 times
Dream Kudos: 75
My Contributions
As far as i know the KeyDown event will only give you information regarding the last key that was pressed


I found this somewhere
QUOTE

The trouble that I can see with this is it seems that the KeyDown event is fired individually for each key; you'll either have to do use booleans as you indicated or the GetAsyncKeyState windows API function
CODE

Public Class Form1

    Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal keyCode As Integer) As Short

    Private _txtBox As TextBox

    Public Sub New()


        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        UnimportantLayout()

    End Sub

    Private Sub TextOnKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
        _txtBox.AppendText(GetKeyString())
    End Sub

    Private Function GetKeyString() As String
        Dim sb As New System.Text.StringBuilder()
        Dim keys(4) As Short

        keys(0) = GetAsyncKeyState(VKey.A)
        keys(1) = GetAsyncKeyState(VKey.B)
        keys(2) = GetAsyncKeyState(VKey.C)
        keys(3) = GetAsyncKeyState(VKey.D)

        If (WasKeyPressed(keys(0))) Then
            sb.Append("A, ")
        End If

        If (WasKeyPressed(keys(1))) Then
            sb.Append("B, ")
        End If

        If (WasKeyPressed(keys(2))) Then
            sb.Append("C, ")
        End If

        If (WasKeyPressed(keys(3))) Then
            sb.Append("D, ")
        End If

        If (sb.Length > 0) Then
            sb.Remove(sb.Length - 2, 2)
        End If

        sb.AppendLine()

        Return sb.ToString()
    End Function

    Private Function WasKeyPressed(ByVal state As Short) As Boolean
        ' For some goofy reason, the compiler thinks that "&H8000" is not
        ' representable in Short, so I had to use an integer.
        Dim highBit As Integer = &H8000

        Return ((state And highBit) = highBit)
    End Function

    Private Enum VKey
        ' Find more key codes at
        ' http://msdn2.microsoft.com/en-us/library/ms645540.aspx
        A = &H41
        B = &H42
        C = &H43
        D = &H44
        E = &H45
    End Enum

    Private Sub UnimportantLayout()
        _txtBox = New TextBox()
        _txtBox.Multiline = True
        _txtBox.Margin = New Padding(10)
        _txtBox.Dock = DockStyle.Fill
        _txtBox.ReadOnly = True
        AddHandler _txtBox.KeyDown, AddressOf TextOnKeyDown
        Me.Controls.Add(_txtBox)
    End Sub

End Class

What I found with this program is that what keys can be detected (at least on my keyboard) is reliant upon the key's location. I could make no combination of C and D work, but A B C, and A B D were OK. You'll have to fill in the codes for more keys to see how it works out, but this would probably be easier than managing several globabl booleans.



This post has been edited by Damage: 24 Aug, 2008 - 09:50 PM
User is offlineProfile CardPM
+Quote Post

Damage
RE: Need Help With Running Application Wile Invisible
24 Aug, 2008 - 10:06 PM
Post #5

D.I.C Addict
Group Icon

Joined: 5 Jun, 2008
Posts: 738



Thanked: 7 times
Dream Kudos: 75
My Contributions
QUOTE

try something like this:

If (((e.Alt And (e.Shift Or e.Control)) And e.KeyCode = Keys.D) Then
' do something
End If

Or

If ((e.Alt And e.Shift) And e.KeyCode = Keys.D) OrElse _
((e.Alt And e.Control) And e.KeyCode = Keys.D) Then
' do something
End If

User is offlineProfile CardPM
+Quote Post

narmer93
RE: Need Help With Running Application Wile Invisible
25 Aug, 2008 - 03:42 AM
Post #6

D.I.C Head
**

Joined: 13 Mar, 2008
Posts: 239



Thanked: 1 times
My Contributions
ok well any of them work if the form is minimized or not in focus mode?
User is offlineProfile CardPM
+Quote Post

gbertoli3
RE: Need Help With Running Application Wile Invisible
25 Aug, 2008 - 06:55 AM
Post #7

DIC at Heart + Code
Group Icon

Joined: 23 Jun, 2008
Posts: 1,046



Thanked: 17 times
Dream Kudos: 950
My Contributions
Try this
gbertoli3's Code

//TODO CODE HIDE
Me.Hide()

//TODO CODE SHOW
Me.Show()


Hope this helps

This post has been edited by gbertoli3: 25 Aug, 2008 - 06:55 AM
User is online!Profile CardPM
+Quote Post

WayneSpangler
RE: Need Help With Running Application Wile Invisible
25 Aug, 2008 - 08:23 AM
Post #8

D.I.C Head
**

Joined: 22 Mar, 2008
Posts: 102



Thanked: 8 times
My Contributions
What you need is a hot key. Here is the code I use. If you have any questions just ask.
CODE
    ' Windows API declarations
    Private Const WM_HOTKEY As Integer = &H312
    Public Const MOD_ALT As Integer = &H1       ' alt key down
    Public Const MOD_CONTROL As Integer = &H2   ' alt control down
    Public Const MOD_SHIFT As Integer = &H4     ' alt shift down

    Public Declare Auto Function RegisterHotKey Lib "user32" (ByVal hWnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Boolean

    Public Declare Auto Function UnregisterHotKey Lib "user32" (ByVal hWnd As IntPtr, ByVal id As Integer) As Boolean

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' you can combine alt, control and/or shift
        ' where I have 1 you can use any number but for each hotkey it must be unique so you can't have another 1
        ' You can register more than one hot key
        'RegisterHotKey(Me.Handle, 1, MOD_ALT Or MOD_CONTROL, Keys.Up)
        RegisterHotKey(Me.Handle, 1, MOD_ALT, Keys.M)
        RegisterHotKey(Me.Handle, 2, MOD_ALT Or MOD_CONTROL, Keys.Down)
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        UnregisterHotKey(Me.Handle, 1)
    End Sub

    Protected Overrides Sub WndProc(ByRef message As System.Windows.Forms.Message)
        If (message.Msg = WM_HOTKEY) Then
            Dim hotKeyId As Integer = message.WParam.ToInt32()

            If hotKeyId = 1 Then
                If Me.WindowState = FormWindowState.Minimized Then Me.WindowState = FormWindowState.Normal
            End If
            If hotKeyId = 2 Then
                If Me.WindowState <> FormWindowState.Minimized Then Me.WindowState = FormWindowState.Minimized
            End If
        End If
        MyBase.WndProc(message) '<<<<<< ALLWAYS ADD THIS = COMPUTER CRASH
    End Sub

User is offlineProfile CardPM
+Quote Post

narmer93
RE: Need Help With Running Application Wile Invisible
25 Aug, 2008 - 01:55 PM
Post #9

D.I.C Head
**

Joined: 13 Mar, 2008
Posts: 239



Thanked: 1 times
My Contributions
is there a shorter way or easier code that can be used when the form is minimized or not in focus,and i press 2 or 3 keys and the form appears
is there one to make it easier than the one u wrote?
User is offlineProfile CardPM
+Quote Post

gbertoli3
RE: Need Help With Running Application Wile Invisible
25 Aug, 2008 - 03:56 PM
Post #10

DIC at Heart + Code
Group Icon

Joined: 23 Jun, 2008
Posts: 1,046



Thanked: 17 times
Dream Kudos: 950
My Contributions
QUOTE(narmer93 @ 25 Aug, 2008 - 02:55 PM) *

is there a shorter way or easier code that can be used when the form is minimized or not in focus,and i press 2 or 3 keys and the form appears
is there one to make it easier than the one u wrote?


Your never going to get anywhere in programming if you think that is too long. You should try making a program. There are lots of lines of code, but as programmers we enjoy writing it. But in this case you were just handed the code for free, and complain about it being too long. You should be more grateful and say thank you.
User is online!Profile CardPM
+Quote Post

narmer93
RE: Need Help With Running Application Wile Invisible
25 Aug, 2008 - 05:31 PM
Post #11

D.I.C Head
**

Joined: 13 Mar, 2008
Posts: 239



Thanked: 1 times
My Contributions
that is too long and i always say thanks when i get what i wanted and this code seems to be longer than to do this
vb.net uses simple codes
once i was trying to learn java and i was asking about how to make it play an mp3 file or an audio file and i got a long code while i can easily play .wav files in vb.net with a short line
and this is the only part in the code that i understad
vb

If hotKeyId = 1 Then
If Me.WindowState = FormWindowState.Minimized Then Me.WindowState = FormWindowState.Normal
End If
If hotKeyId = 2 Then
If Me.WindowState <> FormWindowState.Minimized Then Me.WindowState = FormWindowState.Minimized
End If
End If

all the rest of the code is not easy to understand,at least not for me
and currently i think i will learn C or C++ language and i am looking for the programming programme and i want a new version not a win95 version and before using it ,i have to be sure that it doesn't need anything like the .netframework or JRE and can work on normal windows
is there something like that?

oh sorry cuz i didn't say thanks in the previous posts:)
User is offlineProfile CardPM
+Quote Post

gbertoli3
RE: Need Help With Running Application Wile Invisible
25 Aug, 2008 - 05:37 PM
Post #12

DIC at Heart + Code
Group Icon

Joined: 23 Jun, 2008
Posts: 1,046



Thanked: 17 times
Dream Kudos: 950
My Contributions
What you say is either
I don't understand.
or
Could you explain in the code?
User is online!Profile CardPM
+Quote Post

3 Pages V  1 2 3 >
Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 08:08PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month