Ejemplo n.º 1
0
BOOL EnumHighlights(TCHAR *szBookPath, ENUMBOOKMARK_CALLBACK callback, PVOID param)
{
	HCONFIG hConfig, hFileData, hBookmarks, bookmark;
	int i;

	if((hConfig = OpenConfig(szBookPath)) == 0)
	{
		return FALSE;
	}

	hFileData = OpenConfigSection(hConfig, TEXT("hexFileData"));

	hBookmarks = OpenConfigSection(hFileData, TEXT("bookmarks"));

	for(i = 0; bookmark = EnumConfigSection(hBookmarks, TEXT("bookmark"), i); i++)
	{
		TCHAR name[100], desc[100];
		BOOKMARK bm = { 0, 0, 0, 0, 0, name, 100, desc, 100 };

		GetConfigBookmark(bookmark, &bm);

		callback(&bm, param);	
	}

	return TRUE;
}
Ejemplo n.º 2
0
BOOL UpdateHighlightsFromConfig(HGRIDITEM hRoot, HWND hwndGridView, TCHAR *szBookPath, COLORREF col)
{
	HCONFIG hConf, hBookmarks;
	HBOOKMARK bookmark;
	size_t i;
	TCHAR szFilePath[MAX_PATH];
	GVITEM gvitem = { 0 };

	hConf = OpenConfig(szBookPath);

	if(hConf)
	{
		if(GetConfigStr(hConf, TEXT("hexFileData\\filePath"), szFilePath, MAX_PATH, 0))
		{
			hBookmarks = OpenConfigSection(hConf, TEXT("hexFileData\\bookmarks"));

			for(i = 0; bookmark = EnumConfigSection(hBookmarks, TEXT("bookmark"), (int)i); i++)
			{
				TCHAR name[100], desc[100];
				BOOKMARK bm = { 0, 0, 0, 0, 0, name, 100, desc, 100 };

				// do we need to add a root item?
				if(hRoot == 0)
				{
					GVITEM gvitem = { GVIF_TEXT };
					gvitem.pszText = szFilePath;
					hRoot = GridView_FindChild(hwndGridView, GVI_ROOT, &gvitem);

					if (!hRoot)
						hRoot = CreateBookmarkFileRoot(GVI_ROOT, szFilePath, hwndGridView, FALSE);

					gvitem.mask  = GVIF_PARAM|GVIF_FONT;
					gvitem.iFont = 0; // regular
					gvitem.param = 0;
					GridView_SetItem(hwndGridView, hRoot, &gvitem);
					GridView_DeleteChildren(hwndGridView, hRoot);	
			
					MkRootGVITEM(&gvitem, szFilePath, FALSE, 0);	
					GridView_SetItem(hwndGridView, hRoot, &gvitem);
				}

				GetConfigBookmark(bookmark, &bm);

				FillGridView2(hwndGridView, hRoot, NULL, &bm, col);
						//callback(&bm, param);	
			}

		}

		CloseConfig(hConf);
	}

	return TRUE;
}
Ejemplo n.º 3
0
__hdle OpenConfigFile(const char *filepath)
{
    HCONFIG hConfig;
    
    if (NULL == filepath)
    {
        return NULL;
    }
    hConfig = OpenConfig((char *)filepath, NULL);
    
    return (__hdle)hConfig;
}
Ejemplo n.º 4
0
BOOL UpdateHighlights2(HWND hwndHexView, HWND hwndGridView)
{

	HGRIDITEM hGridItem;
	hGridItem = GVI_ROOT;//GridView_InsertChild(hwndGridView, GVI_ROOT, &gvitem);

	SendMessage(hwndGridView, WM_SETREDRAW, FALSE, 0);
	GridView_DeleteAll(hwndGridView);

	if(hwndHexView == 0)
	{
		// just add bookmarks for specified hexview
		FillHexViewHighlights(GVI_ROOT, hwndHexView, hwndGridView, 0);
	}
	else if(hwndHexView != (HWND)-1)
	{
		int i;

		// add bookmarks for all open files
		for(i = 0; (hwndHexView = EnumHexView(g_hwndMain, i)) != 0; i++)
		{
			AddHexViewHighlights(GVI_ROOT, hwndHexView, hwndGridView, 0);
		}
	}
	else 
	{
		WIN32_FIND_DATA win32fd;
		HANDLE hFind;
		TCHAR szBookPath[MAX_PATH];
		TCHAR szFilePath[MAX_PATH];
		HCONFIG hConf ;

		GetProgramDataPath(szBookPath, MAX_PATH);
		lstrcat(szBookPath, TEXT("\\Bookmarks\\*"));

		// enumerate all files in the bookmarks directory
		if((hFind = FindFirstFile(szBookPath, &win32fd)) != 0)
		{
			do 
			{
				if((win32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
				{
					HWND hwndHV; 
					int i;
					HCONFIG hBookmarks, bookmark;
					HGRIDITEM hItem;

					GetProgramDataPath(szBookPath, MAX_PATH);
					wsprintf(szFilePath, TEXT("%s\\Bookmarks\\%s"), szBookPath, win32fd.cFileName);				

					hConf = OpenConfig(szFilePath);
					GetConfigStr(hConf, TEXT("hexFileData\\filePath"), szFilePath, MAX_PATH, 0);

					if((hwndHV = HexIsOpen(g_hwndMain, szFilePath, 0)) != 0)
					{
						AddHexViewHighlights(GVI_ROOT, hwndHV, hwndGridView, 0);
					}
					else
					{
						hItem = CreateBookmarkFileRoot(GVI_ROOT, szFilePath, hwndGridView, FALSE);
					//EnumHighlights(szBookPath, addgv, hwndGridView);

						hBookmarks = OpenConfigSection(hConf, TEXT("hexFileData\\bookmarks"));

						for(i = 0; bookmark = EnumConfigSection(hBookmarks, TEXT("bookmark"), i); i++)
						{
							TCHAR name[100], desc[100];
							BOOKMARK bm = { 0, 0, 0, 0, 0, name, 100, desc, 100 };

							GetConfigBookmark(bookmark, &bm);

							FillGridView2(hwndGridView, hItem, NULL, &bm, 0);
						//callback(&bm, param);	
						}
					}

					CloseConfig(hConf);
				}

			} while(FindNextFile(hFind, &win32fd));

			FindClose(hFind);
		}


	}

/*	for(hbm = 0; (hbm = HexView_EnumBookmark(hwndHexView, hbm, &bm)) != 0; )
	{
		TCHAR szOffset[32];
		TCHAR szTitle[32];

		_stprintf(szTitle, TEXT("%s"), bm.pszTitle);
		_stprintf(szOffset, TEXT("%08I64X  (%d bytes)"), bm.offset, bm.length);

		FillGridView2(hwndGridView, hGridItem, hbm, szTitle, szOffset, bm.pszText);
	}*/

	SendMessage(hwndGridView, WM_SETREDRAW, TRUE, 0);
	GridView_Update(hwndGridView);

	//ForceClientResize(hwndGridView);
	//InvalidateRect(hwndGridView, 0, 0);

	return TRUE;
}
Ejemplo n.º 5
0
void DeleteBookmarkFromConfig(LPCTSTR szFilename, LPCTSTR szBookmarkName)
{
	WIN32_FIND_DATA win32fd;
	HANDLE hFind;
	TCHAR szBookPath[MAX_PATH];
	TCHAR szFilePath[MAX_PATH];
	TCHAR szRefFilePath[MAX_PATH] = { 0 };

	GetProgramDataPath(szBookPath, MAX_PATH);
	lstrcat(szBookPath, TEXT("\\Bookmarks\\*"));

	// enumerate all files in the bookmarks directory
	if ((hFind = FindFirstFile(szBookPath, &win32fd)) != 0)
	{
		do
		{
			if ((win32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
			{
				GetProgramDataPath(szBookPath, MAX_PATH);
				wsprintf(szFilePath, TEXT("%s\\Bookmarks\\%s"), szBookPath, win32fd.cFileName);

				HCONFIG configFile = OpenConfig(szFilePath);
				if (configFile)
				{
					if (GetConfigStr(configFile, TEXT("hexFileData\\filePath"), szRefFilePath, MAX_PATH, 0) && _tcscmp(szRefFilePath, szFilename) == 0)
					{
						HCONFIG bookmarksSection = OpenConfigSection(configFile, TEXT("hexFileData\\bookmarks"));
						DWORD idx = 0;
						HCONFIG bookmark = 0;
						DWORD countedBookmarks = 0;
						while (bookmark = EnumConfigSection(bookmarksSection, TEXT("bookmark"), idx++))
						{
							TCHAR title[100];
							BOOKMARK bm = { 0 };
							bm.pszTitle = title;
							bm.nMaxTitle = ARRAYSIZE(title);

							if (GetConfigBookmark(bookmark, &bm) && _tcscmp(title, szBookmarkName) == 0)
							{
								DeleteConfigSection(bookmark);
							}
							else
							{
								countedBookmarks++;
							}
						}

						SaveConfig(szFilePath, configFile);
						CloseConfig(configFile);
						if (countedBookmarks == 0)
						{
							DeleteFile(szFilePath);
						}
						break;
					}
					CloseConfig(configFile);
				}
			}

		} while (FindNextFile(hFind, &win32fd));

		FindClose(hFind);
	}
}
Ejemplo n.º 6
0
void main( int argc, char *argv[] ) {
  cout << " Confy V" << Confy_Version << "." << Confy_Revision
       << " --- Copyright 1999 TM Productions" << endl;

  if( argc < 4 )
    Help();

  if( argv[1][0] == '?' )
    Help();

  // Argument Tests
  char * dest = argv[1];
  char * user = argv[2];
  bool   plugins_only = false;

  bool   use_executable = false;
  char   executable[ MAX_PATH_LENGTH ] = "";

  bool   use_dash_c = false;
  char   dash_c[ MAX_PATH_LENGTH ] = "-c";   // Oddly enough, this is correct (ie: "-clw.cfg").  Weird.

  bool   use_flags = false;
  char   flags[ 1024 ] = "";

  bool   use_scene = false;
  char   scene[ MAX_PATH_LENGTH ] = "";

  bool   stop = false;
  for( int first_plugin_cfg = 3; first_plugin_cfg < argc; first_plugin_cfg++ ) {
    switch( argv[first_plugin_cfg][1] ) {
    // Specify Config Path for Layout
    case 'c':
      if( ++first_plugin_cfg >= argc ) {
        cerr << " ERROR: No config file following arguemnt -c!" << endl;
        cerr << " Type Confy ? for help" << endl;
        exit(20);
      }

      use_dash_c = true;
      strcat( dash_c, argv[ first_plugin_cfg ] );

      if( !DirInfo::Exists( argv[ first_plugin_cfg ] ) ) {
        cerr << " ERROR: The -c config file \"" << dash_c << "\" doesn't exist!" << endl;
        cerr << " Type Confy ? for help" << endl;
        exit(20);
      }
      break;

    // Executable
    case 'e':
      if( ++first_plugin_cfg >= argc ) {
        cerr << " ERROR: No executable following argument -e!" << endl;
        cerr << " Type Confy ? for help" << endl;
        exit(20);
      }

      use_executable = true;
      strcpy( executable, argv[ first_plugin_cfg ] );

      if( !DirInfo::Exists( executable ) ) {
        cerr << " ERROR: The executable \"" << executable << "\" doesn't exist!" << endl;
        cerr << " Type Confy ? for help" << endl;
        exit(20);
      }
      break;

    // Flags
    case 'f':
      if( ++first_plugin_cfg >= argc ) {
        cerr << " ERROR: No flags following argument -f!" << endl;
        cerr << " Type Confy ? for help" << endl;
        exit(20);
      }

      use_flags = true;
      strcpy( flags, argv[ first_plugin_cfg ] );

    // Plug-ins Only
    case 'p':
      plugins_only = true;
      break;

    // Scene/Object to pass to Lightwave/Modeler on load
    case 's':
      if( ++first_plugin_cfg >= argc ) {
        cerr << " ERROR: No scene/object file following argument -s!" << endl;
        cerr << " Type Confy ? for help" << endl;
        exit(20);
      }

      use_scene = true;
      strcpy( scene, argv[ first_plugin_cfg ] );

      break;

    // End of options
    default:                   // This is probably the first plugin config file
      stop = true;
      break;
    }

    if( stop )
      break;
  }

  // Test Arguments For Validity
  if( first_plugin_cfg >= argc ) {
    cerr << " ERROR: No plug-in configs specified!" << endl;
    cerr << " Type Confy ? for help" << endl;
    exit( 20 );
  }

  if( use_scene && !use_executable ) {
    cerr << " ERROR:  using -s requires -e" << endl;
    cerr << " Type Confy ? for help" << endl;
    exit(20);
  }

  // Display Settings
  cout << "-Settings:" << endl;
  cout << "  Destination Config:             \"" << dest << "\"" << endl;
  cout << "  User Config:                    \"" << user << "\"" << endl;

  if( plugins_only )
    cout << "  Adding plug-ins only; no settings will be replaced" << endl;

  if( use_executable )
    cout << "  Executable to launch:           \"" << executable << "\"" << endl;

  if( use_scene )
    cout << "  Scene to load into Lightwave:   \"" << scene << "\"" << endl;

  cout << "  Settings and Plug-In Config 0:  \"" << argv[ first_plugin_cfg ] << "\"" << endl;
  for( int i = first_plugin_cfg+1; i < argc; i++ ) 
    cout << "  Plug-In Config " << i-first_plugin_cfg << ":               \"" << argv[ i ] << "\"" << endl;

  // Config Variable Setup
  DynArray< char * >   settings[ num_settings_group_ids ];
  char                 buffer[ 8192 ];
  char               * plugin_type;
  char               * new_name, * old_name;
  unsigned int         j;
  pifstream            in;
  bool                 error = false;
  
  config_type_ids      cfg_type = config_unknown, new_type;
  int                  cfg_version = -1, new_version;
  DynArray< char * > * user_settings_loc = &settings[ user_settings_pre ];

  // ---
  // Load the User Config Settings
  // ---
  try {
    cout << "-Loading User Config..." << endl;
    cfg_type = OpenConfig( user, in );
    if( cfg_type != config_unknown ) {
      cfg_version = GetConfigVersion( in, cfg_type );
      if( cfg_version == -1 )
        throw false;
    }

    if( cfg_type == config_layout ) {
      cout << " User config file is a Layout config, version " << cfg_version << endl;
    } else if( cfg_type == config_modeler ) {
      cout << " User config file is a Modeler config, version " << cfg_version << endl;
    } else {
      cout << " Unknown config file type; L6 config?" << endl;
    }

    while( true ) {
      // Read in a new line
      in.getline( buffer, 8192 );

      // Error Test
      if( (in.fail() || in.bad()) && !in.eof() ) {
        cerr << " ERROR:  File error reading from user config file; aborting" << endl;
        throw false;
      }

      // See if there are any plug-ins here and skip them
      if( strncmp( "Plugin ", buffer, 7 ) == 0 ) {
        user_settings_loc = &settings[ user_settings_post ];
      } else {
        // Add the prev. line to the appropriate array
        user_settings_loc->Add( strdup( buffer ) );
      }

      // EOF test
      if( in.eof() )
        break;
    };

    // ---
    // Load the Plug-In Configs
    // ---
    user_settings_loc = &settings[ user_settings_pre ];
    for( int k=first_plugin_cfg; k < argc; k++ ) {
      cout << "-Loading Plugin Config " << k - first_plugin_cfg << ":  \"" << argv[k] << "\"..." << endl;

      in.close();
      new_type = OpenConfig( argv[ k ], in );
      if( new_type == config_bad ) {
        cerr << " ERROR:  Error opening config file; aborting" << endl;
        throw false;
      } else if( new_type == config_unknown ) {
        if( cfg_type != new_type ) {
          cerr << " ERROR:  Attempting to merge unknown config file (not a .cfg?); aborting" << endl;
          throw false;
        }
      } else if( new_type != cfg_type ) {
        cerr << " ERROR:  Illegal attempt to merge Modeler and Layout configs file; aborting" << endl;
        throw false;
      }

      if( new_type != config_unknown ) {
        new_version = GetConfigVersion( in, cfg_type );
        if( cfg_version != new_version ) {
          cerr << " ERROR:  The configuration files are not the same version; aborting" << endl;
          throw false;
        }
      }

      while( true ) {
        // Read in a new line
        in.getline( buffer, 8192 );

        // Error Test
        if( (in.fail() || in.bad()) && !in.eof() ) {
          cerr << " ERROR:  File error reading from plug-in config file \""
               << argv[ k ] << "\"; aborting" << endl;
          throw false;
        }

        // Update the user config options
        if( !plugins_only && (k == first_plugin_cfg) )
          UpdateUser( buffer, *user_settings_loc, cfg_type );

        // See if there's a plug-in here and store it
        if( strncmp( "Plugin ", buffer, 7 ) == 0 ) {           // The space is so we don't confuse this with 
          user_settings_loc = &settings[ user_settings_post ];

          plugin_type = StringTools::FindWord( buffer, 1 );
          if( plugin_type == NULL ) {
            cerr << " WARNING:  Missing plug-in identifier after keyword \"" << buffer
                 << "\" (config " << k - first_plugin_cfg << ")" << endl;
          } else {
            for( i = 0; i < num_plugin_ids; i++ ) {
              // Figure out what group it's in
              if( strncmp( plugin_type, settings_group_strings[i], strlen( settings_group_strings[i] ) ) == 0 ) {
                break;
              }
            }

            // Test for unknown plug-in types
            if( i == num_plugin_ids ) {
              cerr << " WARNING:  Unknown plug-in type found in this line: \"" << buffer
                   << "\" (config " << k - first_plugin_cfg << ")" << endl;
              settings[ plugins_other ].Add( strdup( buffer ) );
            }

            // See if this plug-in is a duplicate
            new_name = StringTools::FindWord( buffer, 2 );         // This should be the name of the plug-in as found in the .p file
            if( new_name == NULL ) {
              cerr << " WARNING:  The following line contains invalid plug-in information: \"" << buffer
                    << "\" (config " << k - first_plugin_cfg << ")" << endl;
            } else {
              for( j=0; j < settings[i].NumElements(); j++ ) {
                old_name = StringTools::FindWord( settings[i][j], 2 );
                if( old_name == NULL ) {
                  cerr << " WARNING:  The following plug-in line is invalid \"" << buffer << "\"; skipping";
                } else {
                  if( strncmp( old_name, new_name, StringTools::FindWordLength( old_name ) ) == 0 ) {
                    if( StringTools::FindWordLength( old_name ) == StringTools::FindWordLength( new_name ) ) {  // make sure the words are equal length; gets around strncmp() failing on things like "Metaform_Shaper" and "Metaform_Shaper(FASTER)"
                      cerr << " WARNING:  The following plug-in is already in the config: \"" << buffer
                           << "\"; replacing existing with this (config " << k - first_plugin_cfg << ")" << endl;
                      delete settings[i][j];
                      settings[i][j] = strdup( buffer );
                      break;
                    }
                  }
                }
              }

              // Not a duplicate; add it to the end
              if( j == settings[i].NumElements() ) {
                settings[i].Add( strdup( buffer ) );
              }
            }

          }
        }

        // EOF test
        if( in.eof() )
          break;
      };
    }

    in.close();

    // ---
    // Backup the existing config, if needed
    // ---
    if( DirInfo::Exists( dest ) ) {
      char backup[ MAX_PATH_LENGTH ];
      char extension[ MAX_FILENAME_LENGTH ];

      // Generate the backup name
      strcpy( backup, dest );
      char * ext = DirStrings::HasExtension( backup ); // Find any extension
      if( ext ) {                                      // Strip the extension
        strcpy( extension, ext );
        *ext = '\0';
      }
      strcat( backup, "-backup" );                     // Append "-backup"
      strcat( backup, extension );                     // Put the extension back

      cout << "-Destination configs already exists; backing up original as \"" << backup << "\"" << endl;

      // Delete any existing backup file so we can rename this one
      if( DirInfo::Exists( backup ) ) {
        if( DirInfo::Delete( backup ) != DI_DELETE_OK ) {
          cerr << " ERROR:  Unable to remove previously existing backup; aborting" << endl;
          throw false;
        }
      }

      // Rename the existing config
      if( DirInfo::Rename( dest, backup ) != DI_RENAME_OK ) {
        cerr << " ERROR:  Unable to rename existing config as backup; aborting" << endl;
        throw false;
      }
    }


    // ---
    // Output the final config
    // ---
    cout << "-Writing Composite Config \"" << dest << "\"..." << endl;
    ofstream out( dest );
    if( !out ) {
      cerr << " ERROR:  Unable to open output config \"" << dest << "\"; aborting" << endl;
      throw false;
    }

    // Pre-Plugin Settings
    for( j = 0; j < settings[ user_settings_pre ].NumElements(); j++ ) {
      if( settings[ user_settings_pre ][j][0] != '\0' )   // Skip any possible blank lines
        out << settings[ user_settings_pre ][j] << endl;
    }

    // Plug-ins
    for( i = 0; i < num_plugin_ids; i++ ) {
      for( j = 0; j < settings[i].NumElements(); j++ )
        out << settings[i][j] << endl;
    }

    // Post-Plugin Settings
    for( j = 0; j < settings[ user_settings_post ].NumElements(); j++ ) {
      if( settings[ user_settings_post ][j][0] != '\0' )   // Skip any possible blank lines
        out << settings[ user_settings_post ][j] << endl;
    }

  } catch( bool ) {
    error = true;  // We're just here so the clean-up code gets called on errors
  }

  // Free the memory used by the strings
  if( !error )
    cout << "-Cleaning up..." << endl;
  for( i=0; i < num_settings_group_ids; i++ ) {
    for( j = 0; j < settings[i].NumElements(); j++ )
      free( settings[i][j] );
  }

  if( !error ) {
    if( use_executable ) {
      cout << "-Launching \"" << executable << "\"..." << endl;

      // Change the working dir
      char cwd[ MAX_PATH_LENGTH ];
      strcpy( cwd, executable );
      *DirStrings::HasFile( cwd ) = '\0';
      if( cwd[0] != '\0' )
        DirInfo::ChangeWorkingDir( cwd );

      // Build the argument list
      char *exec_args[128];
      int a1 = 0;
      exec_args[ a1++ ] = strdup( DirStrings::GetFilePart( executable ) );

      if( use_dash_c )           // -c option
        exec_args[ a1++ ] = strdup( dash_c );

      if( use_flags ) {          // User-defined flags
        int j = 0;
        strcpy( buffer, flags );

        do {
          if( StringTools::IsolateWord( flags, buffer, j++ )[0] != '\0' )
            exec_args[ a1++ ] = strdup( buffer );

          if( a1 > 126 ) {
            cerr << "  ERROR:  More than 127 arguments being paseed to executable; aborting" << endl;
            exec_args[ a1-1 ] = '\0';
            for( i = 0; exec_args[i] != NULL; i++ )
              free( exec_args[i] );
            return;
          }
        } while( buffer[0] != '\0' );
      }

      if( use_scene )
        exec_args[ a1++ ] = strdup( scene );

      exec_args[ a1++ ] = NULL;          // NULL-terminate the array

      // Display the argument string
      cout << "  Argument String For Executable:  " << endl;
      cout << "  ";
      for( unsigned int i = 0; exec_args[i] != NULL; i++ )
        cout << " " << exec_args[i];
      cout << endl;

      // Run the program asynchronously
      _spawnv( _P_NOWAIT, executable, exec_args );

      // Free the argument list
      for( i = 0; exec_args[i] != NULL; i++ )
        free( exec_args[i] );
    }

    cout << "-Complete!" << endl;
  }
}
Ejemplo n.º 7
0
BOOL CpermoDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO: 在此添加额外的初始化代码
	//AllocConsole();
	//freopen("CONOUT$","w",stdout);
	//bIsWindowsVistaOrGreater = false;
	//判断操作系统版本
// 	DWORD dwVersion = 0;
// 	DWORD dwMajorVersion = 0;
//     DWORD dwMinorVersion = 0; 
// 	dwVersion = ::GetVersion();
// 	dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
//     //dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
// 	if (dwMajorVersion > 5)
// 	{
// 		bIsWindowsVistaOrGreater = true;
// 	}
	/*
	If dwMajorVersion = 6 And dwMinorVersion = 1 Then GetWinVersion = "windows 7"
    If dwMajorVersion = 6 And dwMinorVersion = 0 Then GetWinVersion = "windows vista"
    If dwMajorVersion = 5 And dwMinorVersion = 1 Then GetWinVersion = "windows xp"
    If dwMajorVersion = 5 And dwMinorVersion = 0 Then GetWinVersion = "windows 2000"
	*/
	BOOL bRet = FALSE;
	::SystemParametersInfo(SPI_GETWORKAREA, 0, &rWorkArea, 0);   // 获得工作区大小
	bRet = SetWorkDir();
	if (!bRet)
	{
		AfxMessageBox(_T("额...初始化失败!"));
		return FALSE;
	}
	OpenConfig();
	InitSize();
	CreateInfoDlg();
	GetWindowRect(&rCurPos);
	if (!::GetSystemTimes(&preidleTime, &prekernelTime, &preuserTime))
	{
		return -1;
	}
	m_SubMenu_NetPort.CreatePopupMenu();
	MFNetTraffic m_cTrafficClassTemp;
	//更新:增加对所有发现的网络接口监控遍历,防止监控的接口非连接网络的接口
	double tottraff = 0, maxtmp = 0;
	CString tmp, tmp2;
	int nCount = m_cTrafficClassTemp.GetNetworkInterfacesCount();
	for (int i = 0; i <= nCount; i++)
	{
		if ((tottraff = m_cTrafficClassTemp.GetInterfaceTotalTraffic(i) / (1024.0*1024.0)) > 0)
		{
			if (tottraff > maxtmp)
			{
				maxtmp = tottraff;
				SelectedInterface = i;
				isOnline = TRUE;
			}
		}
		m_cTrafficClassTemp.GetNetworkInterfaceName(&tmp, i);
		tmp2.Format(_T("%s : %.1f MB"), tmp, tottraff);
		m_SubMenu_NetPort.AppendMenu(MF_STRING, i + START_INDEX, tmp2);
	}
	//创建菜单
	InitPopMenu(nCount);
	//默认置顶
	if (bTopmost)
	{
		SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
		m_Menu.CheckMenuItem(IDM_TOPMOST, MF_BYCOMMAND | MF_CHECKED);
	}
	if (bAutoHide)
	{
		m_Menu.CheckMenuItem(IDM_AUTOHIDE, MF_BYCOMMAND | MF_CHECKED);
	}
	if (0 == nShowWay)
	{
		m_Menu.CheckMenuItem(IDM_SHOWBYHOVER, MF_BYCOMMAND | MF_CHECKED);
	}
	else
	{
		m_Menu.CheckMenuItem(IDM_SHOWBYLDOWN, MF_BYCOMMAND | MF_CHECKED);
	}
	if (bShowNetInfo)
	{
		m_Menu.CheckMenuItem(IDM_SHOWNETINFO, MF_BYCOMMAND | MF_CHECKED);
	}
	else
	{
		m_Menu.CheckMenuItem(IDM_SHOWNETINFO, MF_BYCOMMAND | MF_UNCHECKED);
	}
	m_Menu.CheckMenuItem(nSkin, MF_BYCOMMAND | MF_CHECKED); // 在前面打钩 
	m_Menu.CheckMenuItem(IDM_FONTSIZE12 + nFontSize - 12, MF_BYCOMMAND | MF_CHECKED);
	IfAutoRun();//判断是否已经开机自启
	isOnline = TRUE;

	//设置网络监控类型
	m_cTrafficClassDown.SetTrafficType(MFNetTraffic::IncomingTraffic);
	m_cTrafficClassUp.SetTrafficType(MFNetTraffic::OutGoingTraffic);

	//取消任务栏显示
	SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, WS_EX_TOOLWINDOW);
	//每隔一秒刷新CPU和网络信息
	SetTimer(1, 1000, NULL);
	//刷新内存信息
	SetTimer(2, 5000, NULL);
	
	::SetWindowLong( m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
	::SetLayeredWindowAttributes( m_hWnd, 0, nTrans, LWA_ALPHA); // 120是透明度,范围是0~255
	m_Menu.CheckMenuItem(IDM_TRANS0+(255-nTrans)/25, MF_BYCOMMAND | MF_CHECKED);

	return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}
Ejemplo n.º 8
0
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
    if (msg == WM_TRAY) {
        if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK) {
            ToggleState();
            if (lParam == WM_LBUTTONDBLCLK && !(GetAsyncKeyState(VK_SHIFT)&0x8000)) {
                SendMessage(hwnd, WM_OPENCONFIG, 0, 0);
            }
        }
        else if (lParam == WM_MBUTTONDOWN) {
            ShellExecute(NULL, L"open", inipath, NULL, NULL, SW_SHOWNORMAL);
        }
        else if (lParam == WM_RBUTTONDOWN) {
            ShowContextMenu(hwnd);
        }
        else if (lParam == NIN_BALLOONUSERCLICK) {
            hide = 0;
            SendMessage(hwnd, WM_COMMAND, SWM_UPDATE, 0);
        }
        else if (lParam == NIN_BALLOONTIMEOUT) {
            if (hide) {
                RemoveTray();
            }
        }
    }
    else if (msg == WM_UPDATESETTINGS) {
        UpdateLanguage();
        // Reload hooks
        if (ENABLED()) {
            UnhookSystem();
            HookSystem();
        }
        // Reload config language
        if (!wParam && IsWindow(g_cfgwnd)) {
            SendMessage(g_cfgwnd, WM_UPDATESETTINGS, 0, 0);
        }
    }
    else if (msg == WM_ADDTRAY) {
        hide = 0;
        UpdateTray();
    }
    else if (msg == WM_HIDETRAY) {
        hide = 1;
        RemoveTray();
    }
    else if (msg == WM_OPENCONFIG && (lParam || !hide)) {
        OpenConfig(wParam);
    }
    else if (msg == WM_CLOSECONFIG) {
        CloseConfig();
    }
    else if (msg == WM_TASKBARCREATED) {
        tray_added = 0;
        UpdateTray();
    }
    else if (msg == WM_COMMAND) {
        int wmId=LOWORD(wParam), wmEvent=HIWORD(wParam);
        if (wmId == SWM_TOGGLE) {
            ToggleState();
        }
        else if (wmId == SWM_HIDE) {
            hide = 1;
            RemoveTray();
        }
        else if (wmId == SWM_UPDATE) {
            if (MessageBox(NULL,l10n->update_dialog,APP_NAME,MB_ICONINFORMATION|MB_YESNO|MB_TOPMOST|MB_SETFOREGROUND) == IDYES) {
                OpenUrl(APP_URL);
            }
        }
        else if (wmId == SWM_CONFIG) {
            SendMessage(hwnd, WM_OPENCONFIG, 0, 0);
        }
        else if (wmId == SWM_ABOUT) {
            SendMessage(hwnd, WM_OPENCONFIG, 4, 0);
        }
        else if (wmId == SWM_EXIT) {
            DestroyWindow(hwnd);
        }
    }
    else if (msg == WM_QUERYENDSESSION && msghook) {
        showerror = 0;
        UnhookSystem();
    }
    else if (msg == WM_DESTROY) {
        showerror = 0;
        UnhookSystem();
        RemoveTray();
        PostQuitMessage(0);
    }
    else if (msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) {
        // Hide cursorwnd if clicked on, this might happen if it wasn't hidden by hooks.c for some reason
        ShowWindow(hwnd, SW_HIDE);
    }
    return DefWindowProc(hwnd, msg, wParam, lParam);
}