Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdio.h>
- #define ID_TIMER 1
- #define ID_SECONDS 2
- #define ID_MINUTES 3
- #define ID_HOURS 4
- const char classname[] = "someClassName";
- LPCSTR lpcClassname = "wind title";
- int timer[3] = {0, 0, 0};
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, // inchide ochii si imagineaza int main()
- LPSTR lpCmdLine, int nCmdShow)
- {
- WNDCLASSEX wc;
- HWND hwnd;
- MSG msg;
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = classname;
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- if(!RegisterClassEx(&wc))
- {
- MessageBox(NULL, "Window Registration Failed!", "Error!",
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- hwnd = CreateWindowEx(
- WS_EX_OVERLAPPEDWINDOW,
- classname,
- lpcClassname,
- WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- 850,
- 500,
- NULL,
- NULL,
- hInstance,
- NULL );
- if(hwnd == NULL)
- {
- MessageBox(NULL, "Window Creation Failed!", "Error!",
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- while(GetMessage(&msg, NULL, 0, 0) > 0)
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- char cTime[16];
- char cDate[10];
- char cTrecut[14];
- char cText[] = "some text";
- char cText2[] = "s";
- RECT rect;
- switch(msg)
- {
- case WM_PAINT:
- {
- HDC hdc;
- PAINTSTRUCT ps;
- SYSTEMTIME st;
- hdc = BeginPaint(hwnd, &ps);
- GetLocalTime(&st);
- SelectObject(hdc, CreateFont(40, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL)) ;
- sprintf(cTime, "%03d:%02d:%02d", st.wHour, st.wMinute, st.wSecond);
- sprintf(cDate, "%02d.%02d.%02d", st.wDay, st.wMonth, st.wYear);
- sprintf (cTrecut, "%02d : %02d : %02d", timer[0], timer[1], timer[2]);
- TextOut(hdc, 290, 20, cText, sizeof(cText));
- TextOut(hdc, 353, 60, cTime, sizeof(cTime));
- TextOut(hdc, 348, 100, cDate, sizeof(cDate));
- TextOut(hdc, 200, 250, cText2, sizeof(cText2));
- TextOut(hdc, 353, 300, cTrecut, sizeof(cTrecut));
- EndPaint(hwnd, &ps);
- }
- break;
- case WM_CLOSE:
- if (MessageBox(hwnd, "Are you sure?", lpcClassname, MB_ICONQUESTION | MB_OKCANCEL) == IDOK)
- DestroyWindow(hwnd);
- break;
- case WM_CREATE:
- SetTimer(hwnd, ID_TIMER, 1000, NULL);
- SetTimer(hwnd, ID_MINUTES, 60000, NULL);
- SetTimer(hwnd, ID_HOURS, 3600000, NULL);
- break;
- case WM_TIMER:
- switch(wParam)
- {
- case ID_TIMER:
- if (timer[2] == 59)
- timer[2] = 0;
- else
- timer[2]++;
- break;
- case ID_MINUTES:
- if (timer[1] == 59)
- timer[1] = 0;
- else
- timer[1]++;
- break;
- case ID_HOURS:
- if (timer[0] == 23)
- timer[0] = 0;
- else
- timer[0]++;
- break;
- }
- InvalidateRect(hwnd, NULL, false);
- break;
- case WM_DESTROY:
- KillTimer(hwnd, ID_TIMER);
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement