C++ Icon Example Needed

This is a discussion on C++ Icon Example Needed within the C++ Programming forums, part of the General Programming Boards category; Can somebody please send me a .cpp file which show's how to use icons on the windows? I've got a ...

  1. #1
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542

    Question C++ Icon Example Needed

    Can somebody please send me a .cpp file which show's how to use icons on the windows? I've got a tutorial but I cannot figure it out because it's in C, not C++.
    Thanks

  2. #2
    Registered User Octorok101's Avatar
    Join Date
    May 2002
    Posts
    22
    It should be jut the same. C++ is simply C with a few extras

  3. #3
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Yea, but can you send me an example please?
    what does signature stand for?

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    317
    It's not that hard. All you need to do is go into FILE->ADD->RESOURCE. Create a resource file this way. Then right click on the resource and choose ADD, then select icon. This will bring up a 32x32 icon pic which you can change to what you want. Make the id whatever(I will use IDI_ICON), then when you initialize your windows class do:
    Code:
    wndclass.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON));
    hInstance is the handle to your window class(because the icon is stored in the exe).

    MAKEINTRESOURCE is a macro that will convert the resource id into the appropriate data value.

  5. #5
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    If it isnt that hard, can you send me an example please?
    Thanks
    what does signature stand for?

  6. #6
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Code:
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
    
    	static TCHAR szAppName[] = TEXT("My App") ;
    	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_TITLE));
    	wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
    	wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
    	wndclass.lpszMenuName  = NULL ;
    	wndclass.lpszClassName = szAppName ;
    
    	if (!RegisterClass (&wndclass))
    	{
    		MessageBox (NULL, "An Error occoured in Registering the Window Class", 
    				szAppName, MB_ICONERROR) ;
    		return 0 ;
    	}
    
    	TCHAR *pszBuffer = new TCHAR[256];
    	LoadString(hInstance, IDS_TITLEBAR, pszBuffer, 256);
    
    	hwnd = CreateWindow(
    							szAppName,
    							pszBuffer,
    							WS_OVERLAPPEDWINDOW,
    							CW_USEDEFAULT,
    							CW_USEDEFAULT,
    							GetSystemMetrics(SM_CXSCREEN) * 3 / 4,
    							GetSystemMetrics(SM_CYSCREEN) * 3 / 4,
    							NULL,
    							NULL,
    							hInstance,
    							NULL
    						);   
    	
    
         
    	ShowWindow(hwnd, nCmdShow);
    	UpdateWindow(hwnd);
    	delete[] pszBuffer;
         
    	while (GetMessage (&msg, NULL, 0, 0))
    	{
    		TranslateMessage (&msg) ;
    		DispatchMessage (&msg) ;
    	}
    	return msg.wParam;
    
    }

  7. #7
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Err, a lotsa people told me that but, can you send it as a complete cpp file with the resources etc? Cuz I always get an error..
    Thanks
    what does signature stand for?

  8. #8
    Registered User
    Join Date
    May 2002
    Posts
    317
    here:
    Attached Files Attached Files

  9. #9
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    If you told us yourerror we migh be able to help

  10. #10
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Thanks Treveller!
    what does signature stand for?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Icon Help
    By The Brain in forum Windows Programming
    Replies: 11
    Last Post: 04-05-2009, 05:06 PM
  2. Problem with an icon in the TaskBar status area
    By dit6a9 in forum Windows Programming
    Replies: 2
    Last Post: 08-16-2004, 11:33 PM
  3. Icon problem
    By mkyong in forum Windows Programming
    Replies: 0
    Last Post: 02-17-2003, 05:39 PM
  4. Icon? help!
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-16-2001, 06:21 PM
  5. icon in title bar?
    By Unregistered in forum Windows Programming
    Replies: 3
    Last Post: 12-12-2001, 06:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21