LPNMHDR pNMHDR = (LPNMHDR) lParam;
LPNMTVCUSTOMDRAW pNMTVCD = (LPNMTVCUSTOMDRAW) pNMHDR;
NMTVCUSTOMDRAW 和NMHDR 没什么关系呀,怎么能转换?
typedef struct tagNMTVCUSTOMDRAW {
NMCUSTOMDRAW nmcd;
COLORREF clrText;
COLORREF clrTextBk;
#if (_WIN32_IE >= 0x0400)
int iLevel;
#endif
} NMTVCUSTOMDRAW, *LPNMTVCUSTOMDRAW;
typedef struct tagNMHDR {
HWND hwndFrom;
UINT idFrom;
UINT code;
} NMHDR;
LPNMTVCUSTOMDRAW pNMTVCD = (LPNMTVCUSTOMDRAW) pNMHDR;
NMTVCUSTOMDRAW 和NMHDR 没什么关系呀,怎么能转换?
typedef struct tagNMTVCUSTOMDRAW {
NMCUSTOMDRAW nmcd;
COLORREF clrText;
COLORREF clrTextBk;
#if (_WIN32_IE >= 0x0400)
int iLevel;
#endif
} NMTVCUSTOMDRAW, *LPNMTVCUSTOMDRAW;
typedef struct tagNMHDR {
HWND hwndFrom;
UINT idFrom;
UINT code;
} NMHDR;
在这里我们还需要看看NMCUSTOMDRAW 结构,可以注意到它里面包含了一个NMHDR的变量,所以结构NMTVCUSTOMDRAW和NMHDR的前三个变量是一直的,可以通过这两个类型的指针均可以进行访问而不出错。另外两个结构间能进行强制类型转换看我前面的描述,只要该指针的原型确实是NMTVCUSTOMDRAW类型就保证了指针指向的内容的正确性。