Home > Archive > Visual Basic > May 2004 > Keyboard events for DataReport
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Keyboard events for DataReport
|
|
| Mansoor Azam 2004-05-22, 2:30 am |
| I'm using VB 6.0. My clients wants the datareport window to be closed by
pressing 'ESC' but the datareport doesnt have any keyboard event handler. Is
there any simple solution to this. Also my app displays a textfile in
notepad and he wants the same for notepad (close on pressing 'ESC' ).
Any help appreciated
thx
| |
| Rick Rothstein 2004-05-22, 3:30 am |
| > I'm using VB 6.0. My clients wants the datareport window to be closed
by
> pressing 'ESC' but the datareport doesnt have any keyboard event
handler. Is
> there any simple solution to this. Also my app displays a textfile in
> notepad and he wants the same for notepad (close on pressing 'ESC' ).
>
> Any help appreciated
Are you up for a kludge? Add a CommandButton to the form containing the
DataReport, set its Cancel property to True, add whatever code you want
to execute when ESC is pressed to its Click event, place it so that it
is wholly surrounded by some control (I'm guessing the DataReport;
simply size the CommandButton so it is guaranteed to be smaller than the
control) and then place it behind that control by clicking on
Format/Order/SendToBack from VB's menubar (you don't want to see it
while your program runs). When you run the project, pressing ESC will
execute the CommandButton's Click event.
Rick - MVP
| |
| Mansoor Azam 2004-05-22, 5:30 am |
|
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:OtHYYY8PEHA.2520@TK2MSFTNGP11.phx.gbl...
> by
> handler. Is
>
> Are you up for a kludge? Add a CommandButton to the form containing the
> DataReport,
Thanks but I'm a bit by what you mean "form containing the
DataReport".
I cant add a command button to the datareport because the general toolbox is
not available for the datareport and datereport tool box doesnt have a
command button. Do you want me to drop the datareport on a form first? How
do you do that? I just call the show method of the DataReport from one of my
Public Subs in the main module
Public Sub PrintBill( showPreview as Boolean )
.......
.......
If showPreview = True Then
DataReport1.Show vbModal 'show the datareport
Else
DataReport1.PrintReport False 'don't show, just print
End If
.........
.........
.........
End Sub
thx again.
> set its Cancel property to True, add whatever code you want
> to execute when ESC is pressed to its Click event, place it so that it
> is wholly surrounded by some control (I'm guessing the DataReport;
> simply size the CommandButton so it is guaranteed to be smaller than the
> control) and then place it behind that control by clicking on
> Format/Order/SendToBack from VB's menubar (you don't want to see it
> while your program runs). When you run the project, pressing ESC will
> execute the CommandButton's Click event.
>
> Rick - MVP
>
| |
| Rick Rothstein 2004-05-22, 5:30 am |
| > > > I'm using VB 6.0. My clients wants the datareport window to be
closed
in[color=darkred]
'ESC' ).[color=darkred]
the[color=darkred]
>
> Thanks but I'm a bit by what you mean "form containing the
> DataReport".
> I cant add a command button to the datareport because the general
toolbox is
> not available for the datareport and datereport tool box doesnt have a
> command button. Do you want me to drop the datareport on a form first?
How
> do you do that? I just call the show method of the DataReport from one
of my
> Public Subs in the main module
I'm sorry... I am not a database programmer so I have never used the
DataReport. I took a guess that it expressed itself as a control and
could be situated on a form. I guess from your response, that was a bad
guess. If there is not an active form available and if the DataReport
cannot act as a container, then I'm out of my depth regarding your
question. Hopefully, someone will come along whose area of expertise
involves database programming that can help you. I do note, however,
that it is Saturday, so you might have to wait till Monday (and possibly
repost then too).
Rick - MVP
| |
|
|
"Mansoor Azam" <mansoorb@shoa.net> wrote in message
news:2h8gtkFa763hU1@uni-berlin.de...
>
> "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
> news:OtHYYY8PEHA.2520@TK2MSFTNGP11.phx.gbl...
>
> Thanks but I'm a bit by what you mean "form containing the
> DataReport".
> I cant add a command button to the datareport because the general toolbox
is
> not available for the datareport and datereport tool box doesnt have a
> command button. Do you want me to drop the datareport on a form first? How
> do you do that? I just call the show method of the DataReport from one of
my
> Public Subs in the main module
I think you may be able to add/or amend the reports system menu to use the
ESC as hot key or alternatively you can register your own in the report.
'Private Const MOD_ALT = &H1
'Private Const MOD_CONTROL = &H2
'Private Const MOD_SHIFT = &H4
Private Const PM_REMOVE = &H1
Private Const WM_HOTKEY = &H312
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type Msg
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long,
ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long,
ByVal id As Long) As Long
Private Declare Function P Message Lib "user32" Alias "P MessageA"
(lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal
wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private bCancel As Boolean
Private Sub ProcessMessages()
Dim Message As Msg
'loop until bCancel is set to True
Do While Not bCancel
'wait for a message
WaitMessage
'check if it's a HOTKEY-message
If P Message(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE)
Then
'close the report
Unload Me
End If
'let the operating system process other events
DoEvents
Loop
End Sub
Private Sub DataReport_Activate()
Dim ret As Long
bCancel = False
'register the Escape as hotkey
ret = RegisterHotKey(Me.hWnd, &HBFFF&, 0&, vbKeyEscape)
'process the Hotkey messages
ProcessMessages
End Sub
Private Sub DataReport_Terminate()
'Stop handling hotkey
bCancel = True
'unregister hotkey
Call UnregisterHotKey(Me.hWnd, &HBFFF&)
End Sub
| |
| Don Hanfland 2004-05-31, 1:30 pm |
| Hi Mansoor,
Now I'm not positive as to which API method is better then the other but I
prefer to use the SetWindowsHookEx instead, as this gives you the ability to
check for more keys, and is less coding.
Now of course this code comes from ALL API. I have shorten the code to only
encompase the need at hand here.
That being if the ESC key is pressed while the DataReport Viewer is showing.
I hook the function just before bringing up the Datareport.(eg;)
Private Sub Command1_Click()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
'set a keyboard hook
hHook = SetWindowsHookEx(2, AddressOf KeyboardProc, App.hInstance,
App.ThreadID)
If DataEnvironment1.rsCommand1.State = adStateOpen Then
DataEnvironment1.rsCommand1.Close
Set DataReport1.DataSource = Nothing
Set DataReport1.DataSource = DataEnvironment1
DataReport1.Show
End Sub
Now the above code more or less turns on the handling of keystrokes being
pressed and sends the keypress through a function that we can put code into
to do whatever we want based on the keypressed. (this is about the same as a
form's keypreview)
This code would go into a bas module(eg;)
Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA"
(ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal
dwThreadId As Long) As Long
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As
Long
Public hHook As Long
Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long,
ByVal lParam As Long) As Long
'if idHook is less than zero, no further processing is required
If idHook > -1 Then
If wParam = vbKeyEscape Then
Unload DataReport1
End If
End If
End Function
Now all that is left is unhooking the function, and this is done in the
Datareport's Terminate event.(eg;)
Private Sub DataReport_Terminate()
'remove the windows-hook
UnhookWindowsHookEx hHook
End Sub
Now you can do alot more with the KeyBoardProc function, you can add in the
GetKeyState, as in the original piece of this example code from ALLAPI. I
just shorten it to what was needed.
Hope this helps!
Don Hanfland [MVP VB]
"Geoff" <ney@notspam.org> wrote in message
news:c8nif0$ma0$1@newsg4.svr.pol.co.uk...
>
> "Mansoor Azam" <mansoorb@shoa.net> wrote in message
> news:2h8gtkFa763hU1@uni-berlin.de...
closed[color=darkred]
in[color=darkred]
'ESC' ).[color=darkred]
the[color=darkred]
toolbox[color=darkred]
> is
How[color=darkred]
of[color=darkred]
> my
>
> I think you may be able to add/or amend the reports system menu to use
the
> ESC as hot key or alternatively you can register your own in the report.
>
> 'Private Const MOD_ALT = &H1
> 'Private Const MOD_CONTROL = &H2
> 'Private Const MOD_SHIFT = &H4
> Private Const PM_REMOVE = &H1
> Private Const WM_HOTKEY = &H312
> Private Type POINTAPI
> x As Long
> y As Long
> End Type
> Private Type Msg
> hWnd As Long
> Message As Long
> wParam As Long
> lParam As Long
> time As Long
> pt As POINTAPI
> End Type
> Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long,
> ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
> Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As
Long,
> ByVal id As Long) As Long
> Private Declare Function P Message Lib "user32" Alias "P MessageA"
> (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal
> wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
> Private Declare Function WaitMessage Lib "user32" () As Long
> Private bCancel As Boolean
> Private Sub ProcessMessages()
> Dim Message As Msg
> 'loop until bCancel is set to True
> Do While Not bCancel
> 'wait for a message
> WaitMessage
> 'check if it's a HOTKEY-message
> If P Message(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE)
> Then
> 'close the report
> Unload Me
> End If
> 'let the operating system process other events
> DoEvents
> Loop
> End Sub
> Private Sub DataReport_Activate()
> Dim ret As Long
> bCancel = False
> 'register the Escape as hotkey
> ret = RegisterHotKey(Me.hWnd, &HBFFF&, 0&, vbKeyEscape)
> 'process the Hotkey messages
> ProcessMessages
> End Sub
> Private Sub DataReport_Terminate()
> 'Stop handling hotkey
> bCancel = True
> 'unregister hotkey
> Call UnregisterHotKey(Me.hWnd, &HBFFF&)
> End Sub
>
>
|
|
|
|
|