HWND句柄与字符串互转

来源:互联网 发布:中科大物理系知乎 编辑:程序博客网 时间:2024/06/04 06:51

  1. HWND -> std::wstring
    wstring hwnd2ws(HWND hWnd){wchar_t wszHWndView[64] = {};::wnsprintfW(wszHWndView, _countof(wszHWndView), L"%X", hWnd);return wszHWndView;}


  2. std::wstring -> HWND
    HWND ws2hwnd(const wstring& wstr){__int64 i64tmp = __int64(0);std::wstring wstrWnd = wstr;if (wstrWnd[0] != L'0' && (wstrWnd[0] != L'x' || wstrWnd[0] != L'X'))wstrWnd = L"0x" + wstrWnd;::StrToInt64ExW(wstrWnd.c_str(), STIF_SUPPORT_HEX, &i64tmp);return (HWND)i64tmp;}


0 0
原创粉丝点击