PROBLEMA [win32 Api C++]come Impostare Un Icona?

LightSoul94

Utente Attivo
256
16
Salve,
Vorrei impostare un icona al mio software.
Il compilatore che uso è Dev-C++ Bloodshield.
Ho scoperto che è possibile impostare un icona al programma andando su Progetto>Opzioni del Progetto e cliccando su "Sfoglia" selezionando l'immagine in formato *.ico che si desidera usare.

Premetto che ho spuntato la casella "Supporta temi di XP" perché non voglio richiamare il cmd ogni volta che eseguo il programma.

L'icona la legge il software, ma quando apro il programma il frame è senza icona. Ho dimenticato di fare qualcosa?

Vi posto la sorgente del programma che sto scrivendo:

C:
#include <windows.h>
/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    //wincl.hbrBackground = CreatePatternBrush( LoadBitmap( hThisInstance, MAKEINTRESOURCE(BACKGROUND) ) );

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Easy Must have Softwares downloader",       /* Title Text */
           WS_SYSMENU,              /* SYSMENU window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           436,                 /* The programs width */
           180,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}

#define ID_INFO 1
#define ID_ESCI 2
#define ID_WINRAR 3
#define ID_VLC 4
#define ID_ADOBE 5
#define ID_JAVA 6
#define ID_AVIRA 7

/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
            
        case WM_CREATE:{
         
             //*****Creates buttons*****
             CreateWindow(TEXT("BUTTON"), TEXT("WinRar"),
                WS_CHILD | WS_VISIBLE,
                10, 10, 80, 40,
                hwnd, (HMENU) ID_WINRAR, NULL, NULL
                );
            
                CreateWindow(TEXT("BUTTON"), TEXT("VLC"),
                WS_CHILD | WS_VISIBLE,
                130, 10, 80, 40,
                hwnd, (HMENU) ID_VLC, NULL, NULL
                );
            
                CreateWindow(TEXT("BUTTON"), TEXT("Adobe PDF Reader"),
                WS_CHILD | WS_VISIBLE,
                260, 10, 150, 40,
                hwnd, (HMENU) ID_ADOBE, NULL, NULL
                );
            
                CreateWindow(TEXT("BUTTON"), TEXT("Java"),
                WS_CHILD | WS_VISIBLE,
                10, 70, 80, 40,
                hwnd, (HMENU) ID_JAVA, NULL, NULL
                );
            
                CreateWindow(TEXT("BUTTON"), TEXT("Avira"),
                WS_CHILD | WS_VISIBLE,
                130, 70, 80, 40,
                hwnd, (HMENU) ID_AVIRA, NULL, NULL
                );
        
            //*****Code for top bar menu*****
        
            //initialize window segment functions
            HMENU hMenuBar = CreateMenu();
            HMENU hFile = CreateMenu();
            HMENU hEdit = CreateMenu();
            HMENU hOption = CreateMenu();
        
            AppendMenu(hMenuBar, MF_POPUP, (UINT_PTR)hFile, "File");
            AppendMenu(hMenuBar, MF_POPUP, (UINT_PTR)hOption, "?");
        
            AppendMenu(hFile, MF_STRING, ID_ESCI, "Esci");
            AppendMenu(hOption, MF_STRING, ID_INFO, "Info");
        
            SetMenu(hwnd, hMenuBar);
        
        
            break;
        }
 
        case WM_COMMAND: {
         
             if(LOWORD(wParam) == ID_INFO){
                 MessageBox(hwnd, "Prodotto da: Gianluca Caliendo \n Versione: alpha 1.0", "Info", MB_ICONINFORMATION);          
                 }
             
             if(LOWORD(wParam) == ID_ESCI){
                 exit (0);
                 }
            
             //provides a responding message to said button above
             if(LOWORD(wParam) == ID_WINRAR){
              
                  char* linkChar="https://www.winrar.it/prelievo_ok.php?url=prelievo/WRar540it.exe";
                  ShellExecute(NULL, NULL, linkChar, NULL, NULL, SW_SHOWNORMAL);
             }
             if(LOWORD(wParam) == ID_VLC){
                  char* linkChar="http://ftp.rezopole.net/vlc/vlc/2.2.4/win32/vlc-2.2.4-win32.exe";
                  ShellExecute(NULL, NULL, linkChar, NULL, NULL, SW_SHOWNORMAL);
             }
             if(LOWORD(wParam) == ID_ADOBE){
                  char* linkChar="https://get.adobe.com/it/reader/download/?installer=Reader_DC_2015.020.20039_for_Mac_Intel&stype=2727&standalone=1";
                  ShellExecute(NULL, NULL, linkChar, NULL, NULL, SW_SHOWNORMAL);
             }
             if(LOWORD(wParam) == ID_JAVA){
                  char* linkChar="https://www.java.com/inc/BrowserRedirect1.jsp?locale=it";
                  ShellExecute(NULL, NULL, linkChar, NULL, NULL, SW_SHOWNORMAL);
             }
             if(LOWORD(wParam) == ID_AVIRA){
                  char* linkChar="https://package.avira.com/package/oeavira/win/int/avira_it_fass0_580a665e89dd5__ws.exe";
                  ShellExecute(NULL, NULL, linkChar, NULL, NULL, SW_SHOWNORMAL);
             }
         
             break;
        }
    
         
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}
 
Ultima modifica:

Entra

oppure Accedi utilizzando
Discord Ufficiale Entra ora!