这个是最近一段时间遇到的各种花样别出的坑,这些坑只针对D7,不知道啥是D7的可以直接关闭窗口了。
坑1:
D7在Win7及以上版本调试时,只有BuildWithRuntimePackage时才能正确获取Win32MajorVersion,Win32MinorVersion,Win32BuildVersion等值。
不带包编译后,运行时不存在该问题。如果存在,可能需要使用管理员运行,即在程序上右键RunWithAdministrator,该问题的具体原因未知。
坑2:
D7程序启用UAC后,在Win10上无法接收WM_DROPFILE消息,即无法接收从资源管理器拖动到窗口上的文件消息。具体情况请参考:
https://www.vistax64.com/threads/changewindowmessagefilter-what-does-this-really-do.25586/
关键段是这段话:
Vista prohibits applications of different integrity levels from sending most
windows messages between each other. IE in protected mode runs in LOW
integrity; normal applications run in MEDIUM; and programs running with
administrator privileges run as HIGH. (There is also a SYSTEM level for some
system services).
ChangeWindowMessageFilter allows an application in a higher integrity level
to specify additional windows messages that it wants to accept from
applications running in a lower privilege level.
For example, if you run say NOTEPAD.exe, it will have a MEDIUM integirty
level. If you then run an administrative application, let's use task
scheduler as an example, it will run with HIGH integrity level.
notepad is isolated from task scheduler because they are running in
different integrity levels; the system prevents notepad from sending task
scheduler most window messages, prevents it from injecting code into task
scheduler via hooks, prevents it from writing into its process memory, etc,
etc, because of the difference in integrity level.
The ChangeWindowMessageFilter api can be used in this example by task
scheduler to allow it to receive additional window messages from notepad.
简单说,就是程序运行权限不同造成的,当然,也有解决方案,就是使用ChangeWindowMessageFilter函数来提权。
注意,该函数没有ChangeWindowMessageFilterW和ChangeWindowMessageFilterA的区分,你懂的!
所以,最终的答案是:如果你还在用D7,那么当你遇到这个问题时,你的解决方案有两个:一是不用UAC,二是将Explorer.exe提权。表面上看有两个解决方案,实际上只有一个。你懂的。不懂拉到。