home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 February / Chip_2001-02_cd1.bin / sharewar / vecad / source / ExtApp.cpp < prev    next >
C/C++ Source or Header  |  2000-06-23  |  4KB  |  144 lines

  1. /********************************************************************
  2. * Project: VeCAD ver.5.1
  3. * Copyright (C) 1999-2000 by Oleg Kolbaskin.
  4. * All rights reserved.
  5. *
  6. * External Applications
  7. ********************************************************************/
  8. #include <windows.h>
  9. #include <tchar.h>
  10. #include "extapp.h"
  11. #include "vecres.h"
  12.  
  13. extern HWND  ghwMain;    // Main App window
  14.  
  15. // defined in mru.cpp
  16. bool ModifyMenuItem (HMENU hMenu, UINT Cmd, LPCTSTR Text);
  17.  
  18.  
  19. //*******************************************************************
  20. CExtApp::CExtApp ()
  21. {
  22.   ::ZeroMemory( szTitle, sizeof(szTitle) );
  23.   ::ZeroMemory( szFileName, sizeof(szFileName) );
  24. }
  25.  
  26. //-------------------------------------
  27. void CExtApp::SetTitle (LPCTSTR szStr)
  28. {
  29.   _tcsncpy( szTitle, szStr, SZ_EXTAPPTITLE );
  30.   szTitle[SZ_EXTAPPTITLE-1] = 0;
  31. }
  32.  
  33. //-------------------------------------
  34. void CExtApp::SetFileName (LPCTSTR szStr)
  35. {
  36.   _tcsncpy( szFileName, szStr, 255 );
  37.   szFileName[255] = 0;
  38.   _tcslwr( szFileName );
  39. }
  40.  
  41.  
  42.  
  43. //*******************************************************************
  44. CAppList::CAppList ()
  45. {
  46.   n_app = 0;
  47. }
  48.  
  49. //-----------------------------------------------
  50. LPCTSTR CAppList::GetFileName (int Index)
  51. {
  52.   static TCHAR szBuf[256];
  53.   ::ZeroMemory( szBuf, sizeof(szBuf) );
  54.   if (0<=Index && Index<n_app){
  55.     _tcscpy( szBuf, App[Index].GetFileName() );
  56.     return szBuf;
  57.   }
  58.   return NULL;
  59. }
  60.  
  61.  
  62. //-------------------------------------
  63. bool CAppList::Load (CConfig& Cfg)
  64. {
  65.   TCHAR  szKey[64], szVal[300];
  66.   TCHAR  szTitle[SZ_EXTAPPTITLE];  // title for menu
  67.   TCHAR  szFileName[256];         // exe file name
  68.   int i,j,k,len,mode=0;
  69.     
  70.   n_app = 0;
  71.   for (i=0; i<MAX_EXTAPP; i++){
  72.     _stprintf( szKey, _T("EXTAPP%02d"), i );
  73.     if (Cfg.GetValue( szKey, szVal )){
  74.       ::ZeroMemory( szTitle, sizeof(szTitle) );
  75.       ::ZeroMemory( szFileName, sizeof(szFileName) );
  76.       len = _tcslen( szVal );
  77.       k = 0;
  78.       mode = 0;
  79.       for (j=0; j<len; j++){
  80.         if (szVal[j]=='['){
  81.           mode = 1;
  82.           k = 0;
  83.           continue;
  84.         }
  85.         if (szVal[j]==']'){
  86.           mode = 2;
  87.           j++;
  88.           k = 0;
  89.           continue;
  90.         }
  91.         switch( mode ){
  92.           case 1: szTitle[k++]=szVal[j]; break;
  93.           case 2: szFileName[k++]=szVal[j]; break;
  94.         }
  95.       }
  96.       for (j=0; j<n_app; j++){
  97.         if (_tcsicmp( szTitle, App[j].GetTitle())==0 &&
  98.             _tcsicmp( szFileName, App[j].GetFileName())==0)
  99.         {
  100.           j = 1000;  // filename already exist
  101.           break;
  102.         }
  103.       }
  104.       if (j!=1000){
  105.         if (n_app<MAX_EXTAPP){
  106.           App[n_app].SetTitle( szTitle );
  107.           App[n_app].SetFileName( szFileName );
  108.           n_app++;
  109.         }
  110.       }
  111.     }
  112.   }
  113.   UpdateMenu();
  114.   return true;
  115. }
  116.  
  117.  
  118. //-------------------------------------
  119. bool CAppList::UpdateMenu ()
  120. {
  121.   if (n_app>0){
  122.     HMENU hMainMenu = ::GetMenu( ghwMain );
  123.     HMENU hMnu = ::GetSubMenu( hMainMenu, 5 );  // 5 - index of "Tools" item in main menu
  124.     if (hMnu){
  125.       int i;
  126.       ::InsertMenu( hMnu, -1, MF_BYPOSITION, 0, 0 );
  127.       for (i=0; i<n_app; i++){
  128.         ::InsertMenu( hMnu, -1, MF_BYPOSITION, CM_APP_01+i, _T("!") );
  129.       }
  130.       for (i=0; i<n_app; i++){
  131.         ::ModifyMenuItem( hMainMenu, CM_APP_01+i, App[i].GetTitle() );
  132.       }
  133.     }
  134.     // update changes of main menu
  135.     ::DrawMenuBar( ghwMain );
  136.   }
  137.   return true;
  138. }
  139.  
  140. /*
  141. EXTAPP00=[Run program] notepad.exe
  142. EXTAPP01=[Old VeCAD] d:\!oks\v5\v5.exe
  143. */
  144.