Tatiana_Suszkiewicz
Newbie | Ðåäàêòèðîâàòü | Ïðîôèëü | Ñîîáùåíèå | Öèòèðîâàòü | Ñîîáùèòü ìîäåðàòîðó ïîìîãèòå, ïîæàëóéñòà, â çàäà÷å ÷àñû äîëæíû ñìåíÿòüñÿ, êîãäà íàæèìàåøü íà ñîîòâåòñòâóþùóþ êíîïêó, íî ñòðåëî÷íûå ÷àñû íå òîëüêî íå ñìåíÿþò ýëåêòðîííûå, îíè íå ïîÿâëÿþòñÿ äàæå åñëè êíîïêè è ýëåêòðîííûå ÷àñû íå âêëþ÷àòü â êîä Êîä: #include "stdafx.h" #include "chasy.h" #include <time.h> #include <windows.h> #include <windowsx.h> #include <cmath> #include <iostream> using namespace std; #define ID_BUTTON1 100 #define ID_BUTTON2 200 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); void STRELKA (COLORREF, int, int, float); int nFunsterStil; int iwinX = 400, iwinY = 40, iwinXC = iwinX - 150, iwinYC = iwinY; int iDia = 400, iHeight = iDia + 40, iWidth = iDia + 165, iRad = iDia / 2, sizFont = int (iDia / 6.7); int iKorp = 8, iMetM = 3, iMetH = 5; int iRadMet = iRad - iKorp, iRadCFR = iRadMet - sizFont / 2 - iMetH; int penwKorp = 2, penwCfrbl = 2, penwmM = 2, penwmH = 3; COLORREF colKorp = RGB (0, 0, 0), colCfrbl = RGB (150, 150, 150), colStrMH = colKorp, colStrS = RGB (230, 230, 230), colmM = colKorp, colmH = colKorp, colCfr = colKorp; HWND hwnd; HDC hdcMem0, hdcMem, hdc; HBITMAP hBitmap, hOldBitmap; BITMAP bm; PAINTSTRUCT ps; HBRUSH br; HPEN pen; HFONT hFontO, hOldFont; MSG mMsg; LPCTSTR szClassName = L"WindowsApp"; int WINAPI WinMain (HINSTANCE hInst, HINSTANCE, LPSTR, int) { LPCTSTR szClassName = L"MainWindow"; LPCTSTR szTitle = L"CLOCK"; MSG msg; WNDCLASS wc; static HWND hbutton,hbutton2; ZeroMemory (&wc, sizeof (wc)); wc.lpszClassName = szClassName; wc.hInstance = hInst; wc.lpfnWndProc = WndProc ; wc.hCursor = LoadCursor (NULL, IDC_ARROW) ; wc.hIcon = LoadIcon (hInst, L"icon") ; wc.hbrBackground = GetStockBrush (GRAY_BRUSH); RegisterClass (&wc); hwnd = CreateWindow (szClassName, szTitle, WS_OVERLAPPEDWINDOW, iwinX, iwinY, iWidth, iHeight, HWND_DESKTOP, NULL, hInst, NULL); hbutton = CreateWindow(L"button",L"Öèôðîâûå ÷àñû",WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,iDia,50,150,30,hwnd,(HMENU)ID_BUTTON1,hInst,0); hbutton2 = CreateWindow(L"button",L"Ýëåêòðîííûå ÷àñû",WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,iDia,150,150,30,hwnd,(HMENU)ID_BUTTON2,hInst,0); ShowWindow (hwnd, SW_SHOWNORMAL); while (GetMessage (&msg, NULL, 0, 0)) DispatchMessage (&msg); DeleteObject (hwnd); return 0; } LRESULT CALLBACK WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { static int i; switch (msg) { case(WM_CREATE): { SetWindowPos (hwnd, NULL, iwinX, iwinY, iWidth, iHeight, SWP_NOSIZE); hdc = GetDC (hwnd); hdcMem = CreateCompatibleDC (hdc); hdcMem0 = CreateCompatibleDC (hdc); hBitmap = CreateCompatibleBitmap (hdc, iDia, iDia); GetObject (hBitmap, sizeof (BITMAP), &bm); hOldBitmap = SelectBitmap (hdcMem0, hBitmap); //CYFERBL (hwnd); } case(WM_TIMER): { InvalidateRect (hwnd, NULL, FALSE); } case(WM_COMMAND): { switch(LOWORD(wParam)) { case ID_BUTTON1: { HDC hdc = GetDC(hwnd); i = 1; SendMessage(hwnd,WM_PAINT,wParam,lParam); ReleaseDC(hwnd,hdc); return 0; } case ID_BUTTON2: { HDC hdc = GetDC(hwnd); i = 2; SendMessage(hwnd,WM_PAINT,wParam,lParam); ReleaseDC(hwnd,hdc); return 0; } } } case(WM_PAINT): { RECT rect; BeginPaint (hwnd, &ps); int ii, jj, iX, iY, iXc, iYc, t = 0; double fUgol, fUgolc; static int iLength; char cBuffer [80]; SYSTEMTIME chas; GetLocalTime (&chas); if(i==1) { br = CreateSolidBrush (RGB (100, 100, 100)); //ôîí SelectObject (hdcMem0, br); Rectangle (hdcMem0, 0, 0, iDia, iDia); DeleteObject (br); hdcMem = BeginPaint (hwnd, &ps); if(BitBlt) DeleteObject (BitBlt); BitBlt (hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem0, 0, 0, SRCCOPY); float strUgolS, strUgolM, strUgolH; SetTimer (hwnd, 1, 1000, NULL); pen = CreatePen (PS_SOLID, 1, colKorp); //îáîä ÷àñîâ SelectObject (hdcMem0, pen); br = CreateSolidBrush (colKorp); SelectObject (hdcMem0, br); Ellipse (hdcMem0, 0, 0, iDia, iDia); DeleteObject (br); DeleteObject (pen); br = CreateSolidBrush (colCfrbl); //öèôåðáëàò SelectObject (hdcMem0, br); Ellipse (hdcMem0, iKorp, iKorp, iDia - iKorp, iDia - iKorp); DeleteObject (br); pen = CreatePen (PS_SOLID, penwmM, colmM); SelectObject (hdcMem0, pen); for (ii = 1; ii <= 60; ii ++) //ðàçäåëåíèå íà ñåêóíäû { fUgol = - 0.017453292 * 6 * ii; iX = iRad - int(iRadMet * sin (fUgol)); iY = iRad - int(iRadMet * cos (fUgol)); MoveToEx (hdcMem0, iX, iY, NULL); iX = iRad - int((iRadMet - iMetM) * sin (fUgol)); iY = iRad - int((iRadMet - iMetM) * cos (fUgol)); LineTo (hdcMem0, iX, iY); } DeleteObject (pen); pen = CreatePen (PS_SOLID, penwmH, colmH); SelectObject (hdcMem0, pen); for (ii = 1; ii <= 12; ii ++) //ðàçáèåíèå íà ÷àñû { fUgol = - 0.017453292 * 30 * ii; iX = iRad - int(iRadMet * sin (fUgol)); iY = iRad - int(iRadMet * cos (fUgol)); MoveToEx (hdcMem0, iX, iY, NULL); iX = iRad - int((iRadMet - iMetH) * sin (fUgol)); iY = iRad - int((iRadMet - iMetH) * cos (fUgol)); LineTo (hdcMem0, iX, iY); } DeleteObject(pen); static LOGFONT lf; lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN; lf.lfItalic = FALSE; lf.lfWeight = FW_BOLD; lf.lfHeight = sizFont; lf.lfCharSet = DEFAULT_CHARSET; lstrcpy ((LPWSTR)&lf.lfFaceName, L"Impact"); hFontO = CreateFontIndirect (&lf); hOldFont = (HFONT) SelectObject (hdcMem0, hFontO); SetBkMode (hdcMem0, TRANSPARENT); SetTextColor (hdcMem0, colCfr); char ttt1 [80]; for (jj = 1; jj <= 12; jj ++) //öèôðû { fUgolc = -0.017453292 * 30 * jj; iXc = iRad - int(iRadCFR * sin (fUgolc)) - sizFont / 4; iYc = iRad - int(iRadCFR * cos (fUgolc)) - sizFont / 2; wsprintf ((LPWSTR) ttt1, L"%d", jj); TextOut (hdcMem0, iXc, iYc, (LPCWSTR) ttt1, 2 * strlen (ttt1)); } strUgolS = -0.017453292 * 6 * chas.wSecond; strUgolM = -0.017453292 * 6 * chas.wMinute + strUgolS / 60; strUgolH = -0.017453292 * 30 * chas.wHour + strUgolM / 12; STRELKA (colStrMH, 0.6*iRadMet - 4 * iMetH - iMetM, 2, strUgolH); //÷àñîâàÿ STRELKA (colStrMH, 0.8*iRadMet - iMetH - iMetM, 2, strUgolM); //ìèíóòíàÿ STRELKA (colStrS, iRadMet - iMetH - iMetM, 1, strUgolS); //ñåêóíäíàÿ pen = CreatePen (PS_SOLID, 1, colStrMH); br = CreateSolidBrush (colStrMH); SelectBrush (hdcMem, br); Ellipse (hdcMem, iRad - 3, iRad - 3, iRad + 3, iRad + 3); DeleteObject (br); DeleteObject (pen); } if(i==2) { br = CreateSolidBrush (RGB (100, 100, 100)); //ôîí SelectObject (hdcMem0, br); Rectangle (hdcMem0, 0, 0, iDia, iDia); DeleteObject (br); hdcMem = BeginPaint (hwnd, &ps); BitBlt (hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem0, 0, 0, SRCCOPY); SetTimer (hwnd, 1, 1000, NULL); wsprintf ((LPWSTR)cBuffer + iLength, L"%d:%d:%d", chas.wHour, chas.wMinute, chas.wSecond); GetClientRect (hwnd, &rect); rect.top = 200; rect.left = 200; TextOut(hdc,rect.left,rect.top,(LPCWSTR) cBuffer,8*strlen(cBuffer)); } EndPaint (hwnd, &ps); return 0; } case(WM_DESTROY): { KillTimer (hwnd, 1); DeleteBitmap (hBitmap); SelectBitmap (hdcMem, hOldBitmap); DeleteDC (hdcMem); DeleteDC (hdcMem0); PostQuitMessage (0); } default: return (DefWindowProc (hwnd, msg, wParam, lParam)); } } void STRELKA (COLORREF colStr, int radSTR, int shirSTR, float strUgol) { int okrR = 3 * shirSTR; int penwSTR = 2; int strX1 = iRad + int(0.3 * radSTR * sin (strUgol) - shirSTR * cos (strUgol)); int strY1 = iRad + int(0.3 * radSTR * cos (strUgol) + shirSTR * sin (strUgol)); int strX2 = iRad + int(0.3 * radSTR * sin (strUgol) + shirSTR * cos (strUgol)); int strY2 = iRad + int(0.3 * radSTR * cos (strUgol) - shirSTR * sin (strUgol)); int strX = iRad - int(radSTR * sin (strUgol)); int strY = iRad - int(radSTR * cos (strUgol)); POINT pt [3] = {{strX1, strY1}, {strX2, strY2}, {strX, strY}}; pen = CreatePen (PS_SOLID, penwSTR, colStr); SelectObject (hdcMem, pen); br = CreateSolidBrush (colStr); SelectObject (hdcMem, br); Polygon (hdcMem, pt, 3); Ellipse (hdcMem, iRad - okrR, iRad - okrR, iRad + okrR, iRad + okrR); DeleteObject (br); DeleteObject (pen); } |
|