Creating an icon in the titlebar? - Windows XP

I created a resource file (icon.rc) and added the following line:

IDI_ICON1 ICON DISCARDABLE "include/icon.ico"

With this I can create an icon for my exe. But I want to be able to add a custom icon to the titlebar of my app, instead of the boring white box. I have an icon ready (smicon.ico) but I can't find any information on how to add it. Do I add another line to my resource file?
Last edited on
Add another ICON in your rc file and when registering the window class, set it to the hIcon member of the class. Then use that class to make your window.
I added another icon to my rc file, but after that I am still lost.

Could you give me an example? I am very new to C++ and programming. I am not sure what "registering the window class" means.
Last edited on
source file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <windows.h>

LRESULT WndProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam)
{
	switch (Msg)
	{
		case WM_DESTROY:
			PostQuitMessage(0);
	}
	return DefWindowProcA(hWnd, Msg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, char* Cmd, int Show)
{
	WNDCLASS wcl = {CS_HREDRAW|CS_VREDRAW,(WNDPROC)WndProc,0,0,hInst,LoadIcon(hInst,"MyIcon"),//<- icon
		LoadCursor(hInst,MAKEINTRESOURCE(IDC_ARROW)),GetSysColorBrush(COLOR_WINDOW),0,"Window" };
	RegisterClass(&wcl);
	HWND win = CreateWindow("Window","Caption",WS_OVERLAPPEDWINDOW|WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT,640,480,0,0,hInst,0);                 

	MSG Msg;
	while(GetMessage(&Msg,0,0,0))
	{
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}
	return Msg.wParam;
}


rc file:
1
2
3

MyIcon ICON "icon.ico"
Last edited on
do like this:

WNDCLASS wcl = {CS_HREDRAW|CS_VREDRAW,(WNDPROC)WndProc,0,0,hInst,LoadIcon(hInst,(LPCTSTR)MyIcon), LoadCursor(hInst,MAKEINTRESOURCE(IDC_ARROW)),GetSysColorBrush(COLOR_WINDOW),0,"Window" };

and MyIcon might be defined in your resource.h file.


Topic archived. No new replies allowed.