SDC C-Project CF Review 프로그램
LYW
2021-06-28 cf6a4019e9efbc0503bd3fbcf6f951565d028972
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
// DynDialogEx.cpp : ±¸Çö ÆÄÀÏÀÔ´Ï´Ù.
//
 
#include "stdafx.h"
#include "DynDialogEx.h"
#include "afxdialogex.h"
 
 
// CDynDialogEx ´ëÈ­ »óÀÚÀÔ´Ï´Ù.
 
CDynDialogEx::CDynDialogEx(CWnd* pParent /*=NULL*/)
: CDialog()
{
  //{{AFX_DATA_INIT(CDynDialogEx)
  // NOTE: the ClassWizard will add member initialization here
  //}}AFX_DATA_INIT
 
  m_DialogTemplate.style                = WS_CAPTION | WS_SYSMENU | WS_VISIBLE | DS_SETFONT;
  m_DialogTemplate.dwExtendedStyle = WS_EX_DLGMODALFRAME;
  m_DialogTemplate.x                    = 0;
  m_DialogTemplate.y                    = 0;
  m_DialogTemplate.cx                    = 0; // 4 horizontal units are the width of one character
  m_DialogTemplate.cy                    = 0; // 8 vertical units are the height of one character
  m_DialogTemplate.cdit                = 0;  // nr of dialog items in the dialog
 
  m_pParentWnd    = pParent;
  m_strCaption    = _T("");
  m_pFont            = NULL;
  m_wFontSize        = 0;
  m_nCurRow        = FIRSTROW1;
  m_bAddSystemButtons = TRUE;
 
  m_bIsFontCreated = FALSE;
  m_bModelessDlg = FALSE;
}
 
CDynDialogEx::~CDynDialogEx()
{
  CDynDialogItemEx *pDynDialogItemEx = NULL;
  for (INT_PTR i = m_arrDlgItemPtr.GetSize() - 1; i >= 0; i--) {
    pDynDialogItemEx = m_arrDlgItemPtr[i];
    if (pDynDialogItemEx != NULL) {
      delete pDynDialogItemEx;
      pDynDialogItemEx = NULL;
    }
  }
 
  if (m_bIsFontCreated) {
    delete m_pFont;
  }
}
 
CWnd *CDynDialogEx::GetParent()
{
  return m_pParentWnd;
}
 
void CDynDialogEx::AddStyles(DWORD dwStyles)
{
  m_DialogTemplate.style |= dwStyles;
}
 
void CDynDialogEx::RemoveStyles(DWORD dwStyles)
{
  m_DialogTemplate.style &= (~dwStyles);
}
 
void CDynDialogEx::DoDataExchange(CDataExchange* pDX)
{
  CDialog::DoDataExchange(pDX);
  //{{AFX_DATA_MAP(CDynDialogEx)
  // NOTE: the ClassWizard will add DDX and DDV calls here
  //}}AFX_DATA_MAP
 
  CDynDialogItemEx *pDynDialogItemEx = NULL;
  for (INT_PTR i = m_arrDlgItemPtr.GetSize() - 1; i >= 0; i--) {
    pDynDialogItemEx = m_arrDlgItemPtr[i];
    if (pDynDialogItemEx != NULL) {
      pDynDialogItemEx->DoDataExchange(pDX);
    }
  }
}
 
BEGIN_MESSAGE_MAP(CDynDialogEx, CDialog)
  //{{AFX_MSG_MAP(CDynDialogEx)
  ON_WM_CREATE()
  //}}AFX_MSG_MAP
  ON_MESSAGE(WM_HELP, OnHelpMsg)
  ON_WM_MEASUREITEM()        // TMB! 06-12-2001 Adjusted.. was wrongly an ON_MESSAGE()!!
  ON_WM_DRAWITEM()            // TMB! 06-12-2001 Adjusted.. was wrongly an ON_MESSAGE()!!
END_MESSAGE_MAP()
 
/////////////////////////////////////////////////////////////////////////////
// CDynDialogEx message handlers
 
