Results 1 to 12 of 12

Thread: Please help me quicly!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    92

    Unhappy Please help me quicly!

    Hi!

    i have one form and i want the form to minimize when it looses focus( Lost_focus event doesn't work)

    i need to disable the keyboard( mostly the print screen key keycode = 0 and keyascii = 0 don't work )

    PLEASE HELP ME OUT!!

    Thanks a lot once again!

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Q1 : Try using the GetForegroundWindow API in a Timer.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Matthew Gates
    Guest
    Try this:


    VB Code:
    1. 'Module Code:
    2.  
    3. Option Explicit
    4.  
    5. Private Declare Function SetWindowLong Lib "user32" _
    6. Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal ndx As _
    7. Long, ByVal newValue As Long) As Long
    8.  
    9. Private Declare Function CallWindowProc Lib "user32" _
    10. Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal _
    11. hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal _
    12. lParam As Long) As Long
    13.  
    14. Const GWL_WNDPROC = -4
    15. Const WM_KILLFOCUS = &H8
    16.  
    17. Dim saveHWnd As Long
    18. Dim oldProcAddr As Long
    19.  
    20. Sub StartSubclassing(ByVal hWnd As Long)
    21.     saveHWnd = hWnd
    22.     oldProcAddr = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WndProc)
    23. End Sub
    24.  
    25. Sub StopSubclassing()
    26.     SetWindowLong saveHWnd, GWL_WNDPROC, oldProcAddr
    27. End Sub
    28.  
    29. Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, _
    30.     ByVal wParam As Long, ByVal lParam As Long) As Long
    31.     WndProc = CallWindowProc(oldProcAddr, hWnd, uMsg, wParam, lParam)
    32.    
    33. Select Case uMsg
    34.     Case WM_KILLFOCUS
    35.             Form1.WindowState = 1 'Don't forget to change the form name to your form
    36.     End Select
    37. End Function
    38.  
    39.  
    40. 'Form Code:
    41.  
    42.  
    43. Private Sub Form_Load()
    44.     StartSubclassing Me.hWnd
    45. End Sub
    46.  
    47. Private Sub Form_Unload(Cancel As Integer)
    48.     StopSubclassing
    49. End Sub

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    92
    sorry thats chinese for me, ,that works for wich of the two questions?

  5. #5
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Q2 disabling print screen, try:

    VB Code:
    1. Private Declare Function GetAsyncKeyState _
    2. Lib "user32.dll" (ByVal vKey As Long) As Integer
    3.  
    4. Private Const VK_MENU = &H12 'either alt key
    5. Private Const VK_SNAPSHOT = &H2C 'print screen
    6.  
    7. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    8.     If GetAsyncKeyState(VK_MENU) Then
    9.         MsgBox "Alt key pressed"
    10.     ElseIf GetAsyncKeyState(VK_SNAPSHOT) Then
    11.         MsgBox "Print screen key pressed"
    12.         Clipboard.Clear
    13.     End If
    14. End Sub

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    92
    Thanks Mathew your code for minimizing forms works just GREAT!

    But Nucleo' s for disabling any keyboard doesn't sorry! I mean i don't want people to print screen but i think if we could find a way to disable keyboard everything could be solved, any ideas?????

  7. #7
    Matthew Gates
    Guest
    Originally posted by iScanning
    sorry thats chinese for me, ,that works for wich of the two questions?

    Sorry about that, the question I answered was for question 1. A bit better than using the GetForegroundWindow API function with a Timer, as crptcblade suggested.

  8. #8
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Yeah, i knew there was a cleaner way, but I don't speak Chinese either

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    92
    Hey Mathew, yeah it worked just fine, by the way do you have an API call or non Api for disabling the Keyboards?

    Thanks! Sorry for being so persistent!

  10. #10
    Matthew Gates
    Guest
    Two ways I know of...

    1 - Rundll32:


    Code:
    Shell "rundll32 keyboard,disable"

    2 - BlockInput API function (only problem with this is you disable both mouse and keyboard and you have to basically set a timer or something, or else you can't re-enable them, but in the code below, there is an example of setting a time to disable and re-enable them).


    VB Code:
    1. Private Declare Function BlockInput Lib "user32" _
    2. (ByVal fBlock As Long) As Long
    3.  
    4. Private Declare Sub Sleep Lib "kernel32" (ByVal _
    5. dwMilliseconds As Long)
    6.  
    7.  
    8. Private Sub Command1_Click()
    9.  
    10.     DoEvents
    11.     'block the mouse and keyboard input
    12.     BlockInput True
    13.     'wait 10 seconds before unblocking it
    14.     Sleep 10000
    15.     'unblock the mouse and keyboard input
    16.     BlockInput False
    17.  
    18. End Sub

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    92
    Mathew, just a word of appreciation, you really MASTER IT!

    Thanks a lot!

  12. #12
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Originally posted by iScanning

    But Nucleo' s for disabling any keyboard doesn't sorry! I mean i don't want people to print screen but i think if we could find a way to disable keyboard everything could be solved, any ideas?????
    I forgot to mention to turn the form's key preview property to true.

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