source: trunk/src/user32/new/loadres.cpp@ 599

Last change on this file since 599 was 599, checked in by sandervl, 26 years ago

* empty log message *

File size: 7.2 KB
Line 
1/* $Id: loadres.cpp,v 1.6 1999-08-20 15:03:41 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
17//******************************************************************************
18//******************************************************************************
19int WIN32API LoadStringA(HINSTANCE hinst, UINT wID, LPSTR lpBuffer, int cchBuffer)
20{
21 Win32Resource *winres;
22 LPWSTR resstring;
23 int resstrlen = 0;
24
25 winres = (Win32Resource *)FindResourceA(hinst, (LPSTR)wID, RT_STRINGA);
26 if(winres == NULL) {
27 dprintf(("LoadStringA NOT FOUND from %X, id %d buffersize %d\n", hinst, wID, cchBuffer));
28 return 0;
29 }
30
31 resstring = (LPWSTR)winres->lockResource();
32 if(resstring) {
33 resstrlen = min(lstrlenW(resstring)+1, cchBuffer);
34 lstrcpynWtoA(lpBuffer, resstring, resstrlen);
35 lpBuffer[resstrlen-1] = 0;
36 resstrlen--;
37 dprintf(("LoadStringA (%d) %s", resstrlen, lpBuffer));
38 }
39 delete winres;
40
41 dprintf(("LoadStringA from %X, id %d buffersize %d\n", hinst, wID, cchBuffer));
42 return(resstrlen);
43}
44//******************************************************************************
45//******************************************************************************
46int WIN32API LoadStringW(HINSTANCE hinst, UINT wID, LPWSTR lpBuffer, int cchBuffer)
47{
48 Win32Resource *winres;
49 LPWSTR resstring;
50 int resstrlen = 0;
51
52 winres = (Win32Resource *)FindResourceW(hinst, (LPWSTR)wID, RT_STRINGW);
53 if(winres == NULL) {
54 dprintf(("LoadStringW NOT FOUND from %X, id %d buffersize %d\n", hinst, wID, cchBuffer));
55 return 0;
56 }
57
58 resstring = (LPWSTR)winres->lockResource();
59 if(resstring) {
60 resstrlen = min(lstrlenW(resstring)+1, cchBuffer);
61 lstrcpynW(lpBuffer, resstring, resstrlen);
62 lpBuffer[resstrlen-1] = 0;
63 resstrlen--;
64 }
65 delete winres;
66
67 dprintf(("LoadStringW from %X, id %d buffersize %d\n", hinst, wID, cchBuffer));
68 return(resstrlen);
69}
70//******************************************************************************
71//******************************************************************************
72HICON WIN32API LoadIconA(HINSTANCE hinst, LPCSTR lpszIcon)
73{
74 HICON rc;
75
76 rc = (HICON)FindResourceA(hinst, lpszIcon, RT_ICONA);
77 dprintf(("LoadIconA (%X) returned %d\n", hinst, rc));
78 return(rc);
79}
80//******************************************************************************
81//******************************************************************************
82HICON WIN32API LoadIconW(HINSTANCE hinst, LPCWSTR lpszIcon)
83{
84 HICON rc;
85
86 rc = (HICON)FindResourceW(hinst, lpszIcon, RT_ICONW);
87 dprintf(("LoadIconW (%X) returned %d\n", hinst, rc));
88 return(rc);
89}
90//******************************************************************************
91//******************************************************************************
92HCURSOR WIN32API LoadCursorA(HINSTANCE hinst, LPCSTR lpszCursor)
93{
94 HCURSOR rc;
95
96 if((int)lpszCursor >> 16 != 0) {//convert string name identifier to numeric id
97 dprintf(("LoadCursor %s\n", lpszCursor));
98 lpszCursor = (LPCSTR)ConvertNameId(hinst, (char *)lpszCursor);
99 }
100 else dprintf(("LoadCursor %d\n", (int)lpszCursor));
101
102 rc = O32_LoadCursor(hinst, lpszCursor);
103
104 dprintf(("LoadCursor from %X returned %d\n", hinst, rc));
105 return(rc);
106}
107//******************************************************************************
108//******************************************************************************
109HBITMAP WIN32API LoadBitmapA(HINSTANCE hinst, LPCSTR lpszBitmap)
110{
111 HBITMAP rc;
112
113 if((int)lpszBitmap >> 16 != 0)
114 { //convert string name identifier to numeric id
115 dprintf(("lpszBitmap [%s]\n",
116 lpszBitmap));
117
118 lpszBitmap = (LPCSTR)ConvertNameId(hinst,
119 (char *)lpszBitmap);
120 }
121 else
122 dprintf(("lpszBitmap %08xh\n",
123 (int)lpszBitmap));
124
125 rc = O32_LoadBitmap(hinst, lpszBitmap);
126
127 dprintf(("LoadBitmapA returned %08xh\n",
128 rc));
129
130 return(rc);
131}
132//******************************************************************************
133//******************************************************************************
134HBITMAP WIN32API LoadBitmapW(HINSTANCE hinst, LPCWSTR lpszBitmap)
135{
136 char *astring = NULL;
137 HBITMAP rc;
138
139 if((int)lpszBitmap >> 16 != 0) {//convert string name identifier to numeric id
140 astring = UnicodeToAsciiString((LPWSTR)lpszBitmap);
141 dprintf(("lpszBitmap %s\n", astring));
142
143 lpszBitmap = (LPWSTR)ConvertNameId(hinst, (char *)astring);
144 }
145 else dprintf(("lpszBitmap %d\n", (int)lpszBitmap));
146
147 rc = O32_LoadBitmap(hinst, (char *)lpszBitmap);
148 if(astring)
149 FreeAsciiString(astring);
150
151 dprintf(("LoadBitmapW returned %d\n", rc));
152 return(rc);
153}
154//******************************************************************************
155//******************************************************************************
156HCURSOR WIN32API LoadCursorW(HINSTANCE hinst, LPCWSTR lpszCursor)
157{
158 char *astring = NULL;
159 HCURSOR rc;
160
161 if((int)lpszCursor >> 16 != 0) {//convert string name identifier to numeric id
162 astring = UnicodeToAsciiString((LPWSTR)lpszCursor);
163 dprintf(("lpszCursor %s\n", astring));
164 lpszCursor = (LPWSTR)ConvertNameId(hinst, (char *)astring);
165 }
166 else dprintf(("lpszCursor %d\n", (int)lpszCursor));
167
168 rc = O32_LoadCursor(hinst, (char *)lpszCursor);
169 if(astring)
170 FreeAsciiString(astring);
171
172 dprintf(("LoadCursorW returned %d\n", rc));
173 return(rc);
174}
175//******************************************************************************
176//TODO: Far from complete, but works for loading resources from exe
177//fuLoad flag ignored
178//******************************************************************************
179HANDLE WIN32API LoadImageA(HINSTANCE hinst, LPCSTR lpszName, UINT uType,
180 int cxDesired, int cyDesired, UINT fuLoad)
181{
182 HANDLE hRet = 0;
183
184 dprintf(("OS2LoadImageA NOT COMPLETE (%d,%d)\n", cxDesired, cyDesired));
185
186 switch(uType) {
187 case IMAGE_BITMAP:
188 hRet = (HANDLE)LoadBitmapA(hinst, lpszName);
189 break;
190 case IMAGE_CURSOR:
191 hRet = (HANDLE)LoadCursorA(hinst, lpszName);
192 break;
193 case IMAGE_ICON:
194 hRet = (HANDLE)LoadIconA(hinst, lpszName);
195 break;
196 }
197 dprintf(("OS2LoadImageA returned %d\n", (int)hRet));
198
199 return(hRet);
200}
201//******************************************************************************
202//******************************************************************************
203HANDLE WIN32API LoadImageW(HINSTANCE hinst, LPCWSTR lpszName, UINT uType,
204 int cxDesired, int cyDesired, UINT fuLoad)
205{
206 HANDLE hRet = 0;
207
208 dprintf(("OS2LoadImageW NOT COMPLETE (%d,%d)\n", cxDesired, cyDesired));
209
210 switch(uType) {
211 case IMAGE_BITMAP:
212 hRet = (HANDLE)LoadBitmapW(hinst, lpszName);
213 break;
214 case IMAGE_CURSOR:
215 hRet = (HANDLE)LoadCursorW(hinst, lpszName);
216 break;
217 case IMAGE_ICON:
218 hRet = (HANDLE)LoadIconW(hinst, lpszName);
219 break;
220 }
221 dprintf(("OS2LoadImageW returned %d\n", (int)hRet));
222
223 return(hRet);
224}
225//******************************************************************************
226//******************************************************************************
Note: See TracBrowser for help on using the repository browser.