limee
驱动牛犊
驱动牛犊
  • 注册日期2004-03-02
  • 最后登录2006-07-25
  • 粉丝0
  • 关注0
  • 积分10分
  • 威望2点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1004回复:2

请教一段代码的含义

楼主#
更多 发布于:2005-02-28 15:25
疑问在波浪线的部分,谁能回一下,谢谢!

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);
}
zmwk
驱动中牛
驱动中牛
  • 注册日期2001-05-15
  • 最后登录2009-04-05
  • 粉丝0
  • 关注0
  • 积分59分
  • 威望51点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
沙发#
发布于: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;
不就传过来了吗!
 
A strong man can save himself. A great man can save another.
limee
驱动牛犊
驱动牛犊
  • 注册日期2004-03-02
  • 最后登录2006-07-25
  • 粉丝0
  • 关注0
  • 积分10分
  • 威望2点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2005-02-28 16:49
tvi.lParam里面存放的是消息之类的东西,
还是字符串之类的东西?

这是典型的消息机制使用的方法。

info = (PUSBDEVICEINFO)tvi.lParam;

的意思是: 将tvi.lParam强制转化为PUSBDEVICEINFO类型(实际上是指针)。

说白了:tvi.lParam是一个长整形,由TreeView Item定义出来,给使用者任意使用,爱怎么用就怎么用。但由于该类型也就4个字节长,所以要传大量数据的话,比如info结构,就把它当成指针使用:
一方:
   tvi.lParam = (ULONG) (&SUsbDeviceInfo);
另一方:
   info = (PUSBDEVICEINFO)tvi.lParam;
不就传过来了吗!
  
游客

返回顶部