annotate 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
rev   line source
rlm@1 1 #include "stdafx.h"
rlm@1 2 #include "WinResUtil.h"
rlm@1 3
rlm@1 4 static HINSTANCE winResGetInstance(LPCTSTR resType, LPCTSTR resName)
rlm@1 5 {
rlm@1 6 // TODO: make language DLL first
rlm@1 7 return AfxFindResourceHandle(resName, resType);
rlm@1 8 }
rlm@1 9
rlm@1 10 UCHAR *winResGetResource(LPCTSTR resType, LPCTSTR resName)
rlm@1 11 {
rlm@1 12 HINSTANCE winResInstance = winResGetInstance(resType, resName);
rlm@1 13
rlm@1 14 HRSRC hRsrc = FindResourceEx(winResInstance, resType, resName, 0);
rlm@1 15
rlm@1 16 if (hRsrc != NULL)
rlm@1 17 {
rlm@1 18 HGLOBAL hGlobal = LoadResource(winResInstance, hRsrc);
rlm@1 19
rlm@1 20 if (hGlobal != NULL)
rlm@1 21 {
rlm@1 22 UCHAR *b = (UCHAR *)LockResource(hGlobal);
rlm@1 23
rlm@1 24 return b;
rlm@1 25 }
rlm@1 26 }
rlm@1 27 return NULL;
rlm@1 28 }
rlm@1 29
rlm@1 30 HMENU winResLoadMenu(LPCTSTR menuName)
rlm@1 31 {
rlm@1 32 UCHAR *b = winResGetResource(RT_MENU, menuName);
rlm@1 33
rlm@1 34 if (b != NULL)
rlm@1 35 {
rlm@1 36 HMENU menu = LoadMenuIndirect((CONST MENUTEMPLATE *)b);
rlm@1 37
rlm@1 38 if (menu != NULL)
rlm@1 39 return menu;
rlm@1 40 }
rlm@1 41
rlm@1 42 return LoadMenu(NULL, menuName);
rlm@1 43 }
rlm@1 44
rlm@1 45 int winResDialogBox(LPCTSTR boxName, HWND parent, DLGPROC dlgProc, LPARAM lParam)
rlm@1 46 {
rlm@1 47 /*
rlm@1 48 UCHAR * b = winResGetResource(RT_DIALOG, boxName);
rlm@1 49
rlm@1 50 if(b != NULL) {
rlm@1 51
rlm@1 52 return DialogBoxIndirectParam(hInstance,
rlm@1 53 (LPCDLGTEMPLATE)b,
rlm@1 54 parent,
rlm@1 55 dlgProc,
rlm@1 56 lParam);
rlm@1 57 }
rlm@1 58
rlm@1 59 return DialogBoxParam(hInstance,
rlm@1 60 boxName,
rlm@1 61 parent,
rlm@1 62 dlgProc,
rlm@1 63 lParam);
rlm@1 64 */
rlm@1 65 return 0;
rlm@1 66 }
rlm@1 67
rlm@1 68 int winResDialogBox(LPCTSTR boxName, HWND parent, DLGPROC dlgProc)
rlm@1 69 {
rlm@1 70 return winResDialogBox(boxName,
rlm@1 71 parent,
rlm@1 72 dlgProc,
rlm@1 73 0);
rlm@1 74 }
rlm@1 75
rlm@1 76 CString winResLoadString(UINT id)
rlm@1 77 {
rlm@1 78 int stId = id / 16 + 1;
rlm@1 79 HINSTANCE inst = winResGetInstance(RT_STRING, MAKEINTRESOURCE(stId));
rlm@1 80
rlm@1 81 CString res;
rlm@1 82 if (!res.LoadString(id))
rlm@1 83 {
rlm@1 84 // TODO: handle case where string is only in the default English
rlm@1 85 res = "";
rlm@1 86 }
rlm@1 87
rlm@1 88 res.Replace('_', '|');
rlm@1 89
rlm@1 90 return res;
rlm@1 91 }
rlm@1 92
rlm@1 93 CString winResLoadFilter(UINT id)
rlm@1 94 {
rlm@1 95 CString res = winResLoadString(id);
rlm@1 96 res.Replace('_', '|');
rlm@1 97
rlm@1 98 return res;
rlm@1 99 }