如何在C++中合并标志?[已关闭]

cunj1qz1  于 2022-12-27  发布在  其他
关注(0)|答案(1)|浏览(99)

已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题?**添加详细信息并通过editing this post阐明问题。

昨天关门了。
Improve this question
例如,我想为OPENFILENAMEW编写一个 Package 函数,如下所示:

void BrowseForFile(bool bAllowMultiSelect, bool bDontAddToRecent...)
{
     OPENFILENAMEW ofn;
     
     if((bAllowMultiSelect == true) and (bDontAddToRecent == false))
     {
          ofn.Flags = OFN_ALLOWMULTISELECT;
     }

     else if((bAllowMultiSelect == false) and (bDontAddToRecent == true))
     {
          ofn.Flags = OFN_DONTADDTORECENT;
     }

     else if((bAllowMultiSelect == true) and (bDontAddToRecent == true))
     {
          ofn.Flags = OFN_ALLOWMULTISELECT | OFN_DONTADDTORECENT;
     }

     // and so on...
}

我必须把每一个组合都写成那样吗?或者有什么简单的方法可以做到这一点吗?

rjee0c15

rjee0c151#

以下是@IgorTandetnik和@AviBerger建议的解决方案:

void BrowseForFile(bool bAllowMultiSelect, bool bDontAddToRecent...)
{
     OPENFILENAMEW ofn;
     
     if(bAllowMultiSelect == true)
     {
          ofn.Flags |= OFN_ALLOWMULTISELECT;
     }

     if(bDontAddToRecent == true)
     {
          ofn.Flags |= OFN_DONTADDTORECENT;
     }
}

相关问题