问题描述
(小白)我想在自己的“命令行程序”进行到一定时候,创建一个蓝背景的窗口(之后用于画曲线)赋值就卡住了:
//状态机二int state2th(int atypes2th){ typedef struct _WNDCLASS {UINT style; //定义窗口的风格 WNDPROC lpfnWndProc; //指向窗口过程函数的指针int cbClsExtra;//为窗口类结构体,确定需要额外分配多少字符数的空间,默认为0int cbWndExtra;//为实例窗口,确定需要额外分配多少字符数的空间,默认为0HANDLE hInstance; //指向实例窗口的句柄HICON hIcon; //窗口的图标HCURSOR hCursor; //窗口的光标HBRUSH hbrBackground; //指向画刷的句柄LPCTSTR lpszMenuName; //指向菜单名称的指针LPCTSTR lpszClassName; //指向窗口名称的指针 } WNDCLASS; WNDCLASS.style =UINT( CS_HREDRAW | CS_VREDRAW); return 0;}
完整程序:
#include 'stdafx.h'#include<iostream>#include<string>#include<windows.h>#include <time.h> //用到了time函数 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.歼击机 2.预警机'<<endl<<'3.* 4.轰炸机'<<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('歼击机n'); break;case 2:printf('预警机n'); break;case 3:printf('*n'); break;case 4:printf('轰炸机n'); break;default: cout << '产生错误 ' << endl;} } else {{ aircraft_typw = getinair_type(aircraft_typw);}cout << '目标类型指定为 ';switch (aircraft_typw){case 1:printf('歼击机n'); break;case 2:printf('预警机n'); break;case 3:printf('*n'); break;case 4:printf('轰炸机n'); break;default: cout << '产生错误 ' << endl;} } return aircraft_typw;}//状态机二int state2th(int atypes2th){ typedef struct _WNDCLASS {UINT style; //定义窗口的风格 WNDPROC lpfnWndProc; //指向窗口过程函数的指针int cbClsExtra;//为窗口类结构体,确定需要额外分配多少字符数的空间,默认为0int cbWndExtra;//为实例窗口,确定需要额外分配多少字符数的空间,默认为0HANDLE hInstance; //指向实例窗口的句柄HICON hIcon; //窗口的图标HCURSOR hCursor; //窗口的光标HBRUSH hbrBackground; //指向画刷的句柄LPCTSTR lpszMenuName; //指向菜单名称的指针LPCTSTR lpszClassName; //指向窗口名称的指针 } WNDCLASS; WNDCLASS.style =UINT( CS_HREDRAW | CS_VREDRAW); return 0;}int main(){ int airtp;//代表目标类型 1 歼击机 2预警机 3* 4轰炸机 string nextkey; airtp=stateone(); cout<< '按任意键继续 生成航迹' << endl; cin>>nextkey; /* 测试代码 没啥用int testone = 0;cin >> testone;if(testone==1) */state2th(airtp); while (1); return 0;}几个额外问题:
1.之后我还想继续在上面曲线,曲线上点的位置我已经想好怎么算了,用什么函数 或者 组件好用?GDI?2.等我再搞几个这样的程序后,应该用c++,c#?还是其他的编,感觉win32根本跟不上了
问题解答
回答1:好吧 我很逗比的把标准的申明有粘了一遍