Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <string>
- #include <map>
- using namespace std;
- #define ID_DISPLAY 1
- LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
- CHAR szClassName[ ] = "CodeBlocksWindowsApp";
- HWND hColor, hDisplay;
- map<string, COLORREF> ColBase;
- COLORREF BackroundCol = RGB(0,0,0);
- RECT ObszarRysowany;
- void FillBase(){
- ColBase["czerwony"] = RGB(255, 0, 0);
- ColBase["zielony"] = RGB(0, 255, 0);
- ColBase["niebieski"] = RGB(0, 0, 255);
- ColBase["bialy"] = RGB(255, 255, 255);
- ColBase["czarny"] = RGB(0, 0, 0);
- }
- COLORREF fGetCol(string tekst){
- map<string, COLORREF>::iterator cur;
- cur = ColBase.find(tekst);
- return cur->second;
- }
- int WINAPI WinMain (HINSTANCE hThisInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpszArgument,
- int nCmdShow)
- {
- HWND hwnd;
- MSG messages;
- WNDCLASSEX wincl;
- wincl.hInstance = hThisInstance;
- wincl.lpszClassName = szClassName;
- wincl.lpfnWndProc = WindowProcedure;
- wincl.style = CS_DBLCLKS;
- wincl.cbSize = sizeof (WNDCLASSEX);
- wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
- wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
- wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
- wincl.lpszMenuName = NULL;
- wincl.cbClsExtra = 0;
- wincl.cbWndExtra = 0;
- wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
- if (!RegisterClassEx (&wincl))
- return 0;
- FillBase();
- hwnd = CreateWindowEx (
- 0, /* Extended possibilites for variation */
- szClassName, /* Classname */
- "Pobieranie Koloru", /* Title Text */
- WS_OVERLAPPEDWINDOW, /* default window */
- CW_USEDEFAULT, /* Windows decides the position */
- CW_USEDEFAULT, /* where the window ends up on the screen */
- 200, /* The programs width */
- 100, /* and height in pixels */
- NULL, /* The window is a child-window to desktop */
- NULL, /* No menu */
- hThisInstance, /* Program Instance handler */
- NULL /* No Window Creation data */
- );
- hColor = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "Podaj kolor...", WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, 0, 0, 200, 23, hwnd, NULL, hThisInstance, NULL);
- hDisplay = CreateWindowEx(0, "BUTTON", "Wyswietl podany kolor", WS_CHILD | WS_VISIBLE, 0, 23, 200, 23, hwnd, (HMENU)ID_DISPLAY, hThisInstance, NULL);
- ObszarRysowany.left = 0;
- ObszarRysowany.right = 200;
- ObszarRysowany.top = 46;
- ObszarRysowany.bottom = 64;
- ShowWindow (hwnd, nCmdShow);
- while (GetMessage (&messages, NULL, 0, 0))
- {
- TranslateMessage(&messages);
- DispatchMessage(&messages);
- }
- return messages.wParam;
- }
- LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_PAINT:{
- PAINTSTRUCT ps;
- HDC hdc = BeginPaint(hwnd, &ps);
- HBRUSH pedzel = CreateSolidBrush(BackroundCol);
- FillRect(hdc, &ObszarRysowany, pedzel);
- DeleteObject(pedzel);
- EndPaint(hwnd, &ps);
- break;
- }
- case WM_COMMAND:{
- if(wParam == ID_DISPLAY)
- {
- int lenght = GetWindowTextLength(hColor);
- char *tekst = new char[lenght+1];
- GetWindowText(hColor, tekst, lenght+1);
- BackroundCol = fGetCol(tekst);
- delete tekst;
- InvalidateRect(hwnd, NULL, TRUE);
- }
- break;
- }
- case WM_DESTROY:
- PostQuitMessage (0);
- break;
- default:
- return DefWindowProc (hwnd, message, wParam, lParam);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement