简体   繁体   中英

How can I convert project win32 console application into C++ Windows Form?

How can I convert project win32 console application into C++ Windows Form? This is my win32 console code but I want to convert it in C++ Windows Form.

#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<string>
#include<iostream>

using namespace std;

const char TAB='\t';
char varlook;
char s[100];
char name[10];




char str[100],str1[100],str2[100],str3[100],str4[100],var[100];
    int i=0,l,l1,j=0,k=0,d=0;   
    int m=0;
    char keyword[100][100]={"int","float","char","double","if","else","for","while","do","auto","break","case","const",
                            "switch","continue","enum","extern","goto","short","register","return","sizeof","static",
                            "struct","typedef","union","void","while","signed","unsigned","default"};
void main(void)
{
gets(str);
while(str[i]!='\0')
{
while(isspace(str[i]))
i++;
if(isalpha(str[i]))
{
k=0;
while(isalnum(str[i]))
{
str1[k]=str[i];
i++;
k++;
}
str1[k]='\0';
l=0;
while(j<100)
{
if (strcmp(str1,keyword[j])==0)
{
l=1;
break;
}
j++;
}
if(l==1)
{
printf("\n   %s    ERROR- it is keyword ",str1);
break;
}
else
{
printf("\n   %s    Valid Identifier ",str1);
break;
l=0;
while(str1[l]!='\0')
{
var[m++]=str1[l++];
}
}
}
else if (isdigit(str[i]))
{
k=0;
while(isalnum(str[i]) || str[i]=='.')
{
if(str[i]=='.')
d++;
str2[k++]=str[i++];
}
printf("\n   %s    ERROR- it is digit ",str2);
break;
}
}

getche();
}

How can I convert project win32 console application into C++ Windows Form? This is my win32 console code but I want to convert it in C++ Windows Form.

I think this might work:

Right-click the project, Properties, Linker, System, change the SubSystem setting. You'll also have to change your main() method to WinMain(). And you'd better create some windows or there won't be much to look at.

You can utilize C++/CLI

Create a CLR empty project. Add a new item Visual C++ / UI / Windows Form called MyForm add in MyForm.cpp

int main()
{
  Project1::MyForm^ dlg = gcnew Project1::MyForm;
  dlg->ShowDialog();
}

Then go and design your UI by adding a textbox for input, a button to evaluate the content and a label to show the result.

Add an event handler for the button, when you press the button read the contents of the textbox and display the result by putting it in the label box.

This will give you a barebone program but at least it gives you a quick framework.

I would suggest you use a more C++ way of specifying keywords eg with a std::vector or std::map - makes things so much easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM