微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用Web文件参数从MFC启动Microsoft Edge

如何解决使用Web文件参数从MFC启动Microsoft Edge

如果打开控制台提示符,则可以输入以下命令:

start msedge "d:\HTML\Verticle Alignment.HTM"

它将启动Microsoft Edge并打开网页。

所以我尝试在使用MFC的测试程序中以编程方式执行此操作:

void CMFCApplication8Dlg::OnBnClickedButton1()
{
    ExecuteProgram(_T("start"),_T("msedge d:\\HTML\\Verticle Alignment.HTM"));
}


BOOL CMFCApplication8Dlg::ExecuteProgram(CString strProgram,CString strArguments)
{
    SHELLEXECUTEINFO    se = { 0 };
    MSG                 sMessage;
    DWORD               dwResult;

    se.cbSize = sizeof(se);
    se.lpFile = strProgram;
    se.lpParameters = strArguments;
    se.nShow = SW_SHOWDEFAULT;
    se.fMask = SEE_MASK_NOCLOSEPROCESS;
    ShellExecuteEx(&se);

    if (se.hProcess != nullptr)
    {
        do
        {
            dwResult = ::MsgWaitForMultipleObjects(1,&(se.hProcess),FALSE,INFINITE,QS_ALLINPUT);
            if (dwResult != WAIT_OBJECT_0)
            {
                while (PeekMessage(&sMessage,nullptr,NULL,PM_REMOVE))
                {
                    TranslateMessage(&sMessage);
                    dispatchMessage(&sMessage);
                }
            }
        } while ((dwResult != WAIT_OBJECT_0) && (dwResult != WAIT_Failed));

        CloseHandle(se.hProcess);
    }

    if ((DWORD_PTR)(se.hInstApp) < 33)
    {
        // Throw error
        AfxThrowUserException();
        return FALSE;
    }

    return TRUE;
}

但是当我运行它时,我收到此错误消息:

Error

那么如何在 Microsoft Edge 中启动文件?我正在使用最新的Windows 10,因此它是 Microsoft Edge Chromium

我还看到了其他一些问题,这些问题涉及将Edge设置为认浏览器,然后仅“打开”数据文件并将其全部工作,但是在这种情况下,这样做不可行。在我的编辑器中,我有一个菜单弹出窗口,其中列出了所有已安装的浏览器(目前不包括Edge)。但是我想添加Edge,因此需要能够以我的文件以编程方式启动它以进行查看。

解决方法

基于提供给我的评论,并考虑文件名中的空格,这可行:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-26-61e7f03039a6> in <module>
      7 targets = torch.ones(32,128)
      8 
----> 9 loss(inputs,targets.long())

/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py in _call_impl(self,*input,**kwargs)
    725             result = self._slow_forward(*input,**kwargs)
    726         else:
--> 727             result = self.forward(*input,**kwargs)
    728         for hook in itertools.chain(
    729                 _global_forward_hooks.values(),/opt/conda/lib/python3.8/site-packages/torch/nn/modules/loss.py in forward(self,input,target)
    959 
    960     def forward(self,input: Tensor,target: Tensor) -> Tensor:
--> 961         return F.cross_entropy(input,target,weight=self.weight,962                                ignore_index=self.ignore_index,reduction=self.reduction)
    963 

/opt/conda/lib/python3.8/site-packages/torch/nn/functional.py in cross_entropy(input,weight,size_average,ignore_index,reduce,reduction)
   2466     if size_average is not None or reduce is not None:
   2467         reduction = _Reduction.legacy_get_string(size_average,reduce)
-> 2468     return nll_loss(log_softmax(input,1),None,reduction)
   2469 
   2470 

/opt/conda/lib/python3.8/site-packages/torch/nn/functional.py in nll_loss(input,reduction)
   2271         out_size = (n,) + input.size()[2:]
   2272         if target.size()[1:] != input.size()[2:]:
-> 2273             raise ValueError('Expected target size {},got {}'.format(
   2274                 out_size,target.size()))
   2275         input = input.contiguous()

ValueError: Expected target size (32,3),got torch.Size([32,128])
  • 要执行的程序必须是ExecuteProgram(_T("msedge"),_T("\"d:/HTML/Verticle Alignment.HTM\"")); ,而不是msedge
  • 该参数需要用start引号引起来。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。