阅读:1004回复:2
请教一段代码的含义
疑问在波浪线的部分,谁能回一下,谢谢!
VOID UpdateEditControl ( HWND hEditWnd, HWND hTreeWnd, HTREEITEM hTreeItem ) { TV_ITEM tvi; PUSBDEVICEINFO info; // Start with an empty text buffer. // if (!InitTextBuffer()) { return; } // // Get the name of the TreeView item, along with the a pointer to the // info we stored about the item in the item\'s lParam. // tvi.mask = TVIF_HANDLE | TVIF_TEXT | TVIF_PARAM; tvi.hItem = hTreeItem; tvi.pszText = (LPSTR)TextBuffer; tvi.cchTextMax = TextBufferLen-2; // leave space for \"\\r\\n\' TreeView_GetItem(hTreeWnd,&tvi); info = (PUSBDEVICEINFO)tvi.lParam; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 这段代码是什么含义?lParam是什么作用? // // If we didn\'t store any info for the item, just display the item\'s // name, else display the info we stored for the item. // if (info != NULL) { if (info->ConnectionInfo == NULL) { // Must be Root HUB, external devices have Connection Info // AppendTextBuffer(\"Root Hub: %s\\r\\n\", info->HubName); DisplayHubInfo(&info->HubInfo->u.HubInformation); } else { if (info->HubInfo != NULL) { // Must be external HUB external // AppendTextBuffer(\"External Hub: %s\\r\\n\", info->HubName); DisplayHubInfo(&info->HubInfo->u.HubInformation); } else { // Must be external non-HUB device. Nothing special to // display here that isn\'t displayed in connection info // below. } // Display info common to any external device // DisplayConnectionInfo(info->ConnectionInfo, info->StringDescs); if (info->ConfigDesc) { DisplayConfigDesc((PUSB_CONFIGURATION_DESCRIPTOR)(info->ConfigDesc + 1), info->StringDescs); } } } // All done formatting text buffer with info, now update the edit // control with the contents of the text buffer // SetWindowText(hEditWnd, TextBuffer); } |
|
沙发#
发布于:2005-02-28 16:00
这是典型的消息机制使用的方法。
info = (PUSBDEVICEINFO)tvi.lParam; 的意思是: 将tvi.lParam强制转化为PUSBDEVICEINFO类型(实际上是指针)。 说白了:tvi.lParam是一个长整形,由TreeView Item定义出来,给使用者任意使用,爱怎么用就怎么用。但由于该类型也就4个字节长,所以要传大量数据的话,比如info结构,就把它当成指针使用: 一方: tvi.lParam = (ULONG) (&SUsbDeviceInfo); 另一方: info = (PUSBDEVICEINFO)tvi.lParam; 不就传过来了吗! |
|
|
板凳#
发布于:2005-02-28 16:49
tvi.lParam里面存放的是消息之类的东西,
还是字符串之类的东西? 这是典型的消息机制使用的方法。 |
|