Thread: Resource(.rc) Help in DevCPP

  1. #1
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204

    Resource(.rc) Help in DevCPP

    This is the first time im using DevCPP i used to use VC++6. Now im having trouble setting the icon of my app. The exe have the icon correctly set but the titlebar doesnt have it set when i open it. I always see the exclamation mark icon. Im not used to creating my resource script manually so probably it must be it or maybe i just forgot something and i cant see it.

    Heres the code.

    Main:
    Code:
    int WINAPI WinMain( HINSTANCE hThisInstance, HINSTANCE hPrevInstance,
        LPSTR lpStrArg, int iCmdShow )
    {
        MSG msg;
        CWindow *CWMain = new CWindow( hThisInstance );
        SelfMessageBox *msgBox = new SelfMessageBox( CWMain->getWindowHandle() );
    
        CWMain->setWindowProc( CWindowProc );
        CWMain->setIcon( LoadIcon( 0, 
            MAKEINTRESOURCE( IDI_FIDE_ICON ) ) ); // Seticon here
        
        if( CWMain->initializeWindow() == 0 ){
            msgBox->newMessage( "Initialization Error:", "Error", MB_OK ); 
            goto cleanup;
        }
        
        while( GetMessage( &msg, NULL, 0, 0 ) > 0 ){
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
        
        cleanup:
         delete msgBox;
         delete CWMain;
         return msg.wParam;
    }

    Heres is CWindow Class:

    Code:
    #ifndef _CWINDOW_H_
    #define _CWINDOW_H_
    
            class CWindow {
                public:
                    CWindow( HINSTANCE );
                    int initializeWindow();
                    void setVisible( int );  
                    void setWindowProc( WNDPROC );
                    HWND getWindowHandle();
                    void setTitle( char *sTitle );
                    void setIcon( HICON );
                private:
                    WNDPROC wndProc;
    				HWND hwnd;
                    HINSTANCE hInstance;
                    HICON appIcon;
                    long width, height;
                    char szClassName[128] ;
                    char szTitle[128];
                              
                };    
    #endif
    
    int CWindow::initializeWindow()
    {
        WNDCLASSEX wc = { 0 };
        
        wc.cbSize        = sizeof( WNDCLASSEX );
        wc.style         = 0;
        wc.lpfnWndProc   = wndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = appIcon;
        wc.hCursor       = LoadCursor( 0, IDC_ARROW );
        wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
        wc.lpszMenuName  = 0;
        wc.lpszClassName = szClassName;
        wc.hIconSm       = appIcon;
    
        if( RegisterClassEx( &wc ) == 0 )
            return 0;
        else {
    		hwnd = CreateWindowEx( 0, szClassName, szTitle, 
             WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,CW_USEDEFAULT, 
             CW_USEDEFAULT, width, height, NULL, NULL, hInstance, NULL );
             
            if( hwnd == 0 )
                return 0;
        }
    
        setVisible( 1 );
        return 1;  
    }  
    
    void CWindow::setVisible( int iCmdShow )
    {
        ShowWindow( hwnd, iCmdShow );
        UpdateWindow( hwnd );                                                                      
    }
    
    void CWindow::setIcon( HICON pIcon )
    {
        appIcon = pIcon;
    }

    Heres the .rc
    Code:
    IDI_FIDE_ICON ICON DISCARDABLE "resfiles/fide.ico"
    here Resource.h
    Code:
    #define IDI_FIDE_ICON 101

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I think you don't need to load the icon in Dev-C++. Dev-C++ automatically does it if you have something like this in your .rc file:
    Code:
    500 ICON MOVEABLE PURE LOADONCALL DISCARDABLE "resfiles\\fide.ico"
    And I think you know what I mean when I say don't use VC++ in Dev-c++.

  3. #3
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204
    It didnt work.

    heres my rc
    Code:
    101 ICON MOVEABLE PURE LOADONCALL DISCARDABLE "resfiles\\fide.ico"
    my resource.h
    Code:
    #define IDI_FIDE_ICON 101

    This app is supposed to be an MDI app. The Window Proc is not yet complete some parameters in the return value arent set yet. Would this cause a problem with icons not showing??
    Code:
    	LRESULT CALLBACK CWindowProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
    	{
    		
    		switch(msg)
    		{
    			case WM_CREATE:
    			break;
    
    			case WM_COMMAND:
    			break;
    
    			case WM_CLOSE:
    			doClose( hwnd, msg, wParam, lParam );
    			break;
    
    			case WM_SIZE:
    			break;
    
    			case WM_DESTROY:
    			doDestroy( hwnd, msg, wParam, lParam );
    			break;
    
    			case WM_NOTIFY:
    			break;
    
    			default:
    				return DefFrameProc( hwnd, 0, msg, wParam, lParam );  // Not Complete yet. Second param not yet set. 		}
    		
    		return 0;
    	}

  4. #4
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Is your resource script (.rc) being compiled?

  5. #5
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204
    Yes. It shows when compiling. I tried making errors in rc and it detects it. So its being compiled. And also the compiled exe has the icon set. Just wont show when run.

  6. #6
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Well, I didn't even have to define the icon...

  7. #7
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204
    Quote Originally Posted by maxorator
    Well, I didn't even have to define the icon...

    Didnt work. Okay be back ill try to work it out myself. Ill post here wht happens. Thnks for the helps .

  8. #8
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Dev-C++ has some examples with it. You can see how the icons are used there. And you can choose an icon for your program from project options.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. resource.rc CheckBox and Editfield
    By Plasm4 in forum Windows Programming
    Replies: 3
    Last Post: 08-09-2008, 08:24 PM
  2. DLL DevCPP won't take a min.....
    By lechat in forum C++ Programming
    Replies: 3
    Last Post: 11-24-2007, 03:38 PM
  3. DevCpp error: multiple definition of `img'
    By TriKri in forum C++ Programming
    Replies: 8
    Last Post: 01-01-2007, 08:11 PM
  4. [Linker error] undefined reference.(GTK, devcpp)
    By Firestarter in forum C Programming
    Replies: 2
    Last Post: 05-05-2006, 11:04 AM
  5. OpenGL and DevCPP: A dilemma for newbies
    By Sunny in forum Game Programming
    Replies: 12
    Last Post: 04-08-2005, 09:47 AM