我在这里看到了下面的这段代码。我测试了它,它工作正常。
// g_hLink is the handle of the SysLink control.
case WM_NOTIFY:
switch (((LPNMHDR)lParam)->code) // CAST TO NMHDR*
{
case NM_CLICK: // Fall through to the next case.
case NM_RETURN:
{
PNMLINK pNMLink = (PNMLINK)lParam; // CAST TO NMLINK*
LITEM item = pNMLink->item;
if ((((LPNMHDR)lParam)->hwndFrom == g_hLink) && (item.iLink == 0))
{
ShellExecute(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW);
}
else if (wcscmp(item.szID, L"idInfo") == 0)
{
MessageBox(hDlg, L"This isn't much help.", L"Example", MB_OK);
}
break;
}
}
break;
该参数lParam
被强制转换为NMHDR*
和NMLINK*
类型。message的文档WM_NOTIFY
说lParam
可以转换成NMHDR*
,但是NMLINK
是封装的不同结构NMHDR
。
lParam
当我们在这两者之间任意选择一个结构时,实际上会发生什么?