LVN_GETINFOTIP notification

Résolu
juju116 Messages postés 23 Date d'inscription samedi 14 mars 2009 Statut Membre Dernière intervention 1 février 2010 - 23 avril 2009 à 18:37
cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 - 24 avril 2009 à 16:33
bonjour tout le monde!
mon code plante au niveau de la notification. j'arive à compiler, mais a chaque fois que j'execute tout beug quelqu'un pouré me dire ce que j'ai loupé?merci d'avence

#ifdef UNICODE
#define _UNICODE
#endif /* UNICODE */

/* Requis pour LVN_GETINFOTIP */
#define _WIN32_IE 0x0400

#include <windows.h>
#include <tchar.h>
#include <commctrl.h>


HINSTANCE _hThisInstance; /* Handle du module */
HWND _hWnd; /* Handle de la fenêtre */
HWND _hStatusBar; /* Handle sur la bar de status */
HWND _hListView; /* Handle sur la listview */
LPTSTR _lpAppName = _T("ListView"); /* Nom de l'appli */

DWORD _nStatusBarHeight; /* Redimenssionement de la listview */
TCHAR _lpItems[3][10] = {_T("titi"), _T("toto"), _T("tata")};

/**
* Affiche un message d'erreur correspondant à la dernière erreur Win32
*/
DWORD ShowLastError()
{
DWORD nLastError; /* Numéro de l'erreur */
LPTSTR lpMessageBuffer; /* Récupération du message */

nLastError = GetLastError();

/* Formatage du message */
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, nLastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(void*)&lpMessageBuffer, 0, NULL);

/* Affichage du message */
MessageBox(NULL, lpMessageBuffer, _T("ERROR"), MB_OK | MB_ICONERROR);

LocalFree(lpMessageBuffer);
return nLastError;
}

/**
* Traitement des messages
*/
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT nMessage, WPARAM wParam, LPARAM lParam)
{
MINMAXINFO *lpMinMaxInfo; /* Info sur les tailles min et max de la fenêtre */
RECT clientRect; /* Taille de la zone cliente */
int bHandled; /* Pour savoir si le message est traité */
long nResult;

nResult = 0;
bHandled = 0;
switch (nMessage)
{
case WM_GETMINMAXINFO:
lpMinMaxInfo = (MINMAXINFO*)lParam;
lpMinMaxInfo->ptMinTrackSize.x = 300;
lpMinMaxInfo->ptMinTrackSize.y = 200;
bHandled = 1;
break;

case WM_SIZE:
/* On signale à la barre de status que la fenêtre a été redimenssionnée */
SendMessage(_hStatusBar, WM_SIZE, wParam, lParam);

/* On ajuste la taille de la listview */
GetClientRect(_hWnd, &clientRect);
SetWindowPos(_hListView, 0, 0, 0,
clientRect.right - clientRect.left,
clientRect.bottom - clientRect.top - _nStatusBarHeight,
SWP_NOMOVE | SWP_NOZORDER);
break;


LPNMLVGETINFOTIP nmInfoTip;
case WM_NOTIFY:
if (((NMHDR*)lParam)->code == LVN_GETINFOTIP)
nmInfoTip = (LPNMLVGETINFOTIP)lParam;
MessageBox(hWnd, nmInfoTip->pszText, "Notification", MB_OK);

break;

case WM_DESTROY:
/* On signale que le thread va s'arrêter */
PostQuitMessage(0);
bHandled = 1;
break;
}
if (! bHandled)
nResult = DefWindowProc(hWnd, nMessage, wParam, lParam);
return nResult;
}

/**
* Ajoute la barre de status
*/
int CreateStatusBar()
{
int nWidth; /* Largeur de la partie 0 */
RECT statusBarRect; /* Taille de la barre de status */
int nResult;

nResult = 0;

/* Création de la barre de status */
_hStatusBar = CreateWindowEx(0, STATUSCLASSNAME, (LPCTSTR)NULL,
SBARS_SIZEGRIP | WS_CHILD | WS_VISIBLE,
0, 0, 0, 0,
_hWnd, NULL, _hThisInstance, NULL);
if (! _hStatusBar) goto the_end;


/* Affectation du nombre de parties */
nWidth = -1;
SendMessage(_hStatusBar, SB_SETPARTS, (WPARAM)1, (LPARAM)&nWidth);

/* Calcul de la hauteur de la barre de status */
GetWindowRect(_hStatusBar, &statusBarRect);
_nStatusBarHeight = statusBarRect.bottom - statusBarRect.top;

nResult = 1;
the_end:
return nResult;
}

