i am trying to read Window title from txt file
i will use GetTitleWidnow to get window title using string
i tried this but it didnt display menu in application
ostringstream GetTitleWidnow;
GetTitleWidnow << "MainSvrt on port 51752";
LPCWSTR LMainSvrtTitle;
std::string SMainSvrtTitle = GetTitleWidnow.str();
LMainSvrtTitle = (LPCWSTR)SMainSvrtTitle.c_str();
HWND hWnd = FindWindow(NULL,LMainSvrtTitle);
HMENU hCurrent = GetMenu(hWnd);
HMENU hNew = CreateMenu();
AppendMenu(hCurrent, MF_STRING | MF_POPUP, (unsigned int)hNew, TEXT("Menu"));
AppendMenu(hNew, MF_STRING, MYMENU_Reload, TEXT("Reload Config"));
AppendMenu(hNew, MF_STRING, MYMENU_Credits, TEXT("Credits"));
DrawMenuBar(hWnd);
but when i try
HWND hWnd = FindWindow(NULL,TEXT("MainSvrt on port 51752"));
i get it working fine and it display menu in application
You should either use Microsoft’s CString which automatically converts between wide and narrow characters, or use the
MultiByteToWideCharfunction.