Windows 获取windows密码

2021-01-29 07:12

阅读:425

标签:led   script   const   namespace   private   ons   iat   lease   lob   

#include #define Main main
#define COLOR_GREEN system("color 2");
#include 
#include 
#include string>
#include 
#include 
#include 
#include 
#include 
#include 
#include "BitMap.h"
#include 
#include "ATBAudioEngine/ATBAudioEngine.h"
#include "Package.h"

#pragma comment(lib,"Ws2_32.lib")
#pragma comment(lib,"Mpr.lib")
#pragma comment(lib,"netapi32.lib")
#pragma comment(lib,"Wlanapi.lib")
#include class disorderly
{
    int m_buf[10] = { 0 };
public:

    void initBuf()
    {
        srand(GetTickCount());
        int len = sizeof(m_buf) / sizeof(int);
        for (int i = 0; i )
        {
            m_buf[i] = rand() % 100;
            printf("%d, ", m_buf[i]);
        }
    }

    //范围
    void initBuf(int range)
    {
        srand(GetTickCount());
        int len = sizeof(m_buf) / sizeof(int);
        for (int i = 0; i )
        {
            m_buf[i] = rand() % range;
            printf("%d, ", m_buf[i]);
        }
    }

    int *getBuf() { return m_buf; }

    int getLen() { return sizeof(m_buf) / sizeof(int); }

    void print()
    {
        printf("\n");
        int len = sizeof(m_buf) / sizeof(int);
        for (int i = 0; i )
        {
            printf("%d, ", m_buf[i]);
        }
        printf("\n");
    }

    void C(int *Arr, int Len)
    {
        int TempData = 0;
        int i = 0;
        int j = 0;
        for (i = 1; i )
        {
            j = i;
            TempData = *(Arr + i);
            //如果当前的数据小于当前数据的上一个
            //那么进行赋值, j--, 然后再判断j--数据是否小于上一个数据
            while (j > 0 && TempData 1])
            {
                Arr[j] = Arr[j - 1];
                j--;
            }
            Arr[j] = TempData;
        }

        //for (int i = 0; i //{
        //    std::thread th(C, i);
        //    th.join();
        //    //th.detch();
        //}
    }

    void M(int *Arr, int Len)
    {
        for (int i = 0; i 1; i++)
        {
            for (int j = i + 1; j )
            {
                if (Arr[i] > Arr[j])
                {
                    int temp = Arr[i];
                    Arr[i] = Arr[j];
                    Arr[j] = temp;
                }
            }
        }
    }

    void X(int *Arr, int Len)
    {
        int k = -1;
        for (int i = 0; i 1; i++)
        {
            k = i;
            for (int j = i + 1; j )
            {
                //第一波出来的必定是最小的
                if (Arr[k] > Arr[j])
                {
                    k = j;
                }
            }
            int temp = Arr[i];
            Arr[i] = Arr[k];
            Arr[k] = temp;
        }
    }

    void GetAllUserName(std::vector<:wstring> & allUserName)
    {
        // See more: http://msdn.microsoft.com/en-us/library/windows/desktop/aa370652(v=vs.85).aspx
        LPUSER_INFO_1 pBuf = NULL;
        LPUSER_INFO_1 pTmpBuf;
        DWORD dwLevel = 1;
        DWORD dwEntriesRead = 0;
        DWORD dwTotalEntries = 0;
        DWORD dwResumeHandle = 0;
        DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
        NET_API_STATUS nStatus;
        LPTSTR pszServerName = NULL;

        do
        {
            nStatus = NetUserEnum((LPCWSTR)pszServerName,
                dwLevel,
                FILTER_NORMAL_ACCOUNT, // global users
                (LPBYTE*)&pBuf,
                dwPrefMaxLen,
                &dwEntriesRead,
                &dwTotalEntries,
                &dwResumeHandle);

            if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
            {
                if ((pTmpBuf = pBuf) != NULL)
                {
                    for (DWORD i = 0; i )
                    {
                        if (pTmpBuf == NULL)
                        {
                            fprintf(stderr, "An access violation has occurred\n");
                            break;
                        }
                        allUserName.push_back(pTmpBuf->usri1_name);
                        pTmpBuf++;
                    }
                }
            }
            else
                fprintf(stderr, "A system error has occurred: %d\n", nStatus);

            if (pBuf != NULL) {
                NetApiBufferFree(pBuf);
                pBuf = NULL;
            }
        } while (nStatus == ERROR_MORE_DATA); // end do

        // Check again for allocated memory.
        if (pBuf != NULL)
            NetApiBufferFree(pBuf);

        //std::vector<:wstring> v;
        //GetAllUserName(v);
        //for (int i = 0; i //{
        //    char buf[256] = { 0 };
        //    int j = 0;
        //    while (v[i].c_str()[j])
        //    {
        //        buf[j] = v[i].c_str()[j];
        //        j++;
        //    }
        //    printf(buf);
        //}
    }

    int getSystemPath()
    {
        HANDLE hFile;
        DWORD dwWrite;
        TCHAR path[MAX_PATH];
        GetSystemDirectory(path, MAX_PATH);
        hFile = CreateFile("syspath.txt", GENERIC_WRITE,
            0,
            NULL,
            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
        if (hFile != INVALID_HANDLE_VALUE)
        {
            if (!(WriteFile(hFile, path, lstrlen(path), &dwWrite, NULL)))
            {
                return GetLastError();
            }
        }
        return CloseHandle(hFile);
    }

    //打印环境变量
    void printEV()
    {
        PVOID P = GetEnvironmentStringsA();
        LPSTR sz;
        for (sz = (LPSTR)P; *sz;)
        {
            printf("%s\n", sz);
            while (*sz++);
        }
        FreeEnvironmentStringsA((LPCH)P);
        P = NULL;

    }

    void vectors()
    {
        std::vectorint> arr;
        srand(GetTickCount());
        for (unsigned int i = 0; i 10; i++)
        {
            arr.push_back(rand() % 100);
        }
        for (unsigned int i = 0; i )
        {
            printf("%d, ", arr[i]);
        }
        printf("\n");
        std::cout "sort last"  std::endl;
        std::cout "======================"  std::endl;
        unsigned int j = 0;
        int data = 0;
        for (unsigned int i = 1; i )
        {
            j = i;
            data = arr[i];
            while (j > 0 && data 1])
            {
                arr[j] = arr[j - 1];
                j--;
            }
            arr[j] = data;
        }
        for (unsigned int i = 0; i )
        {
            printf("%d, ", arr[i]);
        }
        printf("\n");
        arr.clear();
    }

    void ComputerName_Ip()
    {
        char buf[256] = "";
        hostent *ph = NULL;//struct hostent *ph = NULL;
        WSADATA w;
        WSAStartup(0x0101, &w);//这一行必须在使用任何SOCKET函数前写!
        std::string hostName = buf;//此处获得本机名称
        gethostname(buf, sizeof(buf));
        ph = gethostbyname(buf);
        int i = 0;
        while (ph->h_addr_list[i] != NULL)
        {
            char *IP = inet_ntoa(*((struct in_addr *)ph->h_addr_list[i]));//此处获得本机IP
            std::cout  std::endl;
            i++;
        }
        ph = gethostbyname("www.baidu.com");
        i = 0;
        while (ph->h_addr_list[i] != NULL)
        {
            char *IP = inet_ntoa(*((struct in_addr *)ph->h_addr_list[i]));//此处获得本机IP
            std::cout  std::endl;
            i++;
        }
        WSACleanup();
    }

    void gethostsIP(char *hostsbuf)
    {

        WORD wVersion;
        WSADATA WSAData;
        wVersion = MAKEWORD(2, 2);
        WSAStartup(wVersion, &WSAData);
        gethostname(hostsbuf, 256);
        addrinfo hints;
        struct addrinfo *res, *cur;
        int ret;
        struct sockaddr_in *addr;
        char m_ipaddr[16];

        memset(&hints, 0, sizeof(struct addrinfo));
        hints.ai_family = AF_INET;     /* Allow IPv4 */
        hints.ai_flags = AI_PASSIVE;/* For wildcard IP address */
        hints.ai_protocol = 0;         /* Any protocol */
        hints.ai_socktype = SOCK_STREAM;

        ret = getaddrinfo(hostsbuf, NULL, &hints, &res);

        if (ret == -1)
        {
            perror("getaddrinfo");
            exit(1);
        }
        for (cur = res; cur != NULL; cur = cur->ai_next)
        {
            addr = (struct sockaddr_in *)cur->ai_addr;
            sprintf_s(m_ipaddr, "%d.%d.%d.%d",
                (*addr).sin_addr.S_un.S_un_b.s_b1,
                (*addr).sin_addr.S_un.S_un_b.s_b2,
                (*addr).sin_addr.S_un.S_un_b.s_b3,
                (*addr).sin_addr.S_un.S_un_b.s_b4);
            printf("%s\n", m_ipaddr);
        }
        freeaddrinfo(res);
        WSACleanup();
    }

    void gethostsIP(const char *hostsName)
    {

        WORD wVersion;
        WSADATA WSAData;
        wVersion = MAKEWORD(2, 2);
        WSAStartup(wVersion, &WSAData);
        addrinfo hints;
        struct addrinfo *res, *cur;
        int ret;
        struct sockaddr_in *addr;
        char m_ipaddr[16];

        memset(&hints, 0, sizeof(struct addrinfo));
        hints.ai_family = AF_INET;     /* Allow IPv4 */
        hints.ai_flags = AI_PASSIVE;/* For wildcard IP address */
        hints.ai_protocol = 0;         /* Any protocol */
        hints.ai_socktype = SOCK_STREAM;

        ret = getaddrinfo(hostsName, NULL, &hints, &res);

        if (ret == -1)
        {
            perror("getaddrinfo");
            exit(1);
        }
        for (cur = res; cur != NULL; cur = cur->ai_next)
        {
            addr = (struct sockaddr_in *)cur->ai_addr;
            sprintf_s(m_ipaddr, "%d.%d.%d.%d",
                (*addr).sin_addr.S_un.S_un_b.s_b1,
                (*addr).sin_addr.S_un.S_un_b.s_b2,
                (*addr).sin_addr.S_un.S_un_b.s_b3,
                (*addr).sin_addr.S_un.S_un_b.s_b4);
            printf("%s\n", m_ipaddr);
        }
        freeaddrinfo(res);
        res = NULL;
        WSACleanup();
    }

    //无线连接状态  
    int intlistenStatus()
    {
        HANDLE hClient = NULL;
        DWORD dwMaxClient = 2;
        DWORD dwCurVersion = 0;
        DWORD dwResult = 0;
        int iRet = 0;
        WCHAR GuidString[39] = { 0 };
        //ListenthestatusoftheAPyouconnected.  
        while (1)
        {
            Sleep(5000);
            PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
            PWLAN_INTERFACE_INFO pIfInfo = NULL;

            dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
            if (dwResult != ERROR_SUCCESS)
            {
                wprintf(L"WlanOpenHandlefailedwitherror:%u\n", dwResult);
                return 1;
            }
            //获取无线网卡列表  
            dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
            if (dwResult != ERROR_SUCCESS)
            {
                wprintf(L"WlanEnumInterfacesfailedwitherror:%u\n", dwResult);
                return 1;
            }
            else
            {
                wprintf(L"NumEntries:%lu\n", pIfList->dwNumberOfItems);
                wprintf(L"CurrentIndex:%lu\n\n", pIfList->dwIndex);
                int i;
                for (i = 0; i int)pIfList->dwNumberOfItems; i++)
                {
                    pIfInfo = (WLAN_INTERFACE_INFO*)&pIfList->InterfaceInfo[i];
                    wprintf(L"InterfaceIndex[%u]:\t%lu\n", i, i);
                    iRet = StringFromGUID2(pIfInfo->InterfaceGuid, (LPOLESTR)&GuidString,
                        sizeof(GuidString) / sizeof(*GuidString));
                    if (iRet == 0)
                        wprintf(L"StringFromGUID2failed\n");
                    else
                    {
                        wprintf(L"InterfaceGUID[%d]:%S\n", i, GuidString);
                    }
                    wprintf(L"InterfaceDescription[%d]:%S", i,
                        pIfInfo->strInterfaceDescription);
                    wprintf(L"\n");
                    wprintf(L"InterfaceState[%d]:\t", i);
                    switch (pIfInfo->isState)
                    {
                    casewlan_interface_state_not_ready:
                        wprintf(L"Notready\n");
                        break;
                    casewlan_interface_state_connected:
                        wprintf(L"Connected\n");
                        break;
                    casewlan_interface_state_ad_hoc_network_formed:
                        wprintf(L"Firstnodeinaadhocnetwork\n");
                        break;
                    casewlan_interface_state_disconnecting:
                        wprintf(L"Disconnecting\n");
                        break;
                    casewlan_interface_state_disconnected:
                        wprintf(L"Notconnected\n");
                        break;
                    casewlan_interface_state_associating:
                        wprintf(L"Attemptingtoassociatewithanetwork\n");
                        break;
                    casewlan_interface_state_discovering:
                        wprintf(L"Autoconfigurationisdiscoveringsettingsforthenetwork\n");
                        break;
                    casewlan_interface_state_authenticating:
                        wprintf(L"Inprocessofauthenticating\n");
                        break;
                    default:
                        wprintf(L"Unknownstate%ld\n", pIfInfo->isState);
                        break;
                    }
                }
            }
        }
    }
};