int CDynDialogEx::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
  if (CDialog::OnCreate(lpCreateStruct) == -1)
    return -1;
 
  //if we have no font, create one here
  if (m_pFont == NULL) {
    LOGFONT LogFont;
 
    // Can do better???
    memset(&LogFont, 0x00, sizeof(LogFont));
    _tcsncpy_s(LogFont.lfFaceName, _T("MS Sans Serif"), LF_FACESIZE);
    LogFont.lfHeight = 8;
 
    m_pFont = new CFont;
    m_pFont->CreateFontIndirect(&LogFont);
    SetFont(m_pFont);
    m_bIsFontCreated = TRUE;
  }
 
  //Create all the controls on the dialog
  CDynDialogItemEx *pDynDialogItemEx = NULL;
  for (int i = 0; i < m_arrDlgItemPtr.GetSize(); i++) {
    pDynDialogItemEx = m_arrDlgItemPtr[i];
    if (pDynDialogItemEx != NULL) {
      if (!pDynDialogItemEx->IsDlgItemSubclassed()) {
        if (!pDynDialogItemEx->CreateEx(this)) {
          AfxMessageBox(_T("Failed to create DlgItem."));
        }
        else if (pDynDialogItemEx->GetSafeHwnd() != NULL) {
          pDynDialogItemEx->SetFont(m_pFont, FALSE);
        }
      }
    }
  }
 
  return 0;
}
 
BOOL CDynDialogEx::OnInitDialog() 
{
  //Reposition all the controls on the dialog...
  CDynDialogItemEx *pDynDialogItemEx = NULL;
  for (int i = 0; i < m_arrDlgItemPtr.GetSize(); i++) 
  {
    pDynDialogItemEx = m_arrDlgItemPtr[i];
    if (pDynDialogItemEx != NULL)
    {
      if (!pDynDialogItemEx->IsDlgItemSubclassed() && !pDynDialogItemEx->SetWindowPos(this)) 
      {
        CString strMessage;
        strMessage.Format(_T("Failed SetWindowPos for control %s."), pDynDialogItemEx->GetClassName());
        AfxMessageBox(strMessage);
      }
    }
  }
 
  CDialog::OnInitDialog();
 
  CenterWindow();
 
  return TRUE;  // return TRUE unless you set the focus to a control
  // EXCEPTION: OCX Property Pages should return FALSE
}
 
