Soyez le premier à donner votre avis sur cette source.
Vue 6 915 fois - Téléchargée 810 fois
//-------------------------------------------------------------------- // les includes #include <windows.h> #include <stdio.h> #include <commctrl.h> #include "resource.h" #ifndef _UTIL_H_ #include "util.h" #endif //_UTIL_H_ #ifndef _LIST_VIEW_H_ #include "ListView.h" #endif //_LIST_VIEW_H_ //-------------------------------------------------------------------- // mes includes #ifndef _UTIL_H_ #include "util.h" #endif // _UTIL_H_ BOOL CALLBACK MainDialogProc( HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam ); //-------------------------------------------------------------------- // la ou le programme commmence int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int iCmdShow ) { InitCommonControls(); // on active la boite de dialogue prinpale DialogBox( hInstance, MAKEINTRESOURCE(IDD_DIALOG_MAIN), NULL, MainDialogProc ); return 0 ; } //-------------------------------------------------------------------- // BOOL CALLBACK MainDialogProc( HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam ) { static HWND hwndLV; static int tabSmallIcon[4]; static int tabLargeIcon[4]; static HINSTANCE hInstance; static CHOOSECOLOR cc; switch(iMsg) { case WM_INITDIALOG: { LV_ITEM lvi; char buf[256]; int i; hInstance = MY_GET_INSTANCE(hDlg); hwndLV = GetDlgItem(hDlg,IDC_LIST); InitListViewImage( hwndLV, tabLargeIcon, tabSmallIcon ); // on factorise les initialisations lvi.mask = LVIF_TEXT | LVIF_IMAGE; lvi.iSubItem = 0; lvi.pszText = buf; for(i=0;i<100;i++) { lvi.iItem = i; lvi.cchTextMax = sprintf(buf,"item #%d",i); // au debut on alterne entre chaque couleur, // donc si on reflechis bien il suffit de faire // i&3 pour avoir 0,1,2,3,0,1,2,3,0,... lvi.iImage = tabSmallIcon[i & 3]; ListView_InsertItem(hwndLV,&lvi); } // ChooseColor cc.lStructSize = sizeof(cc); cc.hwndOwner = hDlg; cc.hInstance = hInstance; cc.Flags = CC_ANYCOLOR; return TRUE; } // ------------------------------------- case WM_COMMAND: { switch(LOWORD(wParam)) { case ID_OPTION_STYLES_GRANDSICONES: { ChangeStyle(hwndLV,LVS_ICON); return TRUE; } case ID_OPTION_STYLES_PETITSICONES: { ChangeStyle(hwndLV,LVS_SMALLICON); return TRUE; } case ID_OPTION_STYLES_LISTE: { ChangeStyle(hwndLV,LVS_LIST); return TRUE; } case ID_OPTION_COULEURS_TEXTE: { COLORREF color; // noir cc.rgbResult = RGB(0,0,0); cc.lpCustColors = &color; if(ChooseColor(&cc)) { ListView_SetTextColor(hwndLV,cc.rgbResult); InvalidateRect(hwndLV,NULL,FALSE); } return TRUE; } case ID_OPTION_COULEURS_FOND: { COLORREF color; // blanc cc.rgbResult = RGB(255,255,255); cc.lpCustColors = &color; if(ChooseColor(&cc)) { // il faut changer les deux couleurs ListView_SetBkColor(hwndLV,cc.rgbResult); ListView_SetTextBkColor(hwndLV,cc.rgbResult); InvalidateRect(hwndLV,NULL,TRUE); } return TRUE; } case ID_OPTION_COULEURS_ICONESSELECTIONNES_ROUGE: case ID_OPTION_COULEURS_ICONESSELECTIONNES_VERT: case ID_OPTION_COULEURS_ICONESSELECTIONNES_BLEU: case ID_OPTION_COULEURS_ICONESSELECTIONNES_JAUNE: { UINT nbItem; int iNextItem; nbItem = ListView_GetSelectedCount(hwndLV); if(!nbItem) { return FALSE; } iNextItem = ListView_GetNextItem( hwndLV, -1, LVNI_ALL | LVNI_SELECTED ); while(nbItem--) { int i; LV_ITEM lvi; lvi.iItem = iNextItem; lvi.iSubItem = 0; lvi.mask = LVIF_IMAGE; if(!ListView_GetItem(hwndLV,&lvi)) { DisplayLastError(); } i = 0; switch(LOWORD(wParam)) { case ID_OPTION_COULEURS_ICONESSELECTIONNES_JAUNE: i++; case ID_OPTION_COULEURS_ICONESSELECTIONNES_BLEU: i++; case ID_OPTION_COULEURS_ICONESSELECTIONNES_VERT: i++; } lvi.iImage = tabSmallIcon[i]; ListView_SetItem(hwndLV,&lvi); iNextItem = ListView_GetNextItem( hwndLV, iNextItem, LVNI_ALL | LVNI_SELECTED ); } return TRUE; } } case ID_APROPOS: { MessageBox( hDlg, "Voila un programme sur les ListView.\n" "Vive Windows grace auquel on peut faire les CommonControls dont les ListView !\n" "Vive le langage C, et vive ses inventeurs !\n" "Vive cppfrance.com !\n" "\nAuteur : JCDjcd\n" "Date : Juillet 2003\n", "A propos ...", MB_OK | MB_ICONQUESTION ); return TRUE; } break; } // ------------------------------------- case WM_SYSCOMMAND: { switch(LOWORD(wParam)) { // si on veut quitter case SC_CLOSE: { EndDialog(hDlg,FALSE); break; } } break; } // ------------------------------------- // on ne traite pas le message default: { break; } } return FALSE; }
10 juin 2005 à 16:07
Il faut juste ne pas oublier de linker avec comctl32.lib et le tour est joué.
18 avril 2005 à 16:13
ça peut être utile !
8/10 !
18 juil. 2003 à 21:18
17 juil. 2003 à 18:28
ListView.obj : error LNK2001: unresolved external symbol __imp__ImageList_Create@20
main.obj : error LNK2001: unresolved external symbol __imp__InitCommonControls@0
17 juil. 2003 à 18:27
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.