Research Article

Development of the Object-Oriented Dynamic Simulation Models Using Visual C++ Freeware

Algorithm 10

Modeless dialog box: function ModelessDialogProc (part 1).
1.10  int  CALLBACK ModelessDlgProc(HWND hwnd, UINT message,
  2.10                 WPARAM wParam, LPARAM lParam)
  3.10static  HDC hDC;
  4.10PAINTSTRUCT ps;
  5.10static  HBRUSH g_hbrBackground;
  6.10static int  xChar, xCaps, yChar, xClient, yClient, xClientMax;
  7.10static int  xPos = 1, xMin = 1, xMax = 500, yPos, yMax;
  8.10int  x, y, iPaintBeg, iPaintEnd, yInc, temp, xPosOld;
  9.10static const int  NUMLINES = 2000;
10.10TEXTMETRIC tm;
11.10static char  buf1000;
12.10static  HFONT font;
13.10static  LOGFONT lf;
14.10strcpy_s(lf.lfFaceName, "MS Sans Serif");
15.10lf.lfHeight = 14;
16.10lf.lfWeight = FW_SEMIBOLD;
17.10switch(message)
18.10   case  WM_INITDIALOG:
19.10    hModelessDlg = hwnd;
20.10    g_hbrBackground = CreateSolidBrush(RGB(255, 255, 255));
21.10    hDC = GetDC(hwnd);
22.10    GetTextMetrics(hDC, &tm);
23.10    xChar = tm.tmAveCharWidth;
24.10    xCaps =(tm.tmPitchAndFamily & 1 ? 3: 2) * xChar/2;
25.10    yChar = tm.tmHeight + tm.tmExternalLeading;
26.10    ReleaseDC(hwnd, hDC);
27.10    break;
28.10   case  WM_CLOSE:
29.10    DestroyWindow(hwnd);
30.10    hModelessDlg = 0;
31.10    break;
32.10   case  WM_CTLCOLORDLG:
33.10    return  (LONG)g_hbrBackground;
34.10   case  WM_SIZE:
35.10    yClient = HIWORD(lParam); //retrieving the dimensions of
36.10    xClient = LOWORD (lParam); // the client area
37.10    yMax = max(0, NUMLINES + 2 - yClient/yChar);
38.10    yPos = min(yPos, yMax);
39.10    SetScrollRange(hwnd, SB_VERT, 0, NUMLINES, FALSE);
40.10    SetScrollPos (hwnd, SB_VERT, yPos, TRUE);
41.10    xPos= min(xPos, xMax);
42.10    SetScrollRange(hwnd, SB_HORZ, xMin, xMax, TRUE);
43.10    SetScrollPos(hwnd, SB_HORZ, xPos, TRUE);
44.10    break;