INT_PTR CDynDialogEx::DoModal() 
{
    //Do we need OK and Cancel buttons??
    if (m_bAddSystemButtons) 
    {
        AddSystemButtons();
    }
 
    //
    // Get font info from mainwindow of the application
    //
    CFont* pParentFont = m_pFont;
    if (pParentFont == NULL && m_pParentWnd != NULL) 
    {
        pParentFont = m_pParentWnd->GetFont();
    }
    if (pParentFont == NULL && AfxGetApp()->m_pActiveWnd != NULL) 
    {
        pParentFont = AfxGetApp()->m_pActiveWnd->GetFont();
    }
 
    LOGFONT LogFont;
    memset(&LogFont, 0x00, sizeof(LogFont));
    if (pParentFont != NULL)
    {
        pParentFont->GetLogFont(&LogFont);
    }
    else 
    {
        // Can do better???
        _tcsncpy_s(LogFont.lfFaceName, _T("MS Sans Serif"), LF_FACESIZE);
        LogFont.lfHeight = 8;
    }
 
    //Prework for setting font in dialog...
    //int cWC = MultiByteToWideChar(CP_ACP, 0, LogFont.lfFaceName, -1, NULL, 0);
    int cWC = _tcslen(LogFont.lfFaceName)+1;
    int nFontNameLen = cWC + 1;
    WCHAR *szFontName = new WCHAR[nFontNameLen];
 
    // Copy the string
    //MultiByteToWideChar(CP_ACP, 0, LogFont.lfFaceName, -1, (LPWSTR) szFontName, cWC);
 
#ifdef X
    _tcsncpy(szFontName, LogFont.lfFaceName, cWC);
#else
    int len; char *ptr;
    len = WideCharToMultiByte( CP_ACP, 0, szFontName, -1, NULL, 0, NULL, NULL );
    ptr = (char *)malloc( sizeof(char) * len + 1);
    WideCharToMultiByte( CP_ACP, 0, szFontName, -1, ptr, len, NULL, NULL );
    strncpy(ptr, LogFont.lfFaceName, cWC);
#endif
 
    szFontName[cWC] = 0;
    nFontNameLen = (cWC) * sizeof(WCHAR);
 
    if (m_wFontSize == 0) 
    {
        m_wFontSize = (unsigned short)LogFont.lfHeight;
    }
 
    //Prework for setting caption in dialog...
    //cWC = MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, NULL, 0);
    cWC = m_strCaption.GetLength()+1;
    int szBoxLen = cWC + 1;
    WCHAR *szBoxCaption = new WCHAR[szBoxLen];
 
    // Copy the string
    //MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, (LPWSTR) szBoxCaption, cWC);
 
#ifdef X
    _tcsncpy(szBoxCaption, m_strCaption, cWC);
#else
    len = WideCharToMultiByte( CP_ACP, 0, szBoxCaption, -1, NULL, 0, NULL, NULL );
    ptr = (char *)malloc( sizeof(char) * len + 1);
    WideCharToMultiByte( CP_ACP, 0, szBoxCaption, -1, ptr, len, NULL, NULL );
    strncpy(ptr, m_strCaption, cWC);
#endif
 
    szBoxCaption[cWC] = 0;
    szBoxLen = (cWC) * sizeof(WCHAR);
 
    INT_PTR iRet = -1;
    //Here 's the stuff to build the dialog template in memory
    //without the controls being in the template
    //(Our first try, was this same template with some additional code
    //for each control placed on it, that's why this class is cold Ex :)
    //This gave some problems on WIN9x systems, where EDIT boxes
    //were not shown with 3D-look, but as flat controls)
    int nBufferSize =  sizeof(DLGTEMPLATE) + (2 * sizeof(WORD)) /*menu and class*/ + szBoxLen /*size of caption*/
    + sizeof(WORD) /*fontsize*/ + nFontNameLen /*size of fontname*/;
 
    //Are there any subclassed controls...
    if (m_DialogTemplate.cdit > 0)
    {
        nBufferSize = (nBufferSize + 3) & ~3;  // adjust size to make first control DWORD aligned
 
        CDynDialogItemEx *pDynDialogItemEx = NULL;
        for (int i = 0; i < m_arrDlgItemPtr.GetSize(); i++)
        {
            pDynDialogItemEx = m_arrDlgItemPtr[i];
            if (pDynDialogItemEx != NULL)
            {
                if (pDynDialogItemEx->IsDlgItemSubclassed())
                {
                    int nItemLength = sizeof(DLGITEMTEMPLATE) + 3 * sizeof(WORD);
                    nItemLength += (pDynDialogItemEx->GetCaptionLength() + 1) * sizeof(WCHAR);
 
                    if (i != m_DialogTemplate.cdit - 1) 
                    {   // the last control does not need extra bytes
                        nItemLength = (nItemLength + 3) & ~3;  // take into account gap so next control is DWORD aligned
                    }
                    nBufferSize += nItemLength;
                }
            }
        }
    }
 
    HLOCAL hLocal = LocalAlloc(LHND, nBufferSize);
    if (hLocal != NULL)
    {
        BYTE*    pBuffer = (BYTE*)LocalLock(hLocal);
        if (pBuffer == NULL) 
        {
            LocalFree(hLocal);
            AfxMessageBox(_T("CDynDialogEx::DoModal() : LocalLock Failed"));
        }
 
        BYTE *pdest = pBuffer;
        // transfer DLGTEMPLATE structure to the buffer
        memcpy(pdest, &m_DialogTemplate, sizeof(DLGTEMPLATE));    // DLGTemplate
        pdest += sizeof(DLGTEMPLATE);
        *(WORD*)pdest = 0;                                    // no menu                         -- WORD to say it is 0 bytes
        pdest += sizeof(WORD);                                // Increment
        *(WORD*)(pdest + 1) = 0;                            // use default window class -- WORD to say it is 0 bytes
        pdest += sizeof(WORD);                                // Increment
        memcpy(pdest, szBoxCaption, szBoxLen);            // Caption
        pdest += szBoxLen;
 
        *(WORD*)pdest = m_wFontSize;                        // font size
        pdest += sizeof(WORD);
        memcpy(pdest, szFontName, nFontNameLen);        // font name
        pdest += nFontNameLen;
 
        // will now transfer the information for each one of subclassed controls...
        if (m_DialogTemplate.cdit > 0) 
        {
            CDynDialogItemEx *pDynDialogItemEx = NULL;
            for (int i = 0; i < m_arrDlgItemPtr.GetSize(); i++) 
            {
                pDynDialogItemEx = m_arrDlgItemPtr[i];
                if (pDynDialogItemEx != NULL)
                {
                    if (pDynDialogItemEx->IsDlgItemSubclassed()) 
                    {
                        pdest = pDynDialogItemEx->FillBufferWithItemTemplate(pdest);
                    }
                }
            }
        }
        ASSERT(pdest - pBuffer == nBufferSize); // just make sure we did not overrun the heap
 
        //Next lines to make sure that MFC makes no ASSERTION when PREVIOUS/NEXT is pressed:)
        if (m_lpDialogTemplate != NULL) 
        {
            m_lpDialogTemplate = NULL;
        }
 
        //These are the MFC functions, which do the job...
        if (m_bModelessDlg)
        {
            iRet = CreateIndirect((LPDLGTEMPLATE)pBuffer, m_pParentWnd);        
        }
        else 
        {
            InitModalIndirect((LPDLGTEMPLATE)pBuffer, m_pParentWnd);
            iRet = CDialog::DoModal();
        }
 
        LocalUnlock(hLocal);
        LocalFree(hLocal);
 
        delete [] szBoxCaption;
        delete [] szFontName;
        return iRet;
    }
    else
    {
        AfxMessageBox(_T("CDynDialogEx::DoModal() : LocalAllock Failed"));
        return -1;
    }
}
 
