如何动态更改应用程序的图标?

sdf123321 2006-08-22 10:00:22
我有个VC程序,想要根据读取配置文件的图标文件名称,找到图标文件,根据图标文件来决定应用程序文件的图片,请问如何实现?
...全文
697 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhyytt 2006-08-22
  • 打赏
  • 举报
回复
SetIcon(LoadIcon(0,id), TRUE);
tanyaliji 2006-08-22
  • 打赏
  • 举报
回复
LPARAM)LoadIcon(NULL,IDI_QUESTION
折腾_苏州 2006-08-22
  • 打赏
  • 举报
回复
有个UpdateResource API可以更换资源,可以从别的exe中挖资源过来
http://kb.csdn.net/.net/Articles/200509/62bb93ea-9db7-4693-9034-3f5051ff13c0.html
sdf123321 2006-08-22
  • 打赏
  • 举报
回复
这个我知道,我是想改变应用程序保存在硬盘上的文件的图标
jerry 2006-08-22
  • 打赏
  • 举报
回复
在主框架窗口的 OnCreate函数内

m_hIcon = AfxGetApp()->LoadIcon(....);
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);

m_hIcon 即是你从文件读取的图标。
Seu_why 2006-08-22
  • 打赏
  • 举报
回复
::SendMessage(AfxGetMainWnd->m_hWnd,WM_SETICON,ICON_SMALL,(LPARAM)hIcon);
折腾_苏州 2006-08-22
  • 打赏
  • 举报
回复
HANDLE h = LoadImage(AfxGetResourceHandle(),"C:\\Burn.ico",IMAGE_ICON,0,0,LR_LOADFROMFILE);
::SendMessage(this->m_hWnd,WM_SETICON,ICON_SMALL,(LPARAM)h);
handsomerun 2006-08-22
  • 打赏
  • 举报
回复
给窗口发送

WM_SETICON
This message is sent by an application to associate a new big or small icon with a window.

WM_SETICON wParam = (WPARAM)(BOOL) fType;
lParam = (LPARAM)(HICON) hicon;
Parameters
fType
Specifies the type of icon being set. It is one of the following values:
Value Description
ICON_BIG Sets the large icon for the window.
ICON_SMALL Sets the small icon for the window.




hicon
Handle to the new large or small icon. If this parameter is NULL, the icon indicated by fType is removed.


发送这个消息就可以了
折腾_苏州 2006-08-22
  • 打赏
  • 举报
回复
::SendMessage(this->m_hWnd,WM_SETICON,ICON_SMALL,(LPARAM)LoadIcon(NULL,IDI_QUESTION));
Bible_Chou 2006-08-22
  • 打赏
  • 举报
回复
上面其实就是在注册窗口类的时候直接载入自己想要的图标。
wndclass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_ICON)) ;
Bible_Chou 2006-08-22
  • 打赏
  • 举报
回复
// Win32的

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,

PSTR szCmdLine, int iCmdShow)

{

TCHAR szAppName[] = TEXT ("IconDemo") ;

HWND hwnd ;

MSG msg ;

WNDCLASS wndclass ;


wndclass.style = CS_HREDRAW | CS_VREDRAW ;

wndclass.lpfnWndProc = WndProc ;

wndclass.cbClsExtra = 0 ;

wndclass.cbWndExtra = 0 ;

wndclass.hInstance = hInstance ;

wndclass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_ICON)) ;

wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;

wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;

wndclass.lpszMenuName = NULL ;

wndclass.lpszClassName = szAppName ;

if (!RegisterClass (&wndclass))

{

MessageBox ( NULL, TEXT ("This program requires Windows NT!"),

szAppName, MB_ICONERROR) ;

return 0 ;

}



hwnd = CreateWindow (szAppName, TEXT ("Icon Demo"),

WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT, CW_USEDEFAULT,

CW_USEDEFAULT, CW_USEDEFAULT,

NULL, NULL, hInstance, NULL) ;



ShowWindow (hwnd, iCmdShow) ;

UpdateWindow (hwnd) ;



while (GetMessage (&msg, NULL, 0, 0))

{

TranslateMessage (&msg) ;

DispatchMessage (&msg) ;

}

return msg.wParam ;

}
jerry 2006-08-22
  • 打赏
  • 举报
回复
MSDN 的例子,创建快捷方式并改变图标

/*PARAMETERS
fname_to_create_link = (e.g.) "c:\\mytextfile.txt"
lnk_fname = (e.g.) "yourname.lnk"
*/

void CreateLinkThenChangeIcon(LPTSTR fname_to_create_link,
LPTSTR lnk_fname)
{
HRESULT hres;
IShellLink *psl = NULL;
IPersistFile *pPf = NULL;
WORD wsz[256];
TCHAR buf[256];
int id;
LPITEMIDLIST pidl;

hres = CoCreateInstance( CLSID_ShellLink,

NULL,
CLSCTX_INPROC_SERVER,
IID_IShellLink,
(LPVOID*)&psl);
if(FAILED(hres))
goto cleanup;
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&pPf);
if(FAILED(hres))
goto cleanup;
hres = psl->SetPath(fname_to_create_link);
if(FAILED(hres))

goto cleanup;
//place the shortcut on the desktop
SHGetSpecialFolderLocation(hwnd, CSIDL_DESKTOP, >pidl);

SHGetPathFromIDList(pidl, buf);

lstrcat(buf,"\\");
lstrcat(buf,lnk_fname);

MultiByteToWideChar(CP_ACP, 0, buf, -1, wsz, MAX_PATH);

hres = pPf->Save(wsz, TRUE);

if(FAILED(hres))

goto cleanup;

GetSystemDirectory(buf, 256);

lstrcat(buf,"\\shell32.dll");

hres = psl->SetIconLocation(buf, 1);

if(FAILED(hres))

goto cleanup;

hres = psl->GetIconLocation(buf, 256, &id);

if(FAILED(hres))

goto cleanup;

pPf-&Save(wsz, TRUE);

cleanup:

if(pPf)

pPf->Release();

if(psl)

psl->Release();

}

jerry 2006-08-22
  • 打赏
  • 举报
回复
改变EXE文件的图标? 那就有点难了.不过一个办法是给EXE创建一个连接. 可以在创建的时候改变连接的图标

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