Click here to Skip to main content
Email Password   helpLost your password?

Introduction

I tried to use many grids of different types in Arabic mode but I failed, until I found GridCtrl with source. And then I worked to adapt it to work with Arabic mode in different types of Views or Dialogs.

/////////////////////////////////////////////////////////////////////////////

// Tarek Ahmed


// Disable inheritence of mirroring by children

#define WS_EX_NOINHERITLAYOUT   0x00100000L 
#define WS_EX_LAYOUT_RTL        0x00400000L
// Right to left mirroring

#define WS_EX_LAYOUTRTL         0x00400000L 
// Disable inheritence of mirroring by children 

#define WS_EX_NOINHERITLAYOUT   0x00100000L 
// Disable inheritence of mirroring by children

#define WS_EX_NOINHERIT_LAYOUT  0x00100000L 


BOOL CGridCtrl::Initialise()
{
..............
..............
..............

    if (::IsWindow(m_hWnd))
    {
        // Tarek Ahmed

        ModifyStyleEx(0, 0x00400000L, 0);
        ModifyStyleEx(0, WS_EX_RTLREADING, 0);
        ModifyStyleEx(0, WS_EX_RIGHT, 0);
        ModifyStyleEx(0, WS_EX_CLIENTEDGE, 0);
    }
..............
..............
..............
..............
    return TRUE;
}


// creates the control - use like any other window create control

BOOL CGridCtrl::Create(const RECT& rect, CWnd* pParentWnd, 
                       UINT nID, DWORD dwStyle)
{
..............
..............
..............

    DWORD dwExStyle;

    if ( bCreateOnView )
    {
        if (!CWnd::Create(GRIDCTRL_CLASSNAME, NULL, dwStyle, 
                                rect, pParentWnd, nID))
            return FALSE;

        Initialise();
    }
    else
    {
        // Tarek Ahmed

        dwExStyle ^= 0x00400000L;    
        dwExStyle ^= WS_EX_RTLREADING;
        dwExStyle ^= WS_EX_RIGHT;
        if (!CWnd::CreateEx(dwExStyle, GRIDCTRL_CLASSNAME, GRIDCTRL_CLASSNAME, 
                                 dwStyle, rect, pParentWnd, nID, NULL))
            return FALSE;
    }

..............
..............
..............

    return TRUE;
}

void CGridCtrl::OnTimer(UINT nIDEvent)
{
..............
..............
..............

    if (pt.y > rect.bottom)
    {
        //SendMessage(WM_VSCROLL, SB_LINEDOWN, 0); org code

        SendMessage(WM_KEYDOWN, VK_DOWN, 0);

        if (pt.x < rect.left)
            pt.x = rect.left;
        if (pt.x > rect.right)
            pt.x = rect.right;
        pt.y = rect.bottom;
        OnSelecting(GetCellFromPt(pt));
    }
    else if (pt.y < nFixedRowHeight)
    {
        //SendMessage(WM_VSCROLL, SB_LINEUP, 0);  org code

        SendMessage(WM_KEYDOWN, VK_UP, 0);

        if (pt.x < rect.left)
            pt.x = rect.left;
        if (pt.x > rect.right)
            pt.x = rect.right;
        pt.y = nFixedRowHeight + 1;
        OnSelecting(GetCellFromPt(pt));
    }

    pt = origPt;
    if (pt.x > rect.right)
    {
       // Tarek Ahmed

        // SendMessage(WM_HSCROLL, SB_LINERIGHT, 0);

        SendMessage(WM_KEYDOWN, VK_RIGHT, 0);

        if (pt.y < rect.top)
            pt.y = rect.top;
        if (pt.y > rect.bottom)
            pt.y = rect.bottom;
        pt.x = rect.right;
        OnSelecting(GetCellFromPt(pt));
    }
    else if (pt.x < nFixedColWidth)
    {
       // Tarek Ahmed

        //SendMessage(WM_HSCROLL, SB_LINELEFT, 0);

        SendMessage(WM_KEYDOWN, VK_LEFT, 0);

        if (pt.y < rect.top)
            pt.y = rect.top;
        if (pt.y > rect.bottom)
            pt.y = rect.bottom;
        pt.x = nFixedColWidth + 1;
        OnSelecting(GetCellFromPt(pt));
    }
..............
..............
..............
}

