有兴趣的来看看,期待有人解答
////2017-11-5///
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
# include <conio.h>
# include <windows.h>
# include <pthread.h>
# include <string.h>
# include <time.h>
HANDLE output (char * str , HANDLE hOut , COORD xy)
{
if (hOut == NULL)
hOut = GetStdHandle (STD_OUTPUT_HANDLE);
WriteConsoleOutputCharacterA (hOut , str , strlen (str) , xy , NULL);
return hOut;
}
HANDLE CreateBuffer (void)
{
HANDLE hOutBuffer = CreateConsoleScreenBuffer (GENERIC_READ | GENERIC_WRITE , FILE_SHARE_READ | FILE_SHARE_WRITE ,
NULL , CONSOLE_TEXTMODE_BUFFER , NULL);
return hOutBuffer;
}
struct param
{
HANDLE hOutBuffer;
HANDLE hOut;
COORD xy;
};
void * fun (void * p)
{
param * Param = (param *)p;
char cmd[260];
char times[260];
struct tm *pt;
time_t t;
DWORD n;
while (true && !GetAsyncKeyState (VK_ESCAPE))
{
t = time (NULL);
pt = localtime (&t);
memset (times , 0 , sizeof (times));
memset (cmd , 0 , sizeof (cmd));
sprintf (cmd , "%d:%d:%d" , pt->tm_hour , pt->tm_min , pt->tm_sec);
output (cmd , Param->hOutBuffer , Param->xy);
ReadConsoleOutputCharacterA (Param->hOutBuffer , times , strlen (cmd) , Param->xy , &n);
output (times , Param->hOut , Param->xy);
Sleep (500);
FillConsoleOutputCharacterA (Param->hOut , ' ' , strlen (cmd) , Param->xy , NULL);
}
return 0;
}
void CreateLine (HANDLE hOutBuffer , HANDLE hOut , COORD xy)
{
param p = {hOutBuffer , hOut , xy};
pthread_t thid;
pthread_attr_t attr;
pthread_attr_init (&attr);
pthread_attr_setdetachstate (&attr , PTHREAD_CREATE_JOINABLE);
pthread_attr_setscope (&attr , PTHREAD_SCOPE_PROCESS);
pthread_create (&thid , &attr , fun , &p);
pthread_detach (thid);
}
int main (void)
{
char * str = "\0";
COORD xy = {10 , 10};
HANDLE hOut , hOutBuffer;
hOut = output (str , NULL , xy);
hOutBuffer = CreateBuffer ();
CreateLine (hOutBuffer , hOut , xy);
COORD XY = {10 , 20};
getch ();
output ("你好!" , hOut , XY);
getch ();
return 0;
}
在主函数里,当我加上output ("你好!" , hOut , XY);这一句的时候,为什么前面的时间不显示了呢?