简体   繁体   中英

How to get a notification when windows prompt a dialog (i.e. error message)?

the situation:

a user tries to copy a file to a directory he doesn't have write permission in, he will be prompted with a dialog box.

The requirement:

In a separate unrelated process, I want to get notified when this happens.

Possible solution paths:

  1. subscribe to a system event if one exists.
  2. using hooks

Is this even possible? which of the two is the preferred path?

a code example doing this would be a life saver...

Use SetWindowsHookEx() or SetWinEventHook() to receive notifications when a window is created and about to receive focus. You can then analyze the window contents to see if it matches what you are looking for and act accordingly.

将事件放到try块中,如果用户没有访问权限,它将失败并转到catch块,您可以在其中使用生成的异常来显示对话框

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM