我遇到的其他几个问题与此非常相似:
我正在使用 WTL9.0。我有一个以 CTreeViewCtrlEx 作为其子项的框架窗口。我正在使用 SHGetFileInfo()获取我想在树中使用的图标,但它们显示为黑色背景。这是一个完整的示例。
#define WINVER 0x0601 // Windows 7
#define _WIN32_WINNT 0x0601 // Windows 7
#include <atlbase.h>
#include <atlapp.h>
CAppModule g_AppModule; // WTL version of CComModule
#include <atlwin.h>
#include <atlframe.h>
#include <atlcrack.h>
#include <atlctrls.h>
class MainWnd : public CFrameWindowImpl<MainWnd>
{
private:
typedef MainWnd ThisClass;
typedef CFrameWindowImpl<MainWnd> BaseClass;
static const DWORD TREE_STYLE = TVS_HASLINES | TVS_LINESATROOT |
TVS_HASBUTTONS | WS_CHILD | WS_VISIBLE;
CTreeViewCtrlEx m_Tree;
CImageList m_ImgList;
public:
BEGIN_MSG_MAP(ThisClass)
MSG_WM_CREATE(OnCreate)
MSG_WM_DESTROY(OnDestroy)
CHAIN_MSG_MAP(BaseClass)
END_MSG_MAP()
LRESULT OnCreate(CREATESTRUCT* pCreateStruct)
{
// Create the tree control
LPCTSTR TREE_CLASS = CTreeViewCtrlEx::GetWndClassName();
m_Tree.Create(*this, rcDefault, TREE_CLASS, TREE_STYLE);
m_hWndClient = m_Tree;
// Create the image list
m_ImgList.Create(32, 32, ILC_COLOR32, 1, 1);
SHFILEINFO sFileInfo = { 0 };
const UINT FLAGS = SHGFI_ICON | SHGFI_USEFILEATTRIBUTES;
LPCTSTR PATH = _T("C:\\Windows");
// Get the directory icon
if (0 != ::SHGetFileInfo(PATH, FILE_ATTRIBUTE_DIRECTORY, &sFileInfo,
sizeof(SHFILEINFO), FLAGS))
{
CIcon dirIcon(sFileInfo.hIcon);
m_ImgList.AddIcon(dirIcon);
}
m_Tree.SetImageList(m_ImgList);
// Insert three items into the tree
CTreeItem rootItem =
m_Tree.InsertItem(_T("Root"), 0, 0, TVI_ROOT, TVI_LAST);
m_Tree.InsertItem(_T("Sub1"), 0, 0, rootItem, TVI_LAST);
m_Tree.InsertItem(_T("Sub2"), 0, 0, rootItem, TVI_LAST);
m_Tree.Expand(rootItem);
SetMsgHandled(false);
return 0;
}
void OnDestroy()
{
if (m_Tree.IsWindow())
m_Tree.DestroyWindow();
m_ImgList.Destroy();
SetMsgHandled(false);
}
};
int __stdcall WinMain
(
HINSTANCE hInstance,
HINSTANCE /*hPrevInstance*/,
LPTSTR /*wzCmdLine*/,
int nCmdShow
)
{
g_AppModule.Init(nullptr, hInstance);
MainWnd mainWindow;
MSG msg = { 0 };
if (nullptr == mainWindow.CreateEx())
return 1;
mainWindow.ShowWindow(nCmdShow);
mainWindow.UpdateWindow();
while (0 < ::GetMessage(&msg, nullptr, 0, 0))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
g_AppModule.Term();
return 0;
}
上面的第三个链接似乎表明我需要从图标中获取位图,复制它然后将其添加到图像列表中。
查看 this project 的代码, 但是,这意味着您应该能够简单地使用图标本身。如果您深入研究提供的类,它只是使用图标句柄将其添加到列表中。这种比较的问题在于它是在 C# 中进行的,情况可能有所不同。
This MSDN article确实表明支持 32 位 alpha 混合图标,但我还没有让它们工作。
我已经获得在提供的代码中加载的图标的位图并查看像素数据,图像确实包含 alpha channel 并被列为 32 位。
如果有人知道如何让它工作,你能告诉我吗?
最佳答案
代码没问题,但 Windows 不会被告知正在使用的公共(public)控件的版本。
您必须启用 Visual Style .您可以在项目 list 中执行此操作,或者至少在您的 *.cpp 文件之一中包含以下行:
#pragma comment(linker,"/manifestdependency:\"type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
请注意此 #pragma 指令是特定于 Visual Studio 的,请将 manifest 与其他编译器一起使用。
此外,您还可以添加对 windows 主题的支持:
#include <UxTheme.h>
#pragma comment( lib, "UxTheme.lib" )
...
SetWindowTheme(tree.m_hWnd, L"Explorer", NULL);
结果:
关于c++ - 让 alpha 混合与 CImageList 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40097312/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我有一个包含模块的模型。我想在模块中覆盖模型的访问器方法。例如:classBlah这显然行不通。有什么想法可以实现吗? 最佳答案 您的代码看起来是正确的。我们正在毫无困难地使用这个确切的模式。如果我没记错的话,Rails使用#method_missing作为属性setter,因此您的模块将优先,阻止ActiveRecord的setter。如果您正在使用ActiveSupport::Concern(参见thisblogpost),那么您的实例方法需要进入一个特殊的模块:classBlah
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request
在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo
如果我使用ruby版本2.5.1和Rails版本2.3.18会怎样?我有基于rails2.3.18和ruby1.9.2p320构建的rails应用程序,我只想升级ruby的版本,而不是rails,这可能吗?我必须面对哪些挑战? 最佳答案 GitHub维护apublicfork它有针对旧Rails版本的分支,有各种变化,它们一直在运行。有一段时间,他们在较新的Ruby版本上运行较旧的Rails版本,而不是最初支持的版本,因此您可能会发现一些关于需要向后移植的有用提示。不过,他们现在已经有几年没有使用2.3了,所以充其量只能让更
使用Ruby1.9.2运行IDE提示说需要gemruby-debug-base19x并提供安装它。但是,在尝试安装它时会显示消息Failedtoinstallgems.Followinggemswerenotinstalled:C:/ProgramFiles(x86)/JetBrains/RubyMine3.2.4/rb/gems/ruby-debug-base19x-0.11.30.pre2.gem:Errorinstallingruby-debug-base19x-0.11.30.pre2.gem:The'linecache19'nativegemrequiresinstall
如何将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.你能做的最好的事情是: