home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / sdk / doc / filefrmt / custcntl.txt next >
Encoding:
Text File  |  1995-07-11  |  16.1 KB  |  324 lines

  1. Below is the specification for the Custom Control support
  2. in the Dialog Editor (DlgEdit.Exe) for Windows NT.
  3.  
  4. There are several reasons why the existing Windows 3.x scheme is not
  5. adequate for NT:
  6.  
  7. 1. DlgEdit can easily be crashed by a user.  The way that a custom
  8.    control DLL is written for Win 3.x, it must export three functions at
  9.    three hard-coded ordinals (2, 3 and 4).  The user chooses a menu
  10.    option that invokes a file open dialog, enters the name of a DLL then
  11.    presses OK to ask the Dialog Editor to load this "custom control DLL".
  12.    The editor loads the specified module, checks for and gets the address
  13.    of these ordinals, pushes parms on the stack, and starts calling
  14.    them.  There is no way for it to validate that the DLL that the
  15.    user chose is really a custom control DLL.  It checks for the
  16.    existence of these three ordinals, but because most DLL's will
  17.    have at least four exports, and usually start at 1, this doesn't
  18.    help much.  This means that a user can easily crash the editor
  19.    by trying to load a random DLL, such as USERSRV.DLL.
  20.  
  21. 2. There is no allowance for UNICODE.  The current scheme of exporting
  22.    ordinals does not allow for an xxxA and xxxW version of the api's.
  23.    Also, a set of xxxW structures need to be defined with room for the
  24.    UNICODE strings.
  25.  
  26. 3. The structures passed around have obsolete fields, and some are not
  27.    dword aligned.  This interface was originally written for the Win 3.0
  28.    dialog editor (dialog.exe) and some fields are not necessary for
  29.    the Win 3.1 and NT dialog editor (DlgEdit.Exe).
  30.  
  31. 4. There is no support for some of the new features of the Win 32
  32.    resource file format, such as Extended Styles for controls and
  33.    NLS Language and Sub-Language values.
  34.  
  35. 5. There is no support for some of the features of the new Dialog
  36.    Editor, such as sizing to text, or specifying that the control
  37.    does not take text and allowing the editor to disable the Text
  38.    entry field on the Properties Bar to prevent text from being
  39.    entered for the control.
  40.  
  41. 6. Custom controls are limited to one class per DLL.  This is an
  42.    arbitrary restriction based on the structures used, and groups
  43.    like Pen Windows have had to use hacks to work around this.
  44.  
  45.  
  46. The real driving factor is #2 above, the lack of support for UNICODE.
  47. Because of these reasons, the following will be the support of
  48. Custom Controls in the Win32 (NT) Dialog Editor.  For more information,
  49. look at the CUSTCNTL.H header file.
  50.  
  51.  
  52. -- INITIALIZING A CUSTOM CONTROL ----------------------------------------
  53.  
  54. Custom control DLL's should export one or both of the following
  55. functions by name (the ordinal used for the export does not matter):
  56.  
  57. UINT CALLBACK CustomControlInfoA(LPCCINFOA acci)
  58. UINT CALLBACK CustomControlInfoW(LPCCINFOW acci)
  59.  
  60. The parameter to these functions is either NULL, or a pointer to an
  61. array of CCINFOA or CCINFOW  structures, defined as follows:
  62.  
  63. typedef struct tagCCINFOA {
  64.     CHAR    szClass[CCHCCCLASS];     // Class name for the control.
  65.     DWORD   flOptions;               // Option flags (CCF_* defines).
  66.     CHAR    szDesc[CCHCCDESC];       // Short, descriptive text for the ctrl.
  67.     UINT    cxDefault;               // Default width (in dialog units).
  68.     UINT    cyDefault;               // Default height (in dialog units).
  69.     DWORD   flStyleDefault;          // Default style (WS_CHILD | WS_VISIBLE).
  70.     DWORD   flExtStyleDefault;       // Default extended style.
  71.     DWORD   flCtrlTypeMask;          // Mask for control type styles.
  72.     CHAR    szTextDefault[CCHCCTEXT];// Default text.
  73.     INT     cStyleFlags;             // Entries in the following style table.
  74.     LPCCSTYLEFLAGA aStyleFlags;      // Points to style flag table.
  75.     LPFNCCSTYLEA lpfnStyle;          // Pointer to the Styles function.
  76.     LPFNCCSIZETOTEXTA lpfnSizeToText;// Pointer to the SizeToText function.
  77.     DWORD   dwReserved1;             // Reserved.  Must be zero.
  78.     DWORD   dwReserved2;             // Reserved.  Must be zero.
  79. } CCINFOA, *LPCCINFOA;
  80.  
  81. typedef struct tagCCINFOW {
  82.     WCHAR   szClass[CCHCCCLASS];     // Class name for the control.
  83.     DWORD   flOptions;               // Option flags (CCF_* defines).
  84.     WCHAR   szDesc[CCHCCDESC];       // Short, descriptive text for the ctrl.
  85.     UINT    cxDefault;               // Default width (in dialog units).
  86.     UINT    cyDefault;               // Default height (in dialog units).
  87.     DWORD   flStyleDefault;          // Default style (WS_CHILD | WS_VISIBLE).
  88.     DWORD   flExtStyleDefault;       // Default extended style.
  89.     DWORD   flCtrlTypeMask;          // Mask for control type styles.
  90.     INT     cStyleFlags;             // Entries in the following style table.
  91.     LPCCSTYLEFLAGW aStyleFlags;      // Points to style flag table.
  92.     WCHAR   szTextDefault[CCHCCTEXT];// Default text.
  93.     LPFNCCSTYLEW lpfnStyle;          // Pointer to the Styles function.
  94.     LPFNCCSIZETOTEXTW lpfnSizeToText;// Pointer to the SizeToText function.
  95.     DWORD   dwReserved1;             // Reserved.  Must be zero.
  96.     DWORD   dwReserved2;             // Reserved.  Must be zero.
  97. } CCINFOW, *LPCCINFOW;
  98.  
  99.  
  100.     szClass             - Class name of the control type.  This
  101.                           class must be registered by the DLL with
  102.                           a RegisterClass call.
  103.  
  104.     flOptions           - Option flags, as follows:
  105.  
  106.                             CCF_NOTEXT - The control does not have text.
  107.                                          The Text entry field in the
  108.                                          Properties Bar of the dialog
  109.                                          editor will not allow text to
  110.                                          be entered for this control.
  111.  
  112.     szDesc              - A short description of the control type.  This
  113.                           can be a zero length string.
  114.  
  115.     cxDefault           - Suggested width of new controls of this type.
  116.                           This value is in dialog units (not pixels).
  117.  
  118.     cyDefault           - Suggested height of new controls of this type.
  119.                           This value is in dialog units (not pixels).
  120.  
  121.     flStyleDefault      - Initial style of new controls of this type.
  122.                           At a minimum, this should include WS_VISIBLE
  123.                           and WS_CHILD.
  124.  
  125.     flExtStyleDefault   - Initial extended style of new controls of this type.
  126.  
  127.     flCtrlTypeMask      - A mask that identifies which bits of flStyleDefault
  128.                           are bits that differentiate between the different
  129.                           types of controls in this class.  This can be
  130.                           zero if there is only one type of control
  131.                           defined for this class.  See below for more
  132.                           information.
  133.  
  134.     cStyleFlags         - The number of elements (styles) in the following
  135.                           array.
  136.  
  137.     aStyleFlags         - Pointer to a LPCCSTYLEFLAGA(W) structure(s) that
  138.                           contains style information for the control.
  139.  
  140.     szTextDefault       - Initial text of new controls of this type.  This
  141.                           can be a zero length string for no initial text.
  142.  
  143.     lpfnStyle           - Pointer to the associated custom control Styles
  144.                           function for this control type.  This can be
  145.                           NULL if the custom control does not have a
  146.                           private Styles dialog written for it.  If
  147.                           NULL, a generic Styles dialog will be used
  148.                           by the dialog editor when the user wants to
  149.                           edit the styles for the control.  See below.
  150.  
  151.     lpfnSizeToText      - Pointer to the associated custom control
  152.                           SizeToText function for this control type.
  153.                           This can be NULL if the control cannot be
  154.                           sized to it's text, and is ignored if CCF_NOTEXT
  155.                           is specified for flOptions.  See below.
  156.  
  157.     dwReserved1         - Reserved value.  Must be zero.
  158.  
  159.     dwReserved2         - Reserved value.  Must be zero.
  160.  
  161.  
  162. The CustomControlInfoW function will be used if it is available,
  163. otherwise the CustomControlInfoA function will be used.  The function
  164. must return the number of controls that the DLL supports, or
  165. zero if an error occurs.
  166.  
  167. The CustomControlInfoA(W) function will be called with a NULL parameter
  168. first, to obtain the number of supported controls.  It will then
  169. be called with a pointer to an array of CCINFOA(W) structures.  The
  170. function should fill in this array with information about each of
  171. the control types that it supports.
  172.  
  173. Note that the lpfnStyle and lpfnSizeToText fields, if
  174. not NULL,  will point to functions that expect UNICODE strings/structures
  175. in the CCINFOW structure, or functions that expect ANSI strings if in
  176. the CCINFOA structure.
  177.  
  178. The flCtrlTypeMask field specifies which bits of the flStyleDefault field
  179. are used for defining a different "type" of control within the class.  For
  180. instance, the standard "BUTTON" class includes several different types
  181. of buttons, including Radio Buttons, Push Buttons, Check Boxes, etc.
  182. These different styles of the "BUTTON" class are all distinguished by the
  183. lower four bits of the style.  In this case, the flCtrlTypeMask would
  184. be 0x000F.  There are other styles, such as BS_LEFTTEXT (0x0020) that
  185. can be used with several button types, and the mask would be used to
  186. strip this style out when looking for a match.  The mask value is used
  187. to help the dialog editor match up a custom control from a dialog being
  188. edited with the exact type of the custom control class from the different
  189. control type variants that may have been defined for a class.  Because
  190. each control type within a class can have it's own Styles and
  191. SizeToText function specified, it can be important that a control be
  192. matched up with the proper control type within the custom control DLL.
  193.  
  194. If the custom control DLL only has one control type for each class, or
  195. the same Styles and SizeToText function is used for each of
  196. the different control types within each class, then the flCtrlTypeMask
  197. value can be zero, because it is not important that a certain control
  198. type be matched up with the exact control type from the DLL that it
  199. was originally created from.  In all cases, however, each control type
  200. with the same class name must have the same mask specified.
  201.  
  202.  
  203. -- CHANGING THE STYLES OF A CUSTOM CONTROL ---------------------------
  204.  
  205. When the user of DlgEdit requests that the styles for a custom control
  206. be edited, the editor will call the function specified in the
  207. lpfnStyle field of the CCINFOA(W) structure.  This function should be
  208. written to bring up and process a dialog box that allows the user
  209. to edit the styles of the custom control.  This dialog should be
  210. designed so that it follows the general style guidelines of the existing
  211. styles dialogs in the dialog editor.  The function has the following
  212. prototype:
  213.  
  214. BOOL CALLBACK XxxxStyleA (HWND hwndParent,  LPCCSTYLEA pccs)
  215.  
  216. BOOL CALLBACK XxxxStyleW (HWND hwndParent,  LPCCSTYLEW pccs)
  217.  
  218. The function name 'XxxxStyleA(W)' is a placeholder for the real name
  219. that you give the function.  The actual name does not matter.
  220. It will be called with the following parameters:
  221.  
  222.     hwndParent      - The parent window for the dialog that will be
  223.                       displayed.  The styles function should use
  224.                       this window as the parent of the styles dialog
  225.                       that it displays.
  226.  
  227.     pccs            - Points to a CCSTYLEA(W) structure.  This structure
  228.                       contains the initial style of the control.  The
  229.                       style should be modified based on the user's
  230.                       input from the styles dialog.
  231.  
  232. The CCSTYLEA(W) structures are defined as follows:
  233.  
  234. typedef struct tagCCSTYLEA {
  235.     DWORD   flStyle;                // Style of the control.
  236.     DWORD   flExtStyle;             // Extended style of the control.
  237.     CHAR    szText[CCHCCTEXT];      // Text of the control.
  238.     LANGID  lgid;                   // Language Id of the control's dialog.
  239.     WORD    wReserved1;             // Reserved value.  Do not change.
  240. } CCSTYLEA, *LPCCSTYLEA;
  241.  
  242. typedef struct tagCCSTYLEW {
  243.     DWORD   flStyle;                // Style of the control.
  244.     DWORD   flExtStyle;             // Extended style of the control.
  245.     WCHAR   szText[CCHCCTEXT];      // Text of the control.
  246.     LANGID  lgid;                   // Language Id of the control's dialog.
  247.     WORD    wReserved1;             // Reserved value.  Do not change.
  248. } CCSTYLEW, *LPCCSTYLEW;
  249.  
  250.     flStyle     - Contains the current style of the control.  This
  251.                   should be set to what the user chose before
  252.                   returning.
  253.  
  254.     flExtStyle  - Contains the current extended style of the control.
  255.                   This should be set to what the user chose before
  256.                   returning.
  257.  
  258.     szText      - Contains the current text for this control.  This text
  259.                   can be changed, although it is not recommended.
  260.                   The Properties Bar in DlgEdit allows the text to be
  261.                   changed, and so this functionality does not normally
  262.                   need to be in the styles dialog for the custom control.
  263.                   An exception might be if the text of the control
  264.                   contains special information or control codes, and
  265.                   is interpreted in an unusual way by the custom control.
  266.  
  267.     lgid        - Language id of the dialog the control is in.  Provided
  268.                   for informational purposes only, and should not be
  269.                   changed.
  270.  
  271.     wReserved1  - Reserved value.  Do not change.
  272.  
  273.  
  274. This function should allow the user to change the styles for the control,
  275. update the CCSTYLEA(W) structure with the new values, then return TRUE.
  276. If the user cancels the dialog or an error occurs, the function should
  277. return FALSE.
  278.  
  279. If the lpfnStyle field of the CCINFOA(W) structure is NULL, a default
  280. Styles dialog will be used by the dialog editor.  This dialog will allow
  281. all the bits of the style to be set, but will not have meaningful names
  282. for them, and some bit settings may not be valid for the custom control.
  283. It is better if the custom control provides it's own dialog.
  284.  
  285.  
  286.  
  287. -- SIZING TO TEXT SUPPORT -----------------------------------------------
  288.  
  289. It can be very useful for a custom control to be sized to fit it's text,
  290. along with the other standard controls (radio buttons, push buttons, etc.)
  291. that support this.  However, the dialog editor does not know what size of
  292. a margin, etc. a custom control has, and cannot automatically size it to
  293. fit the text.  The optional lpfnSizeToText field of the CCINFOA(W)
  294. structure allows a custom control to specify a function that will be
  295. called for the custom control when the user specifies that it should be
  296. sized to it's text.  This function will have the following prototype:
  297.  
  298.  
  299. INT CALLBACK XxxxSizeToTextA (DWORD flStyle, DWORD flExtStyle,
  300.                               HFONT hfont,   LPSTR pszText)
  301.  
  302. INT CALLBACK XxxxSizeToTextW (DWORD flStyle, DWORD flExtStyle,
  303.                               HFONT hfont,   LPWSTR pszText)
  304.  
  305.     flStyle     - Style of the control.  This may be necessary to
  306.                   determine how it should be sized.
  307.  
  308.     flExtStyle  - Extended style of the control.  This may be necessary
  309.                   to determine how it should be sized.
  310.  
  311.     hfont       - Either NULL or the font that is selected for the
  312.                   current dialog being edited.  This font should be used
  313.                   when determining the size of the control.  This font
  314.                   should not be deleted or left selected in a DC when
  315.                   the function returns.
  316.  
  317.     pszText     - The text to size the custom control to.
  318.  
  319. The XxxxSizeToTextA(W) function should use the specified styles, font and
  320. text string to determine the minimum size of the custom control,  then should
  321. return this value.  This value should be in pixels, not dialog units.
  322. The function should return -1 if an error occurs.
  323.  
  324.