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