Solved

Disable Keyboard keys.

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

808 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