// move about with keyboard

void CGridCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
..............
..............
..............
        if (!IsCellVisible(next))
        {

            switch (nChar)
            {
            case VK_LEFT:  
                // Tarek Ahmed

                SendMessage(WM_HSCROLL, SB_LINERIGHT, 0); 
                bHorzScrollAction = TRUE;
                break;
                
            case VK_RIGHT:   
                // Tarek Ahmed

                SendMessage(WM_HSCROLL, SB_LINELEFT, 0);  
                bHorzScrollAction = TRUE;
                break;
                
        }

..............
..............
..............
}

Working with views:

void CSomeClassToWorkAsView::OnInitialUpdate() 
{
    CView::OnInitialUpdate();

    // TODO: Add your specialized code here and/or call the base class


    if (!m_InitOn)
    {
        // Create the Gridctrl window

        m_pGridCtrl = new CGridCtrl;
        if (!m_pGridCtrl) return;

        m_pGridCtrl->bCreateOnView = true;

        CRect rect;
        GetClientRect(rect);
        m_pGridCtrl->Create(rect, this, 1001);

        m_InitOn = true;
    }
    if (m_InitOn)
    {
        ReGetData();
    }
}

Working with cells' merge:

            for (col = 0; col < m_Grid.GetColumnCount(); col++)
            { 
                m_Grid.SetItemBkColour(iRowCur, col, RGB(165, 27, 30));
                m_Grid.SetItemFgColour(iRowCur, col, RGB(255, 255, 0));
            }
            m_Grid.SetSelectedRange(iRowCur, ID_QUTNAME, iRowCur, ID_SELX);
            m_Grid.MergeSelectedCells();

Initialize normal control:

#define ID_COL_COUNT        0
#define ID_COL_DOCNO        1
#define ID_COL_DAYCOUNT        2
#define ID_COL_TDATESTART    3
#define ID_COL_TDATEEND        4
#define ID_COL_UAMTCHARGE    5
#define ID_COL_UAMTMOVE        6
#define ID_COL_UAMTENTRY    7
#define ID_COL_UAMTOTHER    8
#define ID_COL_UAMTTOTAL    9
#define ID_COL_COSTCNTR        10
#define ID_COL_MEMO            11


    m_Grid.DeleteAllItems();
    UpdateWindow();
    m_Grid.GetDefaultCell(FALSE, FALSE)->SetBackClr(RGB(0xFF, 0xFF, 0xE0));
    m_Grid.SetFixedColumnSelection(false);
                m_Grid.SetFixedRowSelection(false);
    m_Grid.SetHeaderSort(TRUE);
    m_Grid.EnableColumnHide();
    m_Grid.SetColumnCount(12);

    m_Grid.SetRowCount(1);    

    m_Grid.SetAutoSizeStyle();

    m_Grid.SetCompareFunction(CGridCtrl::pfnCellNumericCompare);

    m_Grid.SetFixedRowCount(1);
    m_Grid.SetFixedColumnCount(1);

    GV_ITEM Item;
    
    Item.mask = GVIF_TEXT|GVIF_PARAM|GVIF_FORMAT;
    Item.nFormat = DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
    Item.nState = 0;
    Item.row = 0;
    Item.col = ID_COL_COUNT;
    Item.strText = "�";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_DOCNO;
    Item.strText = "��� �������";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_DAYCOUNT;
    Item.strText = "��� ������";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_TDATESTART;
    Item.strText = "��� ��         ";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_TDATEEND;
    Item.strText = "������ ��      ";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_UAMTCHARGE;
    Item.strText = "��� �����";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_UAMTMOVE;
    Item.strText = "�. ������";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_UAMTENTRY;
    Item.strText = "�. ������";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_UAMTOTHER;
    Item.strText = "�������";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_UAMTTOTAL;
    Item.strText = "������";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_COSTCNTR;
    Item.strText = "���� �����";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_MEMO;
    Item.strText = _T("�������                          ");
    m_Grid.SetItem(&Item);


    m_Grid.AutoSize();
    m_Grid.ExpandLastColumn();    
    m_Grid.SetEditable(true);
    m_Grid.SetRowResize(false);    