void CDynDialogEx::SetFont(CFont *pFont)
{
  m_pFont = pFont;
}
 
CFont *CDynDialogEx::GetFont()
{
  return m_pFont;
}
 
void CDynDialogEx::SetFontSize(WORD wSize)
{
  m_wFontSize = wSize;
}
 
WORD CDynDialogEx::GetFontSize()
{
  return m_wFontSize;
}
 
void CDynDialogEx::SetUseSystemButtons(BOOL bUse /*= TRUE*/)
{
  m_bAddSystemButtons = bUse;
}
 
void CDynDialogEx::GetDlgRect(LPRECT lpRect)
{
  ASSERT(lpRect);
  lpRect->left   = m_DialogTemplate.x;
  lpRect->top    = m_DialogTemplate.y;
  lpRect->right  = lpRect->left + m_DialogTemplate.cx;
  lpRect->bottom = lpRect->top + m_DialogTemplate.cy;
}
 
void CDynDialogEx::SetDlgRect(LPRECT lpRect)
{
  ASSERT(lpRect);
  //#pragma warning(disable : 4244)
  m_DialogTemplate.cx = (short)(lpRect->right  - lpRect->left);
  m_DialogTemplate.cy = (short)(lpRect->bottom - lpRect->top);
  m_DialogTemplate.x  = (short)(lpRect->left);
  m_DialogTemplate.y  = (short)(lpRect->top);
  //#pragma warning(default : 4244)
}
 
void CDynDialogEx::SetDlgRectangle(LPRECT pRect)
{
  RECT rect;
 
  GetDlgRect(&rect);
  if (rect.left > pRect->left) {
    rect.left = pRect->left;
  }
  if (rect.right < pRect->right) {
    rect.right = pRect->right + 5;
  }
  if (rect.top > pRect->top) {
    rect.top = pRect->top;
  }
  if (rect.bottom < pRect->bottom) {
    rect.bottom = pRect->bottom + 5;
  }
  SetDlgRect(&rect);
}
 
