zoukankan      html  css  js  c++  java
  • win32常用代码整理

    1、ShellExecute 【Use ShellAPI】

       

    ShellExecute(Handle, 'open', 'http://www.cnblogs.com/lovelp/', nil, nil, SW_SHOW);

    2、关于路径

    ExpandFileName() 返回文件的全路径(含驱动器、路径) 
    ExtractFileExt() 从文件名中抽取扩展名 
    ExtractFileName() 从文件名中抽取不含路径的文件名 
    ExtractFilePath() 从文件名中抽取路径名 
    ExtractFileDir() 从文件名中抽取目录名 
    ExtractFileDrive() 从文件名中抽取驱动器名 
    ChangeFileExt() 改变文件的扩展名 
    ExpandUNCFileName() 返回含有网络驱动器的文件全路径 
    ExtractRelativePath() 从文件名中抽取相对路径信息 
    ExtractShortPathName() 把文件名转化为DOS的8·3格式 
    MatchesMask() 检查文件是否与指定的文件名格式匹配

    获取当前路径的3种常用方法:

    ExtractFilePath(ParamStr(0));
    ExtractFilePath(Application.ExeName);
    GetCurrentDir + '';

    3、格式化时间

    FormatDateTime('yyyy-mm-dd',now());


    4、提取时间成分

    YearOf
    MonthOf
    WeekOf
    DayOf
    HourOf
    MinuteOf
    SecondOf

    5、INI操作

    var
      iniFile:TiniFile;
      //创建对象
      iniFile:=TiniFile.Create(iniFilePath+iniFileName);
      //读数据
      iniFile.ReadString('Section','Key','DefaultValue')  //字符串
      iniFile.ReadInteger('Section','Key',DefaultValue) ;//整数
    
      //写数据
      iniFile.WriteString('Section','Key','Value')  //字符串
      iniFile.WriteInteger('Section','Key',tValue) ;
    
    // 释放对象
    iniFile.Free;
    
    //如果想读取整段值,可以用iniFile.ReadSection('SectionName', StringList)将整段数据读到TStringList对象中

    6、读写 注册表 【use Registry】

    procedure TForm1.Button1Click(Sender: TObject);
    var reg:TRegistry;
    begin
      reg:=TRegistry.Create;//创建实例
      reg.RootKey:=HKEY_CURRENT_USER;//指定需要操作的注册表的主键
      if(reg.OpenKey('Softwaredsy',true)) then
      begin
        reg.WriteString('fishname','淡水鱼');//写入字符串类型,也可以是其他类型
        reg.CloseKey;
      end;
      reg.Free;
    end;
    
    
    
    procedure TForm1.Button2Click(Sender: TObject);
    var reg:TRegistry;
    begin
      reg:=TRegistry.Create;//创建实例
      reg.RootKey:=HKEY_CURRENT_USER;//指定需要操作的注册表的主键
      if(reg.OpenKey('Softwaredsy',true)) then
      begin
        showmessage(reg.ReadString('fishname'));//读取注册表
        reg.CloseKey;
      end;
      reg.Free;
    end;
    View Code
  • 相关阅读:
    C#:反射
    静态和非静态类
    数据的存入取出(注册机方式)
    退出unity运行
    网络流基础
    欧拉回路
    博弈论问题
    洛谷P5304 [GXOI/GZOI2019] 旅行者
    [ZJOI2006]物流运输
    POJ3278 Catch that cow
  • 原文地址:https://www.cnblogs.com/lovelp/p/4507090.html
Copyright © 2011-2022 走看看