I am starting myself in the use of microsoft's command-line lib...
I made a simple lib which creates a window by using classes, it has an interesting member function: RegisterClass(try and guess what it does ).
I want the user to use this function to register a single class, specifying the icon, if the hIcon is NULL, I want it to use the default icon, which is a resource.
the part of the code is shown below:
int cMyWindow::RegisterClass(LPCSTR ClassName,HICON hIcon)
{
WNDCLASSEX wc;
int ret;
this->cClassName = new(char[strlen(ClassName)+1]);
strcpy(this->cClassName,ClassName);
wc.cbClsExtra=0;
wc.cbSize=sizeof(WNDCLASSEX);
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)(GetStockObject(BLACK_BRU SH));
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
//THE INTERESTING STUFF STARTS HERE
if(hIcon==NULL)
{
int id=IDI_ICON1;
LPTSTR res=MAKEINTRESOURCE(id);
wc.hIcon=LoadIcon(this->hInstance,res);
ret=GetLastError();
}
else
{
wc.hIcon=hIcon;
ret=GetLastError();
}
//THE INTERESTING STUFF ENDS HERE
wc.hIconSm=NULL;
wc.hInstance=this->hInstance;
wc.lpfnWndProc=WndProc;
wc.lpszClassName=ClassName;
wc.lpszMenuName=NULL;
wc.style=0;
if(RegisterClassEx(&wc))
{
return 1;
}
else
{
throw cError("Class Registration failed\nError found in Line 160");
return 0;
}
}
the
wc.hIcon=LoadIcon(this->hInstance,res);
used to be
wc.hIcon=LoadIcon(this->hInstance,MAKEINTRESOURCE(IDI_ICON1);
but I split it up to see what happened!
when i run it, it runs ok until the MAKEINTRESOURCE, it returns
0x0000060, or something like that (i guess it works!)
but the LoadIcon returns 0!
when I call GetLastError, it returns 0 (Function success)
I don't know what's going on here.
the command line I use to create the lib is:
lib /MACHINE:IX86 hello.obj hello.res
so I don't think that the problem is that I am not linking the resource file!
and, when I run the program which uses the lib, it works, but it doesn't show my icon, it shows the messy windows icon!
Help me please