UINT CDynDialogEx::AddDlgControl(DLGITEMTEMPLATECONTROLS TypeControl,
                                 LPCTSTR lpszCaption,
                                 DWORD dwStyle,
                                 DWORD dwExtendedStyle,
                                 LPRECT pRect /*= NULL*/,
                                 void *pData /*= NULL*/,
                                 UINT nID /*= 0*/)
{
  UINT nRet = 0;
  //In case no rectangle given create our own...
  CRect Rect(FIXEDCOL1, m_nCurRow, FIXEDCOL2, m_nCurRow + ROWSTEPSIZE);
 
  //if no rectangle given use our own...
  if (pRect == NULL) {
    pRect = &Rect;
  }
  //    else {
  //        m_nCurRow = max(m_nCurRow, pRect->bottom) - m_nCurRow;
  //    }
 
  m_nCurRow += (ROWSTEPSIZE);
 
  //Update dialogtemplate boundaries
  SetDlgRectangle(pRect);
 
  //Create control and add to array of controls
  CDynDialogItemEx *pDynDialogItemEx = new CDynDialogItemEx;
  if (pDynDialogItemEx != NULL) {
    nRet = pDynDialogItemEx->InitDialogItem(TypeControl, dwStyle, dwExtendedStyle, pRect, lpszCaption, nID, FALSE, pData);
    m_arrDlgItemPtr.Add(pDynDialogItemEx);
  }
 
  //Return ID of Control we created.
  return nRet;
}
 
UINT CDynDialogEx::AddDlgControl(LPCSTR lpszClassName,
                                 LPCTSTR lpszCaption,
                                 DWORD dwStyle,
                                 DWORD dwExtendedStyle,
                                 LPRECT pRect /*= NULL*/,
                                 void *pData /*= NULL*/,
                                 UINT nID /*= 0*/)
{
  UINT nRet = 0;
  //In case no rectangle given create our own...
  CRect Rect(FIXEDCOL1, m_nCurRow, FIXEDCOL2, m_nCurRow + ROWSTEPSIZE);
 
  //if no rectangle given use our own...
  if (pRect == NULL) {
    pRect = &Rect;
    Rect.right += INPUTCOL;
  }
  //    else {
  //        m_nCurRow = max(m_nCurRow, pRect->bottom) - m_nCurRow;
  //    }
 
  m_nCurRow += (ROWSTEPSIZE);
 
  //Update dialogtemplate boundaries
  SetDlgRectangle(pRect);
 
  //Create control and add to array of controls
  CDynDialogItemEx *pDynDialogItemEx = new CDynDialogItemEx;
  if (pDynDialogItemEx != NULL) {
    nRet = pDynDialogItemEx->InitDialogItem(lpszClassName, dwStyle, dwExtendedStyle, pRect, lpszCaption, nID, FALSE, pData);
    m_arrDlgItemPtr.Add(pDynDialogItemEx);
  }
 
  //Return ID of Control we created.
  return nRet;
}
 
UINT CDynDialogEx::AddSubclassedDlgControl(LPCSTR lpszClassName,
                                           LPCTSTR lpszCaption,
                                           DWORD dwStyle,
                                           DWORD dwExtendedStyle,
                                           LPRECT pRect /*= NULL*/,
                                           UINT nID /*= 0*/)
{
  UINT nRet = 0;
  //In case no rectangle given create our own...
  CRect Rect(FIXEDCOL1, m_nCurRow, FIXEDCOL2, m_nCurRow + ROWSTEPSIZE);
 
  //if no rectangle given use our own...
  if (pRect == NULL) {
    pRect = &Rect;
    Rect.right += INPUTCOL;
  }
  //    else {
  //        m_nCurRow = max(m_nCurRow, pRect->bottom) - m_nCurRow;
  //    }
 
  m_nCurRow += (ROWSTEPSIZE);
 
  //Update dialogtemplate boundaries
  SetDlgRectangle(pRect);
 
  //Create control and add to array of controls
  CDynDialogItemEx *pDynDialogItemEx = new CDynDialogItemEx;
  if (pDynDialogItemEx != NULL) {
    nRet = pDynDialogItemEx->InitDialogItem(lpszClassName, dwStyle, dwExtendedStyle, pRect, lpszCaption, nID, TRUE);
    m_arrDlgItemPtr.Add(pDynDialogItemEx);
    m_DialogTemplate.cdit++;
  }
 
  //Return ID of Control we created.
  return nRet;
}
 
