File's icon

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
28
29
30
#include <windows.h>
#define IDI_ICON1 101
char title[]="New Window";
LRESULT CALLBACK P(HWND A,UINT B,WPARAM C,LPARAM D){
switch(B){
case 0x2:
     PostQuitMessage(0);
     break;
     default:
return DefWindowProc(A,B,C,D);
}
return 0;
}
int WINAPI WinMain(HINSTANCE A,HINSTANCE B,LPSTR C,int d){
HWND E;
MSG F;
WNDCLASS G={0};
G.hInstance=A;
G.lpszClassName=title;
G.lpfnWndProc=P;
G.hbrBackground=GetSysColorBrush(COLOR_3DFACE);
G.hIcon=LoadIcon(NULL,IDI_ICON1);
RegisterClass(&G);
CreateWindow(G.lpszClassName,title,0xcf0000|WS_VISIBLE,50,150,600,450,0,0,A,0);
while(GetMessage(&F,NULL,0,0)){
TranslateMessage(&F);
DispatchMessage(&F);
}
return F.wParam;
}


And i added my resource.rc file:
 
#define IDI_ICON1 ICON "C:\\Smile.ico" 
I tried this.But it doesn't work:
 
G.hIcon=LoadIcon(NULL,"C:\\Smile.ico" );
You should use LoadImage... like this:

1
2
    wincl.hIcon = (HICON)LoadImage(NULL, "C:/icono.ico", IMAGE_ICON, 32,32,LR_LOADFROMFILE);
    wincl.hIconSm = (HICON)LoadImage(NULL, "C:/icono.ico", IMAGE_ICON, 32,32,LR_LOADFROMFILE);
hIcon works.But hIconSm doesn't work.
 
23 C:\icon exam.cpp 'struct WNDCLASS' has no member named 'hIconSm' 
hIconSm is a member of WNDCLASSEX but not WNDCLASS

Andy
Ok.What can i use with WNDCLASS?
closed account (zwA4jE8b)
this is what I used

wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));

you could replace wc with your wincl.

are you using visual studio?

EDIT: In my autogenerated .rc file my icon is

 
IDI_ICON1               ICON                    "C:\\Visual Studio 2010\\Icons\\Smiley.ico"


not #define
Last edited on
CreativeMFS,i tried this method.But this doesn't work on Dev-C++.
You could try just omitting the small icon. (And carry on using LoadImage)

Window might automatically create one by shrinking down the normal one, to support lecagy apps.
Otherwise, you need to replace your WNDCLASS struct with a WNDCLASSEX one.

Note thay WNDCLASSEX is only defined for new enough versions of Windows, so might need the version to be #defined correctly before including windows.h (Visual Studio should do this automatically).

Andy

P.S. Did the Windows header you're using come with Dev-C++, or did you install a Windows SDK?
Last edited on
WNDCLASSEX and WNDCLASS's origin in winuser.h.I added HICON hIconSm in WNDCLASSA and WNDCLASSW.It did not give an error.But did not open a window.
Last edited on
You edited winuser.h to add hIconSm to WNDCLASS?

You should never change any of the Windows headers!!!

Either leave code as it as, witj WNDCLASS, RegisterClass, and no small icon

Or switch to WNDCLASSEX, RegisterClassEx, with a small icon.
Topic archived. No new replies allowed.