Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdio.h>
- HWND hWnd;
- int Timer_CLK = 0;
- CRITICAL_SECTION section = { 0 }; //Критическая секция
- ///////////////////////////////////////////////////// Рисует строку в окне программы
- void xPrint(int x, int y, const char *pChar) //
- {
- HDC hdc = GetDC(hWnd);
- SetTextColor(hdc, RGB(66, 170, 255));
- SetBkColor (hdc, 0);
- TextOut(hdc, x, y, pChar, strlen(pChar));
- ReleaseDC(hWnd,hdc);
- }
- /////////////////////////////////////////////////////
- LPCSTR Rus(LPCTSTR pszIn) //
- {
- static char szBuffer[MAX_PATH];
- CharToOemBuff(pszIn, szBuffer, MAX_PATH);
- return szBuffer;
- }
- void ConsolePrint(const char* str, int Colour)
- {
- EnterCriticalSection(§ion);
- DWORD result;
- COORD coord;
- HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hStdout, Colour); // Изменим цвет текста
- WriteConsole(hStdout, Rus(str), strlen(str), &result, 0);
- LeaveCriticalSection(§ion);
- }
- /*
- // Y - это строка, X - это позиция в строке
- // ============================================
- void ConsolePrint(int Y, int X, const char* str, int Colour)
- {
- DWORD result;
- COORD coord;
- HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hStdout, Colour);
- coord.X = X; // Выбираем позицию
- coord.Y = Y; // Выбираем строку
- SetConsoleCursorPosition(hStdout, coord);
- WriteConsole(hStdout, Rus(str), strlen(str), &result, 0);
- }
- */
- /* какой цвет как обозначается:
- (HEX)
- 0 0 = черный
- 1 1 = синий
- 2 2 = зеленый
- 3 3 = голубой
- 4 4 = красный
- 5 5 = лиловый
- 6 6 = желтый
- 7 7 = белый
- 8 8 = серый
- 9 9 = светло-синий
- 10 a = светло-зеленый
- 11 b = светло-голубой
- 12 c = светло-красный
- 13 d = светло-лиловый
- 14 e = светло-желтый
- 15 f = ярко-белый
- */
- HANDLE hArr[3];
- char sz[150] = "Columbia Pictures Presents",
- sz0[2],
- sz1[2],
- sz2[2],
- sz3[2];
- /////////////////////////////////////////////////////
- DWORD WINAPI WorkThread0(LPVOID param) //
- {
- for(int i = 0; i < 26; ++i)
- {
- sz0[0] = sz[i];
- sz0[1] = 0;
- ConsolePrint(sz0, 14);
- }
- ExitThread(0);
- }
- DWORD WINAPI WorkThread1(LPVOID param)
- {
- for (int i = 0; i < 26; ++i)
- {
- sz1[0] = sz[i];
- sz1[1] = 0;
- ConsolePrint(sz1, 12);
- }
- ExitThread(0);
- }
- DWORD WINAPI WorkThread2(LPVOID param)
- {
- for (int i = 0; i < 26; ++i)
- {
- sz2[0] = sz[i];
- sz2[1] = 0;
- ConsolePrint(sz2, 10);
- }
- ExitThread(0);
- }
- /////////////////////////////////////////////////////
- void spell()
- {
- for (int i = 0; i < 26; ++i)
- {
- sz3[0] = sz[i];
- sz3[1] = 0;
- ConsolePrint(sz3, 13);
- }
- }
- LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
- {
- switch(Message)
- {
- case WM_CREATE: SetTimer(hWnd, 1, 400, 0); // Создаём таймер №1, который срабатывает каждые 0.4 сек.
- break; // Принимаем однократное сообщение для инициализации
- case WM_TIMER: switch(Timer_CLK ++)
- {
- case 2: AllocConsole();
- xPrint(20, 20, "Hello");
- break;
- case 5: //printf("DDfkdjsklj");
- // ConsolePrint(3, 12, "Привет !", 6);
- //ConsolePrint("Привет !", 6);
- InitializeCriticalSection(§ion);
- hArr[0] = CreateThread(NULL, 0, WorkThread0, NULL, 0, 0);
- // spell();
- hArr[1] = CreateThread(NULL, 0, WorkThread1, NULL, 0, 0);
- hArr[2] = CreateThread(NULL, 0, WorkThread2, NULL, 0, 0);
- // WaitForMultipleObjects(3, hArr, TRUE, INFINITE);
- break;
- case 37: FreeConsole();
- xPrint(20, 40, "See you later");
- break;
- }
- break;
- case WM_DESTROY: PostQuitMessage(0);
- break;
- default: return DefWindowProc(hWnd, Message, wParam, lParam);
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
- WNDCLASSEX wc;
- //HWND hwnd;
- MSG Msg;
- memset(&wc, 0, sizeof(wc));
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.lpfnWndProc = WndProc;
- wc.hInstance = hInstance;
- wc.hCursor = LoadCursor(0, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+2);
- wc.lpszClassName = "WindowClass";
- wc.hIcon = LoadIcon(0, IDI_APPLICATION);
- wc.hIconSm = LoadIcon(0, IDI_APPLICATION);
- if(!RegisterClassEx(&wc)) {
- MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
- return 0;
- }
- hWnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Caption",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
- 100,
- 100,
- 640,
- 480,
- 0, 0, hInstance, 0);
- if(hWnd == NULL) {
- MessageBox(0, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
- return 0;
- }
- while(GetMessage(&Msg, 0, 0, 0) > 0) {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- return Msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement