void TerminateOpenFileDialog()
{
    if ( gOpenFileDialog != NULL )
    {
        TerminateDialog( gOpenFileDialog );
    }
}
/*
 * This is the dialog function for displaying a table.
 */
static BOOL CALLBACK TableDisplayFunc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	LPDISPLAYINFO	DisplayInfo;
	LPTABLECELL		Iter;
	LVCOLUMN		Column;
	WNDPROC			OldWndProc;
	LPTABLE			Table;
	LVITEM			Item;
	LPRECT			Margins;
	LPTSTR			DynamicText;
	TCHAR			Text[100];
	LONG			Style;
	RECT			ClientRect;
	RECT			Rect;
	HWND			hWndList;
	HWND			hWndOk;
	int				Width;
	int				Rows, Cols;
	int				Top, Left;
	int				i, j, k;


	switch(Msg) {
		case WM_INITDIALOG:
			DisplayInfo = (LPDISPLAYINFO)lParam;
			SetWindowText (hWnd, DisplayInfo->Title);
			Table = DisplayInfo->Table;
			Rows = GetRows(Table);
			Cols = GetCols(Table);
			hWndList = GetDlgItem(hWnd, IDC_TABLELIST);

			GetWindowRect(hWndList, &ClientRect);
			GetClientWindowRect(hWnd, &Rect);
			Margins = (LPRECT)MemAlloc(sizeof(RECT));
			Margins->bottom = Rect.bottom - ClientRect.bottom;
			Margins->top = ClientRect.top - Rect.top;
			Margins->left = ClientRect.left - Rect.left;
			Margins->right = Rect.right - ClientRect.right;
			SetWindowLong(hWnd, DWL_USER, (LONG)Margins);

			GetClientRect(hWndList, &ClientRect);
			Width = ClientRect.right - ClientRect.left;
			if((Cols == 0) || (Rows == 0)) {
				/* Display an empty table, subclass the list window. */
				OldWndProc = (WNDPROC)GetWindowLong(hWndList, GWL_WNDPROC);
				SetProp(hWndList, SubClassString, OldWndProc);
				SetWindowLong(hWndList, GWL_WNDPROC, (LONG)NewListProc);
				Style = GetWindowLong(hWndList, GWL_STYLE);
				Style |= LVS_NOCOLUMNHEADER;
				SetWindowLong(hWndList, GWL_STYLE, Style);
			}
			SendMessage(hWndList, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
			/* Create header with columns. We create one extra to delete later, because windows does not
			   let you format the first column. */
			if(Cols != 0) {
				for(i=0; i<=Cols; i++) {
					memset(&Column, 0, sizeof(Column));
					if((i==0) || (DisplayInfo->ColumnHeadings == NULL)) {
						wsprintf(Text, _T("%d"), i);
						Column.pszText = Text;
					} else {
						Column.pszText = DisplayInfo->ColumnHeadings[i-1];
					}
					Column.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_FMT;
					Column.fmt = LVCFMT_CENTER;
					Column.cx = Width/Cols;
					if(i == Cols) {
						Column.cx += Width % Cols;
					}
					SendMessage(hWndList, LVM_INSERTCOLUMN, i, (LPARAM)&Column);
				}
				SendMessage(hWndList, LVM_DELETECOLUMN, 0, 0);
			}

			/* Create rows. */
			memset(&Item, 0, sizeof(Item));
			for(i=0; i<Rows; i++) {
				Item.iItem = i;
				SendMessage(hWndList, LVM_INSERTITEM, 0, (LPARAM)&Item);
			}

			/* Insert each table element. */
			for(i=0; i<Rows; i++) {
				for(j=0; j<Cols; j++) {
					Iter = GetTableCell(Table, i, j);
					if(Iter != NULL) {
						DynamicText = NULL;
						memset(&Item, 0, sizeof(Item));
						Item.mask = LVIF_TEXT;
						Item.iItem = i;
						Item.iSubItem = j;
						if(Iter->Type == TABLE_TYPE_INT) {
							wsprintf(Text, _T("%d"), Iter->IntData);
							Item.pszText = Text;
						} else if(Iter->Type == TABLE_TYPE_STRING) {
							Item.pszText = (LPSTR)Iter->Bytes;
						} else if(Iter->Type == TABLE_TYPE_BINARY) {
							DynamicText = (LPTSTR)MemAlloc((3*(Iter->Size) + 2) * sizeof(TCHAR));
							for(k=0; k<Iter->Size; k++) {
								wsprintf(&DynamicText[3*k], _T("%02X "), Iter->Bytes[k]);
							}
							Item.pszText = DynamicText;
						} else {
							Item.pszText = _T("");
						}
						SendMessage(hWndList, LVM_SETITEM, 0, (LPARAM)&Item);
						if(DynamicText != NULL) {
							MemFree(DynamicText);
						}
					}
				}
			}

			return TRUE;
			break;
		case WM_SIZE:
		case WM_SIZING:
			Margins = (LPRECT)GetWindowLong(hWnd, DWL_USER);
			hWndList = GetDlgItem(hWnd, IDC_TABLELIST);
			GetClientRect(hWnd, &ClientRect);
			InvalidateRect(hWndList, NULL, FALSE);
			MoveWindow(hWndList, ClientRect.left + Margins->left, ClientRect.top + Margins->top, ClientRect.right - Margins->right - Margins->left, ClientRect.bottom - Margins->bottom - Margins->top, TRUE);
			hWndOk = GetDlgItem(hWnd, IDOK);
			GetClientRect(hWndOk, &Rect);
			Top = (2*ClientRect.bottom - Margins->bottom)/2 - (Rect.bottom - Rect.top)/2;
			Left = (ClientRect.right - ClientRect.left)/2 - (Rect.right - Rect.left)/2;
			MoveWindow(hWndOk, Left, Top, Rect.right, Rect.bottom, TRUE);
			break;
		case WM_SYSCOMMAND:
			switch(wParam & 0xfff0) {
				case SC_CLOSE:
					TerminateDialog(hWnd);
					return TRUE;
					break;
			}
			break;
		case WM_COMMAND:
			switch(LOWORD(wParam)) {
				case IDOK:
					TerminateDialog(hWnd);
					break;
				case IDCANCEL:
					TerminateDialog(hWnd);
					break;
			}
			return TRUE;
			break;
	}

	return FALSE;
}