|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
[WIN32] PETIT RÉPERTOIRE TÉLÉPHONIQUE ET AUTRES (GESTION LISTVIEW)
Information sur la source
Description
Bonjour à tous. Bon, voilà une petite appli tout "bête". Elle permet d'enregistrer les coordonnées de ses contacts dans un tableau (graphique). Ça existe déjà, je sais. Alors quel intérêt ? - Personnellement, j'avais besoin d'un outil de ce genre, sans vouloir me prendre la tête avec de grosses artilleries comme "Excel" ou les Gestions de bases de données (de plus, je ne me sers pas de 90% de leurs fonctions). - Très petit (l'exécutable fait 46ko (à titre d'exemple, le bloc-note de Windows en fait 69, je crois). - Exemple d'utilisation de listview, d'une part pour moi, puis pour ceux qui seront intéressés. - Besoin d'aucun module extérieur, seul l'exécutable suffit. - Utilisation très simple quoi, clics et double-clics. Codé sous Code::Blocks. Il y a une aide pour l'utilisation, mais je l'explique dans la partie "conclusion".
Source
- #define _WIN32_IE 0x0700
- #include <windows.h>
- #include <commctrl.h>
- #include <stdio.h>
- #include <math.h>
-
- #define HDF_SORTUP 0x0400
- #define HDF_SORTDOWN 0x0200
- //Variables globales et prototypes
- HINSTANCE hinst;
- LRESULT CALLBACK MainWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
- int start=1,grid=1,modif=0;
- HWND hwnd,ListView,hTTip,save,load,hLVHeader,add,supp,aide,about;
- HMENU hMenu;
- #include "define.h"
- //Déclaration de la fenêtre
- int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) {
- //Verification que le programme n'est pas déjà ouvert
- if (FindWindow(0,"Repertoire") != 0) {
- MessageBox(0,"Une application Repertoire est déjà en cours.\t\n"
- "Vous ne pouvez pas ouvrir deux fois cette même application.\t\n","Repertoire - Erreur",MB_OK|MB_ICONERROR);
- return 0;
- }
- //Variables
- MSG msg;
- hinst=hinstance;
- //Paramètres de la fenêtre
- WNDCLASS wc;
- wc.style=0;
- wc.lpfnWndProc=MainWndProc;
- wc.cbClsExtra=0;
- wc.cbWndExtra=0;
- wc.hInstance=hinstance;
- wc.hIcon=LoadIcon(hinstance,MAKEINTRESOURCE(1));
- wc.hCursor=LoadCursor(NULL,IDC_ARROW);
- wc.hbrBackground=(HBRUSH)(COLOR_3DFACE+1);
- wc.lpszMenuName=0;
- wc.lpszClassName="MaWinClass";
- if(!RegisterClass(&wc)) return FALSE;
- //Création de la fenêtre
- int cxS=GetSystemMetrics(SM_CXSCREEN);
- int cyS=GetSystemMetrics(SM_CYSCREEN);
- InitMenus();
- hwnd=CreateWindowEx(WS_EX_WINDOWEDGE,"MaWinClass","Repertoire",WS_CLIPCHILDREN|WS_OVERLAPPEDWINDOW,(cxS-700)/2,(cyS-350)/2,260,350,HWND_DESKTOP,hMenu,hinstance,NULL);
- //Mise en place des contrôles
- add=CreateWindowEx(0,"BUTTON","Ajouter...",BS_DEFPUSHBUTTON|WS_CHILD|WS_VISIBLE,0,0,0,0,hwnd,(HMENU)ID_AJOUTER,hinstance,NULL);
- SendMessage(add,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
- supp=CreateWindowEx(0,"BUTTON","Supprimer",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE|WS_DISABLED,0,0,0,0,hwnd,(HMENU)ID_SUPPRIMER,hinstance,NULL);
- SendMessage(supp,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
- save=CreateWindowEx(0,"BUTTON","Enregistrer",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,0,0,0,0,hwnd,(HMENU)ID_ENREGISTRER,hinstance,NULL);
- SendMessage(save,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
- about=CreateWindowEx(0,"BUTTON","©",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,0,0,0,0,hwnd,(HMENU)ID_ABOUT,hinstance,NULL);
- SendMessage(about,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
- aide=CreateWindowEx(0,"BUTTON","?",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,0,0,0,0,hwnd,(HMENU)ID_AIDE,hinstance,NULL);
- SendMessage(aide,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
-
- InitListView();
- EnableMenuItem((HMENU)MAKEINTRESOURCE("LEMNU"),ID_SUPPRIMER,MF_GRAYED);
- //Création des Tooltips
- TOOLINFO ti;
- RECT rect;
- hTTip=CreateWindow(TOOLTIPS_CLASS,NULL,WS_POPUP|TTS_NOPREFIX,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,hwnd,NULL,hinstance,NULL);
- GetClientRect(hwnd,&rect);
- ti.cbSize=sizeof(TOOLINFO);
- ti.uFlags=TTF_SUBCLASS;
- GetClientRect(hwnd,&rect);
- for(int a=1;a <= 10;a++) {
- ti.hwnd=GetDlgItem(hwnd,a);
- ti.uId=0;
- if (a == ID_LISTVIEW)
- ti.lpszText="Repertoire de contacts";
- else if (a == ID_ENREGISTRER)
- ti.lpszText="Enregistrer les contacts";
- else if (a == ID_CHARGER)
- ti.lpszText="Charger une liste de contacts";
- else if (a == ID_AJOUTER)
- ti.lpszText="Ajouter un contact";
- else if (a == ID_SUPPRIMER)
- ti.lpszText="Supprimer le contact";
- else if (a == ID_ABOUT)
- ti.lpszText="Afficher les copyrights du logiciel";
- else
- ti.lpszText="";
- ti.rect.left=rect.left;
- ti.rect.top=rect.top;
- ti.rect.right=rect.right;
- ti.rect.bottom=rect.bottom;
- SendMessage(hTTip,TTM_ADDTOOL,0,(LPARAM)&ti);
- }
- InitListe();
- //Affichage du programme
- if (!hwnd) return FALSE;
- ShowWindow(hwnd,nCmdShow);
- while (GetMessage(&msg,NULL,0,0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
- //Fonction d'appel
- LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
- LPNMLISTVIEW pnmv;
- HDITEM hdi;
- EnableWindow(save,(modif)?TRUE:FALSE);
- EnableMenuItem(hMenu,ID_ENREGISTRER,(modif)?MF_ENABLED:MF_GRAYED);
- switch (uMsg) {
- case WM_CLOSE:
- VerifSave();
- break;
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case 102:
- VerifSave();
- break;
- case 103:
- if (GetMenuState(hMenu,104,MF_BYCOMMAND) == MF_UNCHECKED) {
- nSort=HDF_SORTUP;
- hdi.fmt&=~HDF_SORTDOWN;
- hdi.fmt|=HDF_SORTUP;
- Header_SetItem(hLVHeader,SUBITEM,&hdi);
- ListView_SortItems(ListView,lpCompareFunctions[nSelectedColumn],0);
- CheckMenuItem(hMenu,104,MF_UNCHECKED);
- CheckMenuItem(hMenu,103,MF_CHECKED);
- }
- break;
- case 104:
- if (GetMenuState(hMenu,104,MF_BYCOMMAND) == MF_UNCHECKED) {
- nSort=HDF_SORTDOWN;
- hdi.fmt&=~HDF_SORTUP;
- hdi.fmt|=HDF_SORTDOWN;
- Header_SetItem(hLVHeader,SUBITEM,&hdi);
- ListView_SortItems(ListView,lpCompareFunctions[nSelectedColumn],0);
- CheckMenuItem(hMenu,103,MF_UNCHECKED);
- CheckMenuItem(hMenu,104,MF_CHECKED);
- }
- break;
- case 105:
- SendMessage(ListView,LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_GRIDLINES,(grid)?~LVS_EX_GRIDLINES:LVS_EX_GRIDLINES);
- CheckMenuItem(hMenu,105,(grid)?MF_UNCHECKED:MF_CHECKED);
- grid=(grid)?0:1;
- break;
- case 106:
- if (MessageBox(hwnd,"Etes-vous sûr(e) de vouloir supprimer tous les contacts ?\t\n",
- "Avertissement",MB_ICONINFORMATION|MB_YESNO) == IDYES) {
- ListView_DeleteAllItems(ListView);
- modif=1;
- }
- break;
- case ID_AJOUTER:
- DialogBox(hinst,"AjoutBox",hwnd,(DLGPROC)DialogProc1);
- break;
- case ID_SUPPRIMER:
- if (MessageBox(hwnd,"Etes-vous sûr(e) de vouloir supprimer ce contact ?\t\n",
- "Avertissement",MB_ICONINFORMATION|MB_YESNO) == IDYES) {
- ListView_DeleteItem(ListView,ITEM);
- EnableWindow(supp,FALSE);
- EnableMenuItem(hMenu,ID_SUPPRIMER,MF_GRAYED);
- modif=1;
- }
- break;
- case ID_ENREGISTRER:
- Save();
- break;
- case ID_AIDE:
- MessageBox(hwnd,Help,"Aide du logiciel",MB_OK|MB_ICONQUESTION);
- break;
- case ID_ABOUT:
- MessageBox(hwnd,"- Repertoire -\nLogiciel pour garder en mémoire les coordonnées de ses ami(e)s\t\n(copyrights © WINKEL Vincent)\t\n",
- "A propos...",MB_OK|MB_ICONASTERISK);
- break;
- }
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- case WM_SIZE:
- int cX=LOWORD(lParam)+1;
- int cY=HIWORD(lParam);
- MoveWindow(ListView,0,0,cX,cY-24,TRUE);
- MoveWindow(add,2,cY-22,70,20,TRUE);
- MoveWindow(supp,72,cY-22,70,20,TRUE);
- MoveWindow(save,142,cY-22,70,20,TRUE);
- MoveWindow(aide,225,cY-22,25,20,TRUE);
- break;
- case WM_SIZING:
- RECT* wndRect=(RECT*)lParam;
- int cXp=wndRect->right-wndRect->left;
- int cYp=wndRect->bottom-wndRect->top;
- if (cXp < 260) wndRect->right=260+wndRect->left;
- if (cYp < 350) wndRect->bottom=350+wndRect->top;
- break;
- case WM_NOTIFY:
- if ((((LPNMHDR)lParam)->hwndFrom) == ListView) {
- if ((((LPNMHDR)lParam)->code) == NM_CLICK) {
- LPNMITEMACTIVATE lpnmitem=(LPNMITEMACTIVATE)lParam;
- ITEM=lpnmitem->iItem;
- EnableWindow(supp,(ITEM != -1)?TRUE:FALSE);
- EnableMenuItem(hMenu,ID_SUPPRIMER,(ITEM != -1)?MF_ENABLED:MF_GRAYED);
- }
- if ((((LPNMHDR)lParam)->code) == NM_DBLCLK) {
- LPNMITEMACTIVATE lpnmitem=(LPNMITEMACTIVATE)lParam;
- ITEM=lpnmitem->iItem;
- SUBITEM=lpnmitem->iSubItem;
- if (ITEM == -1)
- break;
- DialogBox(hinst,"InsertBox",hwnd,(DLGPROC)DialogProc);
- break;
- }
- if ((((LPNMHDR)lParam)->code) == LVN_COLUMNCLICK) {
- pnmv=(LPNMLISTVIEW)lParam;
- hdi.mask=HDI_FORMAT;
- Header_GetItem(hLVHeader,pnmv->iSubItem,&hdi);
- if(pnmv->iSubItem > 0)
- return 0;
- if(nSelectedColumn == pnmv->iSubItem) {
- if(nSort == HDF_SORTDOWN) {
- nSort=HDF_SORTUP;
- hdi.fmt&=~HDF_SORTDOWN;
- hdi.fmt|=HDF_SORTUP;
- }
- else {
- nSort=HDF_SORTDOWN;
- hdi.fmt&=~HDF_SORTUP;
- hdi.fmt|=HDF_SORTDOWN;
- }
- Header_SetItem(hLVHeader,pnmv->iSubItem,&hdi);
- }
- ListView_SortItems(ListView,lpCompareFunctions[nSelectedColumn],0);
- break;
- }
- }
- default:
- return DefWindowProc(hwnd,uMsg,wParam,lParam);
- }
- }
#define _WIN32_IE 0x0700
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include <math.h>
#define HDF_SORTUP 0x0400
#define HDF_SORTDOWN 0x0200
//Variables globales et prototypes
HINSTANCE hinst;
LRESULT CALLBACK MainWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
int start=1,grid=1,modif=0;
HWND hwnd,ListView,hTTip,save,load,hLVHeader,add,supp,aide,about;
HMENU hMenu;
#include "define.h"
//Déclaration de la fenêtre
int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) {
//Verification que le programme n'est pas déjà ouvert
if (FindWindow(0,"Repertoire") != 0) {
MessageBox(0,"Une application Repertoire est déjà en cours.\t\n"
"Vous ne pouvez pas ouvrir deux fois cette même application.\t\n","Repertoire - Erreur",MB_OK|MB_ICONERROR);
return 0;
}
//Variables
MSG msg;
hinst=hinstance;
//Paramètres de la fenêtre
WNDCLASS wc;
wc.style=0;
wc.lpfnWndProc=MainWndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hinstance;
wc.hIcon=LoadIcon(hinstance,MAKEINTRESOURCE(1));
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)(COLOR_3DFACE+1);
wc.lpszMenuName=0;
wc.lpszClassName="MaWinClass";
if(!RegisterClass(&wc)) return FALSE;
//Création de la fenêtre
int cxS=GetSystemMetrics(SM_CXSCREEN);
int cyS=GetSystemMetrics(SM_CYSCREEN);
InitMenus();
hwnd=CreateWindowEx(WS_EX_WINDOWEDGE,"MaWinClass","Repertoire",WS_CLIPCHILDREN|WS_OVERLAPPEDWINDOW,(cxS-700)/2,(cyS-350)/2,260,350,HWND_DESKTOP,hMenu,hinstance,NULL);
//Mise en place des contrôles
add=CreateWindowEx(0,"BUTTON","Ajouter...",BS_DEFPUSHBUTTON|WS_CHILD|WS_VISIBLE,0,0,0,0,hwnd,(HMENU)ID_AJOUTER,hinstance,NULL);
SendMessage(add,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
supp=CreateWindowEx(0,"BUTTON","Supprimer",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE|WS_DISABLED,0,0,0,0,hwnd,(HMENU)ID_SUPPRIMER,hinstance,NULL);
SendMessage(supp,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
save=CreateWindowEx(0,"BUTTON","Enregistrer",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,0,0,0,0,hwnd,(HMENU)ID_ENREGISTRER,hinstance,NULL);
SendMessage(save,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
about=CreateWindowEx(0,"BUTTON","©",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,0,0,0,0,hwnd,(HMENU)ID_ABOUT,hinstance,NULL);
SendMessage(about,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
aide=CreateWindowEx(0,"BUTTON","?",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,0,0,0,0,hwnd,(HMENU)ID_AIDE,hinstance,NULL);
SendMessage(aide,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
InitListView();
EnableMenuItem((HMENU)MAKEINTRESOURCE("LEMNU"),ID_SUPPRIMER,MF_GRAYED);
//Création des Tooltips
TOOLINFO ti;
RECT rect;
hTTip=CreateWindow(TOOLTIPS_CLASS,NULL,WS_POPUP|TTS_NOPREFIX,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,hwnd,NULL,hinstance,NULL);
GetClientRect(hwnd,&rect);
ti.cbSize=sizeof(TOOLINFO);
ti.uFlags=TTF_SUBCLASS;
GetClientRect(hwnd,&rect);
for(int a=1;a <= 10;a++) {
ti.hwnd=GetDlgItem(hwnd,a);
ti.uId=0;
if (a == ID_LISTVIEW)
ti.lpszText="Repertoire de contacts";
else if (a == ID_ENREGISTRER)
ti.lpszText="Enregistrer les contacts";
else if (a == ID_CHARGER)
ti.lpszText="Charger une liste de contacts";
else if (a == ID_AJOUTER)
ti.lpszText="Ajouter un contact";
else if (a == ID_SUPPRIMER)
ti.lpszText="Supprimer le contact";
else if (a == ID_ABOUT)
ti.lpszText="Afficher les copyrights du logiciel";
else
ti.lpszText="";
ti.rect.left=rect.left;
ti.rect.top=rect.top;
ti.rect.right=rect.right;
ti.rect.bottom=rect.bottom;
SendMessage(hTTip,TTM_ADDTOOL,0,(LPARAM)&ti);
}
InitListe();
//Affichage du programme
if (!hwnd) return FALSE;
ShowWindow(hwnd,nCmdShow);
while (GetMessage(&msg,NULL,0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//Fonction d'appel
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
LPNMLISTVIEW pnmv;
HDITEM hdi;
EnableWindow(save,(modif)?TRUE:FALSE);
EnableMenuItem(hMenu,ID_ENREGISTRER,(modif)?MF_ENABLED:MF_GRAYED);
switch (uMsg) {
case WM_CLOSE:
VerifSave();
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case 102:
VerifSave();
break;
case 103:
if (GetMenuState(hMenu,104,MF_BYCOMMAND) == MF_UNCHECKED) {
nSort=HDF_SORTUP;
hdi.fmt&=~HDF_SORTDOWN;
hdi.fmt|=HDF_SORTUP;
Header_SetItem(hLVHeader,SUBITEM,&hdi);
ListView_SortItems(ListView,lpCompareFunctions[nSelectedColumn],0);
CheckMenuItem(hMenu,104,MF_UNCHECKED);
CheckMenuItem(hMenu,103,MF_CHECKED);
}
break;
case 104:
if (GetMenuState(hMenu,104,MF_BYCOMMAND) == MF_UNCHECKED) {
nSort=HDF_SORTDOWN;
hdi.fmt&=~HDF_SORTUP;
hdi.fmt|=HDF_SORTDOWN;
Header_SetItem(hLVHeader,SUBITEM,&hdi);
ListView_SortItems(ListView,lpCompareFunctions[nSelectedColumn],0);
CheckMenuItem(hMenu,103,MF_UNCHECKED);
CheckMenuItem(hMenu,104,MF_CHECKED);
}
break;
case 105:
SendMessage(ListView,LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_GRIDLINES,(grid)?~LVS_EX_GRIDLINES:LVS_EX_GRIDLINES);
CheckMenuItem(hMenu,105,(grid)?MF_UNCHECKED:MF_CHECKED);
grid=(grid)?0:1;
break;
case 106:
if (MessageBox(hwnd,"Etes-vous sûr(e) de vouloir supprimer tous les contacts ?\t\n",
"Avertissement",MB_ICONINFORMATION|MB_YESNO) == IDYES) {
ListView_DeleteAllItems(ListView);
modif=1;
}
break;
case ID_AJOUTER:
DialogBox(hinst,"AjoutBox",hwnd,(DLGPROC)DialogProc1);
break;
case ID_SUPPRIMER:
if (MessageBox(hwnd,"Etes-vous sûr(e) de vouloir supprimer ce contact ?\t\n",
"Avertissement",MB_ICONINFORMATION|MB_YESNO) == IDYES) {
ListView_DeleteItem(ListView,ITEM);
EnableWindow(supp,FALSE);
EnableMenuItem(hMenu,ID_SUPPRIMER,MF_GRAYED);
modif=1;
}
break;
case ID_ENREGISTRER:
Save();
break;
case ID_AIDE:
MessageBox(hwnd,Help,"Aide du logiciel",MB_OK|MB_ICONQUESTION);
break;
case ID_ABOUT:
MessageBox(hwnd,"- Repertoire -\nLogiciel pour garder en mémoire les coordonnées de ses ami(e)s\t\n(copyrights © WINKEL Vincent)\t\n",
"A propos...",MB_OK|MB_ICONASTERISK);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_SIZE:
int cX=LOWORD(lParam)+1;
int cY=HIWORD(lParam);
MoveWindow(ListView,0,0,cX,cY-24,TRUE);
MoveWindow(add,2,cY-22,70,20,TRUE);
MoveWindow(supp,72,cY-22,70,20,TRUE);
MoveWindow(save,142,cY-22,70,20,TRUE);
MoveWindow(aide,225,cY-22,25,20,TRUE);
break;
case WM_SIZING:
RECT* wndRect=(RECT*)lParam;
int cXp=wndRect->right-wndRect->left;
int cYp=wndRect->bottom-wndRect->top;
if (cXp < 260) wndRect->right=260+wndRect->left;
if (cYp < 350) wndRect->bottom=350+wndRect->top;
break;
case WM_NOTIFY:
if ((((LPNMHDR)lParam)->hwndFrom) == ListView) {
if ((((LPNMHDR)lParam)->code) == NM_CLICK) {
LPNMITEMACTIVATE lpnmitem=(LPNMITEMACTIVATE)lParam;
ITEM=lpnmitem->iItem;
EnableWindow(supp,(ITEM != -1)?TRUE:FALSE);
EnableMenuItem(hMenu,ID_SUPPRIMER,(ITEM != -1)?MF_ENABLED:MF_GRAYED);
}
if ((((LPNMHDR)lParam)->code) == NM_DBLCLK) {
LPNMITEMACTIVATE lpnmitem=(LPNMITEMACTIVATE)lParam;
ITEM=lpnmitem->iItem;
SUBITEM=lpnmitem->iSubItem;
if (ITEM == -1)
break;
DialogBox(hinst,"InsertBox",hwnd,(DLGPROC)DialogProc);
break;
}
if ((((LPNMHDR)lParam)->code) == LVN_COLUMNCLICK) {
pnmv=(LPNMLISTVIEW)lParam;
hdi.mask=HDI_FORMAT;
Header_GetItem(hLVHeader,pnmv->iSubItem,&hdi);
if(pnmv->iSubItem > 0)
return 0;
if(nSelectedColumn == pnmv->iSubItem) {
if(nSort == HDF_SORTDOWN) {
nSort=HDF_SORTUP;
hdi.fmt&=~HDF_SORTDOWN;
hdi.fmt|=HDF_SORTUP;
}
else {
nSort=HDF_SORTDOWN;
hdi.fmt&=~HDF_SORTUP;
hdi.fmt|=HDF_SORTDOWN;
}
Header_SetItem(hLVHeader,pnmv->iSubItem,&hdi);
}
ListView_SortItems(ListView,lpCompareFunctions[nSelectedColumn],0);
break;
}
}
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
}
Conclusion
Après avoir ajouté un contact (clic sur "Ajouter") il suffit de double-cliquer sur la case à remplir et ajouter le texte. On peut enregistrer sa liste de contacts, cela créé un fichier 'Ma_liste.wbd' à la racine de l'exécutable. Si vous voulez créer plusieurs listes ben... il faudra les renommer ^^. Je précise aussi que pour la gestion de la listview, je me suis largement inspiré du code de vecchio56 (j'en ai même c/c quelques lignes) disponible ici : http://www.cppfrance.com/codes/TRI-COLONNES-LISTVIEW-WIN32_24239.aspx + utilisation du snippet de BruNews pour s'assurer du dossier courant dans le répertoire de l'exe. Voilà.
Fichier Zip
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
Télécharger le zip
Historique
- 30 octobre 2008 16:17:54 :
- - suppression des commentaires/tests inutiles (aucun rapport avec le code)
- modification du texte de l'aide
- modification de la demande d'enregistrement avant fermeture
- ajout d'une vérification de lancement d'exe (message d'erreur si l'appli est déjà lancée, pour ne pas chambouler les enregistrement de la liste)
- ajout d'une vérification concernant le répertoire courant (snippet de BruNews)
Sources du même auteur
Sources de la même categorie
Sources en rapport avec celle ci
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
ComboBox ds ListView (win32) [ par Arnotic ]
Bonjour, Mon but étant d'intégrer dans un listview un combobox (dans un subitem) j'ai donc créer un combobox par dessus le list view en récupérant
[Win32] Recuperer repertoire d'execution d'un programme [ par dekriss ]
Bonjour, Est ce qu'il existe une fonction qui permet de recuperer le repertoire d'execution d'un programme du type C:\\Program files etc ou si cela
[win32] Sélectionner un subItem dans une ListView [ par julien_boss ]
Bonjour,Existe-t-il un moyen de sélectionner un subItem d'une listview ? Je sais qu'il est possible de sélectionner un item et tous ses subitems grâce
[Win32] sélection listview [ par Spunk62 ]
Bonjour, je voudrais récupérer la valeur de la position d'une colonne et ligne d'une listview.pour les lignes j'ai trouvé ceci (sa fonctionne très bie
problème de compilation de bibliothèque XMlL dans un programme C sous visual Studio. [ par boualiasma ]
Salut,- j' extrais tous les sept archives libxml2-2.7.3.win32, iconv-1.9.2.win32, zlib-1.2.3.win32, libxmlsec-1.2.11+.win32, libxslt-1.1.24.win32, xsl
ActiveX [ par mouloudh ]
Salut la communauté,Je commence avec l'intégration des ActiveX, j'ai pris un tutorial. Il m'indique le chemin d'acces : Project-> Add to project -&
Gros probleme win32 API [ par fredsor ]
Salut a tous, Voila j'ai développé une appli en win32 sous evc++, et je l'ai portée sous dev c++Dans cette appli, j'ai dû créer un tableau, pour cela
cherche le repertoire d'un fichier donnée [ par sousou8555 ]
bonjour j'aimerais avoir comment faire pour recuperer le nom d'un repertoire dont on connait seulement un de ses fichiers merci c urgent:(:(:
Win32 et la résolution [ par fredsor ]
Bonjour a tous, J'ai réalisé une appli en Win32 sous embedded visual c++ (pour des PDA embarqués), que j'ai dû également ensuite adapter pour Windows
Recherche dans listview [ par draluorg ]
Salut a tous,J'ai un petit soucis de perf pour tester l'existance d'un SubItem dans une listview.En fait j'ai une fonction AddLvItem a qui j'envoie le
|
Téléchargements
Logiciels à télécharger sur le même thème :
Comparez les prix Nouvelle version
|