[C win] clock.c - salvaschermo

C & C++ , problemi, richieste e progetti.

Moderators: Bit, ScorpionIT

[C win] clock.c - salvaschermo

Postby NorbiX on Fri Jan 04, 2008 5:14 pm

orologio salvaschermo, si adatta alle dimensioni della console, potete metterlo anche a tutto schermo

con questo ci sono esempi sull'uso dei puntatori e dell'operatore di indirezione * -> MOLTO IMPORTANTE ED ISTRUTTIVO

poi.. winapi, funzioni, strutture, strutture di strutture (^^'), basta credo

clock.c
Code: Select all
// clock, syncronized with local time, by N0R81X - xibron[at]gmail[dot]com

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

void clock(void);
void gotoXY(int x, int y);
void getresolution(int *x, int *y);
void hidecursor(void);

int main()
{
     clock();
}

void clock(void)
{
     int i, width, height, posX, posY;
     SYSTEMTIME lt;

     getresolution(&width, &height);
     hidecursor();

     posX = 1 + rand() % (width - 25);
     posY = 1 + rand() % (height - 3);

     for(i = 0;; i++)
     {
          GetLocalTime(&lt);

          if(i == 2000/50) // change position every 2000ms
          {
               gotoXY(posX, posY-1);
               printf("                         ");
               gotoXY(posX, posY);
               printf("                         ");
               gotoXY(posX, posY+1);
               printf("                         ");

               getresolution(&width, &height);

               posX = 1 + rand() % (width - 25 - 1);
               posY = 1 + rand() % (height - 3 - 1);

               i = 0;
          }

          gotoXY(posX, posY-1);
          printf(" ----------------------- ");
          gotoXY(posX, posY);
          printf("| %02d/%02d/%04d - %02d:%02d.%02d |", lt.wDay, lt.wMonth, lt.wYear, lt.wHour, lt.wMinute, lt.wSecond);
          gotoXY(posX, posY+1);
          printf(" ----------------------- ");

          // printf("%02d/%02d/%04d - %02d:%02d.%02d", lt.wDay, lt.wMonth, lt.wYear, lt.wHour, lt.wMinute, lt.wSecond);

          _sleep(50);
     }
}

void gotoXY(int x, int y)
{
     HANDLE h_stdout;
     COORD coord;

     coord.X = x;
     coord.Y = y;

     h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
     SetConsoleCursorPosition(h_stdout, coord);
}

void getresolution(int *x, int *y)
{
     CONSOLE_SCREEN_BUFFER_INFO c_info;
     HANDLE h_stdout;

     h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
     GetConsoleScreenBufferInfo(h_stdout, &c_info);

     *x = c_info.srWindow.Right;
     *y = c_info.srWindow.Bottom;
}

void hidecursor(void)
{
     HANDLE h_stdout;
     CONSOLE_CURSOR_INFO cur_info;

     cur_info.dwSize = 1; // percentuale della dimensione (1-100)
     cur_info.bVisible = FALSE; // visibilità del cursore

     h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
     SetConsoleCursorInfo(h_stdout, &cur_info);
}


ma la febbre mi ha fatto diventare più intelligente? non ricordavo che le api di windows fosserò così facili da usare, con tutti quei puntatori e quegli indirizzi di memoria da passare..... quasi quasi oserei dire che la microsoft ha fatto un buon lavoro con quelle api

ciao!
#include <antisocialbastard>

anti-social_bastard_init(&norbix);
User avatar
NorbiX
Array[]
 
Posts: 722
Joined: Fri Jul 14, 2006 11:14 am
Location: Inside the N.A.K.

[C win] clock.c - salvaschermo

Sponsor

Sponsor


Return to C/C++

Who is online

Users browsing this forum: No registered users and 1 guest

cron