Cant change icons.

closed account (LAfSLyTq)
i followed this tutorial: http://www.winprog.org/tutorial/simple_window.html
and changing the icons wont work

here is my slightly changed code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <windows.h>
#include "resource.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:
            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         = LoadIcon(NULL, (LPCSTR) IDI_ICON1);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, (LPCSTR) IDI_ICON1);

    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,
        "HALO Mini - Made by TripDaRipper @ BleachGaming.tk",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 640, 420,
        NULL, NULL, hInstance, NULL);

    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;
}


if you are wondering why it says "HALO MINI" its because thats what first came to my mind

here is my program:
http://dl.dropbox.com/u/27086729/Pix/help.PNG
Last edited on
What icon? The window icon assinged to the WNDCLASSEX structure? Also note that LoadIcon() has been superseded. Use LoadImage() instead.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms648045(v=vs.85).aspx
closed account (LAfSLyTq)
wc.hIconSm = LoadIcon(NULL, (LPCSTR) IDI_ICON1);
line 42

and line 37
wc.hIcon = LoadIcon(NULL, (LPCSTR) IDI_ICON1);

see loadicon now?
oh, I saw. I just wasn't sure if you were talking about the icon for the window or the icon of the executable itself.

Did you read the documentation of LoadImage()? You should so you update your code to an updated function.

But if you didn't, you should at least read the LoadIcon()'s documentation (http://msdn.microsoft.com/en-us/library/windows/desktop/ms648072(v=vs.85).aspx ). It will tell you why your icon doesn't show up: Your first parameter is NULL. What does the documentation say about that? It says: If it is NULL then a system icon will be used. But I bet IDI_ICON1 doesn't really map to a valid system icon. Also note that you must not cast to an LPCSTR. You must use the MAKEINTRESOURCE macro. If the tutorial does this cast, well, it is one more black spot for it.
closed account (LAfSLyTq)
Thanks alot bro, this helped me very much, now my program looks like this.
http://dl.dropbox.com/u/27086729/Pix/icon.PNG

But do you know how i would change this?
http://dl.dropbox.com/u/27086729/Pix/lol.PNG
If I remember correctly, the icon for the EXE will be the first icon in the resource section with the lowest identifier number. Add your desired icon and give it the lowest ID. Recompile and see if it changes.
Last edited on
closed account (LAfSLyTq)
didnt work, thanks for the help youve already given me anyways though. if anyone else knows anything about this please help me.
Works OK for me. This is what I did, in Visual Studio 2010 Ultimate:

1. Opened a C++ solution containing a simple C++ project (no frameworks of any kind, just plain C++).
2. I had a Version resource, but no icon resources. So I added a new icon resource from an existing icon file. Visual Studio gave the icon the ID of IDI_ICON1 with a value of 101.
3. I recompiled. Now the executable shows the icon in Windows Explorer.
4. I added a second icon from a different icon file. Visual Studio assigned the resource identifier IDI_ICON2 with a value of 102.
5. I recompiled and as expected, the icon did not change.
6. In the Resource View of Visual Studio, I expanded the ICON subfolder to reveal two items: IDI_ICON1 and IDI_ICON2. I clicked the first one and went to the Properties window where I changed the ID from IDI_ICON1 to IDI_ICON2.
7. I selected the second item (IDI_ICON2) and went to the Properties window, where I changed the ID from IDI_ICON2 to IDI_ICON1. Now the second icon I added has the lowest resource ID (101).
8. I recompiled. Now Windows Explorer shows the new icon for the file.
closed account (LAfSLyTq)
thanks, you are awesome
Topic archived. No new replies allowed.