作者:军校招生顾问天使 | 来源:互联网 | 2023-06-05 19:50
程序写了一点,发现应该先用C++的框架创建窗口,现在在DOS下怎么调用windows的一个窗口用于画点画线12345678910111213141516171819202122232425262728
程序写了一点,发现应该先用C++的框架创建窗口,现在在DOS下怎么调用windows的一个窗口用于画点画线
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| #include "stdafx.h"
#include
#include
#include
#include //用到了time函数
#include
#include
using namespace std;
//声明用来处理消息的函数
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//窗口类对象
//函数功能:产生一个窗口
//函数功能:产生随机数
int stochastic()
{
int sto=0;//随机数
srand((unsigned)time(NULL)); //用时间做种,每次产生随机数不一样
sto= rand() % 4; //产生0-3的随机数
/*测试随机数生成的代码
int testOne= 0;
cout < cin >> testone;
*/
return sto;
}
//函数功能:让用户输入数字完成选择目标机型
int getinair_type(int atype)
{
cout <<"请输入数字选择目标类型"< cin >> atype;
while (atype > 4 || atype <1)
{
cout <<"输入有误,重新输入" < system("cls");
atype=getinair_type(atype);
}
return atype;
}
//函数功能:在随机状态下 完成对机型的赋值
int FUNCaircraft()
{
int aircraft_type = 0;
int stoc = stochastic();
aircraft_type = stoc + 1;
return aircraft_type;
}
//状态机一
int stateone()
{
int choice_model = 0;//choice_model代表用户选择是否完全随机 1是完全随机 2是指定目标类型
int aircraft_typw = 0;//aircraft_typw代表飞行目标类型
cout <<"请输入数字代表想定生成方式" < cin >> choice_model;
if (choice_model == 1)
{
cout <<"选择完全随机"< aircraft_typw = FUNCaircraft();//取随机数 给机型赋值
cout <<"目标随机指定为 ";
switch (aircraft_typw)
{
case 1:printf("jjj机\n"); break;
case 2:printf("yjj\n"); break;
case 3:printf("xxdd\n"); break;
case 4:printf("hzj\n"); break;
default: cout <<"产生错误 " < }
}
else
{
{
aircraft_typw = getinair_type(aircraft_typw);
}
cout <<"目标类型指定为 ";
switch (aircraft_typw)
{
case 1:printf("jjj\n"); break;
case 2:printf("yjj\n"); break;
case 3:printf("xhdd\n"); break;
case 4:printf("hzj\n"); break;
default: cout <<"产生错误 " < }
}
return aircraft_typw;
}
//状态机二
int state2th(int atypes2th)
{
WNDCLASS wndclass;
HINSTANCE hinst = GetModuleHandle(NULL);
//HINSTANCE hInstance AfxGetInstanceHandle();//句柄到当前实例
static TCHAR Myname[] = TEXT("MyWindow");
//std::string sundog="窗口";
//LPCTSTR Myname =(LPCTSTR)sundog.data;
wndclass.style =CS_HREDRAW | CS_VREDRAW; // 窗口类型为缺省类型
wndclass.lpfnWndProc = WndProc; //定义窗口处理函数
wndclass.cbClsExtra = 0; //窗口类无扩展
wndclass.cbWndExtra = 0; //窗口实例无扩展
wndclass.hInstance =hinst; //当前实例句柄
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);//窗口的最小化图标为缺省图标
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); // 窗口采用箭头光标
wndclass.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH)); //窗口背景为白色
wndclass.lpszMenuName = NULL; //窗口无菜单
wndclass.lpszClassName = Myname;
return 0;
}
int main()
{
int airtp;//代表目标类型
string nextkey;
airtp=stateone();
cout<<"按任意键继续 生成航迹" < cin>>nextkey;
/*
测试代码 没啥用
int testOne= 0;
cin >> testone;
if(testOne==1)
*/
state2th(airtp);
while (1);
return 0;
} |