?
Solved

Disable Keyboard keys.

Posted on 2003-11-15
5
Medium Priority
?
939 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 101

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 200 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…
Suggested Courses

650 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