C++操作HTML TABLE要素

2365 ワード

BOOL TableInsertRow(IHTMLTable* TableElement, LONG nRow, IHTMLTableRow* &RowElement)
{
	BOOL IsOk;
	IDispatch *DispRow;

	IsOk = FALSE;
	if (SUCCEEDED(TableElement->insertRow(nRow, &DispRow)))
	{
		IsOk = (SUCCEEDED(DispRow->QueryInterface(IID_IHTMLTableRow, (PVOID*)&RowElement)));
		DispRow->Release();
	}
	return IsOk;
}

BOOL TableGetRow(IHTMLTable* TableElement, LONG nRow, IHTMLTableRow* &Row)
{
	BOOL IsOk;
	IHTMLElementCollection *RowElements;

	IsOk = FALSE;
	if (SUCCEEDED(TableElement->get_rows(&RowElements)))
	{
		VARIANT vName, vIndex;
		IDispatch *DispRowElement;

		VariantInit(&vName);
		VariantInit(&vIndex);
		vName.vt = VT_I4;
		vName.lVal = nRow;
		if (SUCCEEDED(RowElements->item(vName, vIndex, &DispRowElement)))
		{
			IsOk = SUCCEEDED(DispRowElement->QueryInterface(IID_IHTMLTableRow, (PVOID*)&Row));
			DispRowElement->Release();
		}
		RowElements->Release();
	}
	return IsOk;
}

BOOL TableInsertCell(IHTMLTableRow* RowElement, LONG nCell, IHTMLElement* &Cell)
{
	BOOL IsOk;
	IDispatch *DispCell;

	IsOk = FALSE;
	if (SUCCEEDED(RowElement->insertCell(nCell, &DispCell)))
	{
		IsOk = SUCCEEDED(SUCCEEDED(DispCell->QueryInterface(IID_IHTMLElement, (PVOID*)&Cell)));
		DispCell->Release();
	}
	return IsOk;
}

BOOL TableGetCell(IHTMLTableRow* RowElement, LONG nCell, IHTMLElement* &Cell)
{
	BOOL IsOk;
	IHTMLElementCollection *Cells;

	IsOk = FALSE;
	if (SUCCEEDED(RowElement->get_cells(&Cells)))
	{
		VARIANT vName, vIndex;
		IDispatch *DispCellElement;

		VariantInit(&vName);
		VariantInit(&vIndex);
		vName.vt = VT_I4;
		vName.lVal = nCell;
		if (SUCCEEDED(Cells->item(vName, vIndex, &DispCellElement)))
		{
			IsOk = SUCCEEDED(DispCellElement->QueryInterface(IID_IHTMLElement, (PVOID*)&Cell));
			DispCellElement->Release();
		}
		Cells->Release();
	}
	return IsOk;
}

BOOL TableDeleteRow(IHTMLTable* TableElement, LONG nRow)
{
	return SUCCEEDED(TableElement->deleteRow(nRow));
}

BOOL TableGetCell(IHTMLTable* TableElement, LONG nRow, LONG nCell, IHTMLElement* &Cell)
{
	BOOL IsOk;
	IHTMLTableRow *RowElement;

	IsOk = FALSE;
	if (TableGetRow(TableElement, nRow, RowElement))
	{
		IsOk = TableGetCell(RowElement, nCell, Cell);
		RowElement->Release();
	}
	return IsOk;
}