How to Create Customize event for SetWinEventHook()

Sachi 221 Reputation points
2022-01-07T13:19:41.967+00:00

Hi

I am using
private static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess, uint idThread, uint dwFlags);

for hooking window in eventMin im passing EVENT_SYSTEM_MOVESIZEEND = 0x000B; and
eventMax im passing EVENT_SYSTEM_MINIMIZEEND = 0x0017;

So event getting hit for move resize and minimize but when i maximize not getting callback so i refered constant from [https://learn.microsoft.com/en-us/windows/win32/winauto/event-constants][1]

there is no filter for maximize
is it possible to create our customize event(filter) and pass to setWineventhook() so that i can get callback when i maximized window?

please suggest me

Regards
shweta h

Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Castorix31 91,506 Reputation points
    2022-01-07T14:11:46.983+00:00

    You can use EVENT_MIN, EVENT_MAX
    and in the WinEventProc, you can do something like :

     if (idObject == OBJID_WINDOW) 
     {
        if (eventConst == EVENT_OBJECT_LOCATIONCHANGE)
        {
           if (IsZoomed(hWnd))
               Console.Beep(1000, 10);
        }
     }
    

    with

           [DllImport("User32.dll", SetLastError = true)]
            public static extern bool IsZoomed(IntPtr hWnd);
    

1 additional answer

Sort by: Most helpful
  1. Sachi 221 Reputation points
    2022-01-07T16:37:14.68+00:00

    Hi @Castorix31 Thank you for prompt reply

    As u suggested i have used EVENT_MIN, EVENT_MAX but it triggering cursor moves also i want avoid this and when i move or resize or min/max a window i need single call back
    please suggest me
    below is my peace of code
    163228-image.png


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.