Kolorwanie:
Status:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
#include <string>
#include <sstream>
#include <windows.h>
#include <map>
#include <algorithm>
#include <iterator>
namespace patch
{
    template < typename T > std::string to_string( const T& n )
    {
        std::ostringstream stm ;
        stm << n ;
        return stm.str() ;
    }
}

 std::map<HWND,int[4]> dims;

int sx=500,sy=500;
int cx=500,cy=500;
int bsx=100,bsy=100;
int bsw=100,bsh=100;

BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lpar)
{
	RECT rect;
	if(GetWindowRect(hwnd, &rect))
{
  int width = rect.right - rect.left;
  int height = rect.bottom - rect.top;
  std::string str = patch::to_string(width) +" " +patch::to_string(height) ;
char *cstr = new char[str.length() + 1];
strcpy(cstr, str.c_str());
  SetWindowTextA(
hwnd,cstr);
	std::map<HWND,int[4]>::iterator it =dims.begin();
bool jestelem=false;
int tab[4];
	while (it != dims.end())
	{
		HWND item = it->first;
 
		int size[4];
		size= it->second;
 
		if (hwnd==item)
		{
		jestelem=true;
		tab= {size[0],size[1],size[2],size[3]};
		}
 
		it++;
	}
	if (!jestelem)
	{
	dims.insert(std::pair<HWND, int[4]>(hwnd,{rect.left,rect.top,width,height}));	
	}
	else
	{
		SetWindowPos(
  hwnd,
  NULL,
  tab[0]*((float)cx/sx),
  tab[1]*((float)cy/sy),
(int)tab[2]*((float)cx/sx),
(int)tab[3]*((float)cy/sy),
NULL
);
	}

}
	
	
	
}

/* This is where all the input to the window goes to */
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
	switch(Message) {
		
		/* Upon destruction, tell the main thread to stop */
		case WM_DESTROY: {
			PostQuitMessage(0);
			break;
		}
		case WM_SIZE:{
			RECT rect;
if(GetWindowRect(hwnd, &rect))
{
  int width = rect.right - rect.left;
  int height = rect.bottom - rect.top;
  std::string str = patch::to_string(width) +" " +patch::to_string(height)+" "+patch::to_string((float)cx/sx)+" "+patch::to_string((float)cy/sy) ;
char *cstr = new char[str.length() + 1];
cx=width;
cy=height;
strcpy(cstr, str.c_str());
  SetWindowTextA(
hwnd,cstr);
}
EnumChildWindows(hwnd,EnumChildProc,(LPARAM)997);

			break;
		}
		
		/* All other messages (a lot of them) are processed using default procedures */
		default:
			return DefWindowProc(hwnd, Message, wParam, lParam);
	}
	return 0;
}

/* The 'main' function of Win32 GUI programs: this is where execution starts */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
	WNDCLASSEX wc; /* A properties struct of our window */
	HWND hwnd; /* A 'HANDLE', hence the H, or a pointer to our window */
	MSG msg; /* A temporary location for all messages */

	/* zero out the struct and set the stuff we want to modify */
	memset(&wc,0,sizeof(wc));
	wc.cbSize		 = sizeof(WNDCLASSEX);
	wc.lpfnWndProc	 = WndProc; /* This is where we will send messages to */
	wc.hInstance	 = hInstance;
	wc.hCursor		 = LoadCursor(NULL, IDC_ARROW);
	
	/* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
	wc.lpszClassName = "WindowClass";
	wc.hIcon		 = LoadIcon(NULL, IDI_APPLICATION); /* Load a standard icon */
	wc.hIconSm		 = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */

	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,
		CW_USEDEFAULT, /* x */
		CW_USEDEFAULT, /* y */
		sx, /* width */
		sy, /* height */
		NULL,NULL,hInstance,NULL);
		HWND hwndButton = CreateWindow( 
    "BUTTON",  // Predefined class; Unicode assumed 
    "OK",      // Button text 
    WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,  // Styles 
    100,         // x position 
    100,         // y position 
    100,        // Button width
    100,        // Button height
    hwnd,     // Parent window
    NULL,       // No menu.
    hInstance, 
    NULL);      // Pointer not needed.

	if(hwnd == NULL) {
		MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
		return 0;
	}

	/*
		This is the heart of our program where all input is processed and 
		sent to WndProc. Note that GetMessage blocks code flow until it receives something, so
		this loop will not produce unreasonably high CPU usage
	*/
	while(GetMessage(&msg, NULL, 0, 0) > 0) { /* If no error is received... */
		TranslateMessage(&msg); /* Translate key codes to chars if present */
		DispatchMessage(&msg); /* Send it to WndProc */
	}
	return msg.wParam;
}


Copyrights 2014-2019 © Wklejaj.pl Wszelkie prawa zastrzeżone.