Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    [C++] Problema con apertura Dialogbox

    Ciao a tutti! Devo sviluppare un prgramma GUI con c++ e ho iniziato a stendere il codiece per le cose più semplici, ma mi si è già presentato un problma.
    Ho questi file di resource:
    resource.rc
    codice:
    #include "resource.h"
    #include "windows.h"
    
    ID_MENU MENU
    BEGIN
         POPUP "&File"
         BEGIN
              MENUITEM "&Apri...", ID_APRI
              MENUITEM "&Esci", ID_ESCI
         END
         POPUP "&Informazioni"
         BEGIN
              MENUITEM "A&bout", ID_ABOUT
         END
    END
    
    IDD_ABOUT DIALOG DISCARDABLE  0, 0, 239, 66
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "Informazioni su..."
    FONT 8, "MS Sans Serif"
    BEGIN
        DEFPUSHBUTTON   "&OK",IDOK,174,18,50,14
        GROUPBOX        "Informazioni su...",-1,7,7,225,52
        CTEXT           "Un esempio di Finestre",-1,16,18,144,33
    END
    e resource.h
    codice:
    #define ID_MENU 101
    #define ID_DIALOG_ABOUT 102
    
    #define ID_APRI 1001
    #define ID_ESCI 1002
    #define ID_ABOUT 1011
    e fin qui tutto bene, il problema si presenta quando tento di aprire il dialog: ecco il codice
    codice:
    #include <windows.h>
    #include "resource.h"
    
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    BOOL CALLBACK AboutDlgProc(HWND, UINT, WPARAM,LPARAM);
    
    char *szClassName = "NomeClasse";
    
    int WINAPI WinMain (HINSTANCE hInstance,
                        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 = hInstance;
        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 = MAKEINTRESOURCE(ID_MENU);                 /* 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_MENU;
    
        /* Register the window class, and if it fails quit the program */
        if (!RegisterClassEx (&wincl))
            exit(EXIT_FAILURE);
    
        /* The class is registered, let's create the program*/
        hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "TitoloApp",       /* Title Text */
               WS_OVERLAPPED|WS_MINIMIZEBOX|WS_CAPTION|WS_SYSMENU, /* Windows style */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               544,                 /* The programs width */
               375,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
    
        /* Make the window visible on the screen */
        ShowWindow (hwnd, SW_SHOW);
    
        /* 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;
    }
    
    
    /*  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_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                break;
            case WM_COMMAND:
                switch(wParam)
                {
                    case ID_ESCI:
                         PostQuitMessage (0);
                         break;
                    case ID_ABOUT:
                         int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_DIALOG_ABOUT), hwnd, AboutDlgProc);
                         if(ret == -1)
                         MessageBox(NULL,"Impossibile caricare file","Errore",NULL);
                         break;
                }
                 break;
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }
    
    BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
         switch(message)
         {
            case WM_INITDIALOG:
                 return true;
                 break;
            case WM_COMMAND:
                 switch(LOWORD(wParam))
                 {
                    case IDOK:
                        EndDialog(hwnd, IDOK);
                    break;
                 }
                 break;
            default:
                 return false;
         }
         return true;
    }
    Ho notato che la funzione DialogBox ritorna -1, ma non capisco dove sia l'errore... Ogni suggerimento è ben accetto

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,466
    Cerca di comprendere qual e' l'errore effettivo chiamando la GetLasterror subito dopo la DialogBox.

  3. #3
    Inanzi tutto grazie dell'aiuto, ho modificato così:
    codice:
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  /* handle the messages */
        {
            case WM_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                break;
            case WM_COMMAND:
                switch(wParam)
                {
                    case ID_ESCI:
                         PostQuitMessage (0);
                         break;
                    case ID_ABOUT:
                         int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_DIALOG_ABOUT), hwnd, AboutDlgProc);
                         if(ret == -1)
                         {
                                DWORD error;
                                error = GetLastError();
                                char *err = (char*)malloc(sizeof(char)*100);
                                itoa(error,err,10);
                                MessageBox(NULL,err,"Errore",32);
                         }
                         break;
                }
                 break;
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }
    Il numero di errore è 1814 e cercando su msdn mi dice che è un errore SQL: Queries of this type are not supported (Error 1814)... credo ci sia qualcosa che non va...

  4. #4
    Risolto sono un tonno, mancava un _ in una costante

  5. #5
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,466
    Ok ... ma l'errore era

    1814
    The specified resource name cannot be found in the image file. ERROR_RESOURCE_NAME_NOT_FOUND

    Devi cercare tra gli errori Win32 non tra quelli di SQL

  6. #6
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,254
    Il numero di errore è 1814 e cercando su msdn mi dice che è un errore SQL: Queries of this type are not supported (Error 1814)... credo ci sia qualcosa che non va...
    No, 1814 è l'errore ERROR_RESOURCE_NAME_NOT_FOUND (lo trovi nell'header winerror.h). Tradotto ... "nome risorsa non trovato".
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    Java Versions Cheat Sheet

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.