New Post 17. It appeared after i copied all of full page 2 to make a full page 3. It is #post24895
It came from Original post #12, it got shifted down one to post #13 when the original posts 11 12 and 13 where copied on 31 Oct 2024, so it got edited to have the contents of the original post # 13
#post10484
Section Rem 4 is the Function WinSubWinCls_JerkBackOffHooKterd
This picks out the specific event I want, my “Non modal message box” being activated, and changes the window dimensions, using the API thing SetWindowPos
( You will need to experiment about with, mainly, the 10 50 400 150 The other two numbers 0 40 you may want to adjust as well. Understanding those two numbers fully is a bit beyond me – it took me best part of a week to figure out WTF all the other stuff was about ).
The last thing this function does is “kill” or “drop” or ““take off” the “Hook”” or ““Unhook” the hook”. If you don’t do that the function seems to be triggered indefinitely.
A last thing on a similar point: Some other codes doing something similar that I saw, seemed to cause a wild recursion: The size adjustment done in the function seemed to set off the function code again. The stack seemed to be limited to 30. I could not see any reason to do that, and in fact it seemed to cause some weird inconsistent ghostly images to appear on my desktop. My function just does the thing that I think it should do once. It appears more stable. I did have a lot of fun braking things before I got the API stuff correct. But since then the code seems to work well without problems in a number of code situations on different computers and different Excel versions.
( In all the situations that I have tried, my code has Exited as I have expected after an If clause detects if the function is on the start of a first recursion run. ( I think it would probably do no harm to unhook directly after the SetWindowPos , just in case the SetWindowPos does not cause recursion. ( It seems to do no harm to unhook a few times) )
Code:'_-=Rem 4============= Some hidden function / bookmark / bookmarks / cyber Robot thing was brought into life ("I hung or set a hook"). 'That monitors events like my message box popping up. When it catches one it starts this finction and passes to it three parameters. '_The first tells me with a number more exactly what event took place, '_the next is the window identifying number of that window doing that particular event , '_ the last parameter is something maybe to do with the mouse god knows what exactly probably even Sid don't know... but looking at his Avatar I probably wouldn't say that to him as he I don't know if I would want to mess with him... Private Function WinSubWinCls_JerkBackOffHooKerd(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long ' I "set a hook" which should trigger ( things similar to my Meassage box popping up , and gave it the AddressOf this function , 0 , and limited it to this "Thread" on my computer that is to say my Excel ) Let GlobinalCntChopsLog = GlobinalCntChopsLog + 1 ' The idea of this is that I add 1 on entering and subtract 1 when leaving the function. So this would be two if I started an other copy of this code before the first had finished. I am expecting that as the SetWindowPosition seemes to trigger it off again. If GlobinalCntChopsLog = 2 Then Let GlobinalCntChopsLog = GlobinalCntChopsLog - 1: UnHookWindowsHookCodEx hHookTrapCrapNumber: Exit Function ' If I have 2 then that is an indication that recurtion has taken place, that is to say I started another function run caused by SetWindowPosition triggering it off. So i assume then that SetWindowPosition has done what it should so I can "take the hook off" (as if i did not then the function seems to get triggeredt indefinitely even without recusion), and then I exit the function. So I do expect a second copy of the code to run, but due to this it does not do anything other than take the "hook off". I also reduce the count by 1. It is then at 1. But then the first copy of the function ends from just under SetWindowPosition. So then the count is reduced again and is at the initial 0 If lMsg = 5 Then Let Booloks = SetWindowPosition(wParam, 0, 10, 50, 400, 150, 40) ' 5 here is the number for a window about to be activated. This is probably the one I want. (If I catch it when it is starting , 3, then It might then re set the size and position stuff again to the standard after I have done it) Let GlobinalCntChopsLog = GlobinalCntChopsLog - 1 ' Every first copy run of the code has the count reduced to 0 so that when it starts again (as the only first copy active) it will be increased to 1 again to indicate it is a run of the function copy 1 End Function




Reply With Quote
Bookmarks