API是程序吗是用什麼软件能编写啊

API是程序吗是用什麼软件能编写啊,第1张

API是Application Programming Interface的缩写,也就是应用程序调用系统功能的接口。Windows API主要包括系统定义的函数、消息及与之相关的数据类型。我们使用各种开发工具归根结底都是和API打交道。但是API本身比较难掌握,所以开发工具都提供了各种可视的或面向对象的手段,如控件、类等,来使用户即使不太了解API,也可以编写Windows程序。但是这些手段是有限的,不可能包括API的所有方面。所以一些复杂的功能仍然需要调用API来实现。 API的实现可以使用任何编程语言进行编写

#include "stdafxh"

#include <windowsh>

#include <iostream>

#include <cstdio>

#include "Tlhelp32h"

using namespace std;

#define PROCESS_PATH L"C:\\Program Files\\Windows NT\\Accessories\\wordpadexe"

void open()

{

WCHAR proPath[MAX_PATH];

STARTUPINFO si = { sizeof(si) };

PROCESS_INFORMATION pi;

wcscpy(proPath,PROCESS_PATH);

sidwFlags = STARTF_USESHOWWINDOW;

siwShowWindow = TRUE;

BOOL bRet = ::CreateProcess(NULL, proPath, NULL,NULL,FALSE, CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi);

return;

}

void close()

{

PROCESSENTRY32 pe;

HANDLE hProcess;

pedwSize = sizeof (PROCESSENTRY32);

HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);

Process32First(hSnapshot,& pe);

do

{

if ( ! _tcsicmp(peszExeFile,_T( "wordpadexe" )))

{

break;

}

pedwSize = sizeof(PROCESSENTRY32);

} while(Process32Next(hSnapshot, & pe));

STARTUPINFO si = { sizeof(si) };

PROCESS_INFORMATION pi;

sidwFlags = STARTF_USESHOWWINDOW;

siwShowWindow = TRUE;

hProcess = ::OpenProcess(PROCESS_TERMINATE,FALSE,peth32ProcessID); //根据进程ID返回对象句柄

::TerminateProcess(hProcess,0); //根据对象句柄结束进程

CloseHandle(hSnapshot);

CloseHandle(hProcess);

return;

}

int _tmain(int argc, _TCHAR argv[])

{

//return 0;

char a;

while(TRUE)

{

cout<<"please input the command:";

cin>>a;

switch (a)

{

case '1':

open();

cout<<"command confirmed"<<endl;

break;

case '2':

close();

cout<<"command confirmed"<<endl;

break;

case '3':

exit(0);

break;

default:

cout<<"wrong command"<<endl;

}

}

}

但按钮单击事件中,用框控件的数组属性,根据下表来一次获取,每执行一次,下标加1但是,在此之前应设置一个全局变量i。给i赋个初值,然后在将i作为数组下标,最后设置一个判断下表i值为多少时重新赋值为第一张的下标!

下面是完整代码,仅作参考(我用了9张):

using System;

using SystemCollectionsGeneric;

using SystemComponentModel;

using SystemData;

using SystemDrawing;

using SystemText;

using SystemWindowsForms;

namespace PicExplorer

{

public partial class FrmMyPicExp : Form

{

int index = 0;//全局变量

public FrmMyPicExp()

{

InitializeComponent();

}

private void FrmMyPicExp_Load(object sender, EventArgs e)//加载

{

MyPicpictureBoxImage = MyPicimageListImages[index];

}

private void tSBnext_Click_1(object sender, EventArgs e)//下一张 按钮单击事件

{

if (index < 9)

{

MyPicpictureBoxImage = MyPicimageListImages[index + 1];

index++;

}

else

{

index = 0;

MyPicpictureBoxImage = MyPicimageListImages[index];

}

}

private void tSBlast_Click(object sender, EventArgs e)//上一张  按钮单击事件

{

if (index < 9)

{

MyPicpictureBoxImage = MyPicimageListImages[9-index];

index++;

}

else

{

index = 0;

MyPicpictureBoxImage = MyPicimageListImages[index];

}

}

private void tSBplay_Click(object sender, EventArgs e)//自动播放按钮

{

secondtimerStart();

}

private void tSBstop_Click(object sender, EventArgs e)//停止播放按钮

{

secondtimerStop();

}

private void secondtimer_Tick_1(object sender, EventArgs e)//时间控制器,这里可以设置时间间隔

{

if (index < 9)

{

MyPicpictureBoxImage = MyPicimageListImages[index + 1];

index++;

}

else

{

index = 0;

MyPicpictureBoxImage = MyPicimageListImages[index];

}

}

}

}

API是预先定义的接口,以供程序员调用。是一套用来控制系统各个部件的预先定义的函数。 *** 作方式如下:

1、在C++调用系统API之前需要声明相应的头文件。这里使用系统函数 MessageBoxA ,对应头文件:  ”windowsh“。

2、使用尖括号,编译器会先在include目录搜索该头文件;如果未找到,才会在源代码所在目录搜索。2、使用双引号则相反,会先在源代码目录搜索;通常用于包含程序作者自行编写的头文件。

3、可以在第三部的图中看到 MessageBoxA 函数包含四个参数。函数括号内部为参数,每个参数之间用英文逗号隔开。当鼠标指在函数上时,会出现函数说明信息。

4、参数中的NULL为常量0,代表不设置或默认设置。也可以不使用常量,直接写作0。

5、MessageBoxA 函数运行如图所示。

以上就是关于API是程序吗是用什麼软件能编写啊全部的内容,包括:API是程序吗是用什麼软件能编写啊、如何利用Windows提供的API函数,编写程序,实现进程的创建和终止(如创建写字板进程及终止该进程)、利用api写窗口程序,如何实现图片的切换(C语言)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/9853065.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-02
下一篇2023-05-02

发表评论

登录后才能评论

评论列表(0条)

    保存