Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <vector>
- using namespace std;
- LRESULT CALLBACK windowprocessforwindow1(HWND handleforwindow1, UINT message, WPARAM wParam, LPARAM lParam);
- LRESULT CALLBACK windowprocessforwindow2(HWND handleforwindow2, UINT message, WPARAM wParam, LPARAM lParam);
- HINSTANCE hInst, hPrevInst;
- COLORREF color = RGB(68, 68, 68);
- HDC hdc;
- PAINTSTRUCT ps;
- DWORD dColors[3] = {255, 222, 222};
- HWND hEdit1, hEdit2, hEdit3, hEdit4;
- HWND handleforwindow1;
- HWND handleforwindow2;
- WNDCLASSEX windowclassforwindow2;
- int nShowCmdGlob;
- vector<vector<int> > rectaingles;
- vector<COLORREF> colors;
- const int DRAW_MENU_BUTTON = 101;
- const int REFRESH_MENU_BUTTON = 102;
- const int EXIT_MENU_BUTTON = 103;
- int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd) {
- nShowCmdGlob = nShowCmd;
- WNDCLASSEX windowclassforwindow1;
- ZeroMemory(&windowclassforwindow1, sizeof(WNDCLASSEX));
- windowclassforwindow1.cbClsExtra = 0;
- windowclassforwindow1.cbSize = sizeof(WNDCLASSEX);
- windowclassforwindow1.cbWndExtra = 0;
- windowclassforwindow1.hbrBackground = (HBRUSH) COLOR_WINDOW;
- windowclassforwindow1.hCursor = LoadCursor(NULL, IDC_ARROW);
- windowclassforwindow1.hIcon = NULL;
- windowclassforwindow1.hIconSm = NULL;
- windowclassforwindow1.hInstance = hInst;
- windowclassforwindow1.lpfnWndProc = (WNDPROC) windowprocessforwindow1;
- windowclassforwindow1.lpszClassName = "windowclass 1";
- windowclassforwindow1.lpszMenuName = NULL;
- windowclassforwindow1.style = CS_HREDRAW | CS_VREDRAW;
- if (!RegisterClassEx(&windowclassforwindow1)) {
- int nResult = GetLastError();
- MessageBox(NULL,
- "Window class creation failed",
- "Window Class Failed",
- MB_ICONERROR);
- }
- HMENU hMenuPopup = CreateMenu();
- AppendMenu(hMenuPopup, MF_STRING, DRAW_MENU_BUTTON, "Draw");
- AppendMenu(hMenuPopup, MF_STRING, REFRESH_MENU_BUTTON, "Refresh");
- AppendMenu(hMenuPopup, MF_STRING, EXIT_MENU_BUTTON, "Exit");
- RECT screen_rect;
- GetWindowRect(GetDesktopWindow(), &screen_rect);
- int x = screen_rect.right / 2 - 450;
- int y = screen_rect.bottom / 2 - 250;
- handleforwindow1 = CreateWindow(windowclassforwindow1.lpszClassName, "Rectaingles", WS_OVERLAPPEDWINDOW | WS_POPUP | WS_VISIBLE, x, y,
- 900, 500, (HWND) NULL, hMenuPopup, hInst, (LPSTR) NULL);
- ShowWindow(handleforwindow1, nShowCmd);
- hdc = GetDC(handleforwindow1);
- ZeroMemory(&windowclassforwindow2, sizeof(WNDCLASSEX));
- windowclassforwindow2.cbClsExtra = 0;
- windowclassforwindow2.cbSize = sizeof(WNDCLASSEX);
- windowclassforwindow2.cbWndExtra = 0;
- windowclassforwindow2.hbrBackground = (HBRUSH) COLOR_WINDOW;
- windowclassforwindow2.hCursor = LoadCursor(NULL, IDC_ARROW);
- windowclassforwindow2.hIcon = NULL;
- windowclassforwindow2.hIconSm = NULL;
- windowclassforwindow2.hInstance = hInst;
- windowclassforwindow2.lpfnWndProc = (WNDPROC) windowprocessforwindow2;
- windowclassforwindow2.lpszClassName = "window class2";
- windowclassforwindow2.lpszMenuName = NULL;
- windowclassforwindow2.style = CS_HREDRAW | CS_VREDRAW;
- if (!RegisterClassEx(&windowclassforwindow2)) {
- int nResult = GetLastError();
- MessageBox(NULL,
- "Window class creation failed for window 2",
- "Window Class Failed",
- MB_ICONERROR);
- }
- MSG lpMsg;
- while (GetMessage(&lpMsg, NULL, 0, 0)) {
- TranslateMessage(&lpMsg);
- DispatchMessage(&lpMsg);
- }
- return (lpMsg.wParam);
- }
- LRESULT CALLBACK windowprocessforwindow1(HWND handleforwindow, UINT msg, WPARAM wParam, LPARAM lParam) {
- HWND hTest, hAdd, hDel, hFlu, hWin, hCombobox;
- PAINTSTRUCT ps;
- CHOOSECOLOR cc;
- cc.Flags = CC_RGBINIT | CC_FULLOPEN;
- cc.hInstance = NULL;
- cc.hwndOwner = handleforwindow;
- cc.lCustData = 0L;
- cc.lpCustColors = dColors;
- cc.lpfnHook = NULL;
- cc.lpTemplateName = (LPSTR) NULL;
- cc.lStructSize = sizeof(cc);
- cc.rgbResult = RGB(255, 0, 0);
- HBRUSH hBrush;
- switch (msg) {
- case WM_INITDIALOG:
- break;
- case WM_COMMAND:
- if (HIWORD(wParam) == 0) {
- switch (LOWORD(wParam)) {
- case DRAW_MENU_BUTTON:
- handleforwindow2 = CreateWindow(windowclassforwindow2.lpszClassName, "Draw rectaingle", WS_OVERLAPPEDWINDOW, 200, 150, 300, 380, NULL, NULL, hInst, (LPSTR) NULL);
- ShowWindow(handleforwindow2, nShowCmdGlob);
- break;
- case REFRESH_MENU_BUTTON:
- rectaingles.clear();
- colors.clear();
- InvalidateRect(handleforwindow1, NULL, 1);
- break;
- case EXIT_MENU_BUTTON:
- PostQuitMessage(0);
- }
- }
- return 0;
- case WM_PAINT : {
- HDC hdc = BeginPaint(handleforwindow, &ps);
- for (int i = 0; i < rectaingles.size(); i++) {
- RECT r;
- r.left=rectaingles[i][0];
- r.top=rectaingles[i][1];
- r.right=rectaingles[i][2];
- r.bottom=rectaingles[i][3];
- FillRect(hdc, &r, HBRUSH(CreateSolidBrush(colors[i])));
- }
- EndPaint(handleforwindow, &ps);
- break;
- }
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return (DefWindowProc(handleforwindow, msg, wParam, lParam));
- }
- return 0;
- }
- LRESULT CALLBACK windowprocessforwindow2(HWND handleforwindow, UINT msg, WPARAM wParam, LPARAM lParam) {
- CHOOSECOLOR cc;
- cc.Flags = CC_RGBINIT | CC_FULLOPEN;
- cc.hInstance = NULL;
- cc.hwndOwner = handleforwindow;
- cc.lCustData = 0L;
- cc.lpCustColors = dColors;
- cc.lpfnHook = NULL;
- cc.lpTemplateName = (LPSTR) NULL;
- cc.lStructSize = sizeof(cc);
- cc.rgbResult = RGB(255, 0, 0);
- const int SET_COLOR_BUTTON = 1;
- const int DRAW_RECT_BUTTON = 2;
- switch (msg) {
- case WM_CREATE : {
- CreateWindow("STATIC", "Draw rectaingle", WS_VISIBLE | WS_CHILD | SS_LEFT, 10, 10, 200, 100,
- handleforwindow, NULL, hInst, NULL);
- CreateWindow("STATIC", "Left:", WS_VISIBLE | WS_CHILD | SS_LEFT, 10, 50, 200, 100,
- handleforwindow, NULL, hInst, NULL);
- CreateWindow("STATIC", "Top:", WS_VISIBLE | WS_CHILD | SS_LEFT, 10, 100, 200, 100,
- handleforwindow, NULL, hInst, NULL);
- CreateWindow("STATIC", "Right:", WS_VISIBLE | WS_CHILD | SS_LEFT, 10, 150, 200, 100,
- handleforwindow, NULL, hInst, NULL);
- CreateWindow("STATIC", "Bottom:", WS_VISIBLE | WS_CHILD | SS_LEFT, 10, 200, 200, 100,
- handleforwindow, NULL, hInst, NULL);
- hEdit1 = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", 0, WS_CHILD | WS_VISIBLE, 70, 45, 120, 30,
- handleforwindow, (HMENU) 910, NULL, NULL);
- hEdit2 = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", 0, WS_CHILD | WS_VISIBLE, 70, 95, 120, 30,
- handleforwindow, (HMENU) 911, NULL, NULL);
- hEdit3 = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", 0, WS_CHILD | WS_VISIBLE, 70, 145, 120, 30,
- handleforwindow, (HMENU) 912, NULL, NULL);
- hEdit4 = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", 0, WS_CHILD | WS_VISIBLE, 70, 195, 120, 30,
- handleforwindow, (HMENU) 913, NULL, NULL);
- CreateWindow("button", "Set color", WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, 70, 245, 120, 20,
- handleforwindow, (HMENU) SET_COLOR_BUTTON, NULL, NULL);
- CreateWindow("button", "Draw", WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, 70, 295, 120, 20,
- handleforwindow, (HMENU) DRAW_RECT_BUTTON, NULL, NULL);
- break;
- }
- case WM_COMMAND:
- if (HIWORD(wParam) == 0) {
- switch (LOWORD(wParam)) {
- case SET_COLOR_BUTTON:
- if (ChooseColor(&cc)) { color = (COLORREF) cc.rgbResult; }
- return 0;
- case DRAW_RECT_BUTTON:
- char left[9];
- char top[9];
- char right[9];
- char bottom[9];
- GetWindowText(hEdit1,left,9);
- GetWindowText(hEdit2,top,9);
- GetWindowText(hEdit3,right,9);
- GetWindowText(hEdit4,bottom,9);
- vector<int> rectaingle;
- rectaingle.push_back(atoi(left));
- rectaingle.push_back(atoi(top));
- rectaingle.push_back(atoi(right));
- rectaingle.push_back(atoi(bottom));
- rectaingles.push_back(rectaingle);
- colors.push_back(color);
- InvalidateRect(handleforwindow1,NULL,TRUE);
- break;
- }
- }
- return 0;
- case WM_DESTROY: {
- return 0;
- }
- }
- return DefWindowProc(handleforwindow, msg, wParam, lParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement