DUILIB程序 修改exe图标和任务栏图标

1.修改exe图标

     1.1在资源文件中添加一个icon图标,然后重新编译,exe图标就会编程这个添加进来的图标了;

     1.2  如果不行,则需要用到消息;利用LoadIcon加载图标,返回一个图标句柄,然后在窗口创建完成后,利用::SendMessage发送STM_SETICON消息到 duilib窗口来更新图标;

#include<tchar.h>
#include "CDuiFramWnd.h"
#include "CDuiFramWnd_impl.h"
#include "menu.h"
#include"resource.h"
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
	_In_opt_ HINSTANCE hPrevInstance,
	_In_ LPWSTR    lpCmdLine,
	_In_ int       nCmdShow)
{
	CPaintManagerUI::SetInstance(hInstance);
	CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath());//设置资源路径为exe同一路径
	HRESULT hr = ::CoInitialize(NULL);
	if ((FAILED(hr))) return 0;
	//CDuiFramWnd duiFrame;
	
	CDuiFramWnd_impl duiFrame;
	duiFrame.Create(NULL, _T("DUIWnd"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE);
    //修改exe图标
	HICON hIcon = ::LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
	::SendMessage(duiFrame.GetHWND(), STM_SETICON, IMAGE_ICON, (LPARAM)(UINT)hIcon);

	duiFrame.CenterWindow();
	duiFrame.ShowModal();
	::CoUninitialize();
	//::MessageBox(NULL, _T("hello world"), NULL, NULL);
	return 0;
}

2.修改任务栏的图标

  在duilib中的主窗口的InitWindow函数或OnCreate函数中使用SetIcon函数来设置;

SetIcon(IDI_ICON1);
发布了69 篇原创文章 · 获赞 10 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/u010096608/article/details/103703346