/* workarea.cpp */

#include <Windows.h>
#include <cstdlib>
#include <iostream>

void printRect(RECT* r) {	
	std::cout << r->left << ", " << r->top << ", " << r->right << ", " << r->bottom << "\n";
}

bool displayCurrent() {	
	RECT r = { 0 };
	
	if (! SystemParametersInfo( SPI_GETWORKAREA , 0 , &r, 0 )) {
		std::cerr << "err: spi()\n";
		return false;		
	}
	
	std::cout << "Current region: ";
	printRect( &r );
	
	return true;	
}

int main(int argc, char** argv) {
	
	if (! displayCurrent()) {
		return 1;
	}
	
	if (argc == 5) {
		RECT r = { 0 };
		
		r.left   = std::atoi(argv[1]);
		r.top    = std::atoi(argv[2]);
		r.right  = std::atoi(argv[3]);
		r.bottom = std::atoi(argv[4]);
		std::cout << "Setting to: ";
		printRect(&r);
		SystemParametersInfo(SPI_SETWORKAREA, 0, &r, SPIF_UPDATEINIFILE);
		
		displayCurrent();
		
	} else {
		std::cerr << "Usage: workarea x1 y1 x2 y2\n";
		return 1;
		
	}
	
	return 0;
}
