windows编程浅尝辄止 命令行调用exe

老师让拓宽知识面,所以就有了这篇博客。
ps : 只看个hello world就已经晕乎了。

#include <Windows.h>

//main()是控制台应用程序的入口函数
//WinMain()是win32窗口应用程序的入口函数

//HINSTANCE hInstance-->应用程序当前实例句柄

//HINSTANCE hPreInstance-->应用程序前一个实例句柄.
//在16位操作系统上需要传参,对于32位和64位操作系统,已经废弃,需要传NULL

//LPSTR lpCmdLine-->命令行参数

//int nCmdShow-->窗口的显示方式

//WINAPI-->宏定义__stdcall

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, LPSTR lpCmdLine, int nCmdShow) {
	//弹出一个消息提示框
	//MessageBox(父窗口句柄, L"窗口显示内容"(L表示后面的字符串是宽字符串), L"标题", MB_OK(ok按钮));
	
	while (true){
		MessageBox(NULL, L"hello world!", L"this is title", MB_OK);
	}
	
	return 0;
}

命令行调用exe

#include <iostream>
#include <string>
#include <cstring>
using namespace std; 

//argc是命令中字符串个数,argv存每个字符串 
int main(int argc, char** argv) {
	for (int i=0; i<argc; i++){
		cout<<"参数"<<argv[i]<<endl;
	}
	return 0;
}
/*
main.exe -h
参数main.exe
参数-h
*/

版权声明:本文为weixin_42172261原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。