Solved

Disable Keyboard keys.

Posted on 2003-11-15
5
931 Views
Last Modified: 2010-05-01
hi Experts

Can someone please tell me how to disable keys on the keyboard this needs to disable the keys for the WebBroswer control. anyway I have make an eBook Compiler in Visual Basic and I am useing the WebBroswer to show the pages.

in my ebook compiler I have many options one of them is to disable the user from printing. but am haveing problums as the user can simply press the keys CTRL + P and this then brings up the print dialog box. is there anyway I can stop this from happing.

Thank you,
0
Comment
Question by:dreamvb
5 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 9753923
Have you tried trapping for it in the control's keypress event?

I am not sure whether a ctrl-p is trapped by Windows before it is passed to you.

mlmcc
0
 
LVL 4

Author Comment

by:dreamvb
ID: 9754289
It does not have any keypress events.
0
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9757171
you need to use a hook to make your app process all keyboard messages.  this is some code laying around EE here.

'IN A SUB!!!!!!!!!!!!!!!!!!
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
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
   
Private Const GWL_WNDPROC = -4
Private lpPrevWndProc As Long
Public gHW As Long
Public IsHooked As Boolean
   
Private Const WM_MOUSEFIRST = &H200
Private Const WM_MOUSELAST = &H209
Private Const WM_KEYFIRST = &H100
Private Const WM_KEYLAST = &H108
   
   
Public Sub Hook()
    If IsHooked Then
        MsgBox "Don't hook it twice without unhooking, or you will be unable to unhook it."
    Else
        lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, AddressOf WindowProc)
        IsHooked = True
    End If
End Sub
   
Public Sub Unhook()
    Dim temp As Long
    temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
    IsHooked = False
End Sub
   
Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Debug.Print "Message: "; hw, uMsg, wParam, lParam
   
    Select Case uMsg
        Case 258
            If wParam = 16 Then
                ' don't pass messages
                Exit Function
            Else
                WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
            End If
        Case Else
            WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
    End Select
End Function

'-----

That will make sure that ctrl + p doesnt get sent through the hooked object.
0
 
LVL 1

Accepted Solution

by:
RocketMan801 earned 50 total points
ID: 9760669
yeah a low level keyboard hook should be the solution, but may be u would find easier tu subclass the webBrowser control to intercept the print command
0
 
LVL 4

Author Comment

by:dreamvb
ID: 9769713
Hi Thanks this is just what I needed.

Thanks, Agian.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now