void CSomeClassToWork::SetRowColItem(int row)
{
    for (int col = 0; col < m_Grid.GetColumnCount(); col++)
    { 
        CString str;

        GV_ITEM Item;

        Item.mask = GVIF_TEXT|GVIF_PARAM|GVIF_FORMAT;
        Item.nFormat = DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
        Item.nState = 0;
        Item.row = row;
        Item.col = col;

        if ( col == ID_COL_COUNT )
        {
            CString sTemp;
            sTemp.Format("%d", row);
            Item.strText = sTemp;
        }

        if ( col == ID_COL_DOCNO ) 
            Item.strText = _T("");

        if ( col == ID_COL_DAYCOUNT ) 
            Item.strText = _T("00");

        if ( ( col >= ID_COL_COSTCNTR )  && ( col <= ID_COL_MEMO ) )
            Item.strText = _T("");

        if ( ( col >= ID_COL_UAMTCHARGE ) && ( col <= ID_COL_UAMTTOTAL ) ) 
            Item.strText = _T("0.00");


        if ( ( col >= ID_COL_TDATESTART ) && ( col <= ID_COL_TDATEEND ) )
            Item.strText = _T("  -  -    ");

        m_Grid.SetItem(&Item);

        m_Grid.SetItemState(row, col,
                m_Grid.GetItemState(row, col) & ~GVIS_READONLY);

        if ( col == ID_COL_DOCNO ) 
        {
            m_Grid.SetItemState(row, col, 
                  m_Grid.GetItemState(row, col) & ~GVIS_READONLY);

            if (!m_Grid.SetCellType(row, col, RUNTIME_CLASS(CGridCellNormal)))
                return;
        }

        if ( ( col >= ID_COL_COSTCNTR )  && ( col <= ID_COL_MEMO ) )
        {
            m_Grid.SetItemState(row, col, 
                   m_Grid.GetItemState(row, col) & ~GVIS_READONLY);

            if (!m_Grid.SetCellType(row, col, RUNTIME_CLASS(CGridCellNormal)))
                return;
        }

        if ( ( col >= ID_COL_TDATESTART ) && ( col <= ID_COL_TDATEEND ) )
        {
            if (!m_Grid.SetCellType(row, col, RUNTIME_CLASS(CGridCellDateTime)))
                return;

            CGridCellDateTime *pCell = 
                 (CGridCellDateTime*) m_Grid.GetCell(row, col);
            COleDateTime m_cTime;
            m_cTime = COleDateTime::GetCurrentTime();
            pCell->m_cTime = m_cTime;
            CString sTDate;
            sTDate = m_cTime.Format("%Y-%m-%d");
            m_Grid.SetItemText(row, col, sTDate);
        }
    }
    m_Grid.SetItemText(row, ID_COL_DOCNO        , sDocNo        );
    m_Grid.SetItemText(row, ID_COL_DAYCOUNT        , sDayCount        );
    m_Grid.SetItemText(row, ID_COL_TDATESTART    , sTDateStart    );
    m_Grid.SetItemText(row, ID_COL_TDATEEND        , sTDateEnd        );
    m_Grid.SetItemText(row, ID_COL_UAMTCHARGE    , suAmtTCharge    );
    m_Grid.SetItemText(row, ID_COL_UAMTMOVE        , suAmtTMove    );
    m_Grid.SetItemText(row, ID_COL_UAMTENTRY    , suAmtTEntry    );
    m_Grid.SetItemText(row, ID_COL_UAMTOTHER    , suAmtTOther    );
    m_Grid.SetItemText(row, ID_COL_UAMTTOTAL    , suAmtTTotal    );
    m_Grid.SetItemText(row, ID_COL_COSTCNTR        , sCostCnt        );
    m_Grid.SetItemText(row, ID_COL_MEMO            , sHMemo        );
}

Have fun!

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralPrint
Bahman Tahayori
2:05 27 Dec '05  
Dear Tarek,
Thanks a lot for your very interesting changes. But I have a problem with your code. When I use the Print command, the printed table will be very very small and also the table is reversed!!!! How can I solve it.

Thanks to you.
Best regards,
Bahman Tahayori

