Mercurial > vba-linux
diff src/win32/WinResUtil.cpp @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/win32/WinResUtil.cpp Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,99 @@ 1.4 +#include "stdafx.h" 1.5 +#include "WinResUtil.h" 1.6 + 1.7 +static HINSTANCE winResGetInstance(LPCTSTR resType, LPCTSTR resName) 1.8 +{ 1.9 + // TODO: make language DLL first 1.10 + return AfxFindResourceHandle(resName, resType); 1.11 +} 1.12 + 1.13 +UCHAR *winResGetResource(LPCTSTR resType, LPCTSTR resName) 1.14 +{ 1.15 + HINSTANCE winResInstance = winResGetInstance(resType, resName); 1.16 + 1.17 + HRSRC hRsrc = FindResourceEx(winResInstance, resType, resName, 0); 1.18 + 1.19 + if (hRsrc != NULL) 1.20 + { 1.21 + HGLOBAL hGlobal = LoadResource(winResInstance, hRsrc); 1.22 + 1.23 + if (hGlobal != NULL) 1.24 + { 1.25 + UCHAR *b = (UCHAR *)LockResource(hGlobal); 1.26 + 1.27 + return b; 1.28 + } 1.29 + } 1.30 + return NULL; 1.31 +} 1.32 + 1.33 +HMENU winResLoadMenu(LPCTSTR menuName) 1.34 +{ 1.35 + UCHAR *b = winResGetResource(RT_MENU, menuName); 1.36 + 1.37 + if (b != NULL) 1.38 + { 1.39 + HMENU menu = LoadMenuIndirect((CONST MENUTEMPLATE *)b); 1.40 + 1.41 + if (menu != NULL) 1.42 + return menu; 1.43 + } 1.44 + 1.45 + return LoadMenu(NULL, menuName); 1.46 +} 1.47 + 1.48 +int winResDialogBox(LPCTSTR boxName, HWND parent, DLGPROC dlgProc, LPARAM lParam) 1.49 +{ 1.50 + /* 1.51 + UCHAR * b = winResGetResource(RT_DIALOG, boxName); 1.52 + 1.53 + if(b != NULL) { 1.54 + 1.55 + return DialogBoxIndirectParam(hInstance, 1.56 + (LPCDLGTEMPLATE)b, 1.57 + parent, 1.58 + dlgProc, 1.59 + lParam); 1.60 + } 1.61 + 1.62 + return DialogBoxParam(hInstance, 1.63 + boxName, 1.64 + parent, 1.65 + dlgProc, 1.66 + lParam); 1.67 + */ 1.68 + return 0; 1.69 +} 1.70 + 1.71 +int winResDialogBox(LPCTSTR boxName, HWND parent, DLGPROC dlgProc) 1.72 +{ 1.73 + return winResDialogBox(boxName, 1.74 + parent, 1.75 + dlgProc, 1.76 + 0); 1.77 +} 1.78 + 1.79 +CString winResLoadString(UINT id) 1.80 +{ 1.81 + int stId = id / 16 + 1; 1.82 + HINSTANCE inst = winResGetInstance(RT_STRING, MAKEINTRESOURCE(stId)); 1.83 + 1.84 + CString res; 1.85 + if (!res.LoadString(id)) 1.86 + { 1.87 + // TODO: handle case where string is only in the default English 1.88 + res = ""; 1.89 + } 1.90 + 1.91 + res.Replace('_', '|'); 1.92 + 1.93 + return res; 1.94 +} 1.95 + 1.96 +CString winResLoadFilter(UINT id) 1.97 +{ 1.98 + CString res = winResLoadString(id); 1.99 + res.Replace('_', '|'); 1.100 + 1.101 + return res; 1.102 +}