vc6开发笔记一

获得时间、目录

#include <window.h>

//获得当前时间

SYSTEMTIME time;

GetLocalTime(&time);

GetSystemTime(&time);

//获得当前工作目录

char path[255];

GetCurrentDirectory(255, path);

printf("%04d", 12);//打印0012

//获得程序目录

GetModuleFileName(NULL, path, 255);

获得进程号

//获得指定名的进程号

#include <tlhelp32.h>

DWORD GetProcessidByName(LPCTSTR name) {

  PROCESSENTRY32 pe;

  DWORD id = 0;

  HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

  pe.dwSize = sizeof(pe);

  if (!Process32First(hSnapshot, &pe)) return 0;

  while(1) {

    pe.dwSize = sizeof(pe);

    if (Process32Next(hSnapshot, &pe) == FALSE) break;

    if (strcmp(pe.szExeFile, name) == 0) {

      id = pe.th32ProcessID;

      break;

    }

  }

  CloseHandle(hSnapshot);

  return id;

}

posted @ 2014-10-31 15:46  feilv  阅读(172)  评论(0编辑  收藏  举报