Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default API calls, an Event handler, custom menu bar and modal

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default API calls, an Event handler, custom menu bar and modal

There's a mouse wheel handler on my site he

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

If you improve on it, please let me know.

Robin Hammond
www.enhanceddatasystems.com

"DrivenByHim" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event handler in a cell Man Utd Excel Programming 3 June 15th 05 07:44 AM
Global event handler?? [email protected] Excel Programming 1 October 23rd 04 05:31 PM
where is the workbook_open event handler??? Steff_DK[_10_] Excel Programming 2 April 25th 04 02:43 PM
different IDispatch in event handler Dirk[_2_] Excel Programming 0 January 23rd 04 11:04 PM
Cell Event Handler David Excel Programming 3 January 19th 04 04:51 PM


All times are GMT +1. The time now is 03:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"