如何在VC6.0中将控制台应用程序代码转换为MFC应用程序? [英] How can I turn my console application code into MFC application in VC6.0?

查看:114
本文介绍了如何在VC6.0中将控制台应用程序代码转换为MFC应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,你好,
我写了一个控制台应用程序.但是它并不漂亮,我想将其转换为VC6.0中的MFC/SDK应用程序.代码如下:

 #include   <   stdio.h  > 

#include   ><  > 
 #include   " 
 #include   <   stdlib.h  > 

#pragma注释(lib,"ws2_32.lib")

字符 * ip;
字符 add [] = " ;

// 此功能用于获取本地IP地址
字符 * CheckIP( void )// 定义CheckIP()函数
{
    WSADATA wsaData;
    字符名称[ 255 ];

    PHOSTENT hostinfo;

    // 指示MAKEWORD()获取Winsock版本
    如果(WSAStartup(MAKEWORD( 2  0 ),& wsaData)==  0 )
    {


         if (gethostname(name, sizeof (name))==  0 ){

            如果((hostinfo = gethostbyname(name))!= NULL){

                ip = inet_ntoa(*( struct  in_addr *)* hostinfo-> h_addr_list);

                printf(" ,ip); // 放置
            }
        }
        WSACleanup();
    }
    返回 ip;
}


 int  main( void )
{
    CheckIP();

    strcat(add,ip);

    系统(添加);
   /*  在VC ++ 6.0的MFC/SDK中,我可以编写哪些代码将此功能替换为相同的功能?应用程序运行后,黑色控制台窗口不会出现
*/


    系统(" );
    返回  0 ;
} 


有人可以帮我吗?告诉我您的代码.
预先表示感谢.

解决方案

假定您具有支持MFC的Visual Studio或Visual C ++版本,则可以使用新建项目"向导来创建基本的MFC示例.并根据需要添加自己的代码. MSDN网站上有许多示例可以帮助您.


在Visual Studio中启动新的MFC应用程序,然后将代码复制到适当的位置.

您可以使用Microsoft Visual Studio创建Win32或MFC APP.使用CreateWindow API创建按钮和文本框.

在WM_CREATE上:编写逻辑以找到Ip地址并显示在文本框中,或创建按钮事件以在文本框中显示输出


Hello,everyone,
I wrote a console app..But it''s not beautiful, I want to turn it into MFC/SDK application in VC6.0. the code is as follow:

#include<stdio.h>

#include<winsock2.h>
#include"windows.h"
#include<stdlib.h>

#pragma comment(lib,"ws2_32.lib")

char *ip;
char add[]="route -p add 0.0.0.0 mask 0.0.0.0 ";

// this function is to get local ip address
char *CheckIP(void) //define CheckIP() function
{
    WSADATA wsaData;
    char name[255];

    PHOSTENT hostinfo;

    //instruct MAKEWORD() get Winsock version
    if ( WSAStartup( MAKEWORD(2,0), &wsaData ) == 0 )
    {


        if( gethostname ( name, sizeof(name)) == 0) {

            if((hostinfo = gethostbyname(name)) != NULL) {

                ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);

                printf("\n    Your IP is :%s\n",ip); // put
            }
        }
        WSACleanup( );
    }
    return ip;
}


int main(void)
{
    CheckIP();

    strcat(add,ip);

    system(add);
   /* What code can I write to replace this function with the same function in MFC/SDK in VC++6.0? And the black console window don't appear after the application running
*/


    system("pause");
    return 0;
}


Could someone help me? Show me your code.
Thanks in advance.

解决方案

Assuming that you have a version of Visual Studio or Visual C++ that supports MFC then you can use the New Project wizard to create a basic MFC sample and add your own code as appropriate. There are many samples available on the MSDN site to help you.


Start a new MFC application in Visual Studio, and copy your code into it in the appropriate place(s).


hi create a win32 or MFC APP using Microsoft Visual studio. create a button and a text box using CreateWindow API.

on the WM_CREATE: write your logic to find the Ip address and display in the Text Box or Create a button event to display your output in the Text Box


这篇关于如何在VC6.0中将控制台应用程序代码转换为MFC应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