Results 1 to 10 of 10

Thread: [RESOLVED] [2005] Addhandler of Current Window

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    108

    Resolved [RESOLVED] [2005] Addhandler of Current Window

    I want it so that whenever a button is pressed no matter what window its in...my program will know it.

    basically i want to add a handler of the currentwindow.keypress

  2. #2
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    354

    Re: [2005] Addhandler of Current Window

    Quote Originally Posted by Alphamonkey
    I want it so that whenever a button is pressed no matter what window its in...my program will know it.

    basically i want to add a handler of the currentwindow.keypress
    You'll have to use the Windows API for that.

    Here is a good working example in 2005. I got the example workig in the post with a little tweaking.

    http://forums.microsoft.com/msdn/sho...28399&siteid=1

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    108

    Re: [2005] Addhandler of Current Window

    I found this on the link you sent me, but i am still confused as now...how would i tell my program to, when the hotkey is pressed, do something.

    VB Code:
    1. Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
    2. Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer) As Integer
    3. Public Const WM_HOTKEY As Integer = &H312
    4.  
    5. Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    6.     If m.Msg = WM_HOTKEY Then
    7.         ' Pressed the hotkey!
    8.         Debug.WriteLine(m.Msg.ToString & ":" & m.WParam.ToString & ":" & m.LParam.ToString)
    9.     End If
    10.     MyBase.WndProc(m) '<-- Never Ever Forget This!
    11. End Sub
    12. Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    13.     Call UnregisterHotKey(Me.Handle, 9) '<-- Don't forget this
    14. End Sub
    15.  
    16. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    17.     Call RegisterHotKey(Me.Handle, 9, 0, 44) '<-- Play with these settings
    18. End Sub

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Addhandler of Current Window

    You already are:
    VB Code:
    1. Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    2.     If m.Msg = WM_HOTKEY Then
    3.         ' Pressed the hotkey! [COLOR=Red]<--- Woop, Woop[/COLOR]
    4.         Debug.WriteLine(m.Msg.ToString & ":" & m.WParam.ToString & ":" & m.LParam.ToString)
    5.     End If
    6.     MyBase.WndProc(m) '<-- Never Ever Forget This!
    7. End Sub
    If you want to do something other than write a line to the Debug listener then do so.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    354

    Re: [2005] Addhandler of Current Window

    woop woop... i have to remember that one.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    108

    Re: [2005] Addhandler of Current Window

    im still having a problem now.....

    the prtscr works, but only when the application is active.

    VB Code:
    1. Public Class Form1
    2.     Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
    3.     Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer) As Integer
    4.     Public Const WM_HOTKEY As Integer = &H312
    5.  
    6.     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    7.         If m.Msg = WM_HOTKEY Then
    8.             ' Pressed the hotkey!
    9.             PictureBox1.Image = Clipboard.GetImage()
    10.             Me.ShowInTaskbar = False
    11.             Me.WindowState = FormWindowState.Normal
    12.  
    13.         End If
    14.         MyBase.WndProc(m) '<-- Never Ever Forget This!
    15.     End Sub
    16.  
    17.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    18.  
    19.         Me.ShowInTaskbar = True
    20.         Me.WindowState = FormWindowState.Minimized
    21.         RegisterHotKey(Me.Handle, 9, 0, 44)
    22.  
    23.     End Sub
    24.  
    25.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    26.  
    27.         SaveFileDialog1.ShowDialog()
    28.         PictureBox1.Image.Save(SaveFileDialog1.FileName)
    29.     End Sub
    30.  
    31.  
    32.     Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    33.         Call UnregisterHotKey(Me.Handle, 9) '<-- Don't forget this
    34.     End Sub
    35.  
    36.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    37.         Call RegisterHotKey(Me.Handle, 9, 0, 44) '<-- Play with these settings
    38.     End Sub
    39. End Class

    i have it so it minimizes, you press a key (prntscreen) then it takes the screenshot (using windows) and pastes it in the picture box. it goes back to normal windowed mode when prnt screen is pressed, but it doesnt actually prnt screen. Windows only prntscreens when my app is active. If im not making myself clear tell me and i will clarify

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    108

    Re: [2005] Addhandler of Current Window

    also how would i have it so it knows that two hotkeys are pressed.....like alt-prntscreen

  8. #8
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    354

    Re: [RESOLVED] [2005] Addhandler of Current Window

    Code:
    Public Const MOD_ALT = &H1
    
    Call RegisterHotKey(Me.Handle, 14, MOD_ALT, 44)
    I look it up pretty quickly, but I think this is the correct combo. MOD_ALT is correct, 44 is the value in question.

    source:
    http://www.developerfusion.co.uk/show/271/

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    108

    Re: [RESOLVED] [2005] Addhandler of Current Window

    thanxks superbovine! but does anyone know a solution to my original problem?

  10. #10
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    354

    Re: [RESOLVED] [2005] Addhandler of Current Window

    this code should do that, it an API call so, it will global towards windows and it should over ride any key presses.

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