Thanks
Generalcan you help me?
3loop
23:48 27 Jun '05  
Fisrt, sorry for my bad englich.I find your code very interesting and I think you can really help me.I use the microsoft c++6 standard edition(Authors edition) and I want to programme a dialog-based application in tow languages: German und Arabic, with German I found no problems, but with Arabic when I try to write in Arabic in the editor (on the dialog buttons) I becomme comic signs.Can you please tell me how can I solve this problem?

thanks a lot
Anis from Germany
GeneralRe: can you help me?
Tarek Ahmed Abdel Rahmane
3:01 8 Aug '05  
First On Dialog Set the Language Properties to Neutral (Sys. Default)

Second On your Project Settings -> Resources
Set Language To Arabic (Saudi Arabia)

this will work for arabic

Generalnice.
zarzor
9:05 5 May '05  
good job Tarek! Smile

ZARZOR13
GeneralIsaac
Isaac_cm
12:02 19 Dec '04  
I use the Component One FlexGrid in my app (VB .NET CF)
and the fields display nothing for Arabic characters is there a soltions for this ?

thanks
Generalyour code doesn't work in VC7
haoshenghan
20:26 20 Apr '04  
I replace (int) ,and instead it with (UINT),then it works
GeneralVC++ Example
vladFed
3:47 31 Mar '03  
Can you please post VC++ example using this control.
It is not clear how to use it in virtual mode and how to place this control into dialog or FormView.
Thank you.
GeneralRe: VC++ Example
welo_2000
1:55 23 Apr '03  
I made a very simple VC++ sample to use that, if u need it send to me.

all what u need is to write a piece of code similar to the following in ur dialog OnInitDialog():

m_cGrid.bCreateOnView = TRUE;
m_cGrid.Create(rect,this,1001);
m_cGrid.SetEditable(true);
m_cGrid.SetListMode(false);
m_cGrid.EnableDragAndDrop(TRUE);

// Construct the columns and rows
int nRows = 4;
int nCols = 3;
m_cGrid.SetRowCount(nRows+1);
m_cGrid.SetColumnCount(nCols+1);

m_cGrid.SetFixedRowCount(1);
m_cGrid.SetFixedColumnCount(1);

m_cGrid.SetColumnResize(FALSE);
m_cGrid.SetRowResize(FALSE);


int nArrIdx = 0;
for (int nCol = 1 ;nCol <= nCols ;nCol++)
{
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = 0;
Item.col = nCol;
Item.nFormat = DT_WORDBREAK;

CString str;
str.Format("Column %d",nCol);
Item.strText = str;


m_cGrid.SetItem(&Item);
}

for (int nRow = 1 ;nRow <= nRows ;nRow++)
{
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = nRow;
Item.col = 0;
Item.nFormat = DT_WORDBREAK;


CString str;
str.Format("Row %d",nRow);
Item.strText = str;
m_cGrid.SetItem(&Item);
}



Waleed

Waleed Ismail
GeneralRe: VC++ Example
zizzzz
23:18 29 Nov '06  
can you send me a simple example I don't know how to integrate this code in my program .
also I don't know if the GridCtrl is a component that I must insert like I do for a CEdit or a button.
i found many samples but I don't suceed to understand how they introduce this control in CDialog

please help me !
GeneralRe: VC++ Example
zizzzz
0:36 30 Nov '06  
can you explain me
where you declare the m_cGrid and how
and the number 1001 is it the id of the gridctrl


m_cGrid.Create(rect,this,1001);
GeneralSome suggestions
Victor Boctor
20:00 2 Feb '03  
1. Consider adding a picture so the reader knows what you are talking about.
2. Some more explanations / text, rather than just code.
3. Add a credits section to the owner of the code (I understand from the introduction that you are adapting the code to work with Arabic, rather than did the code from scratch).

Regards,
Victor.

phpWebNotes is a page annotation system modelled after php.net.
http://webnotes.sourceforge.net/demo.php[^]
GeneralRe: Some suggestions
Tarek Ahmed Mohamed Abdel Rahmane
5:34 3 Feb '03  
thanks for suggestions
but i upload a picture and not display
Rose

GeneralRe: Some suggestions
Paolo Messina
0:43 4 Feb '03  
The picture won't show unless you put an IMG tag somewhere in the HTML source of your article.

------
Why spend 2 minutes doing it by hand when you can spend all night plus most of the following day writing a system to do it for you? - (Chris Maunder)


Last Updated 2 Feb 2003 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010