Results 1 to 2 of 2

Thread: showing a form

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    Launceston, Tasmania, Australia
    Posts
    44

    Post

    Hiyas all

    What I am looking for is sort of a code to make my form show again when the user presses certain key combination like

    ctrl+s or something or maybe have the form showing when the user moves the cursor to the top right hand corner of the screen?

    also this code is probably asked for alot but has anybody got a reliable code to put your program in the systray, I have been given codes in the past but either the pop up menu wouldn't work or it would screw up and make more than 1 icon half the time.

    thanx for ya time



    ------------------
    Mooose

  2. #2
    New Member
    Join Date
    Feb 2000
    Posts
    15

    Post

    Well... This is what I got... anyone else got any addins?

    'ALL OF THE HOTKEY INFORMATION WAS OBTAINED FROM THE VB-WORLD WEBSITE.

    'I have not been able to activate the form useing the keyboard.
    'Im sure it can be done using an api.

    'Create a menu called "mnuItem" with the caption "Menu Item"
    'In that menu create this sub menu: "mnuShow" with the caption of "Show Form"
    ' you may want to add a few other sub menus to make the entire menu easy to see.

    'FOR THE FOLLOWING CONTROLS JUST USE THE DEFAULT NAMES!!!!
    'Create two frames.
    'In one frame place four Option1 buttons (INDEXED 0 THRU 3!!!)
    'index 0 = Left
    'index 1 = Right
    'index 2 = Top
    'index 3 = Bottom

    'In the other place two Option2 buttons (INDEXED 0 THRU 1!!!)
    'index 0 = Show Form
    'index 1 = Show Menu

    'Add two Command buttons.
    'Command1 Caption = Form Hide
    'Command2 Caption = Menu Visibility

    'Lastly add a timer to the form


    'FORM CODE -------------------------------v
    Public CursorPos As Integer
    Public ShowMode As Integer

    Private Sub Command1_Click()
    Form1.Hide
    End Sub

    Private Sub Command2_Click()
    If mnuItem.Visible = True Then
    mnuItem.Visible = False
    Else
    mnuItem.Visible = True
    End If
    End Sub

    Private Sub Form_Load()
    CursorPos = 0 'Set Menu position to 0 (Left option)
    ShowMode = 0 'Set Form to popup when cursor is moved to side of screen (default)

    'Hotkey Code ------------------------------v
    Me.WindowState = vbMinimized
    'Let windows know what hotkey you want for
    'your app, setting of lParam has no effect
    erg& = SendMessage(Me.hwnd, WM_SETHOTKEY, _
    HK_ALTZ, 0)
    'Check if succesfull
    If erg& <> 1 Then
    MsgBox "You need another hotkey", vbOKOnly, _
    "Error"
    End If

    'Tell windows what it should do, when the hotkey
    'is pressed -> show the window!
    'The setting of wParam and lParam has no effect

    erg& = DefWindowProc(Me.hwnd, WM_SHOWWINDOW, 0, 0)
    'Hotkey Code------------------------------^

    End Sub

    Private Sub mnuShow_Click()
    Form1.Show
    End Sub

    Private Sub Option1_Click(Index As Integer)
    CursorPos = Index
    End Sub

    Private Sub Option2_Click(Index As Integer)
    ShowMode = Index
    End Sub

    'Set Timer1 interval to 1
    Private Sub Timer1_Timer()
    GetCursorPos mousePos 'Get Co-ordinets
    Select Case CursorPos
    Case Is = 0 'Left Side of screen
    If mousePos.x = 0 Then
    If ShowMode = 0 Then
    Form1.Show
    Else
    PopupMenu mnuItem, , 0 - Form1.Left - 100, Screen.Height
    End If
    End If
    Case Is = 1 'Right Side Of Screen
    If mousePos.x + 1 = (Screen.Width / Screen.TwipsPerPixelX) Then
    If ShowMode = 0 Then
    Form1.Show
    Else
    PopupMenu mnuItem, , Screen.Width, Screen.Height
    End If
    End If
    Case Is = 2 'Top of the Screen
    If mousePos.y = 0 Then
    If ShowMode = 0 Then
    Form1.Show
    Else
    PopupMenu mnuItem, , 0 - Form1.Left + (Screen.Width / 2), 0 - Form1.Top - 1000
    End If
    End If
    Case Is = 3 'Bottom of the screen
    If mousePos.y + 1 = (Screen.Height / Screen.TwipsPerPixelY) Then
    If ShowMode = 0 Then
    Form1.Show
    Else
    PopupMenu mnuItem, , 0 - Form1.Left + (Screen.Width / 2), Screen.Height
    End If
    End If
    End Select
    End Sub

    'Module Code ----------------------------v

    Public mousePos As POINTAPI 'Declare variable

    Public Type POINTAPI
    x As Long
    y As Long
    End Type
    Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long


    'Hotkey Code-------------------------------v

    Declare Function SendMessage Lib "user32" Alias _
    "SendMessageA" (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, _
    lParam As Long) As Long

    Declare Function DefWindowProc Lib "user32" _
    Alias "DefWindowProcA" (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, _
    ByVal lParam As Long) As Long

    Public Const WM_SETHOTKEY = &H32
    Public Const WM_SHOWWINDOW = &H18
    Public Const HK_SHIFTA = &H141 'Shift + A
    Public Const HK_SHIFTB = &H142 'Shift * B
    Public Const HK_CONTROLA = &H241 'Control + A
    Public Const HK_ALTZ = &H45A

    'The value of the key-combination has to
    'declared in lowbyte/highbyte-format

    'That means as a hex-number: the last two
    'characters specify the lowbyte (e.g.: 41 = a),
    'the first the highbyte (e.g.: 01 = 1 = Shift)
    'Hotkey Code------------------------------^
    'Module Code ----------------------------^


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width