Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Visual C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 29.05.2010, 11:23   #1
Namie
Новичок
Джуниор
 
Регистрация: 29.05.2010
Сообщений: 2
По умолчанию Создать свойство на (Visual studio)

как создать свойство отображающее системное время
Namie вне форума Ответить с цитированием
Старый 03.06.2010, 23:02   #2
Ytpyfqrf
Пользователь
 
Регистрация: 27.05.2009
Сообщений: 11
По умолчанию

Код:
#include <windows.h>
#include <time.h>

#define ID_TIMER 1

#define YEAR  (datetime->tm_year % 100)
#define MONTH (datetime->tm_mon +1)
#define MDAY (datetime->tm_mday)
#define WDAY (datetime->tm_wday)
#define HOUR (datetime->tm_hour)
#define MIN (datetime->tm_min)
#define SEC (datetime->tm_sec)

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void SizeTheWindow(int *, int *, int *, int *);

char  sDate[2], sTime[2], sAMPM[2][5];
int iDate, iTime;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
     static char szAppName[]="DigClock";
     HWND hwnd;
     MSG msg;
     int xStart, yStart, xClient, yClient;
     WNDCLASSEX  wndclass;
 
     wndclass.cbSize = sizeof(wndclass);
     wndclass.style = CS_HREDRAW | CS_VREDRAW;
     wndclass.lpfnWndProc = WndProc;
     wndclass.cbClsExtra = 0;
     wndclass.cbWndExtra = 0;
     wndclass.hInstance = hInstance;
     wndclass.hIcon = NULL;
     wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
     wndclass.hbrBackground =(HBRUSH) GetStockObject(WHITE_BRUSH);
     wndclass.lpszMenuName = NULL;
     wndclass.lpszClassName = szAppName;
     wndclass.hIconSm = NULL;

     RegisterClassEx(&wndclass);

     SizeTheWindow(&xStart, &yStart, &xClient, &yClient);
     hwnd = CreateWindow(szAppName, szAppName,
                WS_POPUP | WS_DLGFRAME | WS_SYSMENU,
                xStart, yStart, xClient, yClient, NULL, NULL, hInstance, NULL);

    if(!SetTimer(hwnd, ID_TIMER, 1000, NULL))
    {
      MessageBox(hwnd, "Too many clocks or timers!", szAppName,
                MB_ICONEXCLAMATION | MB_OK);
     return FALSE;
     }

     ShowWindow(hwnd, SW_SHOWNOACTIVATE);
     UpdateWindow(hwnd);

     while(GetMessage(&msg, NULL,0,0))
     {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
     }
     return msg.wParam;
     } 

void SizeTheWindow(int *pxStart,  int *pyStart, int *pxClient, int *pyClient) 
     {
     HDC hdc;
     TEXTMETRIC tm;

     hdc = CreateIC("DISPLAY", NULL, NULL, NULL);
     GetTextMetrics(hdc, &tm);
     DeleteDC(hdc);

     *pxClient= 2*GetSystemMetrics(SM_CXDLGFRAME) + 16*tm.tmAveCharWidth; 
     *pxStart = GetSystemMetrics(SM_CXSCREEN)-*pxClient; 
     *pyClient= 2*GetSystemMetrics(SM_CYDLGFRAME)+2*tm.tmHeight; 
     *pyStart=0;
     }

void SetInternational(void)
     {
     static char cName []="intl";

     iDate=GetProfileInt(cName, "iDate", 0);
     iTime=GetProfileInt(cName, "iTime", 0);

     GetProfileString(cName, "sDate",  "/", sDate, 2);
     GetProfileString(cName, "sTime",  ":", sTime, 2);
     GetProfileString(cName, "s1159", "AM", sAMPM[0], 5);
     GetProfileString(cName, "s2359", "PM", sAMPM[1], 5);
     }
 
void WndPaint(HWND hwnd, HDC hdc)
     {
     static char szWday[]="Sun\0Mon\0Tue\0Wed\0Thu\0Fri\0Sat";
     char cBuffer[40];
     int iLength;
     RECT rect;
     struct tm *datetime;
     time_t lTime;

     time(&lTime);
     datetime=localtime(&lTime);

     iLength=wsprintf(cBuffer, "  %s  %d%s%02d%s%02d  \r\n",
              (PSTR) szWday + 4*WDAY,
               iDate == 1 ? MDAY  : iDate == 2 ? YEAR  : MONTH,(PSTR) sDate, 
               iDate == 1 ? MONTH : iDate == 2 ? MONTH : MDAY, (PSTR) sDate, 
               iDate == 1 ? YEAR  : iDate == 2 ? MDAY  : YEAR); 
 
     if(iTime == 1)
          iLength += wsprintf(cBuffer + iLength, "  %02d%s%02d%s%02d  ", 
                               HOUR,(PSTR) sTime, MIN,(PSTR) sTime, SEC); 
     else 
          iLength += wsprintf(cBuffer + iLength, "  %d%s%02d%s%02d %s  ", 
                              (HOUR % 12) ?(HOUR % 12) : 12, 
                              (PSTR) sTime, MIN,(PSTR) sTime, SEC, 
                              (PSTR) sAMPM [HOUR / 12]); 

     GetClientRect(hwnd, &rect);
     DrawText(hdc, cBuffer, -1, &rect, DT_CENTER | DT_NOCLIP);
     }

LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
     {
     HDC hdc;
     PAINTSTRUCT ps;

     switch(iMsg)
          {
          case WM_CREATE:
               SetInternational();
               return 0;

          case WM_TIMER:
               InvalidateRect(hwnd,NULL,FALSE);
               return 0;

          case WM_PAINT:
               hdc = BeginPaint(hwnd, &ps);
               WndPaint(hwnd, hdc);
               EndPaint(hwnd, &ps);
               return 0;

          case WM_WININICHANGE:
               SetInternational();
               InvalidateRect(hwnd, NULL, TRUE);
               return 0;

          case WM_DESTROY:
               KillTimer(hwnd,ID_TIMER);
               PostQuitMessage(0);
               return 0;
          }
     return DefWindowProc(hwnd, iMsg, wParam, lParam);
     }
Вложения
Тип файла: rar DIGCLOCK.rar (46.1 Кб, 9 просмотров)
Ytpyfqrf вне форума Ответить с цитированием
Старый 03.06.2010, 23:04   #3
Ytpyfqrf
Пользователь
 
Регистрация: 27.05.2009
Сообщений: 11
По умолчанию

покапайся в отладчике:

Код:
#include <windows.h> 
#include <time.h> 

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                    PSTR szCmdLine, int iCmdShow) 
{
	int h;
	struct tm  *datetime; 
	time_t      lTime; 
	time(&lTime); 
	datetime = localtime(&lTime); 
	h=datetime->tm_hour; //это для часа и т.д. 

	return 0; 
}
Ytpyfqrf вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Expression Studio и Visual Studio 2010 ждать ли русские версии? Casper-SC Свободное общение 31 25.05.2010 14:31
Как создать диаграмму классов в Visual Studio? Pti44ka Помощь студентам 0 23.03.2010 21:09
Visual Studio Standard 2008 против Visual Studio Express 2008. Стоит ли покупать? Casper-SC Софт 4 31.12.2009 11:46
VISUAL STUDIO 2008 defaul language - как переключить в VISUAL STUDIO 2008 язык программирования, использ Эйнж Общие вопросы C/C++ 0 27.12.2009 20:39
Visual Studio 2008 Создать RichEdit nusik Общие вопросы C/C++ 0 29.05.2009 08:31