PC Review


Reply
Thread Tools Rate Thread

API calls, an Event handler, custom menu bar and modal

 
 
=?Utf-8?B?RHJpdmVuQnlIaW0=?=
Guest
Posts: n/a
 
      8th Feb 2006
In a perfect world, Excel VBA forms would include mouse scroll wheel
functionality. Unfortunately, Excel VBA does not process the WM_MOUSEWHEEL.
I had to write my own event handler using calls to user32.dll.

The problem is, I can't seem to combine "hooking" my event handler (by
making calls to SetWindowLong with the GWL_WNDPROC index) AND making calls to
customize the window (by making calls to SetWindowLong with the GWL_STYLE
index as well as some other basic calls to SetWindowPos).

On top of that, if the excel form is set to "modal" = false, my event
handler seems to be spammed with messages that it won't send off to it's
previous windows handler (Excel). Thus, I cannot keep the excel application
minimized and have my form appear as though it is a separate application.

The event handler is as follows in modified code: (Please assume that all
variables and constants are declared correctly, and that the code is working)

Private Function Fnc_EventHandler(ByVal Lwnd As Long, _
ByVal Lmsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

Dim MouseKeys As Long
Dim Rotation As Long

Select Case Lmsg

'Handle mouse wheel messages
Case WM_MOUSEWHEEL

MouseKeys = wParam And 65535
Rotation = wParam / 65536

'MouseWheel function
Call MouseWheelHandler(Rotation)

'Pass everything else back to excel for processing
Case Else

Fnc_EventHandler = CallWindowProc(g_LocalPrevWndProc, Lwnd,
Lmsg, wParam, lParam)

End Select

End Function

Here is my hook in modified code:

Public Sub Sub_Hook(ByRef FormMain As UserForm, _
ByRef c_Main_ParamRef As My_Main_Class)

Dim WindowStyle As Long

Set g_Form_Main = FormMain
Set c_Main_ParamRef = My_Main_Class

g_LocalHwnd = FindWindow("ThunderdFrame", g_Form_Main.Caption)

g_LocalPrevWndProc = SetWindowLong(g_LocalHwnd, GWL_WNDPROC, AddressOf
Fnc_EventHandler)

'More calls to user32.dll, only my event handler OR the following code
works, not both! The following code adds my form to the taskbar as well as
adds a minimmize button

g_ReturnResult = GetWindowLong(g_LocalHwnd, GWL_STYLE)

If (g_ReturnResult And &H20000) = 0 Then

Call SetWindowLong(g_LocalHwnd, GWL_STYLE, g_ReturnResult Or
WS_MINIMIZEBOX)

End If

WindowStyle = GetWindowLong(g_LocalHwnd, GWL_EXSTYLE)

WindowStyle = WindowStyle Or WS_EX_APPWINDOW

g_ReturnResult = SetWindowPos(g_LocalHwnd, HWND_TOP, _
0, 0, _
0, 0, _
SWP_NOMOVE Or SWP_NOSIZE Or
SWP_NOACTIVATE Or SWP_HIDEWINDOW)

g_ReturnResult = SetWindowLong(g_LocalHwnd, GWL_EXSTYLE, lint_WindowStyle)

g_ReturnResult = SetWindowPos(g_LocalHwnd, HWND_TOP, _
0, 0, _
0, 0, _
SWP_NOMOVE Or SWP_NOSIZE Or
SWP_NOACTIVATE Or SWP_SHOWWINDOW)

End Sub

 
Reply With Quote
 
 
 
 
Robin Hammond
Guest
Posts: n/a
 
      9th Feb 2006
There's a mouse wheel handler on my site here:

http://www.enhanceddatasystems.com/E...istScrolls.htm

If you improve on it, please let me know.

Robin Hammond
www.enhanceddatasystems.com

"DrivenByHim" <(E-Mail Removed)> wrote in message
news:53E0BD86-5389-42E6-8516-(E-Mail Removed)...
> In a perfect world, Excel VBA forms would include mouse scroll wheel
> functionality. Unfortunately, Excel VBA does not process the
> WM_MOUSEWHEEL.
> I had to write my own event handler using calls to user32.dll.
>
> The problem is, I can't seem to combine "hooking" my event handler (by
> making calls to SetWindowLong with the GWL_WNDPROC index) AND making calls
> to
> customize the window (by making calls to SetWindowLong with the GWL_STYLE
> index as well as some other basic calls to SetWindowPos).
>
> On top of that, if the excel form is set to "modal" = false, my event
> handler seems to be spammed with messages that it won't send off to it's
> previous windows handler (Excel). Thus, I cannot keep the excel
> application
> minimized and have my form appear as though it is a separate application.
>
> The event handler is as follows in modified code: (Please assume that all
> variables and constants are declared correctly, and that the code is
> working)
>
> Private Function Fnc_EventHandler(ByVal Lwnd As Long, _
> ByVal Lmsg As Long, _
> ByVal wParam As Long, _
> ByVal lParam As Long) As Long
>
> Dim MouseKeys As Long
> Dim Rotation As Long
>
> Select Case Lmsg
>
> 'Handle mouse wheel messages
> Case WM_MOUSEWHEEL
>
> MouseKeys = wParam And 65535
> Rotation = wParam / 65536
>
> 'MouseWheel function
> Call MouseWheelHandler(Rotation)
>
> 'Pass everything else back to excel for processing
> Case Else
>
> Fnc_EventHandler = CallWindowProc(g_LocalPrevWndProc, Lwnd,
> Lmsg, wParam, lParam)
>
> End Select
>
> End Function
>
> Here is my hook in modified code:
>
> Public Sub Sub_Hook(ByRef FormMain As UserForm, _
> ByRef c_Main_ParamRef As My_Main_Class)
>
> Dim WindowStyle As Long
>
> Set g_Form_Main = FormMain
> Set c_Main_ParamRef = My_Main_Class
>
> g_LocalHwnd = FindWindow("ThunderdFrame", g_Form_Main.Caption)
>
> g_LocalPrevWndProc = SetWindowLong(g_LocalHwnd, GWL_WNDPROC, AddressOf
> Fnc_EventHandler)
>
> 'More calls to user32.dll, only my event handler OR the following code
> works, not both! The following code adds my form to the taskbar as well
> as
> adds a minimmize button
>
> g_ReturnResult = GetWindowLong(g_LocalHwnd, GWL_STYLE)
>
> If (g_ReturnResult And &H20000) = 0 Then
>
> Call SetWindowLong(g_LocalHwnd, GWL_STYLE, g_ReturnResult Or
> WS_MINIMIZEBOX)
>
> End If
>
> WindowStyle = GetWindowLong(g_LocalHwnd, GWL_EXSTYLE)
>
> WindowStyle = WindowStyle Or WS_EX_APPWINDOW
>
> g_ReturnResult = SetWindowPos(g_LocalHwnd, HWND_TOP, _
> 0, 0, _
> 0, 0, _
> SWP_NOMOVE Or SWP_NOSIZE Or
> SWP_NOACTIVATE Or SWP_HIDEWINDOW)
>
> g_ReturnResult = SetWindowLong(g_LocalHwnd, GWL_EXSTYLE,
> lint_WindowStyle)
>
> g_ReturnResult = SetWindowPos(g_LocalHwnd, HWND_TOP, _
> 0, 0, _
> 0, 0, _
> SWP_NOMOVE Or SWP_NOSIZE Or
> SWP_NOACTIVATE Or SWP_SHOWWINDOW)
>
> End Sub
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event Generating Multiple Handler Calls Gary Brown Microsoft C# .NET 2 6th Oct 2006 05:30 AM
How to write the event handler for the custom control ( Menu Item) =?Utf-8?B?bG9zdHdpbmdz?= Microsoft Outlook VBA Programming 2 18th Nov 2005 11:24 PM
Help with custom event handler =?Utf-8?B?dnZlbms=?= Microsoft VB .NET 3 12th Oct 2005 07:47 PM
Custom Event Handler SDF Microsoft ASP .NET 1 5th Jan 2005 04:01 PM
custom event handler Philip Townsend Microsoft ASP .NET 1 16th Oct 2003 09:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:10 PM.