view src/win32/WinResUtil.cpp @ 4:5f6f2134e8ce

apu appears to not be used
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:35:58 -0600
parents f9f4f1b99eed
children
line wrap: on
line source
1 #include "stdafx.h"
2 #include "WinResUtil.h"
4 static HINSTANCE winResGetInstance(LPCTSTR resType, LPCTSTR resName)
5 {
6 // TODO: make language DLL first
7 return AfxFindResourceHandle(resName, resType);
8 }
10 UCHAR *winResGetResource(LPCTSTR resType, LPCTSTR resName)
11 {
12 HINSTANCE winResInstance = winResGetInstance(resType, resName);
14 HRSRC hRsrc = FindResourceEx(winResInstance, resType, resName, 0);
16 if (hRsrc != NULL)
17 {
18 HGLOBAL hGlobal = LoadResource(winResInstance, hRsrc);
20 if (hGlobal != NULL)
21 {
22 UCHAR *b = (UCHAR *)LockResource(hGlobal);
24 return b;
25 }
26 }
27 return NULL;
28 }
30 HMENU winResLoadMenu(LPCTSTR menuName)
31 {
32 UCHAR *b = winResGetResource(RT_MENU, menuName);
34 if (b != NULL)
35 {
36 HMENU menu = LoadMenuIndirect((CONST MENUTEMPLATE *)b);
38 if (menu != NULL)
39 return menu;
40 }
42 return LoadMenu(NULL, menuName);
43 }
45 int winResDialogBox(LPCTSTR boxName, HWND parent, DLGPROC dlgProc, LPARAM lParam)
46 {
47 /*
48 UCHAR * b = winResGetResource(RT_DIALOG, boxName);
50 if(b != NULL) {
52 return DialogBoxIndirectParam(hInstance,
53 (LPCDLGTEMPLATE)b,
54 parent,
55 dlgProc,
56 lParam);
57 }
59 return DialogBoxParam(hInstance,
60 boxName,
61 parent,
62 dlgProc,
63 lParam);
64 */
65 return 0;
66 }
68 int winResDialogBox(LPCTSTR boxName, HWND parent, DLGPROC dlgProc)
69 {
70 return winResDialogBox(boxName,
71 parent,
72 dlgProc,
73 0);
74 }
76 CString winResLoadString(UINT id)
77 {
78 int stId = id / 16 + 1;
79 HINSTANCE inst = winResGetInstance(RT_STRING, MAKEINTRESOURCE(stId));
81 CString res;
82 if (!res.LoadString(id))
83 {
84 // TODO: handle case where string is only in the default English
85 res = "";
86 }
88 res.Replace('_', '|');
90 return res;
91 }
93 CString winResLoadFilter(UINT id)
94 {
95 CString res = winResLoadString(id);
96 res.Replace('_', '|');
98 return res;
99 }