blob: 2ceb5a7b00a69ed5ef7df81669e0a2c68bc708f3 [file] [log] [blame]
Alexandre Julliard902da691995-11-05 14:39:02 +00001This is a short discussion of resources in WineLib.
2
3Introduction
4Resources are used to store dialogs, menus, bitmaps, icons,
5version information, strings, fonts, and accelerators.
6In a Win3.1 programming environment, there are three file formats for
7resources:
8- the RC script, which is human-readable and can be processed by a resource
9compiler
10- the .RES file, which is the output of the resource compiler
11- the .EXE and .DLL files, which store resources as a part of the NE
12file format
13For WineLib, only a part of this is supported. In particular, there is no
14.RES file, the executable is not a NE file (as it is a native Unix executable),
15and some resource types are not implemented: icons, version information,
16strings, and fonts.
17
18Building a WineLib application
19The build process assumes that the C source files and the resource script
20is available. At the moment, a single resource script is recommended.
21This script is processed by winerc:
221) the preprocessor is used to resolve symbolic style name (LBS_STANDARD, ...)
23into numbers. This involves processing windows.h
242) the unused parts of windows.h (type definitions) are removed. This would
25not be necessary if Wine's windows.h would use the RC_INVOKED macro.
263) winerc is invoked to create a binary representation of the resources.
27This representation is stored as C source code (arrays).
284) gcc is used to compile the generated C code.
29Now, each resource is available as a C array to the application. As the
30executable is not in the NE format, it is not possible to retrieve resource
31locations in the executable via name. Instead, the resources have to be
32referenced with their generated C array names. The linker then resolves
33these names in the compiled resource file.
345) The program sources are compiled and linked with the output of step 4.
35A sample build process is in toolkit/Makefile:hello3.
36
37Required changes to the program sources
38Because loading the resources from an instance handle is not possible,
39the *Indirect functions have to be used to load a resource. The C arrays
40can be directly passed to the *Indirect functions. So, instead of writing
41
42 hMenu=LoadMenu(hInstance,"MAIN");
43
44write
45
46 hMenu=LoadMenuIndirect(hello3_MENU_MAIN.bytes);
47
48Fortunately, the Windows API has the following functions available:
49DialogBoxIndirect
50CreateDialogIndirect
51DialogBoxIndirectParam
52CreateDialogIndirectParam
53
54LoadMenuIndirect
55SetDIBitsToDevice
56
57Sample code is available in hello3.c. hello3res.c contains the corresponding
58resources.
59
60Keeping a common source
61Clearly, changing the sources is not very desirable, and suggestions how
62to reduce the amount of work are welcome. In the meantime, two approaches
63allow at least to remain a common source between the Win3.1 code and the
64WineLib code:
651) conditional compiles:
66When compiling a WineLib application, WINELIB is defined. This can be used
67to select Wine-specific code.
682) usage of winerc for Windows: The *Indirect functions are available on
69plain Win3.1, and the resource format is fully compatible. Thus, recompiling
70sources modified for WineLib on Win3.1 is possible and known to work.
71
72Open problems
731) Icons and cursors: For these resources, there is no *Indirect function
74documented. In addition, both are implemented by a set of two resources.
75This is the reason why they are not supported by winerc.
762) Accelerators: Although winerc supports accelerators, there is no
77LoadAcceleratorIndirect function. A work-around would be to define one.
783) Fonts: Font resources are not supported by Wine at all.
794) String tables: Although string tables are not supported by winerc, there
80is no reason not to add such support. Again, some indirect loading would
81be necessary.
825) API requires loading by name: At some places, the name of a resource
83is passed instead of a handle. The WNDCLASS structure contains the name
84of a menu resource, and the icon in a dialog box is referenced by its name.
85(Are there some more places?)
86Clearly, loading the resource by name would be highly desirable. The
87resource compiler currently creates a structure containing all resources
88defined in an RC file. However, it is not clear how WINELIB could find the
89location of this structure, especially, when there is more than one RC file.
90
91