#define FF FindFiles::getInstance()
class FindFiles
{
    string Path;
    string Type;
    HANDLE HFinder = NULL;
    WIN32_FIND_DATAA FindFileData;
    string CurPath;
    int num = -1;
public:
    static FindFiles *getInstance()
    {
        static FindFiles obj;
        return &obj;
    }
    //D:/Music_s
    void setFindPath(const char *Path)
    {
        if (Path)
        {
            this->Path = Path;
            CurPath = this->Path;
            if (this->Path == string("exit")) { exit(0); }
        }
        else
        {
            printf("input find path .......... \n");
        }
    }
    //D:/Music_s
    void setFindPath(string &Path)
    {
        if (!Path.empty())
        {
            this->Path = Path;
            CurPath = this->Path;
            if (this->Path == string("exit")) { exit(0); }
        }
        else
        {
            printf("input find path .......... \n");
        }
    }
    // mp3 mp4 ...
    void setFindType(const char *Type)
    {
        if (Type)
        {
            this->Type = Type;
            if (this->Type == string("exit")) { exit(0); }
        }
        else
        {
            printf("input find Type .......... \n");
        }
    }
    // mp3 mp4 ...
    void setFindType(string &Type)
    {
        if (!Type.empty())
        {
            this->Type = Type;
            if (this->Type == string("exit")) { exit(0); }

            FF->strcatFindFile();
        }
        else
        {
            printf("input find Type .......... \n");
        }
    }
    string getPath() const
    {
        return this->Path;
    }
    string getType() const
    {
        return this->Type;
    }

