CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Custom Icon

  1. #1
    Join Date
    Jul 2005
    Posts
    5

    Custom Icon

    Ok, my first problem as a noob;

    I want to have a custom icon, here's the source; what's the error pls?

    test.cpp
    _______


    Code:
    // INCLUDES ///////////////////////////////////////////////
    #define WIN32_LEAN_AND_MEAN // just say no to MFC
    #include <windows.h> // include all the windows headers
    #include <windowsx.h> // include useful macros
    #include <stdio.h>
    #include <math.h>
    #include RESOURCES.H
    // DEFINES ////////////////////////////////////////////////
    // defines for windows
    #define WINDOW_CLASS_NAME "WINCLASS1"
    // GLOBALS ////////////////////////////////////////////////
    // FUNCTIONS //////////////////////////////////////////////
    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));
    } 
    // WINMAIN ////////////////////////////////////////////////
    int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hprevinstance,LPSTR lpcmdline,int ncmdshow){
    	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(ID_ICON1));
    	winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
    	winclass.hbrBackground  = (HBRUSH)GetStockObject(BLACK_BRUSH);
    	winclass.lpszMenuName = NULL;
    	winclass.lpszClassName = WINDOW_CLASS_NAME;
    	winclass.hIconSm = LoadIcon(hinstance,MAKEINTRESOURCE(ID_ICON1));
    if (!RegisterClassEx(&winclass))
    return(0);
    // create the window
    if (!(hwnd = CreateWindowEx(NULL, WINDOW_CLASS_NAME, "Format C", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    0,0, 400,400, NULL, NULL, hinstance,NULL))) 
    return(0);
    
    while(GetMessage(&msg,NULL,0,0))
    {
    	TranslateMessage(&msg);
    	DispatchMessage(&msg);
    }
    
    return(msg.wParam);
    }
    RESOURCES.RC
    ____________

    Code:
    #include “RESOURCES.H”
    
    ID_ICON1 ICON test.ico
    RESOURCES.H
    ___________

    Code:
    #define ID_ICON1 100


    The error:
    Compiling resources...
    C:\Program Files\Microsoft Visual Studio\MyProjects\test7\files\RESOURCES.H(1) : fatal error RC1004: unexpected end of file found
    Error executing rc.exe.

    test7.exe - 1 error(s), 0 warning(s)

    thanks in advance!
    Last edited by packagedeliverer; July 12th, 2005 at 03:41 PM.

  2. #2
    Join Date
    May 2004
    Location
    Michigan, United States
    Posts
    457

    Re: Custom Icon

    In my resource files, the filename of the icon is enclosed by quotes, so you might want to try this:
    Code:
    #include “RESOURCES.H”
    
    ID_ICON1 ICON "test.ico"
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

  3. #3
    Join Date
    Jul 2005
    Posts
    5

    Re: Custom Icon

    still the same problem, the error says it's the header ...I really don't have a clue since this is one of my first experiments...
    Last edited by packagedeliverer; July 12th, 2005 at 03:57 PM.

  4. #4
    Join Date
    Sep 2004
    Location
    Italy
    Posts
    389

    Re: Custom Icon

    ...
    #include <windows.h> // include all the windows headers
    #include <windowsx.h> // include useful macros
    #include <stdio.h>
    #include <math.h>
    #include "RESOURCES.H" //quotes

    you did it in your rc file

  5. #5
    Join Date
    May 2004
    Location
    Michigan, United States
    Posts
    457

    Re: Custom Icon

    Quote Originally Posted by kkez
    ...
    #include <windows.h> // include all the windows headers
    #include <windowsx.h> // include useful macros
    #include <stdio.h>
    #include <math.h>
    #include "RESOURCES.H" //quotes

    you did it in your rc file
    Good catch, kkez. My intuition told me that he was missing quotes -- I just picked the wrong spot!
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

  6. #6
    Join Date
    Jul 2005
    Posts
    5

    Re: Custom Icon

    Well it still has the same error, so it doesn't seem to be the quotes

    Could any one run a test and verify the error if you'd see it?
    Last edited by packagedeliverer; July 13th, 2005 at 04:30 PM.

  7. #7
    Join Date
    Jul 2005
    Posts
    5

    Re: Custom Icon

    Zipped the dir of the project:
    >>Download<<
    Please have a look at it.
    (created in visual c++ 6.0)

  8. #8
    Join Date
    Jul 2005
    Posts
    5

    Re: Custom Icon

    Oh c'mon guys gimme a hint...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured