summaryrefslogtreecommitdiffstats
path: root/private/ole2ui32/template.cpp
blob: 81244dc95200ad70f4675b3b48d0663e3058b7a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
 * TEMPLATE.CPP
 *
 * Copyright (c)1992 Microsoft Corporation, All Right Reserved
 *
 *
 * CUSTOMIZATION INSTRUCTIONS:
 *
 *  1.  Replace <FILE> with the uppercased filename for this file.
 *      Lowercase the <FILE>.h entry
 *
 *  2.  Replace <NAME> with the mixed case dialog name in one word,
 *      such as InsertObject
 *
 *  3.  Replace <FULLNAME> with the mixed case dialog name in multiple
 *      words, such as Insert Object
 *
 *  4.  Replace <ABBREV> with the suffix for pointer variables, such
 *      as the IO in InsertObject's pIO or the CI in ChangeIcon's pCI.
 *      Check the alignment of the first variable declaration in the
 *      Dialog Proc after this.  I will probably be misaligned with the
 *      rest of the variables.
 *
 *  5.  Replace <STRUCT> with the uppercase structure name for this
 *      dialog sans OLEUI, such as INSERTOBJECT.  Changes OLEUI<STRUCT>
 *      in most cases, but we also use this for IDD_<STRUCT> as the
 *      standard template resource ID.
 *
 *  6.  Find <UFILL> fields and fill them out with whatever is appropriate.
 *
 *  7.  Delete this header up to the start of the next comment.
 */


/*
 * <FILE>.CPP
 *
 * Implements the OleUI<NAME> function which invokes the complete
 * <FULLNAME> dialog.
 *
 * Copyright (c)1992 Microsoft Corporation, All Right Reserved
 */

#include "precomp.h"
#include "common.h"

#include "template.h"

/*
 * OleUI<NAME>
 *
 * Purpose:
 *  Invokes the standard OLE <FULLNAME> dialog box allowing the user
 *  to <UFILL>
 *
 * Parameters:
 *  lp<ABBREV>            LPOLEUI<NAME> pointing to the in-out structure
 *                  for this dialog.
 *
 * Return Value:
 *  UINT            One of the following codes, indicating success or error:
 *                      OLEUI_SUCCESS           Success
 *                      OLEUI_ERR_STRUCTSIZE    The dwStructSize value is wrong
 */

STDAPI_(UINT) OleUI<NAME>(LPOLEUI<STRUCT> lp<ABBREV>)
{
        UINT        uRet;
        HGLOBAL     hMemDlg=NULL;

        uRet = UStandardValidation((LPOLEUISTANDARD)lp<ABBREV>,
                sizeof(OLEUI<STRUCT>), &hMemDlg);

        if (OLEUI_SUCCESS!=uRet)
                return uRet;

        /*
         * PERFORM ANY STRUCTURE-SPECIFIC VALIDATION HERE!
         * ON FAILURE:
         *  {
         *  return OLEUI_<ABBREV>ERR_<ERROR>
         *  }
         */

        //Now that we've validated everything, we can invoke the dialog.
        uRet = UStandardInvocation(<NAME>DialogProc, (LPOLEUISTANDARD)lp<ABBREV>
                                                         , hMemDlg, MAKEINTRESOURCE(IDD_<STRUCT>));

        /*
         * IF YOU ARE CREATING ANYTHING BASED ON THE RESULTS, DO IT HERE.
         */
        <UFILL>

        return uRet;
}

/*
 * <NAME>DialogProc
 *
 * Purpose:
 *  Implements the OLE <FULLNAME> dialog as invoked through the
 *  OleUI<NAME> function.
 *
 * Parameters:
 *  Standard
 *
 * Return Value:
 *  Standard
 */

