Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

porting a dos apllication to win2k

Status
Not open for further replies.

vitellozzo

Programmer
Oct 15, 2003
8
IT
Hello
I've recently used pdcurses to port a dos program under win2k, using vc++ 6.
In my program there is while loop, which must continue (non blocking keyboard read)until the escape character is pressed.
The problem is that i must press it twice to stop the loop and if i press other buttons (before esc)there is a longer delay.
The code is:
... var,def,etc
initscr();
noecho();
cbreak();
nodelay(stdscr,TRUE);
if(has_colors()==FALSE)
{...}
start_color();
init_pair(1,COLOR_WHITE,COLOR_BLUE);
attron(COLOR_PAIR(1));
bkgd(COLOR_PAIR(1));
clear();
....other c code
refresh();
.... other c code
do
{
...other c code plus various refreshes and mvprintw
}while(getch()!=27);

if i put while(getch()==ERR) and press two buttons simultanousely the application exit correctly.
I prefer don't use kbhit() because other libraries conflict with conio.h (and i must use them :()
thanks in advance
V.
 
in windows you do usualy a new thread when you want a paralel execution:

#include<windows.h>
#include<conio.h>
#include<stdio.h>

int run = 0;
/*the paralel execution of something*/
DWORD WINAPI ThreadProc(void* xx)
{
int i = 0;
while(run)
{
Sleep(50);/*saving processor resource*/
i++;
printf(&quot;hello %d\n&quot;, i);
}

return 0;
}
int main()
{

int cch;
int ch;
ULONG th_id;
HANDLE hThreadSvr = 0;
run = 1;/*allow thread running*/
hThreadSvr = CreateThread(0, 0, ThreadProc, (void*)0, 0, &th_id);
while(1)
{
int cch = getch();
if(!cch)ch = getch();/*control key*/
if(cch == 27)
{
run = false;
break;
}
}
run = 0;/*stop thread running*/

return 0;

}

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top