Exemple #1
0
void PopupMenu::checkRadioItem(S32 firstPos, S32 lastPos, S32 checkPos)
{
   // uncheck items
   for(int i = firstPos; i <= lastPos; i++)
      checkItem( i, false);
   
   // check the selected item
   checkItem( checkPos, true);
}
bool CampaignManager::checkAllRequirements(const Event_Component& ec) {
    if (ec.type == EC_REQUIRES_STATUS) {
        if (checkStatus(ec.s))
            return true;
    }
    else if (ec.type == EC_REQUIRES_NOT_STATUS) {
        if (!checkStatus(ec.s))
            return true;
    }
    else if (ec.type == EC_REQUIRES_CURRENCY) {
        if (checkCurrency(ec.x))
            return true;
    }
    else if (ec.type == EC_REQUIRES_NOT_CURRENCY) {
        if (!checkCurrency(ec.x))
            return true;
    }
    else if (ec.type == EC_REQUIRES_ITEM) {
        if (checkItem(ec.x))
            return true;
    }
    else if (ec.type == EC_REQUIRES_NOT_ITEM) {
        if (!checkItem(ec.x))
            return true;
    }
    else if (ec.type == EC_REQUIRES_LEVEL) {
        if (pc->stats.level >= ec.x)
            return true;
    }
    else if (ec.type == EC_REQUIRES_NOT_LEVEL) {
        if (pc->stats.level < ec.x)
            return true;
    }
    else if (ec.type == EC_REQUIRES_CLASS) {
        if (pc->stats.character_class == ec.s)
            return true;
    }
    else if (ec.type == EC_REQUIRES_NOT_CLASS) {
        if (pc->stats.character_class != ec.s)
            return true;
    }
    else {
        // Event component is not a requirement check
        // treat it as if the "requirement" was met
        return true;
    }

    // requirement check failed
    return false;
}
void VerifyServiceTask::doRun()
{
	if (checkItem())
		return;

	updateStatus();

	if (checkBranch())
		return;

	if (checkUnAuthed())
		return;

	if (m_bCheckFiles && !checkFiles())
		return;
	
	//do hooks before tools as tools will change to the downloading tool stage
	if (m_bCheckHooks)
		checkHooks();

	bool end = true;

	if (m_bCheckTools)
		end = !checkTools();

	finishVerify(UserCore::Misc::VerifyComplete::V_COMPLETE, NULL, end);
}
void CDesertConfigDialog::checkItem(HTREEITEM &item)
{
	m_cfgtree.SetCheck(item, 1);
	bool isRoot = (item==m_cfgTreeRootItem);
	std::string itemType = dhelper_ptr->getElementType(cfgTreeMap[item]);
	/*map<HTREEITEM, int>::iterator pos = cfgTreeMap.find(item);
	if(pos!=cfgTreeMap.end())
	{
		int itemId = (*pos).second;
		std::string itemType = dhelper_ptr->getElementType(itemId);
	}
	else return;
	*/
	if(itemType.empty() && !isRoot) return;
	
	if(itemType=="Compound" || isRoot)
	{
		if (m_cfgtree.ItemHasChildren(item))
		{
		   HTREEITEM hNextItem;
		   HTREEITEM hChildItem = m_cfgtree.GetChildItem(item);
		   while (hChildItem != NULL)
		   {
			  checkItem(hChildItem);
			  hNextItem = m_cfgtree.GetNextItem(hChildItem, TVGN_NEXT);
			  hChildItem = hNextItem;
		   }
		}
	}
	
//	checkSiblings_check(item);
}
Exemple #5
0
void TradeWindow::tradeItem(Item *const item, const int quantity,
                            const bool check) const
{
    if (check && !checkItem(item))
        return;

    Net::getTradeHandler()->addItem(item, quantity);
}
Exemple #6
0
void IdentityItem::updateItem( const Polka::Identity &identity )
{
  m_identity = identity;

  foreach( QGraphicsItem *child, childItems() ) {
    delete child;
  }

  if ( identity.type() == "group" ) {
    int circleSize = m_itemSize + 14;
    QGraphicsEllipseItem *groupCircle = new QGraphicsEllipseItem( this );
    groupCircle->setRect( -circleSize/2, -circleSize/2,
      circleSize, circleSize );
    QPen pen;
    pen.setBrush( Qt::white );
    pen.setWidth( 4 );
    groupCircle->setPen( pen );
  }

  QPixmap pixmap = m_model->pixmap( identity );

  QGraphicsItem *item = new QGraphicsPixmapItem( pixmap, this );
  item->setPos( -pixmap.width() / 2, -pixmap.height() / 2 );

  QGraphicsTextItem *textItem = new QGraphicsTextItem( identity.name().value() );

  int textWidth = textItem->boundingRect().width();
  int textHeight = textItem->boundingRect().height();

  m_nameItem = new RoundedRectItem( this );
  m_nameItem->setRect( 0, 0, textWidth, textHeight );
  m_nameItem->setBrush( QColor( 255,255,230 ) );
  m_nameItem->setZValue( 10 );

  textItem->setParentItem( m_nameItem );

  m_nameItem->setPos( - textWidth / 2, 30 );

  m_fanMenu = new FanMenu( this );
  m_fanMenu->setZValue( 50 );

  FanMenuItem *menuItem = m_fanMenu->addItem( i18n("Remove") );
  connect( menuItem, SIGNAL( clicked() ), SLOT( emitRemoveIdentity() ) );
  m_checkMenuItem = m_fanMenu->addItem( i18n("Check") );
  connect( m_checkMenuItem, SIGNAL( clicked() ), SLOT( checkItem() ) );
  if ( identity.type() == "group" ) {
    menuItem = m_fanMenu->addItem( i18n("Go to") );
  } else {
    menuItem = m_fanMenu->addItem( i18n("Show") );
  }
  connect( menuItem, SIGNAL( clicked() ), SLOT( emitShowIdentity() ) );
  m_fanMenu->setupItems();

  hidePopups();
}
LRESULT CDesertConfigDialog::OnTreeViewCheckStateChange(WPARAM wParam, LPARAM lParam) 
{ 
	// Handle message here… 
	for(map<HTREEITEM, int>::iterator i=cfgTreeMap.begin();i!=cfgTreeMap.end();++i)
	{
		HTREEITEM node = (*i).first;
		m_cfgtree.SetItemState(node,0, TVIS_BOLD); 
	}
	
	HTREEITEM  changedItem = (HTREEITEM)lParam; 
	bool check=true;
	if(m_cfgtree.GetCheck(changedItem))
		checkItem(changedItem);
	else
	{
		uncheckItem(changedItem);
		check=false;
	}

	set<int> cfgIds;
	for(long i=0;i<cfgSize;++i)
		cfgIds.insert(i);
	noneChecked = false;
	/*if(!noneChecked) 
		cfgIds.clear();
	updateConfigList(cfgIds);
	updateSize(cfgIds.size());*/

	set<int> valid_ids = computeConfigList(m_cfgTreeRootItem, cfgIds);
	if(!noneChecked) 
		 valid_ids.clear();
	updateConfigList( valid_ids, check);
	int cnt = m_cfglist.GetItemCount();
	int checked=0;
	for(int i=0;i<cnt;++i)
	{
		if(m_cfglist.GetCheck(i))
			checked++;
	}
	updateSize( checked);

	return 0;
} 
Exemple #8
0
// Create a Gltx
bool
QuasarDB::create(Gltx& gltx)
{
    // Can't create transaction before close date
    Company company;
    lookup(company);
    QDate startOfYear = company.startOfYear();

    if (!company.closeDate().isNull()) {
	if (gltx.postDate() <= company.closeDate())
	    return error("Can't create transaction before close date");
    }
    if (!startOfYear.isNull() && company.lastYearClosed()) {
	if (gltx.postDate() < startOfYear)
	    return error("Can't post to last year");
    }

    // Verify station/employee are specified
    if (company.shiftMethod() == Company::BY_STATION) {
	if (gltx.stationId() == INVALID_ID) {
	    // Error if its a transaction type involving cashrec
	    switch (gltx.dataType()) {
	    case DataObject::INVOICE:
	    case DataObject::RECEIPT:
	    case DataObject::NOSALE:
	    case DataObject::PAYOUT:
	    case DataObject::RETURN:
	    case DataObject::SHIFT:
	    case DataObject::TEND_ADJUST:
	    case DataObject::WITHDRAW:
		return error("A station is required");
	    default:
		break;
	    }
	}
    }
    if (company.shiftMethod() == Company::BY_EMPLOYEE) {
	if (gltx.employeeId() == INVALID_ID) {
	    // Error if its a transaction type involving cashrec
	    switch (gltx.dataType()) {
	    case DataObject::INVOICE:
	    case DataObject::RECEIPT:
	    case DataObject::NOSALE:
	    case DataObject::PAYOUT:
	    case DataObject::RETURN:
	    case DataObject::SHIFT:
	    case DataObject::TEND_ADJUST:
	    case DataObject::WITHDRAW:
		return error("An employee is required");
	    default:
		break;
	    }
	}
    }

    // Check shift is not posted if set
    if (gltx.shiftId() != INVALID_ID) {
	Shift shift;
	lookup(gltx.shiftId(), shift);
	if (shift.shiftId() != INVALID_ID)
	    return error("Can't post to a posted shift");
    }

    // Check that change data exists and create if needed
    checkAccount(gltx);
    checkCard(gltx);
    checkItem(gltx);

    // Auto allocate transaction number
    if (gltx.number().stripWhiteSpace() == "#") {
	fixed number = uniqueTxNumber(gltx.dataType());
	gltx.setNumber(number.toString());
    }

    QString cmd = insertCmd("gltx", "gltx_id", "number,reference_str,"
			    "post_date,post_time,memo,station_id,"
			    "employee_id,card_id,store_id,shift_id,"
			    "link_id,printed,paid,amount,data_type");
    Stmt stmt(_connection, cmd);

    insertData(gltx, stmt);
    stmtSetString(stmt, gltx.number());
    stmtSetString(stmt, gltx.reference());
    stmtSetDate(stmt, gltx.postDate());
    stmtSetTime(stmt, gltx.postTime());
    stmtSetString(stmt, gltx.memo());
    stmtSetId(stmt, gltx.stationId());
    stmtSetId(stmt, gltx.employeeId());
    stmtSetId(stmt, gltx.cardId());
    stmtSetId(stmt, gltx.storeId());
    stmtSetId(stmt, gltx.shiftId());
    stmtSetId(stmt, gltx.linkId());
    stmtSetBool(stmt, gltx.printed());
    stmtSetBool(stmt, false);
    stmtSetFixed(stmt, gltx.total());
    stmtSetInt(stmt, gltx.dataType());
    execute(stmt);

    sqlCreateLines(gltx);

    if (!startOfYear.isNull() && gltx.postDate() < startOfYear &&
	    gltx.isActive()) {
	Store store;
	if (!lookup(gltx.storeId(), store)) return false;

	Gltx orig, transfer;
	if (!lookup(store.yearEndTransferId(), transfer)) return false;
	orig = transfer;

	fixed total = 0.0;
	for (unsigned int i = 0; i < gltx.accounts().size(); ++i) {
	    Account account;
	    lookup(gltx.accounts()[i].account_id, account);
	    if (account.type() < Account::Income) continue;

	    AccountLine line;
	    line.account_id = account.id();
	    line.amount = -gltx.accounts()[i].amount;
	    transfer.accounts().push_back(line);

	    total += line.amount;
	}

	if (total != 0.0) {
	    AccountLine line;
	    line.account_id = company.retainedEarnings();
	    line.amount = -total;
	    transfer.accounts().push_back(line);
	}

	if (transfer != orig)
	    if (!update(orig, transfer))
		return false;
    }

    return true;
}
Exemple #9
0
// Update a Gltx
bool
QuasarDB::update(const Gltx& orig, Gltx& gltx)
{
    if (gltx.number() == "#")
	return error("Can't change number to '#'");

    if (orig.dataType() != gltx.dataType()) {
	bool allowed = false;
	switch (orig.dataType()) {
	case DataObject::INVOICE:
	    if (gltx.dataType() == DataObject::RETURN)
		allowed = true;
	    break;
	case DataObject::RETURN:
	    if (gltx.dataType() == DataObject::INVOICE)
		allowed = true;
	    break;
	case DataObject::RECEIVE:
	    if (gltx.dataType() == DataObject::CLAIM)
		allowed = true;
	    break;
	case DataObject::CLAIM:
	    if (gltx.dataType() == DataObject::RECEIVE)
		allowed = true;
	    break;
	default:
	    break;
	}

	if (!allowed)
	    return error("Can't change data type");
    }

    // Can't void or unvoid reconciled or shift posted transaction
    if (orig.isActive() != gltx.isActive()) {
	for (unsigned int i = 0; i < gltx.accounts().size(); ++i)
	    if (!gltx.accounts()[i].cleared.isNull())
		return error("Can't change reconciled transaction");

	if (gltx.shiftId() != INVALID_ID) {
	    Shift shift;
	    lookup(gltx.shiftId(), shift);
	    if (shift.shiftId() != INVALID_ID)
		return error("Can't change transaction from a posted shift");
	}
    }

    // If shift changed, neither can be posted
    if (orig.shiftId() != gltx.shiftId()) {
	if (orig.shiftId() != INVALID_ID) {
	    Shift shift;
	    lookup(orig.shiftId(), shift);
	    if (shift.shiftId() != INVALID_ID)
		return error("Can't change from a posted shift");
	}

	if (gltx.shiftId() != INVALID_ID) {
	    Shift shift;
	    lookup(gltx.shiftId(), shift);
	    if (shift.shiftId() != INVALID_ID)
		return error("Can't insert into a posted shift");
	}
    }

    // Can't change tenders if in a posted shift
    if (gltx.shiftId() != INVALID_ID && orig.tenders() != gltx.tenders()) {
	Shift shift;
	lookup(gltx.shiftId(), shift);
	if (shift.shiftId() != INVALID_ID)
	    return error("Can't change tenders if posted");
    }

    // Reconcile information must match.  Also copy over cleared date
    // when needed since it can be lost on changed transactions.
    for (unsigned int i = 0; i < orig.accounts().size(); ++i) {
	const AccountLine& line = orig.accounts()[i];
	if (line.cleared.isNull()) continue;

	if (i >= gltx.accounts().size())
	    return error("Invalid change to reconciled transaction");
	if (gltx.accounts()[i].account_id != line.account_id)
	    return error("Invalid change to reconciled transaction");
	if (gltx.accounts()[i].amount != line.amount)
	    return error("Invalid change to reconciled transaction");
	gltx.accounts()[i].cleared = line.cleared;
    }

    // Can't change transaction before close date
    Company company;
    lookup(company);
    if (!company.closeDate().isNull()) {
	if (gltx.postDate() <= company.closeDate())
	    return error("Can't change date to before close date");
	if (orig.postDate() <= company.closeDate())
	    return error("Can't change transaction before close date");
    }
    if (!company.startOfYear().isNull()) {
	if (gltx.postDate() < company.startOfYear())
	    return error("Can't change date into last year");
	if (orig.postDate() < company.startOfYear())
	    return error("Can't change transaction in last year");
    }

    // Verify station/employee are specified
    if (company.shiftMethod() == Company::BY_STATION) {
	if (gltx.stationId() == INVALID_ID) {
	    // Error if its a transaction type involving cashrec
	    switch (gltx.dataType()) {
	    case DataObject::INVOICE:
	    case DataObject::RECEIPT:
	    case DataObject::NOSALE:
	    case DataObject::PAYOUT:
	    case DataObject::RETURN:
	    case DataObject::SHIFT:
	    case DataObject::TEND_ADJUST:
	    case DataObject::WITHDRAW:
		return error("A station is required");
	    default:
		break;
	    }
	}
    }
    if (company.shiftMethod() == Company::BY_EMPLOYEE) {
	if (gltx.employeeId() == INVALID_ID) {
	    // Error if its a transaction type involving cashrec
	    switch (gltx.dataType()) {
	    case DataObject::INVOICE:
	    case DataObject::RECEIPT:
	    case DataObject::NOSALE:
	    case DataObject::PAYOUT:
	    case DataObject::RETURN:
	    case DataObject::SHIFT:
	    case DataObject::TEND_ADJUST:
	    case DataObject::WITHDRAW:
		return error("An employee is required");
	    default:
		break;
	    }
	}
    }

    // Check that change data exists and create if needed
    checkAccount(gltx);
    checkCard(gltx);
    checkItem(gltx);

    // NOTE: this doesn't include paid and shouldn't
    QString cmd = updateCmd("gltx", "gltx_id", "number,reference_str,"
			    "post_date,post_time,memo,station_id,"
			    "employee_id,card_id,store_id,shift_id,"
			    "link_id,printed,amount,data_type");
    Stmt stmt(_connection, cmd);

    updateData(orig, gltx, stmt);
    stmtSetString(stmt, gltx.number());
    stmtSetString(stmt, gltx.reference());
    stmtSetDate(stmt, gltx.postDate());
    stmtSetTime(stmt, gltx.postTime());
    stmtSetString(stmt, gltx.memo());
    stmtSetId(stmt, gltx.stationId());
    stmtSetId(stmt, gltx.employeeId());
    stmtSetId(stmt, gltx.cardId());
    stmtSetId(stmt, gltx.storeId());
    stmtSetId(stmt, gltx.shiftId());
    stmtSetId(stmt, gltx.linkId());
    stmtSetBool(stmt, gltx.printed());
    stmtSetFixed(stmt, gltx.total());
    stmtSetInt(stmt, gltx.dataType());
    stmtSetId(stmt, orig.id());
    stmtSetInt(stmt, orig.version());
    execute(stmt);
    if (stmt.getUpdateCount() != 1)
	return error("Data has been changed by another user");

    sqlDeleteLines(orig);
    sqlCreateLines(gltx);

    return true;
}
//***** Quantity should be checked when inputing it
void transaction(unsigned char type,unsigned char msg[]){
	int status;
	int quantity;
	item msg_item;
	// A-upc,name,price,stock,description,imagelink,category
	if (type == 'A'){
		status = checkItem(msg,-1);
		if (status == 0){
			msg_item = getItemFromMsg(msg);
			sendMsg(concat("A,",msg));
			//status = receiveMsg(0);
			status = 1;
			if (status == 1){
				addItem(msg_item);
				updateDatabase();
			}
				else{
				printMsg("Transaction failed!",0,30);
				printf("Transaction failed!\n\n");
			}
		}
		else{
			printMsg("Cannot add the item!",0,30);
			printf("Cannot add the item!\n\n");
		}
		wait(30000000);
	}
	// B-upc,quantity
	else if (type == 'B'){
		quantity = getQuantityFromMsg(msg);
		status = checkItem(msg,quantity);

		if (status == 1){
			sendMsg(concat("B,",msg));
			//status = receiveMsg(0);
			status = 1;
			if (status == 1){
				buyItem(msg_item,quantity);
				updateDatabase();
			}
			else{
				printMsg("Transaction failed!",0,30);
				printf("Transaction failed!\n\n");
			}
		}
		else{
			printMsg("Cannot buy the item!",0,30);
			printf("Cannot buy the item!\n\n");
		}
		wait(30000000);
	}
	// C-upc,name,price,stock,description,imagelink
	else if (type == 'C'){
		status = checkItem(msg,-1);
		if (status == 1){
			msg_item = getItemFromMsg(msg);
			sendMsg(concat("C,",msg));
			//status = receiveMsg(0);
			status = 1;
			if (status == 1){
				changeItem(msg_item);
				msg_item = scan(msg_item.upc);
				printf("Price after:%.2f\n",msg_item.price);
				updateDatabase();
			}
			else{
				printMsg("Transaction failed!",0,30);
				printf("Transaction failed!\n\n");
			}
		}
		else{
			printMsg("Cannot change the item's information!",0,30);
			printf("Cannot change the item's information!\n\n");
		}
		wait(30000000);
	}
}
void ContextMenu::create(HWND hParent, const std::vector<MenuItemUnit> & menuItemArray, const HMENU mainMenuHandle)
{ 
	_hParent = hParent;
	_hMenu = ::CreatePopupMenu();
	bool lastIsSep = false;
	HMENU hParentFolder = NULL;
	generic_string currentParentFolderStr;
	int j = 0;

	for (size_t i = 0, len = menuItemArray.size(); i < len; ++i)
	{
		const MenuItemUnit & item = menuItemArray[i];
		if (item._parentFolderName.empty())
		{
			currentParentFolderStr.clear();
			hParentFolder = NULL;
			j = 0;
		}
		else
		{
			if (item._parentFolderName != currentParentFolderStr)
			{
				currentParentFolderStr = item._parentFolderName;
				hParentFolder = ::CreateMenu();
				j = 0;

				_subMenus.push_back(hParentFolder);
				::InsertMenu(_hMenu, static_cast<UINT>(i), MF_BYPOSITION | MF_POPUP, (UINT_PTR)hParentFolder, currentParentFolderStr.c_str());
			}
		}

		unsigned int flag = MF_BYPOSITION | ((item._cmdID == 0)?MF_SEPARATOR:0);
		if (hParentFolder)
		{
			::InsertMenu(hParentFolder, j++, flag, item._cmdID, item._itemName.c_str());
			lastIsSep = false;
		}
		else if ((i == 0 || i == menuItemArray.size() - 1) && item._cmdID == 0)
		{
			lastIsSep = true;
		}
		else if (item._cmdID != 0)
		{
			::InsertMenu(_hMenu, static_cast<UINT>(i), flag, item._cmdID, item._itemName.c_str());
			lastIsSep = false;
		}
		else if (item._cmdID == 0 && !lastIsSep)
		{
			::InsertMenu(_hMenu, static_cast<int32_t>(i), flag, item._cmdID, item._itemName.c_str());
			lastIsSep = true;
		}
		else // last item is separator and current item is separator
		{
			lastIsSep = true;
		}

		
		if (mainMenuHandle)
		{
			bool isEnabled = (::GetMenuState(mainMenuHandle, item._cmdID, MF_BYCOMMAND)&(MF_DISABLED|MF_GRAYED)) == 0;
			bool isChecked = (::GetMenuState(mainMenuHandle, item._cmdID, MF_BYCOMMAND)&(MF_CHECKED)) != 0;
			if (!isEnabled)
				enableItem(item._cmdID, isEnabled);
			if (isChecked)
				checkItem(item._cmdID, isChecked);
		}

	}
}
Exemple #12
0
void TradeWindow::action(const gcn::ActionEvent &event)
{
    if (!inventoryWindow)
        return;

    Item *const item = inventoryWindow->getSelectedItem();
    const std::string &eventId = event.getId();

    if (eventId == "add")
    {
        if (mStatus != PREPARING)
            return;

        if (!inventoryWindow->isWindowVisible())
        {
            inventoryWindow->setVisible(true);
            return;
        }

        if (!item)
            return;

        if (mMyInventory->getFreeSlot() == -1)
            return;


        if (!checkItem(item))
            return;

        // Choose amount of items to trade
        ItemAmountWindow::showWindow(ItemAmountWindow::TradeAdd, this, item);

        setStatus(PREPARING);
    }
    else if (eventId == "cancel")
    {
        setVisible(false);
        reset();
        PlayerInfo::setTrading(false);

        Net::getTradeHandler()->cancel();
    }
    else if (eventId == "ok")
    {
        mMoneyField->setEnabled(false);
        mAddButton->setEnabled(false);
        mMoneyChangeButton->setEnabled(false);
        receivedOk(true);
        setStatus(PROPOSING);
        Net::getTradeHandler()->confirm();
    }
    else if (eventId == "trade")
    {
        receivedOk(true);
        setStatus(ACCEPTED);
        Net::getTradeHandler()->finish();
    }
    else if (eventId == "money")
    {
        if (mStatus != PREPARING)
            return;

        int v = atoi(mMoneyField->getText().c_str());
        const int curMoney = PlayerInfo::getAttribute(PlayerInfo::MONEY);
        if (v > curMoney)
        {
            if (localChatTab)
            {
                // TRANSLATORS: trade error
                localChatTab->chatLog(_("You don't have enough money."),
                                      BY_SERVER);
            }
            v = curMoney;
        }
        Net::getTradeHandler()->setMoney(v);
        mMoneyField->setText(strprintf("%d", v));
    }
}
Exemple #13
0
/*------------------------------------------------------------------------------------------------------------------
--		FUNCTION:		WndProc
--		DATE:			September 21st, 2012
--		REVISIONS:		n/a
--		DESIGNER:		Ramzi Chennafi
--		PROGRAMMER:		Ramzi Chennafi	
--
--		INTERFACE:		LRESULT CALLBACK WndProc (HWND hwnd, UINT Message,
--                          WPARAM wParam, LPARAM lParam)				
--
--		RETURNS:		LRESULT to the system.
--
--		NOTES:
--		Deals with the main window thread. Requests writes, modification of data settings, usage information and 
--		connect/disconnect buttons. Also creates a new thread to perform read operations.
----------------------------------------------------------------------------------------------------------------------*/
LRESULT CALLBACK WndProc (HWND hwnd, UINT Message,
                          WPARAM wParam, LPARAM lParam)
{
	HMENU			menuHnd	= GetMenu(hwnd);
	
	switch (Message)
   {
		case WM_COMMAND:
		   switch (LOWORD (wParam))
			{
				case IDM_CONNECT:
					if(!io->serialOn){
						if((io->hdSerial = init(io)) != NULL){
							MessageBox (hwnd, TEXT("Client Connected"), TEXT("Dumb Terminal"), MB_OK | MB_ICONEXCLAMATION);
							io->serialOn = true;
							io->readThrd = CreateThread(NULL, 0, execRead, io, 0, &io->threadId);
							EnableMenuItem(menuHnd, IDM_CONNECT, MF_GRAYED);
							DrawMenuBar(hwnd);
						}
					}
				break;

				case IDM_HELP:
					MessageBox (hwnd, TEXT("Choose which port you wish to communicate on and then hit data settings to modify the communication settings.\nConnect will begin a session, hit escape to end the current session.\nAny keyboard input will be transferred during a session."), 
						TEXT("Dumb Terminal"), MB_OK | MB_ICONINFORMATION);
				break;
				
				case ID_PORT_COMM1:
					io->port = TEXT("com1");
					checkItem(menuHnd, COMM1);
				break;
				
				case ID_PORT_COMM3:
					io->port = TEXT("com3");
					checkItem(menuHnd, COMM3);
				break;

          		case IDM_DATA_SETTINGS:
            		io->cc.dwSize = sizeof(COMMCONFIG);
					io->cc.wVersion = 0x100;
					GetCommConfig (hComm, &io->cc, &io->cc.dwSize);
            		if (!CommConfigDialog (io->port, io->hwnd, &io->cc))
               			break;
				break;
			}
		break;

		case WM_CHAR:	
			if(io->serialOn && wParam != VK_ESCAPE){
				writeOutputBuffer(io->hdSerial, wParam);
			}
		break;

		case WM_KEYDOWN:
			if(wParam == VK_ESCAPE && io->serialOn == true){
				io->serialOn = false;
				
				MessageBox (hwnd, TEXT("Client Disconnected"), TEXT("Dumb Terminal"), MB_OK | MB_ICONEXCLAMATION);
				InvalidateRect(hwnd, NULL, FALSE);
				EnableMenuItem(menuHnd, IDM_CONNECT, MF_ENABLED);
				DrawMenuBar(hwnd);
				
				endSession(io->hdSerial, io->readThrd);
			}
		break;

		case WM_DESTROY:	
      		PostQuitMessage (0);
		break;
		
		default:
			 return DefWindowProc (hwnd, Message, wParam, lParam);
	}
	return 0;
}