Chinaunix首页 | 论坛 | 博客
  • 博客访问: 845937
  • 博文数量: 756
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 4980
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:40
文章分类

全部博文(756)

文章存档

2011年(1)

2008年(755)

我的朋友

分类:

2008-10-13 16:09:15

ListProc-cons
////////////////////////////////////////////////////////////////
// ListProc.cpp shows how to write an app that can run from a single EXE 
// as either a console or GUI app. To run in GUI mode, just type the name 
// of the program with command-line args. To run in console/batch mode, 
// type the name followed by any option, such as -help.
//
#include "stdafx.h"
#include "EnumProc.h"

static void help();
static BOOL bBare=FALSE;
static BOOL bClassName=FALSE;
static BOOL bTitle=FALSE;

// check for switch: / or -
inline BOOL isswitch(TCHAR c) { return c==L'/' || c==L'-'; }

/////////////////
// Main entry point for console app.
//
int _tmain(int argc, _TCHAR* argv[])
{
   HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
   TRACE("hcon=%p\n",hcon);

   if (argc <= 1) {
      // Invoked with no command-line args: run in GUI mode.
      TCHAR lpExeName[_MAX_FNAME];
      GetModuleFileName(NULL, lpExeName, _MAX_FNAME);
      LPTSTR ext = lpExeName + _tcslen(lpExeName) - 3;
      _tcscpy(ext,_T("exe"));
      ShellExecute(NULL, _T("open"), lpExeName, NULL, NULL, SW_SHOWNORMAL);
      return 0;
   }

   // Parse command line. Switches can come in any order.
   for (int i=1; i

IniFile
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

////////////////////
// .NET wrapper for an initialization file.
//
namespace IniProfile {

   public class IniFile
   {
      [DllImport("Kernel32.dll")]
      private static extern bool WritePrivateProfileString(
         String section, String key, String val, String filename);

      [DllImport("Kernel32.dll")]
      private static extern int GetPrivateProfileInt(
         String section, String key, int dflt, String filename);

      [DllImport("Kernel32.dll")]
      private static extern int GetPrivateProfileString(
         String section, String key, String dflt,
         StringBuilder buf, int nBufLen, String filename);

      private String iniFileName; // .INI file name
      private Hashtable settings = new Hashtable();
      private String currentSection = "Settings";

      public String Section
      {
         get { return currentSection; }
         set { currentSection = value; }
      }

      // ctor: initialize file name
      public IniFile(String fn, bool useAppDataPath) {
         if (useAppDataPath) {
            iniFileName = Application.UserAppDataPath + "\\" + fn;
         } else {
            iniFileName = fn;
         }
      }

      public int GetIntVal(String key, int dflt)
      {
         return GetPrivateProfileInt(currentSection, key, dflt,
         iniFileName);
      }

      public String GetStrVal(String key, String dflt)
      {
         StringBuilder sb = new StringBuilder(256);
         GetPrivateProfileString(currentSection, key, dflt, sb,
            sb.Capacity, iniFileName);
         return sb.ToString();
      }

      public void SetVal(String key, String val)
      {
         WritePrivateProfileString(currentSection, key, val, iniFileName);
      }

      public void SetVal(String key, int val)
      {
         WritePrivateProfileString(currentSection, key, val.ToString(), 
         iniFileName);
      }

      public void RestoreWinPos(Form form, String section)
      {
         this.Section = section;
         form.Location = new Point(
            GetIntVal("X",form.Location.X), 
            GetIntVal("Y",form.Location.Y));
         form.Size  = new Size(
            GetIntVal("Width", form.Size.Width), 
            GetIntVal("Height",form.Size.Height));
         form.StartPosition = FormStartPosition.Manual; // important!
      }

      public void SaveWinPos(Form form, String section)
      {
         this.Section = section;
         SetVal("X",form.Location.X);
         SetVal("Y",form.Location.Y);
         SetVal("Width", form.Size.Width);
         SetVal("Height",form.Size.Height);
      }
   }
}


--------------------next---------------------

阅读(423) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~