Guest User

Untitled

a guest
Jan 17th, 2016
173
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #define ID_TIMER 1
  4. #define ID_SECONDS 2
  5. #define ID_MINUTES 3
  6. #define ID_HOURS 4
  7.  
  8. const char classname[] = "someClassName";
  9. LPCSTR lpcClassname = "wind title";
  10. int timer[3] = {0, 0, 0};
  11.  
  12. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  13.  
  14.  
  15. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, // inchide ochii si imagineaza int main()
  16.     LPSTR lpCmdLine, int nCmdShow)
  17. {
  18.     WNDCLASSEX wc;
  19.     HWND hwnd;
  20.     MSG msg;
  21.  
  22.     wc.cbSize = sizeof(WNDCLASSEX);
  23.     wc.style = CS_HREDRAW | CS_VREDRAW;
  24.     wc.lpfnWndProc = WndProc;
  25.     wc.cbClsExtra    = 0;
  26.     wc.cbWndExtra    = 0;
  27.     wc.hInstance     = hInstance;
  28.     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);  
  29.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  30.     wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  31.     wc.lpszMenuName  = NULL;
  32.     wc.lpszClassName = classname;
  33.     wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  34.  
  35.  
  36.       if(!RegisterClassEx(&wc))
  37.     {
  38.         MessageBox(NULL, "Window Registration Failed!", "Error!",
  39.             MB_ICONEXCLAMATION | MB_OK);
  40.         return 0;
  41.     }
  42.  
  43.  
  44.    
  45.     hwnd = CreateWindowEx(
  46.         WS_EX_OVERLAPPEDWINDOW,
  47.         classname,
  48.         lpcClassname,
  49.         WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX,  
  50.         CW_USEDEFAULT,
  51.         CW_USEDEFAULT,
  52.         850,
  53.         500,
  54.         NULL,
  55.         NULL,
  56.         hInstance,
  57.         NULL );
  58.  
  59.      if(hwnd == NULL)  
  60.     {
  61.         MessageBox(NULL, "Window Creation Failed!", "Error!",
  62.             MB_ICONEXCLAMATION | MB_OK);
  63.         return 0;
  64.     }
  65.  
  66.     ShowWindow(hwnd, nCmdShow);
  67.     UpdateWindow(hwnd);
  68.  
  69.  
  70.    
  71.      while(GetMessage(&msg, NULL, 0, 0) > 0)
  72.     {
  73.         TranslateMessage(&msg);
  74.         DispatchMessage(&msg);
  75.     }
  76.  
  77.     return msg.wParam;
  78. }
  79.  
  80.  
  81.  
  82. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  83. {
  84.     char cTime[16];
  85.     char cDate[10];
  86.     char cTrecut[14];
  87.     char cText[] = "some text";
  88.     char cText2[] = "s";
  89.  
  90.     RECT rect;
  91.  
  92.     switch(msg)
  93.     {
  94.         case WM_PAINT:
  95.         {
  96.             HDC hdc;
  97.             PAINTSTRUCT ps;
  98.  
  99.             SYSTEMTIME st;
  100.  
  101.             hdc = BeginPaint(hwnd, &ps);
  102.             GetLocalTime(&st);
  103.  
  104.             SelectObject(hdc, CreateFont(40, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL))  ;
  105.  
  106.             sprintf(cTime, "%03d:%02d:%02d", st.wHour, st.wMinute, st.wSecond);
  107.             sprintf(cDate, "%02d.%02d.%02d", st.wDay, st.wMonth, st.wYear);
  108.             sprintf (cTrecut, "%02d : %02d : %02d", timer[0], timer[1], timer[2]);
  109.  
  110.             TextOut(hdc, 290, 20, cText, sizeof(cText));
  111.             TextOut(hdc, 353, 60, cTime, sizeof(cTime));
  112.             TextOut(hdc, 348, 100, cDate, sizeof(cDate));
  113.             TextOut(hdc, 200, 250, cText2, sizeof(cText2));
  114.             TextOut(hdc, 353, 300, cTrecut, sizeof(cTrecut));
  115.  
  116.  
  117.             EndPaint(hwnd, &ps);
  118.         }
  119.         break;
  120.  
  121.         case WM_CLOSE:
  122.             if (MessageBox(hwnd, "Are you sure?", lpcClassname, MB_ICONQUESTION | MB_OKCANCEL) == IDOK)
  123.             DestroyWindow(hwnd);
  124.         break;
  125.  
  126.         case WM_CREATE:
  127.             SetTimer(hwnd, ID_TIMER, 1000, NULL);
  128.             SetTimer(hwnd, ID_MINUTES, 60000, NULL);
  129.             SetTimer(hwnd, ID_HOURS, 3600000, NULL);
  130.  
  131.         break;
  132.  
  133.         case WM_TIMER:
  134.  
  135.             switch(wParam)
  136.             {
  137.                 case ID_TIMER:
  138.                     if (timer[2] == 59)
  139.                         timer[2] = 0;
  140.                     else
  141.                         timer[2]++;
  142.  
  143.                 break;
  144.  
  145.                 case ID_MINUTES:
  146.                     if (timer[1] == 59)
  147.                         timer[1] = 0;
  148.                     else
  149.                         timer[1]++;
  150.  
  151.                 break;
  152.  
  153.                 case ID_HOURS:
  154.                     if (timer[0] == 23)
  155.                         timer[0] = 0;
  156.                     else
  157.                         timer[0]++;
  158.  
  159.                 break;
  160.             }
  161.             InvalidateRect(hwnd, NULL, false);
  162.  
  163.         break;
  164.  
  165.         case WM_DESTROY:
  166.             KillTimer(hwnd, ID_TIMER);
  167.             PostQuitMessage(0);
  168.         break;
  169.  
  170.         default:
  171.             return DefWindowProc(hwnd, msg, wParam, lParam);
  172.     }
  173.     return 0;
  174. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×