Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,
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>


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?
Posted

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.
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900