|
-
Jul 17th, 2001, 08:58 PM
#1
Thread Starter
Lively Member
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!
-
Jul 17th, 2001, 09:15 PM
#2
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
-
Jul 17th, 2001, 09:23 PM
#3
Try this:
VB Code:
'Module Code:
Option Explicit
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal ndx As _
Long, ByVal newValue As Long) As Long
Private Declare Function CallWindowProc Lib "user32" _
Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal _
hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal _
lParam As Long) As Long
Const GWL_WNDPROC = -4
Const WM_KILLFOCUS = &H8
Dim saveHWnd As Long
Dim oldProcAddr As Long
Sub StartSubclassing(ByVal hWnd As Long)
saveHWnd = hWnd
oldProcAddr = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WndProc)
End Sub
Sub StopSubclassing()
SetWindowLong saveHWnd, GWL_WNDPROC, oldProcAddr
End Sub
Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
WndProc = CallWindowProc(oldProcAddr, hWnd, uMsg, wParam, lParam)
Select Case uMsg
Case WM_KILLFOCUS
Form1.WindowState = 1 'Don't forget to change the form name to your form
End Select
End Function
'Form Code:
Private Sub Form_Load()
StartSubclassing Me.hWnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
StopSubclassing
End Sub
-
Jul 17th, 2001, 09:28 PM
#4
Thread Starter
Lively Member
sorry thats chinese for me, ,that works for wich of the two questions?
-
Jul 17th, 2001, 09:31 PM
#5
Registered User
Q2 disabling print screen, try:
VB Code:
Private Declare Function GetAsyncKeyState _
Lib "user32.dll" (ByVal vKey As Long) As Integer
Private Const VK_MENU = &H12 'either alt key
Private Const VK_SNAPSHOT = &H2C 'print screen
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If GetAsyncKeyState(VK_MENU) Then
MsgBox "Alt key pressed"
ElseIf GetAsyncKeyState(VK_SNAPSHOT) Then
MsgBox "Print screen key pressed"
Clipboard.Clear
End If
End Sub
-
Jul 17th, 2001, 09:53 PM
#6
Thread Starter
Lively Member
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?????
-
Jul 17th, 2001, 09:54 PM
#7
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.
-
Jul 17th, 2001, 09:59 PM
#8
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
-
Jul 17th, 2001, 10:06 PM
#9
Thread Starter
Lively Member
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!
-
Jul 17th, 2001, 10:14 PM
#10
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:
Private Declare Function BlockInput Lib "user32" _
(ByVal fBlock As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal _
dwMilliseconds As Long)
Private Sub Command1_Click()
DoEvents
'block the mouse and keyboard input
BlockInput True
'wait 10 seconds before unblocking it
Sleep 10000
'unblock the mouse and keyboard input
BlockInput False
End Sub
-
Jul 17th, 2001, 10:52 PM
#11
Thread Starter
Lively Member
Mathew, just a word of appreciation, you really MASTER IT!
Thanks a lot!
-
Jul 17th, 2001, 11:57 PM
#12
Registered User
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|