/**
* Crée une imagelist utilisée par la listview
*/
int CreateImageList()
{
HIMAGELIST hImageList; /* Handle sur la imagelist */
int nResult;

nResult = 0;

/* Création de la liste */
hImageList = ImageList_Create(GetSystemMetrics(SM_CXICON),
GetSystemMetrics(SM_CYICON),
ILC_MASK, 1, 1);
if (! hImageList) goto the_end;

/* Ajout d'un icône */
if (ImageList_ReplaceIcon(hImageList, -1, LoadIcon(NULL, IDI_APPLICATION)) == -1) goto the_end;

/* Affectation de la imagelist à la listview */
SendMessage(_hListView, LVM_SETIMAGELIST, (WPARAM)LVSIL_NORMAL, (LPARAM)hImageList);

nResult = 1;
the_end:
return nResult;
}

/**
* Crée les items de la listview
*/
int CreateItems()
{
LVITEM item;
int nI;

item.mask = LVIF_TEXT | LVIF_IMAGE;
item.iImage = 0;
item.iSubItem = 0;


/* Initialisation des items */
for (nI = 0; nI < 3; nI++)
{
item.iItem = nI;
item.pszText = _lpItems[nI];
SendMessage(_hListView, LVM_INSERTITEM, 0, (LPARAM)&item);
}

return 1;
}

/**
* Ajoute la listview
*/
int CreateListView()
{
HWND hTips; /* Handle sur les tool tips */
int nResult;

nResult = 0;

_hListView = CreateWindowEx(0, WC_LISTVIEW, (LPCTSTR)NULL,
WS_CHILD | LVS_ICON | WS_VISIBLE,
0, 0, 0, 0,
_hWnd, NULL, _hThisInstance, NULL);
if (! _hListView) goto the_end;

/* Pour que la listview envoie des message lors du survol des items */
SendMessage(_hListView, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_INFOTIP, LVS_EX_INFOTIP);

/* Pour que WM_NOTIFY arrivent instantanément lors du survol d'un item */
hTips = (HWND)SendMessage(_hListView, LVM_GETTOOLTIPS, 0, 0);
SendMessage(hTips, TTM_SETDELAYTIME, TTDT_INITIAL, 1);
SendMessage(hTips, TTM_SETDELAYTIME, TTDT_RESHOW, 1);

if (! CreateImageList()) goto the_end;
if (! CreateItems()) goto the_end;

nResult = 1;
the_end:
return nResult;
}

/**
* Initialise la fenêtre principale de l'appli.
*/
int CreateMyWindow()
{
WNDCLASSEX wincl; /* Classe de la fenêtre utilisée */
int nResult;

nResult = 0;

/* Création de la classe de fenêtre */
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.style = 0;
wincl.lpfnWndProc = WindowProcedure;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hInstance = _hThisInstance;
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wincl.lpszMenuName = 0;
wincl.lpszClassName = _lpAppName;
wincl.hIconSm = NULL;

/* Enregistrement de la classe */
if (! RegisterClassEx(&wincl)) goto the_end;

/* Création de la fenêtre */
_hWnd = CreateWindowEx(0, _lpAppName, _lpAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 500, 300,
HWND_DESKTOP, NULL, _hThisInstance, NULL);
if (! _hWnd) goto the_end;

/* Création de la barre de status */
if (! CreateStatusBar()) goto the_end;

/* Création de la listview */
if (! CreateListView()) goto the_end;

/* Affichage de la fenêtre */
ShowWindow (_hWnd, SW_SHOW);

nResult = 1;
the_end:
return nResult;
}

/**
* Main
*/
int __cdecl WinMainCRTStartup()
{
MSG messages; /* Messages envoyés à l'application */
INITCOMMONCONTROLSEX initCommon; /* Initialisation de comctl32 */
int nResult;

initCommon.dwSize = sizeof(initCommon);
initCommon.dwICC = ICC_BAR_CLASSES | ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&initCommon);

/* Récupération du handle du module */
_hThisInstance = GetModuleHandle(NULL);

if (! CreateMyWindow())
{
nResult = ShowLastError();
goto the_end;
}

/* Boucle de traitement des messages */
while (GetMessage(&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
nResult = messages.wParam;

the_end:
/* ExitProcess nécessaire car sinon c'est un ExitThread */
ExitProcess(nResult);

/* Pour esquiver le warning */
return 0;
}

1 réponse

cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 13
24 avril 2009 à 16:33
Salut,

Tiens, ce code me dis quelque chose.

Tu exécutes la MessageBox quoiqu'il arrive...

    if (((NMHDR*)lParam)->code == LVN_GETINFOTIP)
   {
    nmInfoTip = (LPNMLVGETINFOTIP)lParam;

    MessageBox(hWnd, nmInfoTip->pszText, "Notification", MB_OK);
  }
3
Rejoignez-nous