将控制台应用程序更改为表单应用程序 [英] Changing Console Application to Form Application

查看:87
本文介绍了将控制台应用程序更改为表单应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试将控制台应用程序转换为Windows窗体应用程序,但是我是窗体应用程序的新手.您能帮我转换这部分代码吗?


i am trying to convert console application to windows form application but i am newbie at Form applications. Can you help me to convert this part of codes;

<pre lang="cs">do{
        /* poll the payout device and check for events  */
        if(PollPayoutDevice(&amp;pay) == 0){
            exitLoop = 1;
        }
        Sleep(100);
        if(_kbhit()){
            /* which command key was hit  */
            switch(getchar()){
            case &#39;x&#39;:  /* end run  */
            case &#39;X&#39;:
                exitLoop = 1;
            break;
            case &#39;p&#39;:  /* Payout a value  */
            case &#39;P&#39;:
                printf(&quot;Enter payout value: &quot;);
                scanf_s(&quot;%d&quot;,&amp;payoutValue);
                if(SetPayOutAmount((unsigned long)payoutValue * pay.TrueValueMultiplier) == 0){
                    exitLoop = 1;
                }
            break;
            case &#39;e&#39;: /* empty the payout  */
            case &#39;E&#39;:
                printf(&quot;\nEmptying command sent...\n&quot;);
                if(EmptyPayout()== 0){
                    exitLoop = 1;
                }
                /* enable payout for operations after emptying  */
                if(EnablePayout(&amp;pay) == 0){
                    exitLoop = 1;
                }
            break;
            case &#39;f&#39;:
            case &#39;F&#39;:
                /* TO DO - add function for float command  */
            break;


            }
        }


    }while(!exitLoop);</pre>



在这段代码中,我想实现按钮而不是大小写,但是我遇到这样的问题:我的PollPayoutDevice方法必须始终处于while范围内.当我使用按钮时,程序停止运行,并且仅执行button_click方法中说明的操作.



in this code i want to implement buttons instead of cases but i have a problem like this: My PollPayoutDevice methods must be in while scope all the time. When i use buttons the program stop running and only doing what is explained in button_click methods. How can i fix this?

推荐答案

好吧,我想您需要了解控制台和Win应用程序之间的区别. Windows应用程序是事件驱动的,因此,当您单击按钮时,它将触发一个事件,然后您可以根据需要进行处理.但是在方法范围的尽头,您就走了.

如果需要连续运行,则需要一个线程.因此,您正在寻找的是多线程Windows应用程序.实施起来并不难,但我建议您先阅读一下.
Well, I guess you need to understand the difference between console and win application. Windows application is event driven, so, when you click a button it fires an event and you handle it how ever you want. But at the end of the scope of your method you are gone.

If you need to run continuously then you need a thread. So, what you looking is multi-threaded windows application. It is not hard to implement, but I suggest you read about it first.


快速"答案是手动".创建一个新项目(基于对话框的,sdi或mdi),然后将代码手动移至该项目.当我说这将是最简单的方法时,请相信我.
The "quick" answer is "manually". Create a new project (either dialog based, sdi, or mdi), and manually move your code to it. Believe me when I say this will be the easiest approach.


这篇关于将控制台应用程序更改为表单应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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