1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
//..................
typedef struct MyData {
int val1;
int val2;
} MYDATA, *PMYDATA;
bool A = true;
void Ask(bool A)
{
if (readkey())
A = false;
}
int main ()
{
ClearScreen();
bool A = new bool;
A = true;
PMYDATA pDataArray;
pDataArray = (PMYDATA) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,sizeof(MYDATA));
pDataArray->val1 = 0;
pDataArray->val2 = 100;
CreateThread(NULL,0,MyThreadFunction,pDataArray,NULL,NULL);
SetColor(Blue, White);
CONSOLE_CURSOR_INFO cci;
cci.bVisible = FALSE;
cci.dwSize = 1;
if (!SetConsoleCursorInfo(Global::hStdout,&cci))
cout << GetLastError();
cout << endl << endl << endl << endl << endl;
cout << "\t\tPressing any key when the STOP WATCH is running will stop it.\n\n";
PressAnyKey("\t\tPress any Key to start timer");
ClearScreen();
while (A)
{
gotoxy(27,12);
clock_t TICKS = clock();
cout << Time(TICKS);
Sleep(1000);
ClearScreen();
}
PressAnyKey();
}
//From the Example in MSDN. Have yet to go through it multiple times to
//understand any thing from it
DWORD WINAPI MyThreadFunction( LPVOID lpParam )
{
HANDLE hStdout;
PMYDATA pDataArray;
TCHAR msgBuf[BUF_SIZE];
size_t cchStringSize;
DWORD dwChars;
// Make sure there is a console to receive output results.
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
if( hStdout == INVALID_HANDLE_VALUE )
return 1;
// Cast the parameter to the correct data type.
// The pointer is known to be valid because
// it was checked for NULL before the thread was created.
pDataArray = (PMYDATA)lpParam;
// Print the parameter values using thread-safe functions.
StringCchPrintf(msgBuf, BUF_SIZE, TEXT("Parameters = %d, %d\n"),
pDataArray->val1, pDataArray->val2);
StringCchLength(msgBuf, BUF_SIZE, &cchStringSize);
WriteConsole(hStdout, msgBuf, (DWORD)cchStringSize, &dwChars, NULL);
return 0;
}
|