Home > Software engineering >  Using HOOK to intercept a specified window message, hope to give a code, pseudo code can also
Using HOOK to intercept a specified window message, hope to give a code, pseudo code can also

Time:11-08



In the picture X (closed), send WM_CLOSE program to the window, close a few times, found that the window cannot be started, must restart the system to restart the program,

Is there any way to get "what send when you click on the X" news ". With the realization of the rights of the HOOK, such as, give some code!!!!!


CodePudding user response:

X is shut, will receive [u] WM_SYSCOMMAND SC_CLOSE [/u] news


CodePudding user response:

https://docs.microsoft.com/en-us/windows/win32/menurc/wm-syscommand

CodePudding user response:

refer to the second floor zgl7903 response:
https://docs.microsoft.com/en-us/windows/win32/menurc/wm-syscommand


Is not the same process, are two different processes, a process to monitor the news of another process

CodePudding user response:

Then try SetWindowsHookEx WH_CALLWNDPROC


CodePudding user response:

Void CMyDlg: : OnButton1 ()
{
//TODO: Add your the control notification handler code here
HWND WND=: : FindWindow (" NotePad ", 0);//"no title - notepad");
: : SendMessage (WND, WM_SYSCOMMAND, SC_CLOSE, 0);
}

CodePudding user response:

reference 5 floor schlafenhamster reply:
void CMyDlg: : OnButton1 ()
{
//TODO: Add your the control notification handler code here
HWND WND=: : FindWindow (" NotePad ", 0);//"no title - notepad");
: : SendMessage (WND, WM_SYSCOMMAND, SC_CLOSE, 0);
}


Tried, with the above way to shut down, will cause the program can't start,

- want to listen the the process of news, but I don't know whether using hook can solve

CodePudding user response:

Will cause the program can't start?
Windows 7 vc6 no problem!

CodePudding user response:

refer to 7th floor schlafenhamster response:
will cause the program can't start?
Windows 7 vc6 no problem!


Custom encapsulates the message, not the so-called

CodePudding user response:

https://www.jianshu.com/p/39da24e1a8ee
"The spy++ how to get the window WndProc callback address"
  • Related