Win32程序从列表控件上的子项,数据和值的对话框中搜索值

时间:2014-08-08 04:24:34

标签: winapi

我想在Win32应用程序中使用一个程序,当用户在编辑控件中输入一个字符串时,通过注册表执行搜索,以显示在子键或数据或值中找到的字符串。 应向用户提供完整路径

输出应显示给具有3列子键,数据和值

的网格控件上的用户

我做的一些代码

INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    static HWND hwndButton[3], hwndEdit,hList;
    LPTSTR lpString=new TCHAR[1000];

    for(int i=0;i<100;i++)
{
    wz_reg_path[i][0]=L'\0';
        wz_reg_value[i][0]=L'\0';
        wz_reg_data[i][0]=L'\0';

}

    hwndButton[1] = GetDlgItem (hDlg, IDC_CHECK1);
    hwndButton[2] = GetDlgItem (hDlg, IDC_CHECK2);
    hwndButton[3] = GetDlgItem (hDlg, IDC_CHECK3);
    hwndEdit=GetDlgItem (hDlg, IDC_EDIT1);
    hList=GetDlgItem (hDlg, IDC_LIST1);

    //UNREFERENCED_PARAMETER(lParam);
    switch (message)
    {
    case WM_INITDIALOG:

        return (INT_PTR)TRUE;
    case WM_COMMAND:
        if (LOWORD(wParam) == IDC_BUTTON1)
        {
            EndDialog(hDlg, LOWORD(wParam));
            return (INT_PTR)TRUE;
        }
        if (LOWORD(wParam) == IDOK)
        {
            int stateCheck_check1,stateCheck_check2,stateCheck_check3, editcheck;

            stateCheck_check1=(int) SendMessage (hwndButton[1], BM_GETCHECK, 0, 0) ;
            stateCheck_check2=(int) SendMessage (hwndButton[2], BM_GETCHECK, 0, 0) ;
            stateCheck_check3=(int) SendMessage (hwndButton[3], BM_GETCHECK, 0, 0) ;

            editcheck=GetDlgItemText(hDlg,IDC_EDIT1,lpString,WM_GETTEXTLENGTH);

            if(editcheck >0 && stateCheck_check1==1 )
            {
                HKEY hKey[5];
                hKey[0]=HKEY_CLASSES_ROOT;
                hKey[1]=HKEY_CURRENT_USER;
                hKey[2]=HKEY_LOCAL_MACHINE;
                hKey[3]=HKEY_USERS;
                hKey[4]=HKEY_CURRENT_CONFIG;

                HWND hList;
                hList=GetDlgItem (hDlg, IDC_LIST1);
                LVCOLUMN LvCol;
                LVITEM LvItem;
                memset(&LvCol,0,sizeof(LvCol));
                LvCol.mask=LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM;
                LvCol.cx=0x28;
                LvCol.pszText=L"SubKey";
                LvCol.cx=0x98;
                SendMessage(hList,LVM_INSERTCOLUMN,0,(LPARAM)&LvCol); 

                LvCol.pszText=L"Values"; 
                SendMessage(hList,LVM_INSERTCOLUMN,1,(LPARAM)&LvCol); 

                LvCol.pszText=L"Data";     
                SendMessage(hList,LVM_INSERTCOLUMN,2,(LPARAM)&LvCol); 

                for(int j=0;j<5;j++)
                {
                    EnumerateSubKeys(hDlg,hKey[j],lpString);

                } 

                for(int i=0;i<icount_keys;i++)
                {
                memset(&LvItem,0,sizeof(LvItem)); 
                                LvItem.mask=LVIF_TEXT;
                                LvItem.cchTextMax = 256;
                                LvItem.iItem=1; 
                                LvItem.iSubItem=0;
                                LvItem.pszText= L"%ls", wz_reg_path; 

                                SendMessage(hList,LVM_INSERTITEM,0,(LPARAM)&LvItem);
                }

            }
        }
        break;
    }
    return (INT_PTR)FALSE;
}
DWORD data;

void EnumerateValues(HKEY hKey, DWORD numValues)
{
    DWORD valNameLen = 64;
    DWORD dwIndex = 0;
    LPTSTR valueName = new TCHAR[1000];
    DWORD dataType;

    DWORD dataSize;

    for (int i = 0; i < numValues; i++)
    {

        RegEnumValue(hKey,
            dwIndex,
            valueName,
            &valNameLen,
            NULL,
            &dataType,
            (BYTE*)&data,
            &dataSize);

        dwIndex++;

        wcscpy(wz_reg_value[0],valueName);

    }
}

void EnumerateSubKeys(HWND HDlg1 ,HKEY RootKey, LPTSTR subKey) 
{
    HKEY hKey;
    TCHAR    achClass[MAX_PATH] = TEXT("");   // buffer for class name 
    DWORD    cchClassName = MAX_PATH;  // size of class string 
    DWORD    cSubKeys=0;               // number of subkeys 
    DWORD    cbMaxSubKey;              // longest subkey size 
    DWORD    cchMaxClass;              // longest class string 
    DWORD    cValues;              // number of values for key 
    DWORD    cchMaxValue;          // longest value name 
    DWORD    cbMaxValueData;       // longest value data 
    DWORD    cbSecurityDescriptor; // size of security descriptor 
    FILETIME ftLastWriteTime;      // last write time 

    HKEY hsubKey;
    DWORD  retCode; 


    retCode=RegOpenKeyEx(RootKey, NULL, 0, KEY_ALL_ACCESS, &hKey);

    retCode=RegQueryInfoKey(RootKey,achClass,&cchClassName,NULL,&cSubKeys,
        &cbMaxSubKey,&cchMaxClass,&cValues,&cchMaxValue,&cbMaxValueData,
        &cbSecurityDescriptor,&ftLastWriteTime); 


    if(cSubKeys>0)
    {
        TCHAR currentSubkey[MAX_PATH];

        for(int i=0;i < cSubKeys;i++)
        {
            DWORD currentSubLen=MAX_PATH;

            retCode=RegEnumKeyEx(hKey,    // Handle to an open/predefined key
                i,                // Index of the subkey to retrieve.
                currentSubkey,            // buffer to receives the name of the subkey
                &currentSubLen,             // size of that buffer
                NULL,                // Reserved
                NULL,                // buffer for class string 
                NULL,                // size of that buffer
                &ftLastWriteTime);                // last write time

            if(StrStr(currentSubkey,subKey)!= NULL)
            {
                wcscpy(wz_reg_path[icount_keys],currentSubkey);
                icount_keys++;


                if(icount_keys==99)
                {
                    break;
                }




        retCode=RegOpenKeyEx(RootKey, NULL, 0, KEY_ALL_ACCESS, &hsubKey);
        if(retCode==ERROR_SUCCESS)
        {
                            EnumerateSubKeys(HDlg1,hsubKey, currentSubkey);
        }

            }

        }
    }
    else
    {
        EnumerateValues(hKey, cValues);
    }

    RegCloseKey(hKey); 
}

0 个答案:

没有答案