1 #include <string>
2 #include <Windows.h>
3 #include <tchar.h>
4 #include <Shlobj.h>
5 #include <Shlwapi.h>
6 
7 #include <map>
8 
9 namespace Misc
10 {
PlatformStartup()11   void PlatformStartup()
12   {
13   }
14 
PlatformShutdown()15   void PlatformShutdown()
16   {
17   }
18 
19   std::map<std::string,std::string> keymaps;
InitKeymaps()20   void InitKeymaps()
21   {
22     HKEY hk = NULL;
23     RegOpenKeyExA( HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts", NULL, KEY_READ, &hk );
24 
25     LONG result = NULL;
26     int idx = 0;
27     while ( result != ERROR_NO_MORE_ITEMS )
28     {
29       char szKeyName[255];
30       ZeroMemory(szKeyName,255);
31       DWORD nKeyName = 255;
32       result = RegEnumKeyExA( hk, idx, szKeyName, &nKeyName, NULL, NULL, NULL, NULL);
33       if (result == ERROR_SUCCESS)
34       {
35         HKEY hkSub = NULL;
36         RegOpenKeyExA( hk, szKeyName, NULL, KEY_READ, &hkSub );
37 
38         BYTE szValue[255];
39         ZeroMemory(szValue,255);
40         DWORD nValue = 255;
41         DWORD type = REG_SZ;
42         LONG resultKey = RegQueryValueExA( hkSub, "Layout Text", NULL, &type, szValue, &nValue );
43 
44         CharLowerA( szKeyName );
45         keymaps[szKeyName] = (const char*)szValue;
46       }
47       idx++;
48     }
49   }
50 
GetKeymapName(char * sz)51   void GetKeymapName( char * sz )
52   {
53     char szCode[KL_NAMELENGTH];
54     ::GetKeyboardLayoutNameA(szCode);
55     CharLowerA( szCode );
56     strncpy( sz, keymaps.count(szCode) ? keymaps[szCode].c_str() : "<unknown>" ,255);
57   }
58 
ExecuteCommand(const char * cmd,const char * param)59   bool ExecuteCommand( const char * cmd, const char * param )
60   {
61     HINSTANCE hI = ShellExecute( NULL, NULL, cmd, param, NULL, SW_SHOW );
62     return (int)hI >= 32;
63   }
64 
FileExists(const char * path)65   bool FileExists(const char * path)
66   {
67     return GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES;
68   }
69 
GetDefaultFontPath()70   const char * GetDefaultFontPath()
71   {
72     char windowsPath[ MAX_PATH ];
73     if ( SHGetFolderPath( NULL, CSIDL_WINDOWS, NULL, 0, windowsPath ) != S_OK )
74     {
75       return NULL;
76     }
77     const char* fontPaths[] =
78     {
79       "Fonts\\cour.ttf",
80       NULL
81     };
82     for (int i = 0; fontPaths[i]; ++i)
83     {
84       static char fullPath[ MAX_PATH ] = { 0 };
85       PathCombineA( fullPath, windowsPath, fontPaths[ i ] );
86       if (FileExists( fullPath ))
87       {
88         return fullPath;
89       }
90     }
91     return NULL;
92   }
93 }