BOOL CALLBACK <NAME>DialogProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
        P<STRUCT>               p<ABBREV>;
        BOOL                    fHook=FALSE;

        //Declare Win16/Win32 compatible WM_COMMAND parameters.
        COMMANDPARAMS(wID, wCode, hWndMsg);

        //This will fail under WM_INITDIALOG, where we allocate it.
        p<ABBREV>=(<STRUCT>)PvStandardEntry(hDlg, iMsg, wParam, lParam, &uHook);

        //If the hook processed the message, we're done.
        if (0!=uHook)
                return (BOOL)uHook;

        //Process the temination message
        if (iMsg==uMsgEndDialog)
        {
                EndDialog(hDlg, wParam);
                return TRUE;
        }

        switch (iMsg)
        {
        case WM_DESTROY:
            if (p<ABBREV>)
            {
                //Free any specific allocations before calling StandardCleanup
                StandardCleanup((PVOID)p<ABBREV>, hDlg);
            }
            break;
        case WM_INITDIALOG:
                F<NAME>Init(hDlg, wParam, lParam);
                return TRUE;

        case WM_COMMAND:
                switch (wID)
                {
                case IDOK:
                        /*
                         * PERFORM WHATEVER FUNCTIONS ARE DEFAULT HERE.
                         */
                        SendMessage(hDlg, uMsgEndDialog, OLEUI_OK, 0L);
                        break;

                case IDCANCEL:
                        /*
                         * PERFORM ANY UNDOs HERE, BUT NOT CLEANUP THAT WILL
                         * ALWAYS HAPPEN WHICH SHOULD BE IN uMsgEndDialog.
                         */
                        SendMessage(hDlg, uMsgEndDialog, OLEUI_CANCEL, 0L);
                        break;

                case ID_OLEUIHELP:
                        PostMessage(p<ABBREV>->lpO<ABBREV>->hWndOwner, uMsgHelp
                                                , (WPARAM)hDlg, MAKELPARAM(IDD_<STRUCT>, 0));
                        break;
                }
        break;
        }
        return FALSE;
}


/*
 * F<NAME>Init
 *
 * Purpose:
 *  WM_INITIDIALOG handler for the <FULLNAME> dialog box.
 *
 * Parameters:
 *  hDlg            HWND of the dialog
 *  wParam          WPARAM of the message
 *  lParam          LPARAM of the message
 *
 * Return Value:
 *  BOOL            Value to return for WM_INITDIALOG.
 */

BOOL F<NAME>Init(HWND hDlg, WPARAM wParam, LPARAM lParam)
{
        P<STRUCT>               p<ABBREV>;
        LPOLEUI<STRUCT>         lpO<ABBREV>;
        HFONT                   hFont;

        //1.  Copy the structure at lParam into our instance memory.
        p<ABBREV>=(PSTRUCT)PvStandardInit(hDlg, sizeof(<STRUCT>), TRUE, &hFont);

        //PvStandardInit send a termination to us already.
        if (NULL==p<ABBREV>)
                return FALSE;

        lpO<ABBREV>=(LPOLEUI<STRUCT>)lParam);

        p<ABBREV>->lpO<ABBREV>=lpO<ABBREV>;

        //Copy other information from lpO<ABBREV> that we might modify.
        <UFILL>

        //2.  If we got a font, send it to the necessary controls.
        if (NULL!=hFont)
        {
                //Do this for as many controls as you need it for.
                SendDlgItemMessage(hDlg, ID_<UFILL>, WM_SETFONT, (WPARAM)hFont, 0L);
        }

        //3.  Show or hide the help button
        if (!(p<ABBREV>->lpO<ABBREV>->dwFlags & <ABBREV>F_SHOWHELP))
                StandardShowDlgItem(hDlg, ID_OLEUIHELP, SW_HIDE);

        /*
         * PERFORM OTHER INITIALIZATION HERE.  ON ANY LoadString
         * FAILURE POST OLEUI_MSG_ENDDIALOG WITH OLEUI_ERR_LOADSTRING.
         */

        //n.  Call the hook with lCustData in lParam
        UStandardHook((PVOID)p<ABBREV>, hDlg, WM_INITDIALOG, wParam, lpO<ABBREV>->lCustData);
        return TRUE;
}