void CDynDialogEx::AddSystemButtons()
{
  m_nCurRow += 6;            // Leave some room!
  CRect rect(FIXEDCOL1, m_nCurRow, FIXEDCOL2 - 60, m_nCurRow + (long)(ROWSTEPSIZE * 1.2));
 
  AddDlgControl(BUTTON, _T("OK"), STYLE_BUTTON, EXSTYLE_BUTTON, &rect, NULL, IDOK);
 
  // This has to be revised later.
  rect.left  += 55;
  rect.right += 55;
  AddDlgControl(BUTTON, _T("Annuleren"), STYLE_BUTTON, EXSTYLE_BUTTON, &rect, NULL, IDCANCEL);
 
}
 
void CDynDialogEx::SetWindowTitle(LPCSTR lpszCaption)
{
  m_strCaption = lpszCaption;
}
 
void CDynDialogEx::SetUseModeless(BOOL bModelessDlg /*= TRUE*/)
{
  m_bModelessDlg = bModelessDlg;
}
 
void CDynDialogEx::OnCancel()
{
  if (m_bModelessDlg) {
    DestroyWindow();
  }
  else {
    CDialog::OnCancel();
  }
}
 
void CDynDialogEx::OnOK()
{
  if (m_bModelessDlg) {
    DestroyWindow();
  }
  else {
    CDialog::OnOK();
  }
}
 
BOOL CDynDialogEx::OnCommand(WPARAM wParam, LPARAM lParam) 
{
  //wParam
  //The low-order word of wParam identifies the command ID of the menu item, control, or accelerator.
  //The high-order word of wParam specifies the notification message if the message is from a control.
  //If the message is from an accelerator, the high-order word is 1.
  //If the message is from a menu, the high-order word is 0.
 
  //lParam
  //Identifies the control that sends the message if the message is from a control. Otherwise, lParam is 0.
 
  WORD wControlID = LOWORD(wParam);
  WORD wMessageID = HIWORD(wParam);
 
  if (wControlID != 0) {
    switch (wControlID) {
    case IDOK:
      OnOK();
      return TRUE;
      break;
    case IDCANCEL:
      OnCancel();
      return TRUE;
      break;
    default:
      //if we have a parent send the message to the parent, so we can handle the message over there.
      if (m_pParentWnd != NULL) {
        ::SendMessage(m_pParentWnd->GetSafeHwnd(), WM_COMMAND, wParam, lParam);
      }
      break;
    }
  }
 
  return CDialog::OnCommand(wParam, lParam);
}
 
// Hellup!
afx_msg LRESULT CDynDialogEx::OnHelpMsg(WPARAM wParam, LPARAM lParam)
{
  //lParam        <<-- Contains: (LPHELPINFO)lParam
  // >> typedef  struct  tagHELPINFO { 
  //     UINT     cbSize; 
  //     int      iContextType 
  //     int      iCtrlId; 
  //     HANDLE   hItemHandle; 
  //     DWORD    dwContextId; 
  //     POINT    MousePos; 
  // } HELPINFO, FAR *LPHELPINFO;
 
  //
  // User pressed F1 in dialog, call the OnHelp() function, this can be overridden...
  //
  OnHelp();
  return TRUE;
}
 
// Default implementation of the OnHelp()
// This one is to be overridden by a caller ;)
void CDynDialogEx::OnHelp()
{
  CDialog::OnHelp();
}