Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1237 connectés 

  FORUM HardWare.fr
  Programmation
  API Win32

   [Résolu][c++][apiWin32] gestion de la souris dans listview

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[Résolu][c++][apiWin32] gestion de la souris dans listview

n°1896589
spunk62
Posté le 18-06-2009 à 13:37:26  profilanswer
 

Bonjour, j'ai trouver un code qui fonctionne sur un projet, mais je possède un tabcontrol dans lequel j'ai ma listview, ici ma boite de dialogue s'affiche que quant je change d'onglet.
 

Code :
  1. case WM_NOTIFY :
  2. {
  3.     LPNMHDR pnmhdr;
  4.     pnmhdr=(LPNMHDR)lParam;
  5.     if(pnmhdr->code==NM_CLICK)
  6.     {
  7. DialogBox(hInst, MAKEINTRESOURCE(IDD_CHOIX), hDlg,About);
  8. return 0;
  9.     }
  10. }
  11. break;


de ce faite j'ai modifié le code:

Code :
  1. case WM_NOTIFY :
  2. {
  3.     LPNMHDR pnmhdr;
  4.     pnmhdr=(LPNMHDR)lParam;
  5.     if(pnmhdr->hwndFrom == hlistviewA && pnmhdr->code==NM_CLICK)
  6.     {
  7. DialogBox(hInst, MAKEINTRESOURCE(IDD_CHOIX), hDlg,About);
  8. return 0;
  9.     }
  10. }
  11. break;


Maintenant la boite de dialogue IDD_CHOIX ne s'affiche pu...
 
Ma fenêtre principale et une dialogue box dans laquelle j'ai un tabcontrol plusieurs onglet contenant des boites de dialogue enfant et dans la boite de dialogue enfant 1 j'ai mis une listview.
 
J'explique tout sa car il me semble que hwndFrom ne fonctionne pas avec les boites de dialogue.


Message édité par spunk62 le 24-06-2009 à 23:24:43
mood
Publicité
Posté le 18-06-2009 à 13:37:26  profilanswer
 

n°1896602
olivthill
Posté le 18-06-2009 à 14:04:54  profilanswer
 

Citation :