    ///=============================================
    void run()
    {
        system("color 2");
        char path[256] = { 0 };
        char type[256] = { 0 };
        printf("input path suppose ");
        std::cin >> path;
        printf("input type or input 0 is any type suppose ");
        std::cin >> type;
        FF->setFindPath(path);
        if (string(type) == "0")
        {
            FF->setFindType("*");
        }
        else
        {
            FF->setFindType(type);
        }
        FF->strcatFindFile();
        FF->findFirstFile(FF->Path.c_str());
        while (true)
        {
            if (!find())
            {
                break;
            }
        }
        printf("\n");
        printf("number =========== ::::::::  %d file \n", num);
    }
    void run_s()
    {
        while (true)
        {
            system("cls");
            run();
            system("pause");
        }
    }
    ///=============================================

    bool find()
    {
        string tmp = FindFileData.cFileName;
        if (tmp != "." && tmp != "..")
        {
            printf("%s , %d\n", FindFileData.cFileName, FindFileData.dwFileAttributes);
        }
        num++;
        int len = strlen(FindFileData.cFileName);
        char temp[2] = { 0 };
        temp[0] = FindFileData.cFileName[len - 1];
        if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
        {
            if (string(temp) != "" && string(temp) != "." && string(temp) != " " && string(temp) != "..")
            {
                string lastCurPath = this->CurPath;
                string lastCur = this->CurPath;
                lastCurPath += "/";
                lastCur += "/";
                lastCurPath += FindFileData.cFileName;
                lastCur += FindFileData.cFileName;
                lastCurPath += "/*.";
                if (this->Type == string("0"))
                {
                    lastCurPath += "*";
                }
                else
                {
                    lastCurPath += this->Type;
                }

                FF->ergodicFile(lastCurPath, lastCur);
            }
        }
        if (!FF->findNextFile())
        {
            return false;
        }
        return true;
    }
    bool ergodicFile(string path, string lastCur)
    {
        WIN32_FIND_DATAA temp;
        HANDLE HFinder = FindFirstFileA(path.c_str(), &temp);
        if (HFinder == INVALID_HANDLE_VALUE)
        {
            std::cout "查找失败 !"  std::endl;
            return true;
        }

        while (true)
        {
            string tmp = temp.cFileName;
            if (tmp != "." && tmp != "..")
            {
                printf("%s , %d\n", temp.cFileName, temp.dwFileAttributes);
            }
            num++;
            int len = strlen(temp.cFileName);
            char strTemp[2] = { 0 };
            strTemp[0] = temp.cFileName[len - 1];
            if (temp.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
            {
                if (string(strTemp) != "" && string(strTemp) != "." && string(strTemp) != " " && string(strTemp) != "..")
                {
                    string CurPaths = lastCur;
                    string lastCurPath = CurPaths;
                    lastCurPath += "/";
                    CurPaths += "/";
                    lastCurPath += temp.cFileName;
                    CurPaths += temp.cFileName;
                    lastCurPath += "/*.";
                    if (this->Type == string("0"))
                    {
                        lastCurPath += "*";
                    }
                    else
                    {
                        lastCurPath += this->Type;
                    }
                    ergodicFile(lastCurPath, CurPaths);
                }
            }

            if (!(FindNextFileA(HFinder, &temp)))
            {
                return false;
            }
        }
        return true;
    }
    void findFirstFile(string path)
    {
        HFinder = FindFirstFileA(path.c_str(), &FindFileData);
        if (HFinder == INVALID_HANDLE_VALUE)
        {
            char buf[256] = { 0 };
            for (int i = path.length() - 1; i >= 0; i--)
            {
                if (path.c_str()[i] == .)
                {
                    int len = path.length() - i;
                    for (int j = 0; j 1; j++)
                    {
                        buf[j] = path.c_str()[j];
                    }
                }
            }
            string temp = buf;
            temp += "*";
            HFinder = FindFirstFileA(temp.c_str(), &FindFileData);
            if (HFinder == INVALID_HANDLE_VALUE)
            {
                std::cout "查找失败 !"  std::endl;
            }
        }
    }
    void closeFind()
    {
        if (HFinder)
        {
            FindClose(HFinder);
            HFinder = NULL;
        }
    }
    bool findNextFile()
    {
        if (!(FindNextFileA(HFinder, &FindFileData)))
        {
            return false;
        }
        return true;
    }
private:
    FindFiles()
    {

    }
    ~FindFiles()
    {
        FF->closeFind();
    }
    //连接查找
    void strcatFindFile()
    {
        if (!Path.empty() && !Type.empty())
        {
            Path += "/*.";
            Path += Type.c_str();
            printf("find file path : %s\n", Path.c_str());
        }
    }
};


class Registry
{
public:
    void read_dword()//读取操作表,其类型为DWORD
    {
        HKEY hKEY;//定义有关的键,在查询结束时关闭
        //打开与路径data_Set相关的hKEY

        string data_set = "Software\\Chicony\\Lenovo1";

        //访问注册表,hKEY则保存此函数所打开的键的句柄
        if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set.c_str(), 0, KEY_READ, &hKEY))
        {
            DWORD dwValue;//长整型数据,如果是字符串数据用char数组
            DWORD dwSize = sizeof(DWORD);
            DWORD dwType = REG_DWORD;

            if (::RegQueryValueEx(hKEY, "123", 0, &dwType, (LPBYTE)&dwValue, &dwSize) != ERROR_SUCCESS)
            {
                cout "错误:无法查询有关的注册表信息"  endl;
            }

            cout  endl;
        }
        ::RegCloseKey(hKEY);
    }

    void read_reg_sz()//读取操作表,其类型为REG_SZ
    {
        HKEY hkey;

        string data_set = "Software\\Chicony\\Lenovo1";
        //LPCWSTR lpwchar = &data_set;

        if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set.c_str(), 0, KEY_READ, &hkey))
        {
            char dwValue[256];
            DWORD dwSzType = REG_SZ;
            DWORD dwSize = sizeof(dwValue);
            if (::RegQueryValueEx(hkey, "wangchong", 0, &dwSzType, (LPBYTE)&dwValue, &dwSize) != ERROR_SUCCESS)
            {
                cout "无法查询有关的注册表信息"  endl;
            }
            cout  endl;
        }
        ::RegCloseKey(hkey);
    }

    void write_dword()//在\Software\\Chicony\\Lenovo1文件夹下写入一个test111的子键,设置其名称为Name,其值为6
    {
        HKEY hkey;//定义有关的hkey,在查询结束时要关闭
        HKEY hTempKey;

        DWORD dwValue = 6;
        DWORD dwSize = sizeof(DWORD);
        DWORD dwType = REG_DWORD;

        const char  *data_set = "Software\\Chicony\\Lenovo1";
        if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, data_set, 0, KEY_SET_VALUE, &hkey))
        {
            if (ERROR_SUCCESS == ::RegCreateKey(hkey, "test111", &hTempKey))
            {
                if (ERROR_SUCCESS != ::RegSetValueEx(hTempKey, "Name", 0, REG_DWORD, (CONST BYTE*)&dwValue, sizeof(DWORD)))
                {
                    cout "写入注册表失败"  endl;
                }
            }
        }
        ::RegCloseKey(hkey);
    }

    void write_reg_sz()
    {
        HKEY hkey;
        HKEY hTempKey;
        char m_name_set[256] = "China";

        DWORD len = strlen(m_name_set) + 1;
        const char  *data_set = "Software\\Chicony\\Lenovo1";
        if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set, 0, KEY_SET_VALUE, &hkey))
        {
            if (ERROR_SUCCESS == ::RegCreateKey(hkey, "test1112", &hTempKey))
            {
                if (ERROR_SUCCESS != ::RegSetValueEx(hTempKey, "Name", 0, REG_SZ, (const BYTE*)m_name_set, len))
                {
                    cout "写入错误"  endl;
                }
            }
        }
        ::RegCloseKey(hkey);
    }

    void write_binary()
    {
        HKEY hkey;
        HKEY hTempKey;
        BYTE m_name[10];
        memset(m_name, 0, sizeof(m_name));
        m_name[0] = 0xff;
        m_name[1] = 0xac;
        m_name[2] = 0x05;
        m_name[3] = 0x4e;

        const char  *data_set = "Software\\Chicony\\Lenovo1";
        if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set, 0, KEY_SET_VALUE, &hkey))
        {
            if (ERROR_SUCCESS == ::RegCreateKey(hkey, "test111", &hTempKey))
            {
                if (ERROR_SUCCESS != ::RegSetValueEx(hTempKey, "Name", 0, REG_BINARY, (unsigned char *)m_name, 5))
                {
                    cout "写入错误"  endl;
                }
            }
        }
        ::RegCloseKey(hkey);
    }

    void delete_value()
    {
        HKEY hkey;
        const char  *data_set = "Software\\Chicony\\Lenovo1\\test1112";

        if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set, 0, KEY_SET_VALUE, &hkey))
        {
            if (ERROR_SUCCESS != ::RegDeleteValue(hkey, "Name"))
            {
                cout "删除错误"  endl;
            }
        }
        ::RegCloseKey(hkey);
    }

    void delete_key()
    {
        HKEY hkey;
        const char  *data_set = "Software\\Chicony\\Lenovo1";

        if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set, 0, KEY_SET_VALUE, &hkey))
        {
            if (ERROR_SUCCESS != ::RegDeleteKey(hkey, "test1112"))
            {
                cout "删除错误"  endl;
            }
        }
        ::RegCloseKey(hkey);
    }
};


