• 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
  • 相关阅读:
    《区块链100问》第33集:在交易平台投资区块链资产
    Python学习(三)数组属性方法总结
    Python学习(二)Numpy学习
    数学之美 第2章 自然语言处理:从规则到统计
    数学之美 第1章 文字和语言 vs 数字和信息
    Python学习(一)基础知识
    Python使用技巧(不定期更新)
    玩转Git三剑客——04. 创建第一个仓库并配置local用户信息、05. 通过几次commit来认识工作区和暂存区
    玩转Git三剑客——02. 安装Git、03. 使用Git之前需要做的最小配置
    玩转Git三剑客——01. 课程综述
  • 原文地址:https://www.cnblogs.com/lovelp/p/4507090.html
Copyright © 2020-2023  润新知