How do i change my icon?

Pages: 12
May 19, 2012 at 11:03pm
closed account (LAfSLyTq)
I want to change the icon of my Win32 program, but i have no idea how to, im guessing i have to get a rousource file which my program did not start with, how do i fix this? i just want tochange the icon.
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
78
79
80
81
82
83
84
85
86
87
#include <windows.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_LBUTTONDOWN:
// BEGIN NEW CODE
        {
            char szFileName[MAX_PATH];
            HINSTANCE hInstance = GetModuleHandle(NULL);

            GetModuleFileName(hInstance, szFileName, MAX_PATH);
            MessageBox(hwnd, szFileName, "This program is:", MB_OK | MB_ICONINFORMATION);
        }
// END NEW CODE
        break;
        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, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    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,
        "Section 13 - 2D Demo",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
        NULL, NULL, hInstance, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, "Windows 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;
}
Last edited on May 19, 2012 at 11:20pm
May 19, 2012 at 11:20pm
closed account (LAfSLyTq)
please help
May 20, 2012 at 2:52am
May 20, 2012 at 3:23am
Just supply an appropiate handle to hIcon and hIconSm members of WNDCLASSEX structure. The handle can be obtained from LoadIcon() or from LoadImage().
May 20, 2012 at 7:52am
I can see your code is calling LoadIcon with IDI_APPLICATION, so...

If you just want to change the icon your app always uses, then you just have to edit your exisiting .rc file so IDI_APPLICATION identifies your new icon file. You will find a line like

IDI_APPLICATION ICON "filename.ico"

or

IDI_APPLICATION ICON "resource files\filename.ico"

Or, having found out which file IDI_APPLICATION identifies, you could just replace the .ico file (I would use this approach if the file has a generic name, like app.ico)

Then you just have to rebuild the .rc file and relink.

Or do you want to replace the icon while the app is running?

Andy

Last edited on May 20, 2012 at 7:54am
May 22, 2012 at 1:04am
closed account (LAfSLyTq)
i dont think you guys are understanding me, i have no resource.h file, so where am i supposed to add "IDI_APPLICATION ICON "filename.ico"" ?
May 22, 2012 at 2:37am
closed account (LAfSLyTq)
help>?
May 22, 2012 at 10:53am
May 22, 2012 at 1:23pm
i dont think you guys are understanding me, i have no resource.h file, so where am i supposed to add "IDI_APPLICATION ICON "filename.ico"" ?
How about looking at the link I posted for you. Use it to change your application's icon the easiest, most complete way possible, without having to dink with resource files and linking and the like.
May 22, 2012 at 6:07pm
closed account (LAfSLyTq)
im not using the link you provided because that is not legitimate. i dont need that program to do anything, everything i need should be provided with visual basic.

edit: studios*
Last edited on May 22, 2012 at 8:14pm
May 22, 2012 at 6:13pm
closed account (LAfSLyTq)
@coder777 this im sorry to say, didnt help me...
May 22, 2012 at 6:58pm
im not using the link you provided because that is not legitimate.

What? You ask how to do something and then reject an answer because it is "not legitimate". Bull crap. More like 'it is too easy'.

i dont need that program to do anything,

"that program" does exactly what you asked for: "I want to change the icon of my Win32 program, but i have no idea how to". It is the reason it exists, and is still on the net due to demand by developers who know what they are doing.

everything i need should be provided with visual basic.

Perhaps your problem is that you don't have a clue what language you are using. When you figure that out maybe it'll get easier. Hint: the IDE project options might help.

Because of your idiot attitude you've just made my ignore list. Good luck with everyone else. (Hint: most competent programmers don't have time to humor snotty attitudes.)
May 22, 2012 at 8:13pm
closed account (LAfSLyTq)
i meant visual studios, and i do know what programming language i am using retard. its obvious.
May 22, 2012 at 10:12pm
closed account (z05DSL3A)
Hmm, calling Duoas a retard...that'll get you a lot of help.

If you give more information, what version of VS you are using, what project type you started with, etc. then people will not have to play guessing games with you and there will be less stress all-round.
May 22, 2012 at 10:41pm
closed account (LAfSLyTq)
Visual studio 2010
Empty Project under Visual C++ Category
May 23, 2012 at 2:26am
closed account (LAfSLyTq)
help please
May 23, 2012 at 8:20am
closed account (z05DSL3A)
Look in the Solution Explorer. (if needed expand the tree)
Right click on the project name and in the context menu and navigate to
add->Resource...

in the add rescue dialog box either select Icon and click new (if you are drawing your own) or select Import... if you have an .ico file you want to use.

If you select import, change the file type to Icon file (.ico) and locate your icon file and click open.

Most of the work will now be done for you (adding resource.h, an RC file connecting them up in the project...)

Now go back to your main cpp file and add #include "resource.h" to it and change
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); to
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIcon = LoadIcon(NULL, (LPCSTR) IDI_ICON1);

and that should work.

P.S. if you get stuck at any point along the way, use the lost art of pressing F1 for help.


May 25, 2012 at 9:10pm
closed account (LAfSLyTq)
Thanks, this helped me with making resources, but now theres is another problem and the F1 button leads me to "This page does not exist" sooooo yea....

it displays my window for the program just fine, but the icon is all of a sudden a triangle exclamation mark... and im still using the default icon... ._. help?
May 27, 2012 at 8:38pm
closed account (LAfSLyTq)
Here is my 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, IDI_APPLICATION);
    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;
}
May 27, 2012 at 11:13pm
closed account (LAfSLyTq)
help please
Pages: 12