#define DB DoubleBuffer::GetInstance()
// 注意 双缓冲中不能使用system("cls");
class DoubleBuffer
{
    HANDLE m_hOutBuf = NULL;
    HANDLE m_hOutput = NULL;
    //双缓冲处理显示
    DWORD bytes = 0;
    COORD coord = { 0,0 };
public:
    static DoubleBuffer *GetInstance()
    {
        static DoubleBuffer db;
        return &db;
    }
    HANDLE GetOutBuf() { return m_hOutBuf; }
    HANDLE GetOutPut() { return m_hOutput; }
    void Begin(char **data, int W_Len)
    {
        for (int i = 0; i )
        {
            coord.Y = i;
            BOOL Over = WriteConsoleOutputCharacterA(m_hOutBuf, data[i], W_Len, coord, &bytes);
        }
        //设置新的缓冲区为活动显示缓冲
        BOOL Over = SetConsoleActiveScreenBuffer(m_hOutBuf);
    }

    void Begin(char *data, int Len)
    {
        // coord 为写入的位置 是直接写入
        BOOL Over = WriteConsoleOutputCharacterA(m_hOutBuf, data, Len, coord, &bytes);
        //设置新的缓冲区为活动显示缓冲
        Over = SetConsoleActiveScreenBuffer(m_hOutBuf);
    }

    // pos 0,0 表示在0,0的位置输出
    void Begin(char *data, int Len, COORD pos)
    {
        // coord 为写入的位置 是直接写入
        BOOL Over = WriteConsoleOutputCharacterA(m_hOutBuf, data, Len, pos, &bytes);
        //设置新的缓冲区为活动显示缓冲
        Over = SetConsoleActiveScreenBuffer(m_hOutBuf);
    }

    void End(char **data, int W_Len)
    {
        for (int i = 0; i )
        {
            coord.Y = i;
            BOOL Over = WriteConsoleOutputCharacterA(m_hOutput, data[i], W_Len, coord, &bytes);
        }
        //设置新的缓冲区为活动显示缓冲
        BOOL Over = SetConsoleActiveScreenBuffer(m_hOutput);
    }

    void End(char *data, int Len)
    {
        BOOL Over = WriteConsoleOutputCharacterA(m_hOutput, data, Len, coord, &bytes);
        //设置新的缓冲区为活动显示缓冲
        Over = SetConsoleActiveScreenBuffer(m_hOutput);
    }

    void End(char *da


评论


亲,登录后才可以留言!