case WM_NOTIFY :
{
    LPNMHDR pnmhdr;
    pnmhdr=(LPNMHDR)lParam;

Ce n'est pas la même chose que dans la documentation, http://msdn.microsoft.com/en-us/li [...] S.85).aspx, qui indique

Citation :

NM_CLICK (list view) Notification
Sent by a list-view control when the user clicks an item with the left mouse button. This notification message is sent in the form of a WM_NOTIFY message.
 
Syntax
NM_CLICK
    lpnmitem = (LPNMITEMACTIVATE) lParam;
 
Parameters
lpnmitem
Version 4.71. Pointer to an NMITEMACTIVATE structure that contains additional information about this notification message. The iItem, iSubItem, and ptAction members of this structure contain information about the item.
 
Return Value
Remarks
The iItem member of lpnmitem is only valid if the icon or first-column label has been clicked. To determine which item is selected when a click takes place elsewhere in a row, send an LVM_SUBITEMHITTEST message.
Notification Requirements
Minimum DLL Version None  
Header commctrl.h  
Minimum operating systems Windows NT 3.51, Windows 95
...
NMITEMACTIVATE Structure
Contains information about an LVN_ITEMACTIVATE notification message.  
 
Syntax
typedef struct tagNMITEMACTIVATE {
    NMHDR hdr;
    int iItem;
    int iSubItem;
    UINT uNewState;
    UINT uOldState;
    UINT uChanged;
    POINT ptAction;
    LPARAM lParam;
    UINT uKeyFlags;
} NMITEMACTIVATE, *LPNMITEMACTIVATE;M

Autrement dit, il semble qu'une étape ait été brulée, et que le bon code serait plutôt:

case WM_NOTIFY :
{
    LPNMITEMACTIVATE lpnmitem;
    lpnmitem = (LPNMITEMACTIVATE) lParam;
    if(lpnmitem->hdr->hwndFrom == hlistviewA && lpnmitem->hdr->code==NM_CLICK)
    {
       DialogBox(hInst, MAKEINTRESOURCE(IDD_CHOIX), hDlg,About);
       return 0;
    }
}
break;

Edit : J'ai corrigé le pnmhr en hdr.


Message édité par olivthill le 18-06-2009 à 15:24:06
n°1896617
spunk62
Posté le 18-06-2009 à 15:05:45  profilanswer
 

j'ai une erreur en reprenant ton code: error C2039  
:'pnmhdr' : n'est pas membre de 'tagNMITEMACTIVATE'
:voir la déclaration de 'tagNMITEMACTIVATE'
 
Merci pour ton aide !


Message édité par spunk62 le 18-06-2009 à 15:20:16
n°1896712
spunk62
Posté le 18-06-2009 à 19:12:20  profilanswer
 

Voila, mon code compile:

Code :
  1. case WM_NOTIFY :
  2.   {
  3.         LPNMITEMACTIVATE lpnmitem;
  4.         lpnmitem = (LPNMITEMACTIVATE) lParam;
  5.          if(lpnmitem->hdr.hwndFrom == hlistviewA && lpnmitem->hdr.code==NM_CLICK)
  6.         {
  7.          DialogBox(hInst, MAKEINTRESOURCE(IDD_CHOIX), hDlg,About);
  8.          return 0;
  9.         }
  10.    }
  11. break;


 
Mais ma boite de dialogue ne se lance toujours pas quant je clique sur une cellule de ma listview...
 

Code :
  1. case WM_NOTIFY :
  2.   {
  3.        DialogBox(hInst, MAKEINTRESOURCE(IDD_CHOIX), hDlg,About);
  4.    }
  5. break;


en faisant ceci ma boite de dialogue se lance a chaque fois que je change d'onglet ... :fou:  
 
une idée?


Message édité par spunk62 le 18-06-2009 à 20:24:57
n°1896892
spunk62
Posté le 19-06-2009 à 11:46:21  profilanswer
 

Re,
 
j'ai créé un nouveau projet simple avec une listview (listview déclarer dans case WM_INITDIALOG:) le code fonctionne, après j'ai créé une procédure listview dans un autre fichier "procedure.cpp" (comme dans mon code) sa ne fonctionnait pu, solution:
déclarer la listview en dehors de la procédure (la déclarer dans INITDIALOG).
Le problème c'est que je charge un fichier puis j'affiche la listview garce au menu (ex: outils\tableau)
voici mon code:

Code :
  1. #include <windows.h>
  2. #include <commctrl.h>
  3. #include "resource.h"
  4. #include "procedure.h"
  5. #include <commctrl.h>
  6. HINSTANCE hInst;
  7. bool tab=false;
  8. bool TabListA=false;
  9. static LVITEM lvi;
  10. static LVHITTESTINFO lvhti;
  11. static Plot *P1;
  12. // Déclaration des fonctions du module.
  13. static HWND Childtab;
  14. static HWND ChildAnalyse;
  15. static HWND ChildIndic;
  16. static int CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
  17. static int MsgInitDialog (HWND);
  18. static int MsgNotify  (WPARAM, LPARAM);
  19. static int MsgCommand  (WPARAM, LPARAM);
  20. static int CALLBACK Childtab_DlgProc(HWND, UINT, WPARAM, LPARAM);
  21. static int CALLBACK ChildAnalyse_DlgProc(HWND, UINT, WPARAM, LPARAM);
  22. static int CALLBACK ChildIndic_DlgProc(HWND, UINT, WPARAM, LPARAM);
  23. static void UpdateChildTab(HWND);
  24. static INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  25. //Dialog principale
  26. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
  27. {
  28. hInst=hInstance;
  29. return DialogBox(hInstance,MAKEINTRESOURCE(IDD_MAIN),NULL,DlgProc);
  30. }
  31. //MainDlgProc :
  32. int CALLBACK DlgProc(HWND hDlg,UINT message, WPARAM wParam, LPARAM lParam)
  33. {
  34. static int cx,cy;
  35. static Plot *P2,*P3;
  36. int wmId, wmEvent;
  37. static HWND hlistview,hlistviewA;
  38. switch (message)
  39.     {
  40.  case WM_SIZE:
  41.  cx = LOWORD (lParam) ;
  42.  cy = HIWORD (lParam) ;
  43.  break;
  44. case WM_INITDIALOG :
  45.    return MsgInitDialog(hDlg);
  46.  case WM_DESTROY :
  47.  {
  48.   // destruction des dialogues enfants
  49.   DestroyWindow(Childtab);
  50.                         DestroyWindow(ChildAnalyse);
  51.   DestroyWindow(ChildIndic);
  52.   return 0;
  53.  }
  54.  case WM_NOTIFY :
  55.  {
  56.         LPNMITEMACTIVATE lpnmitem;
  57.         lpnmitem = (LPNMITEMACTIVATE) lParam;
  58.           if(lpnmitem->hdr.hwndFrom == hlistviewA && lpnmitem->hdr.code==NM_CLICK)
  59.           {
  60.             DialogBox(hInst, MAKEINTRESOURCE(IDD_CHOIX), hDlg,About);
  61.             return 0;
  62.           }
  63.  // mise à jour de l'affichage des dialogues enfants
  64.  LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  65.    if(lpnmhdr->code == TCN_SELCHANGE)
  66.    {
  67.      UpdateChildTab(hDlg);
  68.      return 0;
  69.    }
  70.  }
  71.        break;
  72. case WM_COMMAND:
  73.  wmId    = LOWORD(wParam);
  74.  wmEvent = HIWORD(wParam);
  75.        
  76.  // Analyse les sélections de menu :
  77.  switch (wmId)
  78.  {
  79.  case ID_FICHIER_QUITTER:
  80.   EndDialog(hDlg,0);
  81.   break;
  82.  case ID_FICHIER_OUVRIR:
  83.             chargertableau (hDlg,hlistview,ChildAnalyse);
  84.   break;
  85.  case ID_OUTILS_TABLEAU:
  86.   listview (hlistview,Childtab);
  87.   break;
  88.  case ID_OUTILS_ANALYSE:
  89.   TabListA=true;
  90.                         listviewA (hlistviewA,ChildAnalyse);
  91.   break;
  92.  case ID_OUTILS_INDICATEUR:
  93.   break;
  94.  }
  95.  break;//break du switch
  96.   break;//break du WM_COMMAND
  97.       case WM_CLOSE:
  98.  //Fermer la boite de dialogue:
  99.  EndDialog(hDlg,0);
  100.   break;
  101.      }
  102. return 0;
  103. }
  104. int MsgInitDialog(HWND hDlg)
  105. {
  106. Childtab = CreateDialog(hInst, MAKEINTRESOURCE(IDD_TAB),
  107.         hDlg, Childtab_DlgProc);
  108. ChildAnalyse = CreateDialog(hInst, MAKEINTRESOURCE(IDD_ANALYSE),
  109.         hDlg, ChildAnalyse_DlgProc);
  110. ChildIndic = CreateDialog(hInst, MAKEINTRESOURCE(IDD_INDICATEUR),
  111.         hDlg, ChildIndic_DlgProc);
  112. // ajout des onglets
  113. HWND hTabCtrl = GetDlgItem(hDlg, IDC_TAB1);
  114. TCITEM tci;
  115. tci.mask = TCIF_TEXT;
  116. tci.pszText = "Raport ";
  117. SendMessage(hTabCtrl, TCM_INSERTITEM, 0, (LPARAM) &tci);
  118. tci.pszText = "Analyse ";//hlistviewA
  119. SendMessage(hTabCtrl, TCM_INSERTITEM, 1, (LPARAM) &tci);
  120. tci.pszText = "Taux";
  121. SendMessage(hTabCtrl, TCM_INSERTITEM, 2, (LPARAM) &tci);
  122. tci.pszText = "Pareto";
  123. SendMessage(hTabCtrl, TCM_INSERTITEM, 3, (LPARAM) &tci);
  124. // détermination du rectangle où placer les dialogues enfants à partir du rectangle
  125. // du tabctrl, conversion dans le systemde coordonnée de la boîte de dialogue parente
  126. RECT rcTabCtrl;
  127. GetWindowRect(hTabCtrl, &rcTabCtrl);
  128. SendMessage(hTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM) &rcTabCtrl);
  129. MapWindowPoints(NULL, hDlg, (LPPOINT) &rcTabCtrl, 2);
  130. // taille du dialogue enfant
  131. RECT rcChildTab;
  132. GetWindowRect(Childtab, &rcChildTab);
  133. int x = (rcTabCtrl.left+rcTabCtrl.right)/2 - (rcChildTab.right-rcChildTab.left)/2;
  134. int y = (rcTabCtrl.top+rcTabCtrl.bottom)/2 - (rcChildTab.bottom-rcChildTab.top)/2;
  135. SetWindowPos(Childtab, NULL, x, y, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_NOREDRAW);
  136.     RECT rcChildAnalyse;
  137. GetWindowRect(ChildAnalyse, &rcChildAnalyse);
  138. int x1 = (rcTabCtrl.left+rcTabCtrl.right)/2 - (rcChildAnalyse.right-rcChildAnalyse.left)/2;
  139. int y1 = (rcTabCtrl.top+rcTabCtrl.bottom)/2 - (rcChildAnalyse.bottom-rcChildAnalyse.top)/2;
  140. SetWindowPos(ChildAnalyse, NULL, x, y, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_NOREDRAW);
  141.     RECT rcChildIndic;
  142. GetWindowRect(ChildIndic, &rcChildIndic);
  143. int x2 = (rcTabCtrl.left+rcTabCtrl.right)/2 - (rcChildIndic.right-rcChildIndic.left)/2;
  144. int y2 = (rcTabCtrl.top+rcTabCtrl.bottom)/2 - (rcChildIndic.bottom-rcChildIndic.top)/2;
  145. SetWindowPos(ChildIndic, NULL, x, y, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_NOREDRAW);
  146. // affichage de l'onglet un et mise à jour
  147. SendMessage(hTabCtrl, TCM_SETCURSEL, 0, 0);
  148. UpdateChildTab(hDlg);
  149. return TRUE;
  150. }
  151. // UpdateChildTab :
  152. void UpdateChildTab(HWND hDlg)
  153. {
  154. // afficher le dialogue correspondant à l'onglet sélectionné et masquer les autres
  155. HWND hTabCtrl = GetDlgItem(hDlg, IDC_TAB1);
  156. int nSelected = SendMessage(hTabCtrl, TCM_GETCURSEL, 0, 0);
  157. ShowWindow(Childtab, (0==nSelected)? SW_SHOW : SW_HIDE);
  158. ShowWindow(ChildAnalyse, (1==nSelected)? SW_SHOW : SW_HIDE);
  159.     ShowWindow(ChildIndic, (2==nSelected)? SW_SHOW : SW_HIDE);
  160. }
  161. int CALLBACK Childtab_DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  162. {
  163. return 0;
  164. }
  165. int CALLBACK ChildAnalyse_DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  166. {
  167. return 0;
  168. }
  169. int CALLBACK ChildIndic_DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  170. {
  171. return 0;
  172. }
  173. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  174. {
  175. UNREFERENCED_PARAMETER(lParam);
  176. switch (message)
  177. {
  178. case WM_INITDIALOG:
  179.  return (INT_PTR)TRUE;
  180. case WM_COMMAND:
  181.  if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  182.  {
  183.   EndDialog(hDlg, LOWORD(wParam));
  184.   return (INT_PTR)TRUE;
  185.  }
  186.  break;
  187. }
  188. return (INT_PTR)FALSE;
  189. }


 
