Previous 15994 Revisions Next

r8161 Tuesday 25th May, 2010 at 04:37:32 UTC by Firewave
[WINUI] Improved error reporting of icon image list creation and added GetSystemErrorMessage()
[src/osd/winui]mui_util.c mui_util.h winui.c

src/osd/winui/mui_util.c
r8160r8161
582582}
583583
584584
585void GetSystemErrorMessage(DWORD dwErrorId, TCHAR **tErrorMessage)
586{
587   if( FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwErrorId, 0, (LPTSTR)tErrorMessage, 0, NULL) == 0 )
588   {
589      *tErrorMessage = (LPTSTR)LocalAlloc(LPTR, MAX_PATH * sizeof(TCHAR));
590      _tcscpy(*tErrorMessage, TEXT("Unknown Error"));
591   }
592}
585593
594
586595//============================================================
587596//  win_extract_icon_utf8
588597//============================================================
r8160r8161
694703   
695704   return result;
696705}
706
src/osd/winui/winui.c
r8160r8161
51085108
51095109static DWORD GetShellLargeIconSize(void)
51105110{
5111   DWORD  dwSize, dwLength = 512, dwType = REG_SZ;
5111   DWORD  dwSize = 32, dwLength = 512, dwType = REG_SZ;
51125112   TCHAR  szBuffer[512];
51135113   HKEY   hKey;
5114   LONG   lRes;
5115   LPTSTR tErrorMessage = NULL;
51145116
51155117   /* Get the Key */
5116   RegOpenKey(HKEY_CURRENT_USER, TEXT("Control Panel\\desktop\\WindowMetrics"), &hKey);
5118   lRes = RegOpenKey(HKEY_CURRENT_USER, TEXT("Controlanel\\Desktop\\WindowMetrics"), &hKey);
5119   if( lRes != ERROR_SUCCESS )
5120   {
5121      GetSystemErrorMessage(lRes, &tErrorMessage);
5122      MessageBox(GetMainWindow(), tErrorMessage, TEXT("Large shell icon size registry access"), MB_OK | MB_ICONERROR);
5123      LocalFree(tErrorMessage);
5124      return dwSize;
5125   }
5126
51175127   /* Save the last size */
5118   RegQueryValueEx(hKey, TEXT("Shell Icon Size"), NULL, &dwType, (LPBYTE)szBuffer, &dwLength);
5128   lRes = RegQueryValueEx(hKey, TEXT("Shell Icon Size"), NULL, &dwType, (LPBYTE)szBuffer, &dwLength);
5129   if( lRes != ERROR_SUCCESS )
5130   {
5131      GetSystemErrorMessage(lRes, &tErrorMessage);
5132      MessageBox(GetMainWindow(), tErrorMessage, TEXT("Large shell icon size registry query"), MB_OK | MB_ICONERROR);
5133      LocalFree(tErrorMessage);
5134      RegCloseKey(hKey);
5135      return dwSize;
5136   }
5137
51195138   dwSize = _ttol(szBuffer);
51205139   if (dwSize < 32)
51215140      dwSize = 32;
r8160r8161
51495168// create iconlist for Listview control
51505169static void CreateIcons(void)
51515170{
5171   DWORD dwSmallIconSize = GetShellSmallIconSize();
51525172   DWORD dwLargeIconSize = GetShellLargeIconSize();
51535173   HICON hIcon;
51545174   int icon_count;
r8160r8161
51755195   dwStyle = GetWindowLong(hwndList,GWL_STYLE);
51765196   SetWindowLong(hwndList,GWL_STYLE,(dwStyle & ~LVS_TYPEMASK) | LVS_ICON);
51775197
5178   hSmall = ImageList_Create(GetShellSmallIconSize(),GetShellSmallIconSize(),
5198   hSmall = ImageList_Create(dwSmallIconSize, dwSmallIconSize,
51795199                       ILC_COLORDDB | ILC_MASK, icon_count, icon_count + grow);
5200
5201   if (NULL == hSmall) {
5202      win_message_box_utf8(hwndList, "Cannot allocate small icon image list", "Allocation error - Exiting", IDOK);
5203      PostQuitMessage(0);
5204   }
5205   
51805206   hLarge = ImageList_Create(dwLargeIconSize, dwLargeIconSize,
51815207                       ILC_COLORDDB | ILC_MASK, icon_count, icon_count + grow);
51825208
5183   if (NULL == hSmall || NULL == hLarge) {
5184      win_message_box_utf8(hwndList, "Cannot allocate Icon lists", "Allocation error - Exiting", IDOK);
5209   if (NULL == hLarge) {
5210      win_message_box_utf8(hwndList, "Cannot allocate large icon image list", "Allocation error - Exiting", IDOK);
51855211      PostQuitMessage(0);
51865212   }
51875213
src/osd/winui/mui_util.h
r8160r8161
6363
6464BOOL SafeIsAppThemed(void);
6565
66// provides result of FormatMessage()
67// resulting buffer must be free'd with LocalFree()
68void GetSystemErrorMessage(DWORD dwErrorId, TCHAR **tErrorMessage);
69
6670HICON win_extract_icon_utf8(HINSTANCE inst, const char* exefilename, UINT iconindex);
6771TCHAR* win_tstring_strdup(LPCTSTR str);
6872HANDLE win_create_file_utf8(const char* filename, DWORD desiredmode, DWORD sharemode,

Previous 15994 Revisions Next


© 1998-2018 The MESS Team