x7code 发表于 2012-12-27 22:36:24

api一日一练 第12天 GetCurrentDirectory SetCurrentDirectory

1:获取当前的路径 设置当前路径

#include "stdafx.h"

int APIENTRY WinMain(HINSTANCE hInstance,

                     HINSTANCE hPrevInstance,

                     LPSTR   lpCmdLine,

                     int       nCmdShow)

{
    char path;
      ZeroMemory(path,100);//清零
      GetCurrentDirectory(100,path);//获取当前路径
      MessageBox(NULL,path,"xqmsyk.com",NULL);
    SetCurrentDirectory("c:\\");//设置当前路径
      GetCurrentDirectory(100,path);
      MessageBox(NULL,path,"xqmsyk.com",NULL);
      return 0;
}


//本节课的思考题是 FindFirstFile 和 FindNextFile的用法

jiayuanfu 发表于 2012-12-27 23:24:19

学习了,谢谢

lengxue 发表于 2012-12-28 08:59:18

不错

hackbs 发表于 2012-12-28 15:51:44

课堂作业



// 获取路径并且改变.cpp : Defines the entry point for the application.
//

#include "stdafx.h"

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR   lpCmdLine,
                     int       nCmdShow)
{
        // TODO: Place code here.
        TCHAR path;
        TCHAR mbpath;
       
        GetModuleFileName(NULL,path,256);

        int ret =
                MessageBox(NULL,path,TEXT("提示!"),
                MB_ICONQUESTION | MB_YESNO);
        if ( IDYES == ret )
        {
      strcpy(mbpath,"c:\\lovexq\\love.exe");
                MoveFileEx(path,mbpath,
                        MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED );
      MessageBox(NULL,mbpath,TEXT("提示!"),MB_OK);
                }
        return 0;
}



-------------------------------思考题------------------------
                     知道那两个函数的用法 但是不知道怎么写列子。 请小七指点.....

君子坦蛋蛋 发表于 2012-12-28 17:27:19

交课后作业。。今天作业是完成了。但是完成的效果不知道怎么能显示出来。我在想是不是要用win32控制台应用程序建立这个工程?求解答。。。
查找E盘的嘿嘿交作业文件夹


#include "stdafx.h"
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR   lpCmdLine,
                     int       nCmdShow)
{
// TODO: Place code here.
    WIN32_FIND_DATA fData;
HANDLE hFile = FindFirstFile("e:\\嘿嘿交作业", &fData);
    if( hFile )
{
FindNextFile(hFile, &fData);
}
CloseHandle(hFile);
return 0;
}


echotxl 发表于 2013-4-6 13:32:10

补上落下的课,。。。
页: [1]
查看完整版本: api一日一练 第12天 GetCurrentDirectory SetCurrentDirectory