J'ai vraiment besoin de votre aide ! merci


Message édité par spunk62 le 19-06-2009 à 11:49:51
n°1897186
Trap D
Posté le 20-06-2009 à 08:09:57  profilanswer
 

Pour t'aider, il faudrait qu'on puisse compiler, et il manque au moins "procedure.h"

n°1898947
spunk62
Posté le 24-06-2009 à 23:29:17  profilanswer
 

J'ai résolu mon problème :
 
le  ( case WM_NOTIFY ) était celui de la boite de dialogue principale ici hDlg or ma listview est sur une boite de dialogue enfant appelé ChildAnalise il suffisait juste de créer une fonction ( int CALLBACK ChildAnalyse_DlgProc ) qui elle écouterai les événements sur ma listview !  
 
merci encore pour votre aide
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  API Win32

   [Résolu][c++][apiWin32] gestion de la souris dans listview

 

Sujets relatifs
[Resolu]Tronquer une chaine de caractèreErreur Excel nombre de polices [RESOLU]
[Résolu] pyhon & envoie d'xml par post[VBS][RESOLU][SCRIPT]Script de suppression de fichiers temporaires
[RESOLU]JTable : colorier ligne ou cellule selon critère de provenanceprobleme pour parser des dates [résolu]
[Résolu] MySQL : LEFT JOIN et GROUP BY - récupérer la dernière valeur[Résolu] Comment bien structurer mes classes ?
[Resolu]Problème de compilation API MYSQL[RESOLU] - [JTree] Ne pas afficher tous les noeuds
Plus de sujets relatifs à : [Résolu][c++][apiWin32] gestion de la souris dans listview


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR