⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hwpage.c

📁 winNT技术操作系统,国外开放的原代码和LIUX一样
💻 C
📖 第 1 页 / 共 3 页
字号:
        /* move the IDC_PROPERTIES button */
        y = cy - (2 * ptMargin.y) - (rcButton.bottom - rcButton.top);
        x = cx - ptMarginGroup.x - (rcButton.right - rcButton.left);
        if (!(dwp = DeferWindowPos(dwp,
                                   hButton,
                                   NULL,
                                   x,
                                   y,
                                   0,
                                   0,
                                   SWP_NOSIZE | SWP_NOZORDER)))
        {
            return;
        }

        /* move the IDC_TROUBLESHOOT button */
        hButton = GetDlgItem(hpd->hWnd,
                             IDC_TROUBLESHOOT);
        GetWindowRect(hButton,
                      &rcButton);
        x -= (ptMargin.x / 2) + (rcButton.right - rcButton.left);
        if (!(dwp = DeferWindowPos(dwp,
                                   hButton,
                                   NULL,
                                   x,
                                   y,
                                   0,
                                   0,
                                   SWP_NOSIZE | SWP_NOZORDER)))
        {
            return;
        }

        EndDeferWindowPos(dwp);
    }
}


static VOID
EnableTroubleShoot(PHARDWARE_PAGE_DATA hpd,
                   BOOL Enable)
{
    HWND hBtnTroubleShoot = GetDlgItem(hpd->hWnd,
                                       IDC_TROUBLESHOOT);

    ShowWindow(hBtnTroubleShoot,
               Enable ? SW_SHOW : SW_HIDE);
}


static INT_PTR
CALLBACK
HardwareDlgProc(IN HWND hwndDlg,
                IN UINT uMsg,
                IN WPARAM wParam,
                IN LPARAM lParam)
{
    PHARDWARE_PAGE_DATA hpd;
    INT_PTR Ret = FALSE;

    hpd = (PHARDWARE_PAGE_DATA)GetWindowLongPtr(hwndDlg,
                                                DWL_USER);

    if (hpd != NULL || uMsg == WM_INITDIALOG)
    {
        switch (uMsg)
        {
            case WM_NOTIFY:
            {
                NMHDR *pnmh = (NMHDR*)lParam;
                if (pnmh->hwndFrom == hpd->hWndDevList)
                {
                    switch (pnmh->code)
                    {
                        case LVN_ITEMCHANGED:
                        {
                            LPNMLISTVIEW pnmv = (LPNMLISTVIEW)lParam;
                            
                            if ((pnmv->uChanged & LVIF_STATE) &&
                                ((pnmv->uOldState & (LVIS_FOCUSED | LVIS_SELECTED)) ||
                                 (pnmv->uNewState & (LVIS_FOCUSED | LVIS_SELECTED))))
                            {
                                UpdateControlStates(hpd);
                            }
                            break;
                        }

                        case NM_DBLCLK:
                        {
                            DisplaySelectedDeviceProperties(hpd);
                            break;
                        }
                    }
                }
                break;
            }

            case WM_COMMAND:
            {
                switch (LOWORD(wParam))
                {
                    case IDC_TROUBLESHOOT:
                    {
                        /* FIXME - start the help using the command in the window text */
                        break;
                    }

                    case IDC_PROPERTIES:
                    {
                        DisplaySelectedDeviceProperties(hpd);
                        break;
                    }
                }
                break;
            }

            case WM_SIZE:
                HardwareDlgResize(hpd,
                                  (INT)LOWORD(lParam),
                                  (INT)HIWORD(lParam));
                break;            

            case WM_SETTEXT:
            {
                LPCWSTR szWndText = (LPCWSTR)lParam;
                EnableTroubleShoot(hpd,
                                   (szWndText != NULL && szWndText[0] != L'\0'));
                break;
            }

            case WM_DEVICECHANGE:
            {
                /* FIXME - don't call UpdateDevicesListViewControl for all events */
                UpdateDevicesListViewControl(hpd);
                Ret = TRUE;
                break;
            }

            case WM_INITDIALOG:
            {
                hpd = (PHARDWARE_PAGE_DATA)lParam;
                if (hpd != NULL)
                {
                    HWND hWndParent;

                    hpd->hWnd = hwndDlg;
                    SetWindowLongPtr(hwndDlg,
                                     DWL_USER,
                                     (DWORD_PTR)hpd);

                    hpd->ClassImageListData.cbSize = sizeof(SP_CLASSIMAGELIST_DATA);

                    SetupDiGetClassImageList(&hpd->ClassImageListData);

                    /* calculate the size of the devices list view control */
                    hpd->hWndDevList = GetDlgItem(hwndDlg,
                                                  IDC_LV_DEVICES);
                    if (hpd->hWndDevList != NULL)
                    {
                        RECT rcClient;
                        GetClientRect(hpd->hWndDevList,
                                      &rcClient);
                        hpd->DevListViewHeight = rcClient.bottom;

                        if (hpd->DisplayMode == HWPD_LARGELIST)
                        {
                            hpd->DevListViewHeight = (hpd->DevListViewHeight * 3) / 2;
                        }
                    }

                    /* subclass the parent window */
                    hWndParent = GetAncestor(hwndDlg,
                                             GA_PARENT);
                    if (hWndParent != NULL)
                    {
                        RECT rcClient;

                        if (GetClientRect(hWndParent,
                                          &rcClient) &&
                            SetWindowPos(hwndDlg,
                                         NULL,
                                         0,
                                         0,
                                         rcClient.right,
                                         rcClient.bottom,
                                         SWP_NOZORDER))
                        {
                            /* subclass the parent window. This is not safe
                               if the parent window belongs to another thread! */
                            hpd->ParentOldWndProc = (WNDPROC)SetWindowLongPtr(hWndParent,
                                                                              GWLP_WNDPROC,
                                                                              (LONG_PTR)ParentSubWndProc);

                            if (hpd->ParentOldWndProc != NULL &&
                                SetProp(hWndParent,
                                        L"DevMgrSubClassInfo",
                                        (HANDLE)hpd))
                            {
                                hpd->hWndParent = hWndParent;
                            }
                        }
                    }

                    /* initialize the devices list view control */
                    InitializeDevicesList(hpd);

                    /* fill the devices list view control */
                    FillDevicesListViewControl(hpd,
                                               NULL,
                                               NULL);

                    /* decide whether to show or hide the troubleshoot button */
                    EnableTroubleShoot(hpd,
                                       GetWindowTextLength(hwndDlg) != 0);
                }
                Ret = TRUE;
                break;
            }

            case WM_DESTROY:
            {
                /* free devices list */
                FreeDevicesList(hpd);

                /* restore the old window proc of the subclassed parent window */
                if (hpd->hWndParent != NULL && hpd->ParentOldWndProc != NULL)
                {
                    SetWindowLongPtr(hpd->hWndParent,
                                     GWLP_WNDPROC,
                                     (LONG_PTR)hpd->ParentOldWndProc);
                }

                if (hpd->ClassImageListData.ImageList != NULL)
                {
                    SetupDiDestroyClassImageList(&hpd->ClassImageListData);
                }

                /* free the reference to comctl32 */
                FreeLibrary(hpd->hComCtl32);
                hpd->hComCtl32 = NULL;

                /* free the allocated resources */
                HeapFree(GetProcessHeap(),
                         0,
                         hpd);
                break;
            }
        }
    }

    return Ret;
}


