- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有点困惑。当一个文件被拖到一个带有 WS_EX_ACCEPTFILES 标记的窗口上时,它会将一个 PostMessage 放入 WndProc 函数中,该函数将 UINT 消息设置为 WM_DROPFILES,并且根据
https://msdn.microsoft.com/en-us/library/windows/desktop/bb774303(v=vs.85).aspx
WPARAM = (WPARAM) (HDROP) hDrop;所以我是否错误地假设我可以使用 WPARAM 来初始化 HDROP 或只是将它传递到 DragQueryFile ??
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_CREATE:
return 0;
case WM_DROPFILES:
TCHAR* FilePath;
HDROP hDrop = wParam; //wParam cannot be used to ini. an entity of type HDROP
//HDROP hdrop = (HDROP)wParam; initialization of hDrop is skipped by case label
DragQueryFile(wParam, 0, FilePath, 0); //wParam not compatible
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
感谢各种帮助。
最佳答案
您需要将 wparam 转换为 HDROP,然后迭代提供缓冲区的丢弃文件路径。
case WM_DROPFILES:
{
auto const drop_handle{reinterpret_cast< ::HDROP >(wParam)};
auto const dropped_files_count
{
::DragQueryFileW(drop_handle, 0xFFFFFFFF, nullptr, 0)
};
::std::vector< wchar_t > buffer;
for(::UINT dropped_file_index{0}; dropped_files_count != dropped_file_index; ++dropped_file_index)
{
auto const file_path_symbols_count_excluding_terminating_null
{
::DragQueryFileW(drop_handle, dropped_file_index, nullptr, 0)
};
if(0 < file_path_symbols_count_excluding_terminating_null)
{
auto const buffer_size{file_path_symbols_count_excluding_terminating_null + 1};
buffer.resize(buffer_size);
auto const copied_symbols_count_excluding_terminating_null
{
::DragQueryFileW(drop_handle, dropped_file_index, buffer.data(), buffer_size)
};
if(copied_symbols_count_excluding_terminating_null == file_path_symbols_count_excluding_terminating_null)
{
buffer.back() = L'\0'; // just in case....
// buffer now contains file path...
}
}
}
break;
}
但是请注意,即使处理 WM_DROPFILES
应该有效,处理拖放的首选方法是实现 IDropTarget
interface和 register it as drop target handler为您的应用。
关于c++ - 将 WPARAM 传递到 DragQueryFile 不兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43823771/
我尝试在 PowerPoint 中使用 VBA 访问剪贴板中的文件,但 DragQueryFile 始终返回 0。 这里我的代码被剪掉了 Private Declare PtrSafe Functio
我有点困惑。当一个文件被拖到一个带有 WS_EX_ACCEPTFILES 标记的窗口上时,它会将一个 PostMessage 放入 WndProc 函数中,该函数将 UINT 消息设置为 WM_DRO
我已经编写了一个 shell 扩展(由 The Complete Idiot's Guide to Writing Shell Extensions 指导),在我升级到 Windows 7(32 位)
我是一名优秀的程序员,十分优秀!