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 88 89 90 91 92
| // ProjTuto.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
struct memoire_dialog
{
int toto;
};
//Attention, si cette taille n'est pas assez grande, le comportement est indéfini
//Pour bien faire, il faudrait allouer dynamiquement le buffer.
//Peut-être pour une prochaîne leçon...
#define COMBOBOX_BUFFER_SIZE 80
BOOL HandleWmCommand(HWND hWnd, WORD controlId, WORD notifyCode, HWND hControl)
{
BOOL ret = TRUE;
switch(controlId)
{
case IDOK:
EndDialog(hWnd, 42);
break;
case IDCANCEL:
EndDialog(hWnd, 0);
break;
case IDC_BUTTON1:
{
LRESULT index = SendDlgItemMessage(hWnd, IDC_COMBO1, CB_GETCURSEL, 0, 0);
if(index==CB_ERR)
MessageBox(hWnd, TEXT("Rien n'est sélectionné!"), NULL, MB_OK);
else
{
TCHAR buf[COMBOBOX_BUFFER_SIZE] = TEXT("");
SendDlgItemMessage(hWnd, IDC_COMBO1, CB_GETLBTEXT, index, (LPARAM)buf);
ShellExecute(hWnd, TEXT("open"), buf, NULL, NULL, SW_SHOWNORMAL);
}
}
break;
default:
ret = FALSE;
}
return ret;
}
//Note: devrait être INT_PTR, mais Visual 6 le déclare comme long.
BOOL CALLBACK TutoDialogProc(
HWND hWnd, //[in] Handle de fenêtre de la boîte de dialogue
UINT uMessage, //[in] N° de message.
WPARAM wParam, //[in] Valeur dépendante du message
LPARAM lParam //[in] Valeur dépendante du message
) //Retourne TRUE si la fonction a traité elle-même le message.
{
INT_PTR ret = TRUE;
struct memoire_dialog *pMem = (struct memoire_dialog *)GetWindowLongPtr(hWnd, DWLP_USER);
switch(uMessage)
{
//Construction et destruction
case WM_INITDIALOG:
pMem = (struct memoire_dialog *)malloc(sizeof *pMem);
SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)pMem);
SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)TEXT("http://www.developpez.net/forums/"));
SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)TEXT("http://www.developpez.com/"));
SendDlgItemMessage(hWnd, IDC_COMBO1, CB_SETCURSEL, 1, 0);
break;
case WM_NCDESTROY:
free(pMem);
pMem = NULL;
SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)pMem);
break;
case WM_COMMAND: //Clic sur un bouton
ret = HandleWmCommand(hWnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam);
break;
default:
//Indique qu'on n'a pas traité le message,
//il faut donc que le système le fasse pour nous.
ret = FALSE;
}
return ret;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
int ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, TutoDialogProc, 0);
return ret;
} |