home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / chap13 / cosmo / cosmo.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  16KB  |  712 lines

  1. /*
  2.  * COSMO.CPP
  3.  * Cosmo Chapter 13
  4.  *
  5.  * WinMain and CCosmoFrame implementations.
  6.  *
  7.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Microsoft
  10.  * Internet  :  kraigb@microsoft.com
  11.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  12.  */
  13.  
  14.  
  15. #define INITGUIDS
  16. #include "cosmo.h"
  17.  
  18.  
  19. /*
  20.  * WinMain
  21.  *
  22.  * Purpose:
  23.  *  Main entry point of application.  Should register the app class
  24.  *  if a previous instance has not done so and do any other one-time
  25.  *  initializations.
  26.  */
  27.  
  28. int PASCAL WinMain (HINSTANCE hInst, HINSTANCE hPrev
  29.     , LPSTR pszCmdLine, int nCmdShow)
  30.     {
  31.     PCCosmoFrame    pFR;
  32.     FRAMEINIT       fi;
  33.     WPARAM          wRet;
  34.  
  35.     //Attempt to allocate and initialize the application
  36.     pFR=new CCosmoFrame(hInst, hPrev, pszCmdLine, nCmdShow);
  37.  
  38.     if (NULL==pFR)
  39.         return -1;
  40.  
  41.     fi.idsMin=IDS_FRAMEMIN;
  42.     fi.idsMax=IDS_FRAMEMAX;
  43.     fi.idsStatMin=IDS_STATMESSAGEMIN;
  44.     fi.idsStatMax=IDS_STATMESSAGEMAX;
  45.     fi.idStatMenuMin=ID_MENUFILE;
  46.     fi.idStatMenuMax=ID_MENUHELP;
  47.     fi.iPosWindowMenu=WINDOW_MENU;
  48.     fi.cMenus=CMENUS;
  49.  
  50.     fi.x=CW_USEDEFAULT;
  51.     fi.y=CW_USEDEFAULT;
  52.     fi.cx=440;
  53.     fi.cy=460;
  54.  
  55.     //If we can initialize pFR, start chugging messages
  56.     if (pFR->Init(&fi))
  57.         wRet=pFR->MessageLoop();
  58.  
  59.     delete pFR;
  60.     return wRet;
  61.     }
  62.  
  63.  
  64.  
  65.  
  66. /*
  67.  * CCosmoFrame::CCosmoFrame
  68.  * CCosmoFrame::~CCosmoFrame
  69.  *
  70.  * Constructor Parameters:
  71.  *  hInst           HINSTANCE from WinMain
  72.  *  hInstPrev       HINSTANCE from WinMain
  73.  *  pszCmdLine      LPSTR from WinMain
  74.  *  nCmdShow        int from WInMain
  75.  */
  76.  
  77. CCosmoFrame::CCosmoFrame(HINSTANCE hInst, HINSTANCE hInstPrev
  78.     , LPSTR pszCmdLine, int nCmdShow)
  79.     : CFrame(hInst, hInstPrev, pszCmdLine, nCmdShow)
  80.     {
  81.     UINT        i;
  82.  
  83.     for (i=0; i<5; i++)
  84.         m_hBmpLines[i]=NULL;
  85.  
  86.     m_uIDCurLine=0;
  87.     m_fInitialized=FALSE;
  88.     m_pIClassDataTran=NULL;
  89.     return;
  90.     }
  91.  
  92.  
  93. CCosmoFrame::~CCosmoFrame(void)
  94.     {
  95.     UINT        i;
  96.  
  97.     for (i=0; i<5; i++)
  98.         {
  99.         if (NULL!=m_hBmpLines[i])
  100.             DeleteObject(m_hBmpLines[i]);
  101.         }
  102.  
  103.     if (NULL!=m_pIClassDataTran)
  104.         {
  105.         m_pIClassDataTran->LockServer(FALSE);
  106.         m_pIClassDataTran->Release();
  107.         }
  108.  
  109.     OleFlushClipboard();
  110.  
  111.     if (m_fInitialized)
  112.         OleUninitialize();
  113.  
  114.     return;
  115.     }
  116.  
  117.  
  118.  
  119.  
  120. /*
  121.  * CCosmoFrame::Init
  122.  *
  123.  * Purpose:
  124.  *  Call CoInitialize then calling down into the base class
  125.  *  initialization.
  126.  *
  127.  * Parameters:
  128.  *  pFI             PFRAMEINIT containing initialization parameters.
  129.  *
  130.  * Return Value:
  131.  *  BOOL            TRUE if initialization succeeded, FALSE otherwise.
  132.  */
  133.  
  134. BOOL CCosmoFrame::Init(PFRAMEINIT pFI)
  135.     {
  136.     HRESULT     hr;
  137.  
  138.     CHECKVER_OLE;
  139.  
  140.     if (FAILED(OleInitialize(NULL)))
  141.         return FALSE;
  142.  
  143.     m_fInitialized=TRUE;
  144.  
  145.     /*
  146.      * Obtain the Data Transfer Object class factory and lock it.
  147.      * This will improve the speed of clipboard and (later)
  148.      * drag & drop operations that involve this class.
  149.      */
  150.     hr=CoGetClassObject(CLSID_DataTransferObject
  151.         , CLSCTX_INPROC_SERVER, NULL, IID_IClassFactory
  152.         , (PPVOID)&m_pIClassDataTran);
  153.  
  154.     if (SUCCEEDED(hr))
  155.         m_pIClassDataTran->LockServer(TRUE);
  156.  
  157.     return CFrame::Init(pFI);
  158.     }
  159.  
  160.  
  161.  
  162. /*
  163.  * CCosmoFrame::CreateCClient
  164.  *
  165.  * Purpose:
  166.  *  Constructs a new client specific to the application.
  167.  *
  168.  * Parameters:
  169.  *  None
  170.  *
  171.  * Return Value:
  172.  *  PCClient        Pointer to the new client object.
  173.  */
  174.  
  175. PCClient CCosmoFrame::CreateCClient(void)
  176.     {
  177.     return (PCClient)(new CCosmoClient(m_hInst, this));
  178.     }
  179.  
  180.  
  181.  
  182.  
  183.  
  184. /*
  185.  * CCosmoFrame::RegisterAllClasses
  186.  *
  187.  * Purpose:
  188.  *  Registers all classes used in this application.
  189.  *
  190.  * Parameters:
  191.  *  None
  192.  *
  193.  * Return Value:
  194.  *  BOOL            TRUE if registration succeeded, FALSE otherwise.
  195.  */
  196.  
  197. BOOL CCosmoFrame::RegisterAllClasses(void)
  198.     {
  199.     WNDCLASS        wc;
  200.  
  201.     //First let the standard frame do its thing
  202.     if (!CFrame::RegisterAllClasses())
  203.         return FALSE;
  204.  
  205.     /*
  206.      * We want a different background color for the document
  207.      * because the Polyline we put in the document will paint
  208.      * with COLOR_WINDOW which by default which is CLASSLIB's
  209.      * default document color.
  210.      */
  211.  
  212.     GetClassInfo(m_hInst, SZCLASSDOCUMENT, &wc);
  213.     UnregisterClass(SZCLASSDOCUMENT, m_hInst);
  214.  
  215.     wc.hbrBackground=(HBRUSH)(COLOR_APPWORKSPACE+1);
  216.  
  217.     if (!RegisterClass(&wc))
  218.         return FALSE;
  219.  
  220.     //Register the Polyline window.
  221.     wc.style         = CS_HREDRAW | CS_VREDRAW;
  222.     wc.hInstance     = m_hInst;
  223.     wc.cbClsExtra    = 0;
  224.     wc.lpfnWndProc   = PolylineWndProc;
  225.     wc.cbWndExtra    = CBPOLYLINEWNDEXTRA;
  226.     wc.hIcon         = NULL;
  227.     wc.hCursor       = LoadCursor(NULL, IDC_CROSS);
  228.     wc.hbrBackground = NULL;
  229.     wc.lpszMenuName  = NULL;
  230.     wc.lpszClassName = SZCLASSPOLYLINE;
  231.  
  232.     if (!RegisterClass(&wc))
  233.         return FALSE;
  234.  
  235.     return TRUE;
  236.     }
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243. /*
  244.  * CCosmoFrame::PreShowInit
  245.  *
  246.  * Purpose:
  247.  *  Called from Init before intially showing the window.  We do
  248.  *  whatever else we want here, modifying nCmdShow as necessary
  249.  *  which affects ShowWindow in Init.
  250.  *
  251.  * Parameters:
  252.  *  None
  253.  *
  254.  * Return Value:
  255.  *  BOOL            TRUE if this initialization succeeded,
  256.  *                  FALSE otherwise.
  257.  */
  258.  
  259. BOOL CCosmoFrame::PreShowInit(void)
  260.     {
  261.     CreateLineMenu();
  262.     CheckLineSelection(IDM_LINESOLID);
  263.     return TRUE;
  264.     }
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271. /*
  272.  * CCosmoFrame::CreateLineMenu
  273.  *
  274.  * Purpose:
  275.  *  Initializes the bitmaps used to create the Line menu and
  276.  *  replaces the text items defined in the application resources
  277.  *  with these bitmaps.  Note that the contents of m_hBmpLines
  278.  *  must be cleaned up when the application terminates.
  279.  *
  280.  * Parameters:
  281.  *  None
  282.  *
  283.  * Return Value:
  284.  *  None
  285.  */
  286.  
  287. void CCosmoFrame::CreateLineMenu(void)
  288.     {
  289.     HMENU       hMenu;
  290.     HDC         hDC, hMemDC;
  291.     HPEN        hPen;
  292.     HGDIOBJ     hObj;
  293.     TEXTMETRIC  tm;
  294.     UINT        i, cx, cy;
  295.  
  296.  
  297.     hMenu=GetSubMenu(GetMenu(m_hWnd), 3);   //Line menu.
  298.     hDC=GetDC(m_hWnd);
  299.  
  300.     //Create each line in a menu item 8 chars wide, one char high.
  301.     GetTextMetrics(hDC, &tm);
  302.     cx=tm.tmAveCharWidth*8;
  303.     cy=tm.tmHeight;
  304.  
  305.     /*
  306.      * Create a memory DC in which to draw lines, and bitmaps
  307.      * for each line.
  308.      */
  309.     hMemDC=CreateCompatibleDC(hDC);
  310.     ReleaseDC(m_hWnd, hDC);
  311.  
  312.     for (i=0; i<5; i++)
  313.         {
  314.         m_hBmpLines[i]=CreateCompatibleBitmap(hMemDC, cx, cy);
  315.         SelectObject(hMemDC, m_hBmpLines[i]);
  316.  
  317.         PatBlt(hMemDC, 0, 0, cx, cy, WHITENESS);
  318.  
  319.         hPen=CreatePen(i, 1, 0L);       //i=line style like PS_SOLID
  320.         hObj=SelectObject(hMemDC, hPen);
  321.  
  322.         MoveToEx(hMemDC, 0, cy/2, NULL);
  323.         LineTo(hMemDC, cx, cy/2);
  324.  
  325.         ModifyMenu(hMenu, IDM_LINEMIN+i, MF_BYCOMMAND | MF_BITMAP
  326.             , IDM_LINEMIN+i, (LPTSTR)(LONG)(UINT)m_hBmpLines[i]);
  327.  
  328.         SelectObject(hMemDC, hObj);
  329.         DeleteObject(hPen);
  330.         }
  331.  
  332.     CheckMenuItem(hMenu, IDM_LINESOLID, MF_CHECKED);
  333.     DeleteDC(hMemDC);
  334.  
  335.     return;
  336.     }
  337.  
  338.  
  339.  
  340.  
  341. /*
  342.  * CCosmoFrame::CreateToolbar
  343.  *
  344.  * Purpose:
  345.  *  Procedure to create all the necessary toolbar buttons.
  346.  *
  347.  * Parameters:
  348.  *  None
  349.  *
  350.  * Return Value:
  351.  *  UINT            Number of tools added to the bar.
  352.  */
  353.  
  354. UINT CCosmoFrame::CreateToolbar(void)
  355.     {
  356.     UINT            iLast;
  357.     UINT            uState=GIZMO_NORMAL;
  358.     UINT            utCmd =GIZMOTYPE_BUTTONCOMMAND;
  359.     UINT            utEx  =GIZMOTYPE_BUTTONATTRIBUTEEX;
  360.  
  361.     //Insert the standard ones.
  362.     iLast=CFrame::CreateToolbar();
  363.  
  364.     /*
  365.      * Insert File Import in the 5th position and account for
  366.      * it in iLast.
  367.      */
  368.     m_pTB->Add(utCmd, 4, IDM_FILEIMPORT, m_dxB, m_dyB
  369.         , NULL, m_hBmp, 2, uState);
  370.     iLast++;
  371.  
  372.     //Separator
  373.     m_pTB->Add(GIZMOTYPE_SEPARATOR, iLast++, 0, 6, m_dyB
  374.         , NULL, NULL, 0, uState);
  375.  
  376.     /*
  377.      * For the Background bitmap, preserve our use of black
  378.      * (part of the image)
  379.      */
  380.     m_pTB->Add(utCmd, iLast++, IDM_COLORBACKGROUND, m_dxB, m_dyB
  381.         , NULL, m_hBmp, 3, GIZMO_NORMAL | PRESERVE_BLACK);
  382.  
  383.     m_pTB->Add(utCmd, iLast++, IDM_COLORLINE, m_dxB, m_dyB
  384.         , NULL, m_hBmp, 4, uState);
  385.  
  386.     //Separator
  387.     m_pTB->Add(GIZMOTYPE_SEPARATOR, iLast++, 0, 6, m_dyB
  388.         , NULL, NULL, 0, uState);
  389.  
  390.     //Line styles.
  391.     m_pTB->Add(utEx, iLast++, IDM_LINESOLID, m_dxB, m_dyB
  392.         , NULL, m_hBmp, 5, uState);
  393.     m_pTB->Add(utEx, iLast++, IDM_LINEDASH, m_dxB, m_dyB
  394.         , NULL, m_hBmp, 6, uState);
  395.     m_pTB->Add(utEx, iLast++, IDM_LINEDOT, m_dxB, m_dyB
  396.         , NULL, m_hBmp, 7, uState);
  397.     m_pTB->Add(utEx, iLast++, IDM_LINEDASHDOT, m_dxB, m_dyB
  398.         , NULL, m_hBmp, 8, uState);
  399.     m_pTB->Add(utEx, iLast++, IDM_LINEDASHDOTDOT, m_dxB, m_dyB
  400.         , NULL, m_hBmp, 9, uState);
  401.  
  402.     return iLast;
  403.     }
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412. /*
  413.  * CCosmoFrame::OnCommand
  414.  *
  415.  * Purpose:
  416.  *  WM_COMMAND handler for the Cosmo frame window that just
  417.  *  processes the line menu and the color menu leaving the
  418.  *  CFrame to do everything else.
  419.  *
  420.  * Parameters:
  421.  *  hWnd            HWND of the frame window.
  422.  *  wParam          WPARAM of the message.
  423.  *  lParam          LPARAM of the message.
  424.  *
  425.  * Return Value:
  426.  *  LRESULT         Return value for the message.
  427.  */
  428.  
  429. LRESULT CCosmoFrame::OnCommand(HWND hWnd, WPARAM wParam
  430.     , LPARAM lParam)
  431.     {
  432.     PCCosmoDoc      pDoc;
  433.     TCHAR           szFile[CCHPATHMAX];
  434.     BOOL            fOK;
  435.     UINT            i, uTemp;
  436.     COLORREF        rgColors[16];
  437.     CHOOSECOLOR     cc;
  438.  
  439.     COMMANDPARAMS(wID, wCode, hWndMsg);
  440.  
  441.     /*
  442.      * Don't bother with anything during first initialization,
  443.      * skipping many toolbar notifications.
  444.      */
  445.     if (m_fInit)
  446.         return 0L;
  447.  
  448.     pDoc=(PCCosmoDoc)m_pCL->ActiveDocument();
  449.  
  450.     /*
  451.      * Check for the line style commands which are
  452.      * IDM_LINEMIN+<style>.  We handle this by changing the menu
  453.      * and toolbar, then we pass it to the document for real
  454.      * processing.
  455.      */
  456.     if (NULL!=pDoc && IDM_LINEMIN <= wID && IDM_LINEMAX >=wID)
  457.         {
  458.         CheckLineSelection(wID);
  459.         pDoc->LineStyleSet(wID-IDM_LINEMIN);
  460.         return 0L;
  461.         }
  462.  
  463.     switch (wID)
  464.         {
  465.         case IDM_FILEIMPORT:
  466.             szFile[0]=0;
  467.             fOK=SaveOpenDialog(szFile, CCHPATHMAX, IDS_FILEIMPORT
  468.                 , TRUE, &i);
  469.  
  470.             if (fOK)
  471.                 {
  472.                 uTemp=pDoc->Load(FALSE, szFile);
  473.                 pDoc->ErrorMessage(uTemp);
  474.                 }
  475.  
  476.             return (LRESULT)fOK;
  477.  
  478.  
  479.         case IDM_COLORBACKGROUND:
  480.         case IDM_COLORLINE:
  481.             //Invoke the color chooser for either color
  482.             uTemp=(IDM_COLORBACKGROUND==wID)
  483.                 ? DOCCOLOR_BACKGROUND : DOCCOLOR_LINE;
  484.  
  485.             for (i=0; i<16; i++)
  486.                 rgColors[i]=RGB(0, 0, i*16);
  487.  
  488.             memset(&cc, 0, sizeof(CHOOSECOLOR));
  489.             cc.lStructSize=sizeof(CHOOSECOLOR);
  490.             cc.lpCustColors=rgColors;
  491.             cc.hwndOwner=hWnd;
  492.             cc.Flags=CC_RGBINIT;
  493.             cc.rgbResult=pDoc->ColorGet(uTemp);
  494.  
  495.             if (ChooseColor(&cc))
  496.                 pDoc->ColorSet(uTemp, cc.rgbResult);
  497.  
  498.             break;
  499.  
  500.  
  501.         default:
  502.            CFrame::OnCommand(hWnd, wParam, lParam);
  503.         }
  504.  
  505.     return 0L;
  506.     }
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513. /*
  514.  * CCosmoFrame::OnDocumentDataChange
  515.  *
  516.  * Purpose:
  517.  *  Update the Line menu and toolbar if the style in the data
  518.  *  changes.
  519.  *
  520.  * Parameters:
  521.  *  pDoc            PCDocument notifying the sink.
  522.  *
  523.  * Return Value:
  524.  *  None
  525.  */
  526.  
  527. void CCosmoFrame::OnDocumentDataChange(PCDocument pDoc)
  528.     {
  529.     CheckLineSelection(IDM_LINEMIN
  530.         +((PCCosmoDoc)pDoc)->LineStyleGet());
  531.     return;
  532.     }
  533.  
  534.  
  535.  
  536.  
  537. /*
  538.  * CCosmoFrame::OnDocumentActivate
  539.  *
  540.  * Purpose:
  541.  *  Informs us that document activation changed, so update the UI
  542.  *  for that new document.
  543.  *
  544.  * Parameters:
  545.  *  pDoc            PCDocument notifying the sink.
  546.  *
  547.  * Return Value:
  548.  *  None
  549.  */
  550.  
  551. void CCosmoFrame::OnDocumentActivate(PCDocument pDoc)
  552.     {
  553.     CheckLineSelection(IDM_LINEMIN
  554.         +((PCCosmoDoc)pDoc)->LineStyleGet());
  555.     return;
  556.     }
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564. /*
  565.  * CCosmoFrame::UpdateMenus
  566.  *
  567.  * Purpose:
  568.  *  Handles the WM_INITMENU message for the frame window.  Depending
  569.  *  on the existence of an active window, menu items are selectively
  570.  *  enabled and disabled.
  571.  *
  572.  * Parameters:
  573.  *  hMenu           HMENU of the menu to intialize
  574.  *  iMenu           UINT position of the menu.
  575.  *
  576.  * Return Value:
  577.  *  None
  578.  */
  579.  
  580. void CCosmoFrame::UpdateMenus(HMENU hMenu, UINT iMenu)
  581.     {
  582.     PCDocument  pDoc;
  583.     BOOL        fOK=FALSE;
  584.     BOOL        fCallDefault=TRUE;
  585.     UINT        i;
  586.     UINT        uTemp;
  587.     UINT        uTempE;
  588.     UINT        uTempD;
  589.  
  590.     pDoc=m_pCL->ActiveDocument();
  591.  
  592.     uTempE=MF_ENABLED | MF_BYCOMMAND;
  593.     uTempD=MF_DISABLED | MF_GRAYED | MF_BYCOMMAND;
  594.     uTemp=((NULL!=pDoc) ? uTempE : uTempD);
  595.  
  596.     //File menu:  If there is document window, disable Import.
  597.     if (m_phMenu[0]==hMenu)
  598.         EnableMenuItem(hMenu, IDM_FILEIMPORT, uTemp);
  599.  
  600.     //Color menu:  no document, no commands
  601.     if (m_phMenu[2]==hMenu)
  602.         {
  603.         EnableMenuItem(hMenu, IDM_COLORBACKGROUND, uTemp);
  604.         EnableMenuItem(hMenu, IDM_COLORLINE,       uTemp);
  605.         fCallDefault=FALSE;
  606.         }
  607.  
  608.     //Line menu:  no document, no commands
  609.     if (m_phMenu[3]==hMenu)
  610.         {
  611.         for (i=IDM_LINEMIN; i<=IDM_LINEMAX; i++)
  612.             EnableMenuItem(hMenu, i, uTemp);
  613.  
  614.         fCallDefault=FALSE;
  615.         }
  616.  
  617.     if (fCallDefault)
  618.         CFrame::UpdateMenus(hMenu, iMenu);
  619.  
  620.     return;
  621.     }
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628. /*
  629.  * CCosmoFrame::UpdateToolbar
  630.  *
  631.  * Purpose:
  632.  *  Enables and disables tools depending on whether we have
  633.  *  a document or not.
  634.  *
  635.  * Parameters:
  636.  *  None
  637.  *
  638.  * Return Value:
  639.  *  None
  640.  */
  641.  
  642. void CCosmoFrame::UpdateToolbar(void)
  643.     {
  644.     BOOL        fLast;
  645.     UINT        i;
  646.  
  647.     //Save the last enabled state before CFrame changes it
  648.     fLast=m_fLastEnable;
  649.  
  650.     //Let the default hack on its tools
  651.     CFrame::UpdateToolbar();
  652.  
  653.     /*
  654.      * If CFrame::UpdateToolbar changed anything, then we need
  655.      * to change as well--if nothing changes, nothing to do.
  656.      */
  657.     if (fLast!=m_fLastEnable)
  658.         {
  659.         m_pTB->Enable(IDM_FILEIMPORT, m_fLastEnable);
  660.  
  661.         m_pTB->Enable(IDM_COLORBACKGROUND, m_fLastEnable);
  662.         m_pTB->Enable(IDM_COLORLINE,       m_fLastEnable);
  663.  
  664.         for (i=IDM_LINEMIN; i <= IDM_LINEMAX; i++)
  665.             m_pTB->Enable(i, m_fLastEnable);
  666.         }
  667.  
  668.     return;
  669.     }
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676. /*
  677.  * CCosmoFrame::CheckLineSelection
  678.  *
  679.  * Purpose:
  680.  *  Maintains the bitmap menu and the tools for the line selection.
  681.  *  Both are mutially exclusive option lists where a selection in
  682.  *  one has to affect the other.
  683.  *
  684.  * Parameters:
  685.  *  uID             UINT ID of the item to be selected
  686.  *
  687.  * Return Value:
  688.  *  None
  689.  */
  690.  
  691. void CCosmoFrame::CheckLineSelection(UINT uID)
  692.     {
  693.     UINT        i;
  694.     HMENU       hMenu;
  695.  
  696.     //Update menus and tools if the selection changed.
  697.     if (uID!=m_uIDCurLine)
  698.         {
  699.         m_uIDCurLine=uID;
  700.         hMenu=GetMenu(m_hWnd);
  701.  
  702.         //Uncheck all lines initially.
  703.         for (i=IDM_LINEMIN; i<=IDM_LINEMAX; i++)
  704.             CheckMenuItem(hMenu, i, MF_UNCHECKED | MF_BYCOMMAND);
  705.  
  706.         CheckMenuItem(hMenu, uID, MF_CHECKED | MF_BYCOMMAND);
  707.         m_pTB->Check(uID, TRUE);
  708.         }
  709.  
  710.     return;
  711.     }
  712.