Board index » Visual Studio » Keyboard events for DataReport
|
PerryIsrael
|
|
PerryIsrael
|
Keyboard events for DataReport
Visual Studio260
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
Registered User |
Sat May 22 01:29:15 CDT 2004
Re:Keyboard events for DataReportQuoteI'm using VB 6.0. My clients wants the datareport window to be closed 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
Registered User |
Sat May 22 03:23:00 CDT 2004
Re:Keyboard events for DataReport"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net>wrote in message Quote>I'm using VB 6.0. My clients wants the datareport window to be closed 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. Quoteset its Cancel property to True, add whatever code you want - |
| Rick
Registered User |
Sat May 22 03:38:52 CDT 2004
Re:Keyboard events for DataReportQuote>>I'm using VB 6.0. My clients wants the datareport window to be 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 - |
| Geoff
Registered User |
Sat May 22 08:07:01 CDT 2004
Re:Keyboard events for DataReport"Mansoor Azam" <mansoorb@shoa.net>wrote in message Quote
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 PeekMessage Lib "user32" Alias "PeekMessageA" (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 PeekMessage(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
Registered User |
Mon May 31 11:52:09 CDT 2004
Re:Keyboard events for DataReport
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: www.allapi.net/">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 Quote
- |
