windows api

#include"dir.h"

#include<Windows.h>

#include<stdio.h>

#define INFO_BUFFER_SIZE 32767

TCHAR  infoBuf[INFO_BUFFER_SIZE];

WIN32_FIND_DATA FindFileData;

void Dir::getAllDir()

{

DWORD  bufCharCount = INFO_BUFFER_SIZE;

if(GetComputerName(infoBuf, &bufCharCount))  //计算机名

{

printf("the computer name : %s \n",infoBuf);

}

if( GetUserName( infoBuf, &bufCharCount ) ) // 用户名

{

      printf("the user name : %s \n",infoBuf);

}

if( GetSystemDirectory( infoBuf, INFO_BUFFER_SIZE ) ) // "C:\Windows\system32"

{

        printf("the system directory: %s \n",infoBuf);

}

if( GetWindowsDirectory( infoBuf, INFO_BUFFER_SIZE ) ) //"C:\Windows\"

{

printf("the windows directory: %s \n",infoBuf);

}

if(GetCurrentDirectory(INFO_BUFFER_SIZE, infoBuf)) // 当前路径

{

printf("the current directory: %s \n",infoBuf);

}

HANDLE hFind;


int size = strlen(infoBuf);

infoBuf[size] = '*';  // 在查找文件的时候* 很重要, eg://infoBuf = "E:\\projects\\algorithm\\algorithm*";才能查找该目录下的所有文件

infoBuf[size + 1] = '\0';

hFind = FindFirstFile(infoBuf, &FindFileData);

if (hFind != INVALID_HANDLE_VALUE)

{

printf("the file name: %s \n",FindFileData.cFileName);

//FindClose(hFind);

}

do

{

     printf("the file name: %s \n",FindFileData.cFileName);

}while(FindNextFile(hFind, &FindFileData)); //

}

windows 文件和文件路劲的操作

api 查询URL: https://docs.microsoft.com/en-us/windows/win32/api


RegisterClass and CreateWindow

BOOL InitApplication(HINSTANCE hinstance)

{

    WNDCLASSEX wcx; 

    wcx.lpszClassName = "MainWClass";  // name of window class 

}

hwnd = CreateWindow(

        "MainWClass",        // name of window class 

这两个值是有关联的,需要保持一致,否则窗口不能注册,也显示不了。

该参数的解释:

A null-terminated string or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero. If lpClassName is a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, provided that the module that registers the class is also the module that creates the window. The class name can also be any of the predefined system class names. For a list of system class names, see the Remarks section.


scanf使用中断

scanf("%s", str, length); length 这个长度一定要配置

scanf("%legth s",str); 这个不会报错,但是会中断

具体原因得看源代码的实现方式

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。