If an application specifies FCF_ACCELTABLE, FCF_ICON, FCF_MENU, FCF_STANDARD, FS_ACCELTABLE, FS_ICON, or FS_STANDARD when creating a frame window, the application must provide the resources to support the specified style. Failure to do so causes the window creation to fail. Depending on the style, a frame window might attempt to load one or more resources from the application's executable files.
The following table shows the frame-control flags and frame-window styles that require resources:
┌────────────────────┬────────────────────┬────────────────────┐ │Flag │Style │Description │ ├────────────────────┼────────────────────┼────────────────────┤ │FCF_ACCELTABLE │FS_ACCELTABLE │Requires an │ │ │ │accelerator-table │ │ │ │resource. The frame │ │ │ │window uses the │ │ │ │accelerator table to│ │ │ │translate WM_CHAR │ │ │ │messages to │ │ │ │WM_COMMAND, WM_HELP,│ │ │ │or WM_SYSCOMMAND │ │ │ │messages. │ ├────────────────────┼────────────────────┼────────────────────┤ │FCF_ICON │FS_ICON │Requires an icon │ │ │ │resource. The frame │ │ │ │window draws the │ │ │ │icon when the user │ │ │ │minimizes the │ │ │ │window. │ ├────────────────────┼────────────────────┼────────────────────┤ │FCF_MENU │FS_MENU │Requires a │ │ │ │menu-template │ │ │ │resource. A frame │ │ │ │window uses the menu│ │ │ │template to create a│ │ │ │menu containing the │ │ │ │commands and menus │ │ │ │specified by the │ │ │ │resource. │ ├────────────────────┼────────────────────┼────────────────────┤ │FCF_STANDARD │FS_STANDARD │Requires a │ │ │ │menu-template │ │ │ │resource │ │ │ │(FCF_STANDARD only),│ │ │ │an accelerator-table│ │ │ │resource, and an │ │ │ │icon resource. │ └────────────────────┴────────────────────┴────────────────────┘
You can use the resource compiler to add icon, menu, and accelerator-table resources to the application's executable file. Each resource must have a resource identifier that matches the resource identifier specified in the FRAMECDATA structure passed to WinCreateWindow or in the idResources parameter of WinCreateStdWindow.
Note: For detailed information about icon, menu, and accelerator-table resources, see Mouse Pointers and Icons, Menus, and Keyboard Accelerators, respectively.
The following sample code illustrates how to use WinCreateStdWindow to load and set up certain resources for a frame window. Normally the first step is to set up a header file defining the the IDs of the applicable resources:
#define ID_RESOURCE 301 #define IDM_OPTIONS 350 #define IDM_SHIFT 351 #define IDM_EXIT 352Then, make a resource (.RC) file, defining each resource:
#include <os2.h> /* Icon */ POINTER ID_RESOURCE sampres.ico /* Accelerator table */ ACCELTABLE ID_RESOURCE BEGIN VK_F10, IDM_SHIFT, VIRTUALKEY VK_F3 , IDM_EXIT, VIRTUALKEY END /* Menu */ MENU ID_RESOURCE BEGIN SUBMENU "~Options", IDM_OPTIONS BEGIN MENUITEM "~Shift Colors\tF10", IDM_SHIFT MENUITEM "~Exit\tF3", IDM_EXIT END END
When using WinCreateStdWindow with more than one resource, each resource can have the same ID, as in the above example (ID_RESOURCE or 1), but only if each resource is of a different type. Resources of the same type must have unique IDs. Use FCF flags to indicate what resources to load:
ULONG flFrameFlags= FCF_TITLEBAR | /* Title bar */ FCF_SIZEBORDER | /* Size border */ FCF_MINMAX | /* Min & Max buttons */ FCF_SYSMENU | /* System menu */ FCF_SHELLPOSITION | /* System size & position */ FCF_TASKLIST | /* Add name to task list */ FCF_ICON | /* Add icon */ FCF_ACCELTABLE | /* Add accelerator table */ FCF_MENU; /* Add menu */
Use 0 (or NULL) in the seventh parameter of WinCreateStdWindow to indicate that the resource is stored in the application file, as follows:
hwndFrame = WinCreateStdWindow( HWND_DESKTOP, /* Parent is desktop window */ WS_VISIBLE, /* Make frame window visible */ &flFrameFlags, /* Frame controls */ "ResSamClient", /* Window class for client */ NULL, /* No window title */ WS_VISIBLE, /* Make client window visible */ (HMODULE) 0, /* Resources in application module */ ID_RESOURCE, /* Resource identifier */ NULL); /* Pointer to client window handle */
Following is the full listing of the sample program:
#define INCL_PM #include <os2.h> MRESULT EXPENTRY ClientWndProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2); int main(int argc, char *argv, char *envp) { HWND hwndFrame; HWND hwndClient; HMQ hmq; QMSG qmsg; HAB hab; ULONG flFrameFlags= FCF_TITLEBAR | /* Title bar */ FCF_SIZEBORDER | /* Size Border */ FCF_MINMAX | /* Min & Max Buttons */ FCF_SYSMENU | /* System Menu */ FCF_SHELLPOSITION | /* System size & position */ FCF_TASKLIST | /* Add name to task list */ FCF_ICON | /* Add icon */ FCF_ACCELTABLE | /* Add accelerator table */ FCF_MENU; /* Add menu */ hab = WinInitialize(0); hmq = WinCreateMsgQueue(hab, 0); WinRegisterClass( hab, /* Anchor block handle */ "ResSamClient", /* Name of class being registered */ (PFNWP)ClientWndProc, /* Window procedure for class */ CS_SIZEREDRAW | /* Class style */ CS_HITTEST, /* Class style */ 0); /* Extra bytes to reserve */ hwndFrame = WinCreateStdWindow( HWND_DESKTOP, /* Parent is desktop window */ WS_VISIBLE, /* Make frame window visible */ &flFrameFlags, /* Frame controls */ "ResSamClient", /* Window class for client */ NULL, /* No window title */ WS_VISIBLE, /* Make client window visible */ (HMODULE) 0, /* Resources in application module */ ID_RESOURCE, /* Resource identifier */ NULL); /* Pointer to client window handle */ while (WinGetMsg(hab, &qmsg, 0, 0, 0)) WinDispatchMsg(hab, &qmsg); WinDestroyWindow(hwndFrame); WinDestroyMsgQueue(hmq); WinTerminate(hab); return 0; } MRESULT EXPENTRY ClientWndProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2); { RECTL rcl; HPS hps; static LONG lColor=CLR_RED; switch (msg) { case WM_PAINT: hps=WinBeginPaint(hwnd,(HPS) NULL, &rcl); /* Get hps */ WinFillRect(hps,&rcl,lColor); /* Fill the window */ WinEndPaint(hps); /* Free hps */ return 0; case WM_COMMAND: switch (SHORT1FROMMP(mp1)) { case IDM_SHIFT: /* Shift selected */ if (lColor==CLR_RED) /* Change the color */ lColor=CLR_BLUE; else lColor=CLR_RED; WinInvalidateRect(hwnd,(PRECTL)NULL,0UL); /* Paint Window */ return 0; case IDM_EXIT: /* Exit selected */ WinPostMsg(hwnd,WM_CLOSE,MPVOID,MPVOID); /* Exit program */ return 0; } } return WinDefWindowProc (hwnd, msg, mp1, mp2); }