Thread: Resources, icon, resources....

  1. #1
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269

    Resources, icon, resources....

    OK now im lost, my tutorials aren't working, and this is where i turn to next: on my source code i have:

    Code:
    #include <windows.h>
    #include "resource2.h"
    
    const char g_szClassName[] = "myWindowClass";
    
    // Step 4: the Window Procedure
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        switch(msg)
        {
            case WM_CLOSE:
                MessageBox (NULL, "Im sorry you have to leave", "i'm sorry", 0);
                MessageBox (NULL, "C'ya", "GoodBye", 0);
                DestroyWindow(hwnd);
            break;
            case WM_DESTROY:
                PostQuitMessage(0);
            break;
            default:
                return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        LPSTR lpCmdLine, int nCmdShow)
    {
        WNDCLASSEX wc;
        HWND hwnd;
        MSG Msg;
    
        //Step 1: Registering the Window Class
        wc.cbSize        = sizeof(WNDCLASSEX);
        wc.style         = 0;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = NULL;
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+0);
        wc.lpszMenuName  = NULL;
        wc.lpszClassName = g_szClassName;
        wc.hIconSm       = NULL;
    
        if(!RegisterClassEx(&wc))
        {
            MessageBox(NULL, "Window Registration Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    
        // Step 2: Creating the Window
        hwnd = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            g_szClassName,
            "Dont ask im just testing functions",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT, 800, 500,
            NULL, NULL, hInstance, NULL);
            HICON hMyIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
    
        if(hwnd == NULL)
        {
            MessageBox(NULL, "Window Creation Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
    
        // Step 3: The Message Loop
        while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        return Msg.wParam;
    }
    Here is my resource2.h file:

    Code:
    #define IDI_MYICON  101
    And here is my resource2.rc file:

    Code:
    #include "resource2.h"
    
    IDI_MYICON ICON "my_icon.ico"
    Ok i am trying to lode the icon "my_icon.ico", but it still has the dumb icon. whats wrong?
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  2. #2
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb Try this...

    While setting all the members of the Window Class, put this:

    wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: [email protected]

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  3. #3
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    Yes, SyntaxBubble is right. I command you to do as he says.
    And here's why he's right:

    Lean-mean-programming and design machine. I can do many pro things, but I'm just 14. If you don't like it deal with it. And, yes, I'm taken. If you want to know more about me, <a href="mailto:[email protected]">e-mail me</a>. And <a href="http://www.angelfire.com/exreme3/starfield">visit my web site, too.
    But that is how you do it? BTW Bubble, who are you taken by?

  4. #4
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    hmmm that didn't seem to work. does it work different for dev c++?
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  5. #5
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Post I have Dev-C++...

    I use Dev-C++. This is what mine looks like:

    wincl.hIcon = LoadIcon(hThisInstance, MAKEINTRESOURCE(500));

    In the resource edit I just did:

    500 ICON "C:/Dev-C++/Icon/File Management.ico"
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: [email protected]

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  6. #6
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    I used to have Dev C++ and it worked then. Do you have the right .lib's and .h's?

  7. #7
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269

    Unhappy

    uh-oh.......lib's?
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  8. #8
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    dunno, if you're using VC++ and when you started off you went to file, new, then under projects went to "Win32 Application", all the libs should be there.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  9. #9
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    ok then what are the right .lib's and .h's?
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  10. #10
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    no idea - I just let VC++ do all the libs and stuff for me
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  11. #11
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    Tisk tisk tisk, if you are using DirectX or other graphics libs or anything that VC++ doesn't include by default , VC++ doesn't include those libs automaticaly... Trust me, I know from experience.

  12. #12
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    SyntaxBubble is right: you need to put the full path to your icon file in the resource script for DevC++4. This is an idiosyncrasy of the IDE and not of the underlying compiler, MinGW; it has been rectified in the various Devc++5 beta releases so you can properly use relative paths in those versions.

    Generally, to attach an icon to a wnd set the hIcon paramater of the WNDLASSEX structure to the handle of your icon; you can also set the hIconSm parameter if you wish.

    Alternatively, after wnd creation you can send a WM_SETICON message to the window, eg:
    Code:
    SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)LoadIcon(hInst,MAKEINTRESOURCE(IDI_ICON));
    where IDI_ICON is your icon id. This latter technique is also good for dialog boxes.

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, 04:06 PM
  2. Getting at system Icon resources
    By Mastadex in forum Windows Programming
    Replies: 12
    Last Post: 06-29-2007, 09:19 AM
  3. resources with dev-c++
    By lambs4 in forum Windows Programming
    Replies: 0
    Last Post: 04-13-2003, 06:06 AM
  4. Icon problem
    By mkyong in forum Windows Programming
    Replies: 0
    Last Post: 02-17-2003, 05:39 PM
  5. icon in title bar?
    By Unregistered in forum Windows Programming
    Replies: 3
    Last Post: 12-12-2001, 06:43 PM