Solved

Disable Keyboard keys.

Posted on 2003-11-15
5
932 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

919 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

18 Experts available now in Live!

Get 1:1 Help Now