How to convert a data of type LPTSTR to HWND?

How to convert a data of type LPTSTR to HWND?

i tried: example

LPTSTR hwnd         = L"0x000511E8";
HWND   window_hwnd  = (HWND)hwnd;

But the value on window_hwnd is not the same as before, and I cant find the window by utilizing this value.

Answer

I think you mean: How to convert a string to a HWND value? That can be done like this:

#include <Windows.h>
#include <string>

int main()
{
    const std::wstring hwnd_str{ L"0x000511E8" };    // to show std::wstring :)
    auto value = std::stoull(hwnd_str, nullptr, 16); // convert from hex (base 16) to unsigned long long (needed for HWND conversion next line)
    HWND window_hwnd = reinterpret_cast<HWND>(value);
}