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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
|
/*************************************************************************
**
** OLE 2 Sample Code
**
** dialogs.c
**
** This file contains dialog functions and support function
**
** (c) Copyright Microsoft Corp. 1992 - 1993 All Rights Reserved
**
*************************************************************************/
#include "outline.h"
OLEDBGDATA
extern LPOUTLINEAPP g_lpApp;
static char g_szBuf[MAXSTRLEN+1];
static LPSTR g_lpszDlgTitle;
// REVIEW: should use string resource for messages
static char ErrMsgInvalidRange[] = "Invalid Range entered!";
static char ErrMsgInvalidValue[] = "Invalid Value entered!";
static char ErrMsgInvalidName[] = "Invalid Name entered!";
static char ErrMsgNullName[] = "NULL string disallowed!";
static char ErrMsgNameNotFound[] = "Name doesn't exist!";
/* InputTextDlg
* ------------
*
* Put up a dialog box to allow the user to edit text
*/
BOOL InputTextDlg(HWND hWnd, LPSTR lpszText, LPSTR lpszDlgTitle)
{
int nResult;
g_lpszDlgTitle = lpszDlgTitle;
lstrcpy((LPSTR)g_szBuf, lpszText); // preload dialog with input text
nResult = DialogBox(g_lpApp->m_hInst, (LPSTR)"AddEditLine", hWnd,
(DLGPROC)AddEditDlgProc);
if (nResult) {
lstrcpy(lpszText, (LPSTR)g_szBuf);
return TRUE;
} else {
return FALSE;
}
}
/* AddEditDlgProc
* --------------
*
* This procedure is associated with the dialog box that is included in
* the function name of the procedure. It provides the service routines
* for the events (messages) that occur because the end user operates
* one of the dialog box's buttons, entry fields, or controls.
*/
BOOL CALLBACK EXPORT AddEditDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
{
HWND hEdit;
switch(Message) {
case WM_INITDIALOG:
/* initialize working variables */
hEdit=GetDlgItem(hDlg,IDD_EDIT);
SendMessage(hEdit,EM_LIMITTEXT,(WPARAM)MAXSTRLEN,0L);
SetWindowText(hDlg, g_lpszDlgTitle);
SetDlgItemText(hDlg,IDD_EDIT, g_szBuf);
break; /* End of WM_INITDIALOG */
case WM_CLOSE:
/* Closing the Dialog behaves the same as Cancel */
PostMessage(hDlg, WM_COMMAND, IDCANCEL, 0L);
break; /* End of WM_CLOSE */
case WM_COMMAND:
switch (wParam) {
case IDOK:
/* save data values entered into the controls
** and dismiss the dialog box returning TRUE
*/
GetDlgItemText(hDlg,IDD_EDIT,(LPSTR)g_szBuf,MAXSTRLEN+1);
EndDialog(hDlg, TRUE);
break;
case IDCANCEL:
/* ignore data values entered into the controls
** and dismiss the dialog box returning FALSE
*/
EndDialog(hDlg, FALSE);
break;
}
break; /* End of WM_COMMAND */
default:
return FALSE;
}
return TRUE;
} /* End of AddEditDlgProc */
/* SetLineHeightDlgProc
* --------------------
*
* Dialog procedure for set line height
*/
BOOL CALLBACK EXPORT SetLineHeightDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
{
BOOL fTranslated;
BOOL fEnable;
static LPINT lpint;
int nHeight;
static int nMaxHeight;
switch (Message) {
case WM_INITDIALOG:
{
char cBuf[80];
nMaxHeight = XformHeightInPixelsToHimetric(NULL,
LISTBOX_HEIGHT_LIMIT);
lpint = (LPINT)lParam;
SetDlgItemInt(hDlg, IDD_EDIT, *lpint, FALSE);
wsprintf(cBuf, "Maximum value is %d units", nMaxHeight);
SetDlgItemText(hDlg, IDD_LIMIT, (LPSTR)cBuf);
break;
}
case WM_COMMAND:
switch (wParam) {
case IDOK:
if (IsDlgButtonChecked(hDlg, IDD_CHECK)) {
*lpint = -1;
}
else {
/* save the value in the edit control */
nHeight = GetDlgItemInt(hDlg, IDD_EDIT,
(BOOL FAR*)&fTranslated, FALSE);
if (!fTranslated || !nHeight || (nHeight>nMaxHeight)){
OutlineApp_ErrorMessage(g_lpApp,
ErrMsgInvalidValue);
break;
}
*lpint = nHeight;
}
EndDialog(hDlg, TRUE);
break;
case IDCANCEL:
*lpint = 0;
EndDialog(hDlg, FALSE);
break;
case IDD_CHECK:
fEnable = !IsDlgButtonChecked(hDlg, IDD_CHECK);
EnableWindow(GetDlgItem(hDlg, IDD_EDIT), fEnable);
EnableWindow(GetDlgItem(hDlg, IDD_TEXT), fEnable);
break;
}
break; /* WM_COMMAND */
case WM_CLOSE: /* Closing the Dialog behaves the same as Cancel */
PostMessage(hDlg, WM_COMMAND, IDCANCEL, 0L);
break; /* End of WM_CLOSE */
default:
return FALSE;
}
return TRUE;
} /* end of SetLineHeightProc */
/* DefineNameDlgProc
* -----------------
*
* Dialog procedure for define name
*/
BOOL CALLBACK EXPORT DefineNameDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
{
static HWND hCombo;
static LPOUTLINEDOC lpOutlineDoc = NULL;
static LPOUTLINENAMETABLE lpOutlineNameTable = NULL;
LPOUTLINENAME lpOutlineName = NULL;
UINT nIndex;
LINERANGE lrSel;
BOOL fTranslated;
switch(Message) {
case WM_INITDIALOG:
/* initialize working variables */
hCombo=GetDlgItem(hDlg,IDD_COMBO);
lpOutlineDoc = (LPOUTLINEDOC) lParam;
lpOutlineNameTable = OutlineDoc_GetNameTable(lpOutlineDoc);
SendMessage(hCombo,CB_LIMITTEXT,(WPARAM)MAXNAMESIZE,0L);
NameDlg_LoadComboBox(lpOutlineNameTable, hCombo);
OutlineDoc_GetSel(lpOutlineDoc, (LPLINERANGE)&lrSel);
lpOutlineName = OutlineNameTable_FindNamedRange(
lpOutlineNameTable,
&lrSel
);
/* if current selection already has a name, hilight it */
if (lpOutlineName) {
nIndex = (int) SendMessage(
hCombo,
CB_FINDSTRINGEXACT,
(WPARAM)0xffff,
(LPARAM)(LPCSTR)lpOutlineName->m_szName
);
if (nIndex != CB_ERR) {
SendMessage(hCombo, CB_SETCURSEL, (WPARAM)nIndex, 0L);
}
}
SetDlgItemInt(hDlg, IDD_FROM, (UINT)lrSel.m_nStartLine+1,FALSE);
SetDlgItemInt(hDlg, IDD_TO, (UINT)lrSel.m_nEndLine+1, FALSE);
break; /* End of WM_INITDIALOG */
case WM_CLOSE:
/* Closing the Dialog behaves the same as Cancel */
PostMessage(hDlg, WM_COMMAND, IDD_CLOSE, 0L);
break; /* End of WM_CLOSE */
case WM_COMMAND:
switch(wParam) {
case IDOK:
GetDlgItemText(hDlg,IDD_COMBO,(LPSTR)g_szBuf,MAXNAMESIZE);
if(! SendMessage(hCombo,WM_GETTEXTLENGTH,0,0L)) {
MessageBox(
hDlg,
ErrMsgNullName,
NULL,
MB_ICONEXCLAMATION
);
break;
} else if(SendMessage(hCombo,CB_GETCURSEL,0,0L)==CB_ERR &&
_fstrchr(g_szBuf, ' ')) {
MessageBox(
hDlg,
ErrMsgInvalidName,
NULL,
MB_ICONEXCLAMATION
);
break;
} else {
nIndex = (int) SendMessage(hCombo,CB_FINDSTRINGEXACT,
(WPARAM)0xffff,(LPARAM)(LPCSTR)g_szBuf);
/* Line indices are 1 less than the number in
** the row heading
*/
lrSel.m_nStartLine = GetDlgItemInt(hDlg, IDD_FROM,
(BOOL FAR*)&fTranslated, FALSE) - 1;
if(! fTranslated) {
OutlineApp_ErrorMessage(g_lpApp,
ErrMsgInvalidRange);
break;
}
lrSel.m_nEndLine = GetDlgItemInt(hDlg, IDD_TO,
(BOOL FAR*)&fTranslated, FALSE) - 1;
if (!fTranslated ||
(lrSel.m_nStartLine < 0) ||
(lrSel.m_nEndLine < lrSel.m_nStartLine) ||
(lrSel.m_nEndLine >= OutlineDoc_GetLineCount(
lpOutlineDoc))) {
OutlineApp_ErrorMessage(g_lpApp,
ErrMsgInvalidRange);
break;
}
if(nIndex != CB_ERR) {
NameDlg_UpdateName(
hCombo,
lpOutlineDoc,
nIndex,
g_szBuf,
&lrSel
);
} else {
NameDlg_AddName(
hCombo,
lpOutlineDoc,
g_szBuf,
&lrSel
);
}
}
// fall through
case IDD_CLOSE:
/* Ignore data values entered into the controls */
/* and dismiss the dialog window returning FALSE */
EndDialog(hDlg,0);
break;
case IDD_DELETE:
GetDlgItemText(hDlg,IDD_COMBO,(LPSTR)g_szBuf,MAXNAMESIZE);
if((nIndex=(int)SendMessage(hCombo,CB_FINDSTRINGEXACT,
(WPARAM)0xffff,(LPARAM)(LPCSTR)g_szBuf))==CB_ERR)
MessageBox(hDlg, ErrMsgNameNotFound, NULL, MB_ICONEXCLAMATION);
else {
NameDlg_DeleteName(hCombo, lpOutlineDoc, nIndex);
}
break;
case IDD_COMBO:
if(HIWORD(lParam) == CBN_SELCHANGE) {
nIndex=(int)SendMessage(hCombo, CB_GETCURSEL, 0, 0L);
lpOutlineName = (LPOUTLINENAME)SendMessage(
hCombo,
CB_GETITEMDATA,
(WPARAM)nIndex,
0L
);
SetDlgItemInt(
hDlg,
IDD_FROM,
(UINT) lpOutlineName->m_nStartLine + 1,
FALSE
);
SetDlgItemInt(
hDlg,
IDD_TO,
(UINT) lpOutlineName->m_nEndLine + 1,
FALSE
);
}
}
break; /* End of WM_COMMAND */
default:
return FALSE;
}
return TRUE;
} /* End of DefineNameDlgProc */
/* GotoNameDlgProc
* ---------------
*
* Dialog procedure for goto name
*/
BOOL CALLBACK EXPORT GotoNameDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
{
static HWND hLBName;
static LPOUTLINEDOC lpOutlineDoc = NULL;
static LPOUTLINENAMETABLE lpOutlineNameTable = NULL;
UINT nIndex;
LINERANGE lrLineRange;
LPOUTLINENAME lpOutlineName;
switch(Message) {
case WM_INITDIALOG:
/* initialize working variables */
lpOutlineDoc = (LPOUTLINEDOC) lParam;
lpOutlineNameTable = OutlineDoc_GetNameTable(lpOutlineDoc);
hLBName=GetDlgItem(hDlg,IDD_LINELISTBOX);
NameDlg_LoadListBox(lpOutlineNameTable, hLBName);
// highlight 1st item
SendMessage(hLBName, LB_SETCURSEL, 0, 0L);
// trigger to initialize edit control
SendMessage(hDlg, WM_COMMAND, (WPARAM)IDD_LINELISTBOX,
MAKELONG(hLBName, LBN_SELCHANGE));
break; /* End of WM_INITDIALOG */
case WM_CLOSE:
/* Closing the Dialog behaves the same as Cancel */
PostMessage(hDlg, WM_COMMAND, IDCANCEL, 0L);
break; /* End of WM_CLOSE */
case WM_COMMAND:
switch(wParam) {
case IDD_LINELISTBOX:
if(HIWORD(lParam) == LBN_SELCHANGE) {
// update the line range display
nIndex=(int)SendMessage(hLBName, LB_GETCURSEL, 0, 0L);
lpOutlineName = (LPOUTLINENAME)SendMessage(hLBName, LB_GETITEMDATA,
(WPARAM)nIndex,0L);
if (lpOutlineName) {
SetDlgItemInt(
hDlg,
IDD_FROM,
(UINT) lpOutlineName->m_nStartLine + 1,
FALSE
);
SetDlgItemInt(
hDlg,
IDD_TO,
(UINT) lpOutlineName->m_nEndLine + 1,
FALSE
);
}
break;
}
// double click will fall through
else if(HIWORD(lParam) != LBN_DBLCLK)
break;
case IDOK:
nIndex=(int)SendMessage(hLBName,LB_GETCURSEL,0,0L);
if(nIndex!=LB_ERR) {
lpOutlineName = (LPOUTLINENAME)SendMessage(hLBName,
LB_GETITEMDATA, (WPARAM)nIndex, 0L);
lrLineRange.m_nStartLine=lpOutlineName->m_nStartLine;
lrLineRange.m_nEndLine = lpOutlineName->m_nEndLine;
OutlineDoc_SetSel(lpOutlineDoc, &lrLineRange);
} // fall through
case IDCANCEL:
/* Ignore data values entered into the controls */
/* and dismiss the dialog window returning FALSE */
EndDialog(hDlg,0);
break;
}
break; /* End of WM_COMMAND */
default:
return FALSE;
}
return TRUE;
} /* End of GotoNameDlgProc */
/* NameDlg_LoadComboBox
* --------------------
*
* Load defined names into combo box
*/
void NameDlg_LoadComboBox(LPOUTLINENAMETABLE lpOutlineNameTable,HWND hCombo)
{
LPOUTLINENAME lpOutlineName;
int i, nIndex;
int nCount;
nCount=OutlineNameTable_GetCount((LPOUTLINENAMETABLE)lpOutlineNameTable);
if(!nCount) return;
SendMessage(hCombo,WM_SETREDRAW,(WPARAM)FALSE,0L);
for(i=0; i<nCount; i++) {
lpOutlineName=OutlineNameTable_GetName((LPOUTLINENAMETABLE)lpOutlineNameTable,i);
nIndex = (int)SendMessage(
hCombo,
CB_ADDSTRING,
0,
(LPARAM)(LPCSTR)lpOutlineName->m_szName
);
SendMessage(hCombo,CB_SETITEMDATA,(WPARAM)nIndex,(LPARAM)lpOutlineName);
}
SendMessage(hCombo,WM_SETREDRAW,(WPARAM)TRUE,0L);
}
/* NameDlg_LoadListBox
* -------------------
*
* Load defined names into list box
*/
void NameDlg_LoadListBox(LPOUTLINENAMETABLE lpOutlineNameTable,HWND hListBox)
{
int i;
int nCount;
int nIndex;
LPOUTLINENAME lpOutlineName;
nCount=OutlineNameTable_GetCount((LPOUTLINENAMETABLE)lpOutlineNameTable);
SendMessage(hListBox,WM_SETREDRAW,(WPARAM)FALSE,0L);
for(i=0; i<nCount; i++) {
lpOutlineName=OutlineNameTable_GetName((LPOUTLINENAMETABLE)lpOutlineNameTable,i);
nIndex = (int)SendMessage(
hListBox,
LB_ADDSTRING,
0,
(LPARAM)(LPCSTR)lpOutlineName->m_szName
);
SendMessage(hListBox,LB_SETITEMDATA,(WPARAM)nIndex,(LPARAM)lpOutlineName);
}
SendMessage(hListBox,WM_SETREDRAW,(WPARAM)TRUE,0L);
}
/* NameDlg_AddName
* ---------------
*
* Add a name to the name table corresponding to the name dialog
* combo box.
*/
void NameDlg_AddName(HWND hCombo, LPOUTLINEDOC lpOutlineDoc, LPSTR lpszName, LPLINERANGE lplrSel)
{
LPOUTLINEAPP lpOutlineApp = (LPOUTLINEAPP)g_lpApp;
LPOUTLINENAME lpOutlineName;
lpOutlineName = OutlineApp_CreateName(lpOutlineApp);
if (lpOutlineName) {
lstrcpy(lpOutlineName->m_szName, lpszName);
lpOutlineName->m_nStartLine = lplrSel->m_nStartLine;
lpOutlineName->m_nEndLine = lplrSel->m_nEndLine;
OutlineDoc_AddName(lpOutlineDoc, lpOutlineName);
} else {
// REVIEW: do we need error message here?
}
}
/* NameDlg_UpdateName
* ------------------
*
* Update a name in the name table corresponding to a name in
* the name dialog combo box.
*/
void NameDlg_UpdateName(HWND hCombo, LPOUTLINEDOC lpOutlineDoc, int nIndex, LPSTR lpszName, LPLINERANGE lplrSel)
{
LPOUTLINENAME lpOutlineName;
lpOutlineName = (LPOUTLINENAME)SendMessage(
hCombo,
CB_GETITEMDATA,
(WPARAM)nIndex,
0L
);
OutlineName_SetName(lpOutlineName, lpszName);
OutlineName_SetSel(lpOutlineName, lplrSel, TRUE /* name modified */);
OutlineDoc_SetModified(lpOutlineDoc, TRUE, FALSE, FALSE);
}
/* NameDlg_DeleteName
* ------------------
*
* Delete a name from the name dialog combo box and corresponding
* name table.
*/
void NameDlg_DeleteName(HWND hCombo, LPOUTLINEDOC lpOutlineDoc, UINT nIndex)
{
SendMessage(hCombo,CB_DELETESTRING,(WPARAM)nIndex,0L);
OutlineDoc_DeleteName(lpOutlineDoc, nIndex);
}
/* PlaceBitmap
* -----------
*
* Places a bitmap centered in the specified control in the dialog on the
* specified DC.
*
*/
PlaceBitmap(HWND hDlg, int control, HDC hDC, HBITMAP hBitmap)
{
BITMAP bm;
HDC hdcmem;
HBITMAP hbmOld;
RECT rcControl; // Rect of dialog control
int width, height;
GetObject(hBitmap, sizeof(BITMAP), &bm);
hdcmem= CreateCompatibleDC(hDC);
hbmOld = SelectObject(hdcmem, hBitmap);
// Get rect of control in screen coords, and translate to our dialog
// box's coordinates
GetWindowRect(GetDlgItem(hDlg, control), &rcControl);
MapWindowPoints(NULL, hDlg, (LPPOINT)&rcControl, 2);
width = rcControl.right - rcControl.left;
height = rcControl.bottom - rcControl.top;
BitBlt(hDC, rcControl.left + (width - bm.bmWidth) / 2,
rcControl.top + (height - bm.bmHeight) /2,
bm.bmWidth, bm.bmHeight,
hdcmem, 0, 0, SRCCOPY);
SelectObject(hdcmem, hbmOld);
DeleteDC(hdcmem);
return 1;
}
/* AboutDlgProc
* ------------
*
* Dialog procedure for the About function
*/
BOOL CALLBACK EXPORT AboutDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
{
int narrVersion[2];
static HBITMAP hbmLogo;
switch(Message) {
case WM_INITDIALOG:
// get version number of app
wsprintf(g_szBuf, "About %s", (LPCSTR)APPNAME);
SetWindowText(hDlg, (LPCSTR)g_szBuf);
OutlineApp_GetAppVersionNo(g_lpApp, narrVersion);
wsprintf(g_szBuf, "%s version %d.%d", (LPSTR) APPDESC,
narrVersion[0], narrVersion[1]);
SetDlgItemText(hDlg, IDD_APPTEXT, (LPCSTR)g_szBuf);
// Load bitmap for displaying later
hbmLogo = LoadBitmap(g_lpApp->m_hInst, "LogoBitmap");
TraceDebug(hDlg, IDD_BITMAPLOCATION);
ShowWindow(GetDlgItem(hDlg, IDD_BITMAPLOCATION), SW_HIDE);
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint(hDlg, &ps);
// Display bitmap in IDD_BITMAPLOCATION control area
PlaceBitmap(hDlg, IDD_BITMAPLOCATION, ps.hdc, hbmLogo);
EndPaint(hDlg, &ps);
}
break;
case WM_CLOSE :
PostMessage(hDlg, WM_COMMAND, IDOK, 0L);
break;
case WM_COMMAND :
switch(wParam) {
case IDOK:
case IDCANCEL:
if (hbmLogo) DeleteObject(hbmLogo);
EndDialog(hDlg,0);
break;
}
break;
default :
return FALSE;
}
return TRUE;
}
|