I wrote a small function to open the WinUser.h file then parse the contents and output in any format i need. I can then create a std::map<int, std::string> and use it for lookup.
void makefile()
{
const std::string outfilename = "C:\\Users\\<username>\\Documents\\Projects\\WinUser.h.txt";
const std::string infilename = "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.26100.0\\um\\WinUser.h";
// open output file
// open input file
// read in 1 line
// if begins "#define <whitespace> WM_<non white space> <white space> ignore remaining"
// copy group 1 (WM_ message with WM_ stripped off)
// sprint to output file "\t{ WM_" <group 1> ", \"WM_" <group 1> \"},\n"
// loop until end of input file
// close input file
// close output file
std::regex pattern("\\s*#define\\s+WM_([A-Z_]+)\\s");
std::smatch matches;
FILE* pfo = NULL;
errno_t err = fopen_s(&pfo, outfilename.c_str(), "a");
if (err == 0)
{
std::ifstream ifstrm(infilename.c_str());
std::string s;
while (!ifstrm.eof() && !ifstrm.fail())
{
std::getline(ifstrm, s, '\n');
bool res = std::regex_search(s, matches, pattern);
if (res && matches.size() > 1)
{
std::string s2 = std::string("WM_") + matches[1].str().c_str();
//fprintf(pfo, "\t\t{ %s,\t\"%s\" },\n", s2.c_str(), s2.c_str());
fprintf(pfo, "\t\tmypair(%s, \"%s\"),\n", s2.c_str(), s2.c_str());
}
// else requested group was not found
}
fclose(pfo);
}
}
// Uncommented fprintf above will print out text to file in the form that std::pair can use
// In your code, add...
typedef std::pair<int, std::string> mypair;
mypair mparray[261] =
{
// then copy contents from the output text file and paste here...
mypair(WM_NULL, "WM_NULL"),
mypair(WM_CREATE, "WM_CREATE"),
mypair(WM_DESTROY, "WM_DESTROY"),
mypair(WM_MOVE, "WM_MOVE"),
mypair(WM_SIZE, "WM_SIZE"),
mypair(WM_ACTIVATE, "WM_ACTIVATE"),
mypair(WM_SETFOCUS, "WM_SETFOCUS"),
mypair(WM_KILLFOCUS, "WM_KILLFOCUS"),
. . .
};
// You can then write code to add to a std::map