c++ - 在DOS下,如何创建一个窗口用于绘图。

浏览:35日期:2023-04-02

问题描述

程序写了一点,发现应该先用C++的框架创建窗口,现在在DOS下怎么调用windows的一个窗口用于画点画线

#include 'stdafx.h'#include<iostream>#include<string>#include<windows.h>#include <time.h> //用到了time函数 #include <windowsx.h>#include <tchar.h>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 <<sto << endl<< '任意键继续' << endl;cin >> testone; */return sto;}//函数功能:让用户输入数字完成选择目标机型int getinair_type(int atype){ cout << '请输入数字选择目标类型'<<endl<<'1.JJ机 2.YJ机'<<endl<<'3.XXdd 4.HZ'<<endl; cin >> atype; while (atype > 4 || atype < 1) {cout << '输入有误,重新输入' << endl;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 << '请输入数字代表想定生成方式' << endl << '1.完全随机 2.制定目标类型' << endl; cin >> choice_model; if (choice_model == 1) {cout << '选择完全随机'<<endl;aircraft_typw = FUNCaircraft();//取随机数 给机型赋值cout << '目标随机指定为 ';switch (aircraft_typw){case 1:printf('jjj机n'); break;case 2:printf('yjjn'); break;case 3:printf('xxddn'); break;case 4:printf('hzjn'); break;default: cout << '产生错误 ' << endl;} } else {{ aircraft_typw = getinair_type(aircraft_typw);}cout << '目标类型指定为 ';switch (aircraft_typw){case 1:printf('jjjn'); break;case 2:printf('yjjn'); break;case 3:printf('xhddn'); break;case 4:printf('hzjn'); break;default: cout << '产生错误 ' << endl;} } 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<< '按任意键继续 生成航迹' << endl; cin>>nextkey; /* 测试代码 没啥用int testone = 0;cin >> testone;if(testone==1) */state2th(airtp); while (1); return 0;}

问题解答

回答1:

可以试试OpenCV或者octave

相关文章: