Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <time.h>
- //V-6
- LPCSTR registration_error_message = "Couldn't initialize class!";
- LPCSTR registration_error_title = "Error: initializing";
- LPCSTR creating_window_error_title = "Error: creating";
- LPCSTR creating_window_error_message = "Couldn't create window!";
- LPCSTR button_show_text = "Show";
- LPCSTR button_clear_text = "Clear";
- LPCSTR button_about_text = "About";
- LPCSTR main_window_name = "Hello App";
- LPCSTR main_window_class = "hello_class";
- LPCSTR about_text = "Sergey Rakhmanov (IU3-21B)";
- LRESULT CALLBACK window_callback(HWND, UINT, WPARAM, LPARAM);
- HINSTANCE hInst;
- int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
- HWND main_window;
- MSG msg;
- WNDCLASSEX wc;
- wc.cbSize = sizeof(wc);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = window_callback;
- wc.lpszMenuName = NULL;
- wc.lpszClassName = main_window_class;
- wc.cbWndExtra = 0;
- wc.cbClsExtra = 0;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
- wc.hInstance = hInstance;
- if(!RegisterClassEx(&wc)){
- MessageBox(NULL, registration_error_message, registration_error_title, MB_OK);
- return NULL;
- }
- main_window = CreateWindow(main_window_class, main_window_name, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
- if(!main_window){MessageBox(NULL, creating_window_error_message, creating_window_error_title, MB_OK); return NULL; }
- ShowWindow(main_window, iCmdShow);
- UpdateWindow(main_window);
- while(GetMessage(&msg, NULL, 0, 0)){ TranslateMessage(&msg); DispatchMessage(&msg); }
- return msg.wParam ;
- }
- #define BTN_WIDTH 150
- #define BTN_HEIGHT 20
- LRESULT CALLBACK window_callback(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam){
- HDC hdc;
- PAINTSTRUCT ps;
- RECT rect;
- HWND button_show, button_clear, button_author;
- int loword;
- static int choise = 0;
- static HPEN hpen;
- static HBRUSH hbrush;
- switch (iMsg) {
- case WM_CREATE :
- button_show = CreateWindow ("button", button_show_text, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 100, 50, BTN_WIDTH, BTN_HEIGHT, hwnd, (HMENU) 1, hInst, NULL);
- button_clear = CreateWindow ("button", button_clear_text, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 100, 100, BTN_WIDTH, BTN_HEIGHT, hwnd, (HMENU) 2, hInst, NULL);
- button_author = CreateWindow ("button", button_about_text, WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON, 100, 250, BTN_WIDTH, BTN_HEIGHT, hwnd, (HMENU) 3, hInst, NULL);
- return 0;
- case WM_COMMAND :
- hpen = CreatePen(PS_SOLID, 10,RGB(204, 51, 0));
- hbrush = CreateSolidBrush(RGB(204, 51, 0));
- loword=LOWORD(wParam);
- switch(loword){
- case 1: choise = 1; break; case 2: choise = 2; break; case 3: choise = 3; break; default: break; }
- InvalidateRect(hwnd, NULL, TRUE);
- return 0;
- case WM_PAINT:
- hdc = BeginPaint(hwnd, &ps);
- GetClientRect(hwnd, &rect);
- SelectObject(hdc, hbrush);
- SelectObject(hdc, hpen);
- switch(choise){
- case 1:
- Rectangle(hdc, 600, 100, 624, 300);
- hbrush = CreateSolidBrush(RGB(0, 255, 0));
- hpen = CreatePen(PS_SOLID, 10,RGB(0, 255, 0));
- SelectObject(hdc, hbrush);
- SelectObject(hdc, hpen);
- Ellipse(hdc, 525, 50, 698, 200);
- break;
- case 2:
- break; case 3:
- TextOut(hdc, 500, 100, about_text, strlen(about_text));
- break; }
- EndPaint(hwnd, &ps); return 0; case WM_DESTROY : PostQuitMessage(0); return 0; } return DefWindowProc (hwnd, iMsg, wParam, lParam) ; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement