All pastes #280471 Raw Edit

VoiDeD

public cpp v1 · immutable
·published 2006-12-15 22:53 UTC
rendered paste body
/*  * Base Converter :: VoiDAPI Test Project * ----------------------------------- * Coded by: VoiDeD * * Uses: - GNU C library (string) *       - itoa(), from somewhere... *       - VoiDAPI * * Time Spent: 40mins of bug smashing **/#include "voidapi.h"//main windowv_window* wnd;//three textboxesv_control* inputbox;v_control* basebox;v_control* outputbox;void calcbase(v_control* ctrl, void* data) { //function called when the input and base text boxes' text is changed	//allocate memory for the output string	char* buff = (char*)malloc(256);		//check for empty textboxes	if (basebox->get_text() == NULL || inputbox->get_text() == NULL) {		outputbox->set_text("Abort, abort!");		return;	}	//check for 0 in base textbox	if (atoi(basebox->get_text()) == 0) {		outputbox->set_text("Abort, abort!");		return;	}	//make sure base is divisible by 2	if (atoi(basebox->get_text()) % 2) {		outputbox->set_text("Abort, abort!");		return;	}		//convert input and base text to ints	int input = atoi(inputbox->get_text());	int base = atoi(basebox->get_text());		//convert to base	itoa(input, buff, base); //itoa() does all the heavy lifting... ;P				 //why reinvent the wheel? :>	//set output text	outputbox->set_text(buff);}void exit(v_window* wind) {	//destroy the window	wind->destroy();}int main(int argc, char* argv[]) {	//create the window	wnd = new v_window("Base Converter", new v_size(260,85));		//create the textboxes	inputbox = new v_textbox(new v_size(200, 20), new v_point(5, 5), wnd->get_hwnd(), false);	basebox = new v_textbox(new v_size(40, 20), new v_point(210, 5), wnd->get_hwnd(), false);	outputbox = new v_textbox(new v_size(245, 20), new v_point(5, 30), wnd->get_hwnd(), false);		//initilization stuff	outputbox->disable();	basebox->set_text("10");		//register events	wnd->register_event(WM_CLOSE, &exit);	inputbox->register_event(EN_CHANGE, &calcbase);	basebox->register_event(EN_CHANGE, &calcbase);		//add controls	wnd->control_add(inputbox);	wnd->control_add(basebox);	wnd->control_add(outputbox);		//show the window	wnd->show();}