1 | /* $Id: loadres.cpp,v 1.7 1999-08-20 20:09:50 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Win32 resource API functions for OS/2
|
---|
5 | *
|
---|
6 | * Copyright 1998 Sander van Leeuwen
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | */
|
---|
12 | #include <os2win.h>
|
---|
13 | #include <user32.h>
|
---|
14 | #include <winres.h>
|
---|
15 | #include <heapstring.h>
|
---|
16 | #include <oslibres.h>
|
---|
17 |
|
---|
18 | //******************************************************************************
|
---|
19 | //******************************************************************************
|
---|
20 | int WIN32API LoadStringA(HINSTANCE hinst, UINT wID, LPSTR lpBuffer, int cchBuffer)
|
---|
21 | {
|
---|
22 | Win32Resource *winres;
|
---|
23 | LPWSTR resstring;
|
---|
24 | int resstrlen = 0;
|
---|
25 |
|
---|
26 | winres = (Win32Resource *)FindResourceA(hinst, (LPSTR)wID, RT_STRINGA);
|
---|
27 | if(winres == NULL) {
|
---|
28 | dprintf(("LoadStringA NOT FOUND from %X, id %d buffersize %d\n", hinst, wID, cchBuffer));
|
---|
29 | return 0;
|
---|
30 | }
|
---|
31 |
|
---|
32 | resstring = (LPWSTR)winres->lockResource();
|
---|
33 | if(resstring) {
|
---|
34 | resstrlen = min(lstrlenW(resstring)+1, cchBuffer);
|
---|
35 | lstrcpynWtoA(lpBuffer, resstring, resstrlen);
|
---|
36 | lpBuffer[resstrlen-1] = 0;
|
---|
37 | resstrlen--;
|
---|
38 | dprintf(("LoadStringA (%d) %s", resstrlen, lpBuffer));
|
---|
39 | }
|
---|
40 | delete winres;
|
---|
41 |
|
---|
42 | dprintf(("LoadStringA from %X, id %d buffersize %d\n", hinst, wID, cchBuffer));
|
---|
43 | return(resstrlen);
|
---|
44 | }
|
---|
45 | //******************************************************************************
|
---|
46 | //******************************************************************************
|
---|
47 | int WIN32API LoadStringW(HINSTANCE hinst, UINT wID, LPWSTR lpBuffer, int cchBuffer)
|
---|
48 | {
|
---|
49 | Win32Resource *winres;
|
---|
50 | LPWSTR resstring;
|
---|
51 | int resstrlen = 0;
|
---|
52 |
|
---|
53 | winres = (Win32Resource *)FindResourceW(hinst, (LPWSTR)wID, RT_STRINGW);
|
---|
54 | if(winres == NULL) {
|
---|
55 | dprintf(("LoadStringW NOT FOUND from %X, id %d buffersize %d\n", hinst, wID, cchBuffer));
|
---|
56 | return 0;
|
---|
57 | }
|
---|
58 |
|
---|
59 | resstring = (LPWSTR)winres->lockResource();
|
---|
60 | if(resstring) {
|
---|
61 | resstrlen = min(lstrlenW(resstring)+1, cchBuffer);
|
---|
62 | lstrcpynW(lpBuffer, resstring, resstrlen);
|
---|
63 | lpBuffer[resstrlen-1] = 0;
|
---|
64 | resstrlen--;
|
---|
65 | }
|
---|
66 | delete winres;
|
---|
67 |
|
---|
68 | dprintf(("LoadStringW from %X, id %d buffersize %d\n", hinst, wID, cchBuffer));
|
---|
69 | return(resstrlen);
|
---|
70 | }
|
---|
71 | //******************************************************************************
|
---|
72 | //******************************************************************************
|
---|
73 | HICON WIN32API LoadIconA(HINSTANCE hinst, LPCSTR lpszIcon)
|
---|
74 | {
|
---|
75 | Win32Resource *winres;
|
---|
76 | HICON hIcon;
|
---|
77 |
|
---|
78 | hIcon = OSLibWinQuerySysIcon((ULONG)lpszIcon);
|
---|
79 | if(hIcon == 0) {//not a system icon
|
---|
80 | winres = (Win32Resource *)FindResourceA(hinst, lpszIcon, RT_ICONA);
|
---|
81 | if(winres == 0) {
|
---|
82 | winres = (Win32Resource *)FindResourceA(hinst, lpszIcon, RT_GROUP_ICONA);
|
---|
83 | }
|
---|
84 | if(winres) {
|
---|
85 | hIcon = OSLibWinCreateIcon(winres->lockOS2Resource());
|
---|
86 | delete winres;
|
---|
87 | }
|
---|
88 | }
|
---|
89 | dprintf(("LoadIconA (%X) returned %x\n", hinst, hIcon));
|
---|
90 |
|
---|
91 | return(hIcon);
|
---|
92 | }
|
---|
93 | //******************************************************************************
|
---|
94 | //******************************************************************************
|
---|
95 | HICON WIN32API LoadIconW(HINSTANCE hinst, LPCWSTR lpszIcon)
|
---|
96 | {
|
---|
97 | Win32Resource *winres;
|
---|
98 | HICON hIcon;
|
---|
99 |
|
---|
100 | hIcon = OSLibWinQuerySysIcon((ULONG)lpszIcon);
|
---|
101 | if(hIcon == 0) {//not a system icon
|
---|
102 | winres = (Win32Resource *)FindResourceW(hinst, lpszIcon, RT_ICONW);
|
---|
103 | if(winres == 0) {
|
---|
104 | winres = (Win32Resource *)FindResourceW(hinst, lpszIcon, RT_GROUP_ICONW);
|
---|
105 | }
|
---|
106 | if(winres) {
|
---|
107 | hIcon = OSLibWinCreateIcon(winres->lockOS2Resource());
|
---|
108 | delete winres;
|
---|
109 | }
|
---|
110 | }
|
---|
111 | dprintf(("LoadIconW (%X) returned %x\n", hinst, hIcon));
|
---|
112 |
|
---|
113 | return(hIcon);
|
---|
114 | }
|
---|
115 | //******************************************************************************
|
---|
116 | //******************************************************************************
|
---|
117 | HCURSOR WIN32API LoadCursorA(HINSTANCE hinst, LPCSTR lpszCursor)
|
---|
118 | {
|
---|
119 | Win32Resource *winres;
|
---|
120 | HCURSOR hCursor;
|
---|
121 |
|
---|
122 | hCursor = OSLibWinQuerySysPointer((ULONG)lpszCursor);
|
---|
123 | if(hCursor == 0) {//not a system pointer
|
---|
124 | winres = (Win32Resource *)FindResourceA(hinst, lpszCursor, RT_CURSORA);
|
---|
125 | if(winres == 0) {
|
---|
126 | winres = (Win32Resource *)FindResourceA(hinst, lpszCursor, RT_GROUP_CURSORA);
|
---|
127 | }
|
---|
128 | if(winres) {
|
---|
129 | hCursor = OSLibWinCreatePointer(winres->lockOS2Resource());
|
---|
130 | delete winres;
|
---|
131 | }
|
---|
132 | }
|
---|
133 | dprintf(("LoadCursorA (%X) returned %x\n", hinst, hCursor));
|
---|
134 |
|
---|
135 | return(hCursor);
|
---|
136 | }
|
---|
137 | //******************************************************************************
|
---|
138 | //******************************************************************************
|
---|
139 | HCURSOR WIN32API LoadCursorW(HINSTANCE hinst, LPCWSTR lpszCursor)
|
---|
140 | {
|
---|
141 | Win32Resource *winres;
|
---|
142 | HCURSOR hCursor;
|
---|
143 |
|
---|
144 | hCursor = OSLibWinQuerySysPointer((ULONG)lpszCursor);
|
---|
145 | if(hCursor == 0) {//not a system pointer
|
---|
146 | winres = (Win32Resource *)FindResourceW(hinst, lpszCursor, RT_CURSORW);
|
---|
147 | if(winres == 0) {
|
---|
148 | winres = (Win32Resource *)FindResourceW(hinst, lpszCursor, RT_GROUP_CURSORW);
|
---|
149 | }
|
---|
150 | if(winres) {
|
---|
151 | hCursor = OSLibWinCreatePointer(winres->lockOS2Resource());
|
---|
152 | delete winres;
|
---|
153 | }
|
---|
154 | }
|
---|
155 | dprintf(("LoadCursorW (%X) returned %x\n", hinst, hCursor));
|
---|
156 |
|
---|
157 | return(hCursor);
|
---|
158 | }
|
---|
159 | //******************************************************************************
|
---|
160 | //******************************************************************************
|
---|
161 | HBITMAP WIN32API LoadBitmapA(HINSTANCE hinst, LPCSTR lpszBitmap)
|
---|
162 | {
|
---|
163 | HBITMAP rc;
|
---|
164 |
|
---|
165 | if(HIWORD(lpszBitmap) != 0)
|
---|
166 | { //convert string name identifier to numeric id
|
---|
167 | dprintf(("lpszBitmap [%s]\n", lpszBitmap));
|
---|
168 |
|
---|
169 | lpszBitmap = (LPCSTR)ConvertNameId(hinst, (char *)lpszBitmap);
|
---|
170 | }
|
---|
171 | else dprintf(("lpszBitmap %08xh\n", (int)lpszBitmap));
|
---|
172 |
|
---|
173 | rc = O32_LoadBitmap(hinst, lpszBitmap);
|
---|
174 |
|
---|
175 | dprintf(("LoadBitmapA returned %08xh\n", rc));
|
---|
176 |
|
---|
177 | return(rc);
|
---|
178 | }
|
---|
179 | //******************************************************************************
|
---|
180 | //******************************************************************************
|
---|
181 | HBITMAP WIN32API LoadBitmapW(HINSTANCE hinst, LPCWSTR lpszBitmap)
|
---|
182 | {
|
---|
183 | char *astring = NULL;
|
---|
184 | HBITMAP rc;
|
---|
185 |
|
---|
186 | if(HIWORD(lpszBitmap) != 0) {//convert string name identifier to numeric id
|
---|
187 | astring = UnicodeToAsciiString((LPWSTR)lpszBitmap);
|
---|
188 | dprintf(("lpszBitmap %s\n", astring));
|
---|
189 |
|
---|
190 | lpszBitmap = (LPWSTR)ConvertNameId(hinst, (char *)astring);
|
---|
191 | }
|
---|
192 | else dprintf(("lpszBitmap %d\n", (int)lpszBitmap));
|
---|
193 |
|
---|
194 | rc = O32_LoadBitmap(hinst, (char *)lpszBitmap);
|
---|
195 | if(astring)
|
---|
196 | FreeAsciiString(astring);
|
---|
197 |
|
---|
198 | dprintf(("LoadBitmapW returned %d\n", rc));
|
---|
199 | return(rc);
|
---|
200 | }
|
---|
201 | //******************************************************************************
|
---|
202 | //TODO: Far from complete, but works for loading resources from exe
|
---|
203 | //fuLoad flag ignored
|
---|
204 | //******************************************************************************
|
---|
205 | HANDLE WIN32API LoadImageA(HINSTANCE hinst, LPCSTR lpszName, UINT uType,
|
---|
206 | int cxDesired, int cyDesired, UINT fuLoad)
|
---|
207 | {
|
---|
208 | HANDLE hRet = 0;
|
---|
209 |
|
---|
210 | dprintf(("LoadImageA NOT COMPLETE (%d,%d)\n", cxDesired, cyDesired));
|
---|
211 |
|
---|
212 | switch(uType) {
|
---|
213 | case IMAGE_BITMAP:
|
---|
214 | hRet = (HANDLE)LoadBitmapA(hinst, lpszName);
|
---|
215 | break;
|
---|
216 | case IMAGE_CURSOR:
|
---|
217 | hRet = (HANDLE)LoadCursorA(hinst, lpszName);
|
---|
218 | break;
|
---|
219 | case IMAGE_ICON:
|
---|
220 | hRet = (HANDLE)LoadIconA(hinst, lpszName);
|
---|
221 | break;
|
---|
222 | default:
|
---|
223 | dprintf(("LoadImageA: unsupported type %d!!", uType));
|
---|
224 | return 0;
|
---|
225 | }
|
---|
226 | dprintf(("LoadImageA returned %d\n", (int)hRet));
|
---|
227 |
|
---|
228 | return(hRet);
|
---|
229 | }
|
---|
230 | //******************************************************************************
|
---|
231 | //******************************************************************************
|
---|
232 | HANDLE WIN32API LoadImageW(HINSTANCE hinst, LPCWSTR lpszName, UINT uType,
|
---|
233 | int cxDesired, int cyDesired, UINT fuLoad)
|
---|
234 | {
|
---|
235 | HANDLE hRet = 0;
|
---|
236 |
|
---|
237 | dprintf(("LoadImageW NOT COMPLETE (%d,%d)\n", cxDesired, cyDesired));
|
---|
238 |
|
---|
239 | switch(uType) {
|
---|
240 | case IMAGE_BITMAP:
|
---|
241 | hRet = (HANDLE)LoadBitmapW(hinst, lpszName);
|
---|
242 | break;
|
---|
243 | case IMAGE_CURSOR:
|
---|
244 | hRet = (HANDLE)LoadCursorW(hinst, lpszName);
|
---|
245 | break;
|
---|
246 | case IMAGE_ICON:
|
---|
247 | hRet = (HANDLE)LoadIconW(hinst, lpszName);
|
---|
248 | break;
|
---|
249 | default:
|
---|
250 | dprintf(("LoadImageW: unsupported type %d!!", uType));
|
---|
251 | return 0;
|
---|
252 | }
|
---|
253 | dprintf(("LoadImageW returned %d\n", (int)hRet));
|
---|
254 |
|
---|
255 | return(hRet);
|
---|
256 | }
|
---|
257 | //******************************************************************************
|
---|
258 | //******************************************************************************
|
---|