Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <tchar.h>
- #include <stdlib.h>
- #include <ctime>
- bool flag = true;
- void OpenTxte() //функция открытия блокнота
- {
- // Create empty process startup info.
- STARTUPINFO sInfo;
- ZeroMemory(&sInfo, sizeof(STARTUPINFO));
- // Reserve memoryt for process information.
- PROCESS_INFORMATION pInfo;
- // Create process.
- CreateProcess(L"C:\\Windows\\Notepad.exe",
- NULL, NULL, NULL, FALSE, NULL, NULL, NULL, &sInfo, &pInfo);
- }
- LRESULT CALLBACK myWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- switch (uMsg)
- {
- case WM_CLOSE: //Выход из программы
- PostQuitMessage(0);
- return 0;
- case WM_PAINT: //Смена цвета окна на рандомное
- if (GetAsyncKeyState(VK_RETURN)){
- HDC hdc;
- PAINTSTRUCT ps;
- RECT rc;
- HBRUSH hBrush;
- int a = rand()%256, b = rand()%256, c = rand()%256;
- hdc = BeginPaint(hWnd, &ps); //начинаем рисовать
- GetClientRect(hWnd, &rc); //получаем координаты окна
- hBrush = CreateSolidBrush(RGB(a, b, c)); //создаём новую кисть
- FillRect(hdc, &rc, hBrush); //рисуем
- EndPaint(hWnd, &ps); //заканчиваем рисовать
- }
- return 0;
- }
- return DefWindowProc(hWnd, uMsg, wParam, lParam);
- }
- void main()
- {
- srand(time(NULL));
- // Get the handler of module that will be associated with a window.
- // In this case it will be handler of the executable file of current process.
- HINSTANCE hInstance = GetModuleHandle(NULL);
- // Create brush that will fill the background of the window.
- HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 255));
- // Create window class.
- WNDCLASS winClass;
- winClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
- winClass.lpfnWndProc = (WNDPROC)myWndProc;
- winClass.cbClsExtra = 0;
- winClass.cbWndExtra = 0;
- winClass.hInstance = hInstance;
- winClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
- winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
- winClass.hbrBackground = hBrush; //Цвет окна
- winClass.lpszMenuName = NULL;
- winClass.lpszClassName = L"MyWindowclass";
- // Register class in the system.
- RegisterClass(&winClass);
- // Create window.
- HWND hWnd = CreateWindow(L"MyWindowclass", L"Window by raw API",
- WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
- 100, 100, 320, 240,
- NULL, NULL, hInstance, NULL);
- // Show window.
- ShowWindow(hWnd, SW_SHOW);
- // Loop while window is not closed.
- MSG message;
- while (true)
- {
- if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
- {
- if (message.message == WM_QUIT)
- break;
- else
- {
- TranslateMessage(&message);
- DispatchMessage(&message);
- }
- }
- if (GetAsyncKeyState(VK_CONTROL)){
- if (GetAsyncKeyState('Q')){ DestroyWindow(hWnd); UnregisterClass(L"MyWindowclass", hInstance); DeleteObject(hBrush); WM_QUIT; break; }
- }
- if (GetAsyncKeyState(VK_ESCAPE)){ DestroyWindow(hWnd); UnregisterClass(L"MyWindowclass", hInstance); DeleteObject(hBrush); WM_QUIT; break; }
- if (GetAsyncKeyState(VK_RETURN)){
- WM_PAINT;
- }
- if (GetAsyncKeyState(VK_LSHIFT)){
- if (GetAsyncKeyState('C') && flag){
- flag = false;
- OpenTxte();
- }
- }
- }
- // Delete window.
- DestroyWindow(hWnd);
- // Remove window class.
- UnregisterClass(L"MyWindowclass", hInstance);
- // Delete brush.
- DeleteObject(hBrush);
- }
Advertisement
Add Comment
Please, Sign In to add comment