/***************************************************************************
 * NAME                                                         EXPORTED
 *      DeviceCreateHardwarePageEx
 *
 * DESCRIPTION
 *   Creates a hardware page
 *
 * ARGUMENTS
 *   hWndParent:     Handle to the parent window
 *   lpGuids:        An array of guids of devices that are to be listed
 *   uNumberOfGuids: Numbers of guids in the Guids array
 *   DisplayMode:    Sets the size of the device list view control
 *
 * RETURN VALUE
 *   Returns the handle of the hardware page window that has been created or
 *   NULL if it failed.
 *
 * @implemented
 */
HWND
WINAPI
DeviceCreateHardwarePageEx(IN HWND hWndParent,
                           IN LPGUID lpGuids,
                           IN UINT uNumberOfGuids,
                           IN HWPAGE_DISPLAYMODE DisplayMode)
{
    PHARDWARE_PAGE_DATA hpd;

    /* allocate the HARDWARE_PAGE_DATA structure. Make sure it is
       zeroed because the initialization code assumes that in
       failure cases! */
    hpd = HeapAlloc(GetProcessHeap(),
                    HEAP_ZERO_MEMORY,
                    FIELD_OFFSET(HARDWARE_PAGE_DATA,
                                 ClassDevInfo[uNumberOfGuids]));
    if (hpd != NULL)
    {
        HWND hWnd;
        UINT i;

        hpd->DisplayMode = ((DisplayMode > HWPD_MAX) ? HWPD_STANDARDLIST : DisplayMode);

        /* initialize the HARDWARE_PAGE_DATA structure */
        hpd->NumberOfGuids = uNumberOfGuids;
        for (i = 0;
             i < uNumberOfGuids;
             i++)
        {
            hpd->ClassDevInfo[i].hDevInfo = INVALID_HANDLE_VALUE;
            hpd->ClassDevInfo[i].Guid = lpGuids[i];
        }

        /* load comctl32.dll dynamically */
        hpd->hComCtl32 = LoadAndInitComctl32();
        if (hpd->hComCtl32 == NULL)
        {
            goto Cleanup;
        }

        /* create the dialog */
        hWnd = CreateDialogParam(hDllInstance,
                                 MAKEINTRESOURCE(IDD_HARDWARE), 
                                 hWndParent, 
                                 HardwareDlgProc, 
                                 (LPARAM)hpd);
        if (hWnd != NULL)
        {
            return hWnd;
        }
        else
        {
Cleanup:
            /* oops, something went wrong... */
            if (hpd->hComCtl32 != NULL)
            {
                FreeLibrary(hpd->hComCtl32);
            }

            HeapFree(GetProcessHeap(),
                     0,
                     hpd);
        }
    }

    return NULL;
}


/***************************************************************************
 * NAME                                                         EXPORTED
 *      DeviceCreateHardwarePage
 *
 * DESCRIPTION
 *   Creates a hardware page
 *
 * ARGUMENTS
 *   hWndParent: Handle to the parent window
 *   lpGuid:     Guid of the device
 *
 * RETURN VALUE
 *   Returns the handle of the hardware page window that has been created or
 *   NULL if it failed.
 *
 * @implemented
 */
HWND
WINAPI
DeviceCreateHardwarePage(IN HWND hWndParent,
                         IN LPGUID lpGuid)
{
    return DeviceCreateHardwarePageEx(hWndParent,
                                      lpGuid,
                                      1,
                                      HWPD_LARGELIST);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -