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 / chap12 / cosmo / cosmo.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  16KB  |  723 lines

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