jjzjj

c++ - 将 WPARAM 传递到 DragQueryFile 不兼容?

coder 2024-06-12 原文

我有点困惑。当一个文件被拖到一个带有 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 interfaceregister it as drop target handler为您的应用。

关于c++ - 将 WPARAM 传递到 DragQueryFile 不兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43823771/

有关c++ - 将 WPARAM 传递到 DragQueryFile 不兼容?的更多相关文章

  1. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

  2. ruby - rails 3 redirect_to 将参数传递给命名路由 - 2

    我没有找到太多关于如何执行此操作的信息,尽管有很多关于如何使用像这样的redirect_to将参数传递给重定向的建议:action=>'something',:controller=>'something'在我的应用程序中,我在路由文件中有以下内容match'profile'=>'User#show'我的表演Action是这样的defshow@user=User.find(params[:user])@title=@user.first_nameend重定向发生在同一个用户Controller中,就像这样defregister@title="Registration"@user=Use

  3. ruby-on-rails - 如何生成传递一些自定义参数的 `link_to` URL? - 2

    我正在使用RubyonRails3.0.9,我想生成一个传递一些自定义参数的link_toURL。也就是说,有一个articles_path(www.my_web_site_name.com/articles)我想生成如下内容:link_to'Samplelinktitle',...#HereIshouldimplementthecode#=>'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...我如何编写link_to语句“alàRubyonRailsWay”以实现该目的?如果我想通过传递一些

  4. ruby - 在 Ruby 中按名称传递函数 - 2

    如何在Ruby中按名称传递函数?(我使用Ruby才几个小时,所以我还在想办法。)nums=[1,2,3,4]#Thisworks,butismoreverbosethanI'dlikenums.eachdo|i|putsiend#InJS,Icouldjustdosomethinglike:#nums.forEach(console.log)#InF#,itwouldbesomethinglike:#List.iternums(printf"%A")#InRuby,IwishIcoulddosomethinglike:nums.eachputs在Ruby中能不能做到类似的简洁?我可以只

  5. 【鸿蒙应用开发系列】- 获取系统设备信息以及版本API兼容调用方式 - 2

    在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList​()Obt

  6. ruby - 使用 `+=` 和 `send` 方法 - 2

    如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:

  7. ruby - 如何计算 Liquid 中的变量 +1 - 2

    我对如何计算通过{%assignvar=0%}赋值的变量加一完全感到困惑。这应该是最简单的任务。到目前为止,这是我尝试过的:{%assignamount=0%}{%forvariantinproduct.variants%}{%assignamount=amount+1%}{%endfor%}Amount:{{amount}}结果总是0。也许我忽略了一些明显的东西。也许有更好的方法。我想要存档的只是获取运行的迭代次数。 最佳答案 因为{{incrementamount}}将输出您的变量值并且不会影响{%assign%}定义的变量,我

  8. ruby - 如何将 Puma::Configuration 传递给 Sinatra? - 2

    这是我的网络应用:classFront我是这样开始的(请不要建议使用Rack):Front.start!这是我的Puma配置对象,我不知道如何传递给它:require'puma/configuration'Puma::Configuration.new({log_requests:true,debug:true})说真的,怎么样? 最佳答案 配置与您运行的方式紧密相关puma服务器。运行的标准方式puma-pumaCLI命令。为了配置puma配置文件config/puma.rb或config/puma/.rb应该提供(参见examp

  9. jquery - 如何将 AJAX 变量从 jQuery 传递到他们的 Controller ? - 2

    我有一个电子邮件表格。但是我正在制作一个测试电子邮件表单,用户可以在其中添加一个唯一的电子邮件,并让电子邮件测试将其发送到该特定电子邮件。为了简单起见,我决定让测试电子邮件通过ajax执行,并将整个内容粘贴到另一个电子邮件表单中。我不知道如何将变量从我的HAML发送到我的Controllernew.html.haml-form_tagadmin_email_blast_pathdoSubject%br=text_field_tag'subject',:class=>"mass_email_subject"%brBody%br=text_area_tag'message','',:nam

  10. arrays - Ruby 数组 += vs 推送 - 2

    我有一个数组数组,想将元素附加到子数组。+=做我想做的,但我想了解为什么push不做。我期望的行为(并与+=一起工作):b=Array.new(3,[])b[0]+=["apple"]b[1]+=["orange"]b[2]+=["frog"]b=>[["苹果"],["橙子"],["Frog"]]通过推送,我将推送的元素附加到每个子数组(为什么?):a=Array.new(3,[])a[0].push("apple")a[1].push("orange")a[2].push("frog")a=>[[“苹果”、“橙子”、“Frog”]、[“苹果”、“橙子”、“Frog”]、[“苹果”、“

随机推荐