home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / win32 / WinResUtil.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-13  |  2.6 KB  |  110 lines

  1. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
  2. // Copyright (C) 1999-2003 Forgotten
  3. // Copyright (C) 2004 Forgotten and the VBA development team
  4.  
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2, or(at your option)
  8. // any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software Foundation,
  17. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18.  
  19. #include "stdafx.h"
  20.  
  21. static HINSTANCE winResGetInstance(LPCTSTR resType, LPCTSTR resName)
  22. {
  23.   // TODO: make language DLL first
  24.   return AfxFindResourceHandle(resName, resType);
  25. }
  26.  
  27.  
  28. UCHAR *winResGetResource(LPCTSTR resType, LPCTSTR resName)
  29. {
  30.   HINSTANCE winResInstance = winResGetInstance(resType, resName);
  31.  
  32.   HRSRC hRsrc = FindResourceEx(winResInstance, resType, resName, 0);
  33.  
  34.   if(hRsrc != NULL) {
  35.     HGLOBAL hGlobal = LoadResource(winResInstance, hRsrc);
  36.  
  37.     if(hGlobal != NULL) {
  38.       UCHAR * b = (UCHAR *)LockResource(hGlobal);
  39.  
  40.       return b;
  41.     }
  42.   }
  43.   return NULL;
  44. }
  45.  
  46. HMENU winResLoadMenu(LPCTSTR menuName)
  47. {
  48.   UCHAR * b = winResGetResource(RT_MENU, menuName);
  49.   
  50.   if(b != NULL) {
  51.     HMENU menu = LoadMenuIndirect((CONST MENUTEMPLATE *)b);
  52.     
  53.     if(menu != NULL)
  54.       return menu;
  55.   }
  56.  
  57.   return LoadMenu(NULL, menuName);
  58. }
  59.  
  60. int winResDialogBox(LPCTSTR boxName,
  61.                     HWND parent,
  62.                     DLGPROC dlgProc,
  63.                     LPARAM lParam)
  64. {
  65.   /*
  66.     UCHAR * b = winResGetResource(RT_DIALOG, boxName);
  67.   
  68.     if(b != NULL) {
  69.     
  70.     return DialogBoxIndirectParam(hInstance,
  71.     (LPCDLGTEMPLATE)b,
  72.     parent,
  73.     dlgProc,
  74.     lParam);
  75.     }
  76.  
  77.     return DialogBoxParam(hInstance,
  78.     boxName,
  79.     parent,
  80.     dlgProc,
  81.     lParam);
  82.   */
  83.   return 0;
  84. }
  85.  
  86. int winResDialogBox(LPCTSTR boxName,
  87.                     HWND parent,
  88.                     DLGPROC dlgProc)
  89. {
  90.   return winResDialogBox(boxName,
  91.                          parent,
  92.                          dlgProc,
  93.                          0);
  94. }
  95.  
  96. CString winResLoadString(UINT id)
  97. {
  98.   int stId = id / 16 + 1;
  99.   HINSTANCE inst = winResGetInstance(RT_STRING, MAKEINTRESOURCE(stId));
  100.   
  101.   CString res;
  102.   if(res.LoadString(id))
  103.     return res;
  104.  
  105.   // TODO: handle case where string is only in the default English
  106.   res = "";
  107.  
  108.   return res;
  109. }
  110.