Advertisement

To use a resource.

Started by April 15, 2002 07:39 PM
14 comments, last by Wachar 22 years, 7 months ago
Here's the total code. When I run Lamoth's code, the icon is on top too, on the Window title bar. So, I copy and pasted the code, changing only the header file, and the MAKEINTRESOURCE(here**), and set the icon to NULL etc. But when I run it then, it doesn't show it on top. See again...

Main.cpp

    #define WIN32_LEAN_AND_MEAN#include <windows.h>#include "RESOURCES.H"LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam){	PAINTSTRUCT		ps;	HDC				hdc;	switch(msg)	{	case WM_CREATE:		{			return(0);		} break;			case WM_PAINT:		{			hdc = BeginPaint(hwnd, &ps);			EndPaint(hwnd, &ps);			return(0);		} break;	case WM_DESTROY:		{			PostQuitMessage(0);			return(0);		} break;	default:break;	}	return(DefWindowProc(hwnd, msg, wparam, lparam));}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){	WNDCLASSEX winclass;	HWND		hwnd;	MSG			msg;	winclass.cbSize = sizeof(WNDCLASSEX);	winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;	winclass.lpfnWndProc	= WindowProc;	winclass.cbClsExtra		= 0;	winclass.cbWndExtra		= 0;	winclass.hInstance		= hInstance;	winclass.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));	winclass.hCursor		= LoadCursor(NULL, IDC_ARROW);	winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);	winclass.lpszMenuName	= NULL;	winclass.lpszClassName	= "WINCLASS1";	winclass.hIconSm		= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));	if(!RegisterClassEx(&winclass))		return(0);		if(!(hwnd = CreateWindowEx(NULL,							  "WINCLASS1",							  "My Awesome Window!",							  WS_OVERLAPPEDWINDOW | WS_VISIBLE,							  0,0,							  400,400,							  NULL,							  NULL,							  hInstance,							  NULL)))	return(0);	while(TRUE)	{		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))		{			if(msg.message == WM_QUIT)				break;			TranslateMessage(&msg);			DispatchMessage(&msg);		}	}	return(msg.wParam);}  


The .h file

  #define IDI_ICON1	100  


And the icon file...here's the branch..

Resource File(folder)

ICONS

IDI_ICON1

What's up with this?! Argh!


----------------------
Always will be smarter
than you,
--=ME=--
----------------------

[edited by - Wachar on April 16, 2002 7:05:13 PM]
Wachar's Eternity <-<-<-<-<- Me own site!
Your icon file should contain two icons - one at 32x32 and one at 16x16. The 16x16 one is to be used for the window title bar while the 32x32 one is used for the start bar.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! | Asking Smart Questions | Internet Acronyms ]
Thanks to Kylotan for the idea!
Advertisement
It still doesn''t work...where are you supposed to put what? Also, WHERE are you supposed to put Lamoth''s .rc code in? And, I can''t change the little icon on the Start menu. I changed it in the .rc file but it won''t change on the Start menu...

----------------------
Always will be smarter
than you,
--=ME=--
----------------------
Wachar's Eternity <-<-<-<-<- Me own site!
I don''t use LaMothe''s code, I''ve never read LaMothe''s code, and I suggest you learn to understand what is going on rather than what someone else did.

That said, if you''re editing an icon in the VC resource editor (say at 32x32), you need to add a new device (it''s a little button just above the editing area) for the new resolution. Then use LoadImage to set that as the small icon. Here''s an excerpt from my own code:

      // set application icons    {      HICON hIcon   = reinterpret_cast<HICON>( ::LoadImage( hInstance, MAKEINTRESOURCE( IDI_APPICON ),        IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR ) );      HICON hIconSm = reinterpret_cast<HICON>( ::LoadImage( hInstance, MAKEINTRESOURCE( IDI_APPICON ),        IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR ) );      ::SendMessage( hwnd, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>( hIcon ) );      ::SendMessage( hwnd, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>( hIconSm ) );    }  


[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! | Asking Smart Questions | Internet Acronyms ]
Thanks to Kylotan for the idea!
Where do you put that code? In the main cpp file?

----------------------
Always will be smarter
than you,
--=ME=--
----------------------
Wachar's Eternity <-<-<-<-<- Me own site!
quote: Original post by Wachar
Where do you put that code? In the main cpp file?

Yes.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! | Asking Smart Questions | Internet Acronyms ]
Thanks to Kylotan for the idea!

This topic is closed to new replies.

Advertisement