Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Subclassing in Excel ! ...So frustrating !

Nice hack NickHK,

I 've actually used this trick before and to get rid of the flickering I
just don't use the ScreenUpdating property anywhere in the code.

My real purpose for asking this question was to see some Subclassing code in
Excel which is not easy to find.

Thanks again.

Jaafar.



"NickHK" wrote:

Jafaar,
How about a hack with a non subclassing way ?

A transparent, borderless image box, which will fire the MouseMove event. You get quite a flicker (which you may be able to do something about), but if the test area is small compared to the area of
the worksheet, you may be OK.

Private Sub Image1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim MyRange As Object
Dim RetVal As Long

Image1.Visible = False

With Application
.ScreenUpdating = False
With .Windows(1)
RetVal = GetCursorPos(pa)

Set MyRange = .RangeFromPoint(pa.X, pa.Y)

MyRange.Value = "Done"
End With
.ScreenUpdating = True
End With

Image1.Visible = True

End Sub

NickHk


On Sun, 1 May 2005 13:11:08 -0700, "RAFAAJ2000" wrote:

Hi Bob,

Thanks for your quick reply.

Here is a simple example that is supposed to display a standard Msgbox
whenever the user hovers the mouse over cell A1.

The code seems correct to me but it just doesn't work. In fact it crashes
the whole application !

Code goes into a Standard module:


Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal
lpsz2 As String) As Long


Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

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

Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Type POINTAPI
x As Long
y As Long
End Type

Const GWL_WNDPROC As Long = (-4)
Const WM_MOUSEMOVE = &H200

Dim OldWindowProc As Long
Dim hwnd As Long
Dim lngCurPos As POINTAPI
Dim R As Range

Sub SubClass()

'Subclass The ONLY loaded workbook Window
hwnd = Application.hwnd
hwnd = FindWindowEx(hwnd, 0, "XLDESK", vbNullString)
hwnd = FindWindowEx(hwnd, 0, "EXCEL7", vbNullString)

OldWindowProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf NewWindowProc)

End Sub

Function NewWindowProc(ByVal hwnd As Long, ByVal Msg _
As Long, ByVal wParam As Long, ByVal lParam As Long) As _
Long

Set R = ActiveWindow.RangeFromPoint(lngCurPos.x, lngCurPos.y)

If Msg = WM_MOUSEMOVE And R.Address = Range("a1").Address Then
MsgBox "The Mouse is over cell 'A1'", vbInformation
End If
' Pass Intercepted Messages To The Original WinProc
NewWindowProc = CallWindowProc(OldWindowProc, hwnd, Msg, wParam,
lParam)
End Function


Sub UnSubclass()
'UnSubclass The WB window
SetWindowLong hwnd, GWL_WNDPROC, OldWindowProc
End Sub


Caution!! : Before running this code make sure you have saved all your
work as it will crash the Excel application!!!!!!


Unless I am missing something obvious, If anyone out there in the Excel
community can make this simple subclassing example work , I will be amazed !!


Jaafar.
Regards.





"Bob Phillips" wrote:

It works. Show the code.



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
Frustrating options in Excel vs 2003 skm Excel Discussion (Misc queries) 4 September 17th 08 06:36 PM
Very Frustrating - Please Help! picklevote Excel Worksheet Functions 1 September 14th 05 01:32 AM
Simple but frustrating Gordon[_2_] Excel Programming 4 December 18th 04 09:06 PM
Subclassing the EXCEL7 window Timster Excel Programming 0 August 12th 04 12:54 PM
Bizarre and frustrating bug NJD Excel Programming 5 January 28th 04 09:50 PM


All times are GMT +1. The time now is 07:39 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"