1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Could I have some help with drawing ?( MFC )

Discussion in 'Win32' started by domain, May 18, 2007.

  1. domain

    domain New Member

    Joined:
    May 1, 2007
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    Hi everyone :)
    I'm building a program that manipulates with Singly Linked List which has a one data member ( int ), and there are many functions like: add first, delete, ...
    The problem is: How can I draw the list ? ( It is okay if each node represented by a square and inside it there is the int data ).

    These are some pics of my program :

    The main window:
    [​IMG]


    Resource View:
    [​IMG]


    Files View:
    [​IMG]


    Class View:
    [​IMG]


    ( I created a class for each dialog, is that ok ? )


    This the source code for "Singly Linked List intDlg":

    PHP:


    // Singly Linked List intDlg.cpp : implementation file
    //

    #include "stdafx.h"
    #include "Singly Linked List int.h"
    #include "Singly Linked List intDlg.h"

    //$$$$$$$$$$$$$$$$$$$$
    #include "AddFirst.h"
    #include "Delete.h"
    #include "Size.h"
    #include "Print.h"
    #include "About.h"
    //$$$$$$$$$$$$$$$$$$$$


    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif

    /////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App About



    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
    //$$$$$$$$$$$$$$$$$$$$$$$ Node Class $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//

    //$$$$$$$$$$$$$$$$$$$
    AddFirst addFirstDLG;
    Delete deleteDLG;
    Size sizeDLG;
    Print 
    printDLG;
    About aboutDLG;
    //$$$$$$$$$$$$$$$$$$$

    class Node
    {
    public:
        
    Node( int );
        ~
    Node();

        
    int DATA;
        
    Nodenext;
    };

    Node::Nodeint nd )
    {
        
    DATA nd;
        
    next NULL;
    }

    Node::~Node()
    {
        
    next NULL;
    }



    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
    //$$$$$$$$$$$$$$$$$$$$$$$ Node Class $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//


    /*********************
    **********************/
    NodefirstPtr NULL;
    int sizeOfList;
    /**********************
    *********************/



    class CAboutDlg : public CDialog
    {
    public:
        
    CAboutDlg();

    // Dialog Data
        //{{AFX_DATA(CAboutDlg)
        
    enum IDD IDD_ABOUTBOX };
        
    //}}AFX_DATA

        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CAboutDlg)
        
    protected:
        
    virtual void DoDataExchange(CDataExchangepDX);    // DDX/DDV support
        //}}AFX_VIRTUAL

    // Implementation
    protected:
        
    //{{AFX_MSG(CAboutDlg)
        //}}AFX_MSG
        
    DECLARE_MESSAGE_MAP()
    };

    CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
        
    //{{AFX_DATA_INIT(CAboutDlg)
        //}}AFX_DATA_INIT
    }

    void CAboutDlg::DoDataExchange(CDataExchangepDX)
    {
        
    CDialog::DoDataExchange(pDX);
        
    //{{AFX_DATA_MAP(CAboutDlg)
        //}}AFX_DATA_MAP
    }

    BEGIN_MESSAGE_MAP(CAboutDlgCDialog)
        
    //{{AFX_MSG_MAP(CAboutDlg)
            // No message handlers
        //}}AFX_MSG_MAP
    END_MESSAGE_MAP()

    /////////////////////////////////////////////////////////////////////////////
    // CSinglyLinkedListintDlg dialog

    CSinglyLinkedListintDlg::CSinglyLinkedListintDlg(CWndpParent /*=NULL*/)
        : 
    CDialog(CSinglyLinkedListintDlg::IDDpParent)
    {
        
    //{{AFX_DATA_INIT(CSinglyLinkedListintDlg)
            // NOTE: the ClassWizard will add member initialization here
        //}}AFX_DATA_INIT
        // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
        
    m_hIcon AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }

    void CSinglyLinkedListintDlg::DoDataExchange(CDataExchangepDX)
    {
        
    CDialog::DoDataExchange(pDX);
        
    //{{AFX_DATA_MAP(CSinglyLinkedListintDlg)
            // NOTE: the ClassWizard will add DDX and DDV calls here
        //}}AFX_DATA_MAP
    }

    BEGIN_MESSAGE_MAP(CSinglyLinkedListintDlgCDialog)
        
    //{{AFX_MSG_MAP(CSinglyLinkedListintDlg)
        
    ON_WM_SYSCOMMAND()
        
    ON_WM_PAINT()
        
    ON_WM_QUERYDRAGICON()
        
    ON_BN_CLICKED(IDC_EXITOnExit)
        
    ON_BN_CLICKED(IDC_DELETEOnDelete)
        
    ON_BN_CLICKED(IDC_ADD_AFTEROnAddAfter)
        
    ON_BN_CLICKED(IDC_ADD_BEFOREOnAddBefore)
        
    ON_BN_CLICKED(IDC_SIZEOnSize)
        
    ON_BN_CLICKED(IDC_IS_EMPTYOnIsEmpty)
        
    ON_BN_CLICKED(IDC_SWAPOnSwap)
        
    ON_BN_CLICKED(IDC_IN_LISTOnInList)
        
    ON_BN_CLICKED(IDC_GET_INDEXOnGetIndex)
        
    ON_BN_CLICKED(IDC_PRINTOnPrint)
        
    ON_BN_CLICKED(IDC_ADD_FIRSTOnAddFirst)
        
    ON_BN_CLICKED(IDC_ABOUTOnAbout)
        
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()

    /////////////////////////////////////////////////////////////////////////////
    // CSinglyLinkedListintDlg message handlers

    BOOL CSinglyLinkedListintDlg::OnInitDialog()
    {
        
    CDialog::OnInitDialog();

        
    // Add "About..." menu item to system menu.

        // IDM_ABOUTBOX must be in the system command range.
        
    ASSERT((IDM_ABOUTBOX 0xFFF0) == IDM_ABOUTBOX);
        
    ASSERT(IDM_ABOUTBOX 0xF000);

        
    CMenupSysMenu GetSystemMenu(FALSE);
        if (
    pSysMenu != NULL)
        {
            
    CString strAboutMenu;
            
    strAboutMenu.LoadString(IDS_ABOUTBOX);
            if (!
    strAboutMenu.IsEmpty())
            {
                
    pSysMenu->AppendMenu(MF_SEPARATOR);
                
    pSysMenu->AppendMenu(MF_STRINGIDM_ABOUTBOXstrAboutMenu);
            }
        }

        
    // Set the icon for this dialog.  The framework does this automatically
        //  when the application's main window is not a dialog
        
    SetIcon(m_hIconTRUE);            // Set big icon
        
    SetIcon(m_hIconFALSE);        // Set small icon
        
        // TODO: Add extra initialization here
        
        
    return TRUE;  // return TRUE  unless you set the focus to a control
    }

    void CSinglyLinkedListintDlg::OnSysCommand(UINT nIDLPARAM lParam)
    {
        if ((
    nID 0xFFF0) == IDM_ABOUTBOX)
        {
            
    CAboutDlg dlgAbout;
            
    dlgAbout.DoModal();
        }
        else
        {
            
    CDialog::OnSysCommand(nIDlParam);
        }
    }

    // If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.

    void CSinglyLinkedListintDlg::OnPaint() 
    {
        if (
    IsIconic())
        {
            
    CPaintDC dc(this); // device context for painting

            
    SendMessage(WM_ICONERASEBKGND, (WPARAMdc.GetSafeHdc(), 0);

            
    // Center icon in client rectangle
            
    int cxIcon GetSystemMetrics(SM_CXICON);
            
    int cyIcon GetSystemMetrics(SM_CYICON);
            
    CRect rect;
            
    GetClientRect(&rect);
            
    int x = (rect.Width() - cxIcon 1) / 2;
            
    int y = (rect.Height() - cyIcon 1) / 2;

            
    // Draw the icon
            
    dc.DrawIcon(xym_hIcon);
        }
        else
        {
            
    CDialog::OnPaint();
        }
    }

    // The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CSinglyLinkedListintDlg::OnQueryDragIcon()
    {
        return (
    HCURSORm_hIcon;
    }

    void CSinglyLinkedListintDlg::OnExit() 
    {
        
    // TODO: Add your control notification handler code here
        
    MessageBox("Thank you for using our program","Singly Linked List"MB_ICONINFORMATION );
        exit(
    1);
    }

    void CSinglyLinkedListintDlg::OnAddFirst() 
    {
        
    // TODO: Add your control notification handler code here
        
    addFirstDLG.DoModal();
        
    int newData addFirstDLG.m_data;

        
    NodenewNode = new NodenewData );

        if ( 
    firstPtr != NULL )
            {
            
    newNode->next=firstPtr;
            
    firstPtr=newNode;
            }
        else
            
    firstPtr newNode;            
    }

    void CSinglyLinkedListintDlg::OnDelete() 
    {
        
    // TODO: Add your control notification handler code here
        
    NodecurrentPtr firstPtr;
        
    NodeprevPtr NULL;
        
    bool deleted false;

        
    deleteDLG.DoModal();
        
    int sd deleteDLG.m_toDelete;

        while( 
    currentPtr != NULL )
        {
            if ( 
    currentPtr->DATA == sd )
            {
                if ( 
    currentPtr == firstPtr )
                {
                    
    firstPtr firstPtr->next;
                    
    delete currentPtr;
                    
    MessageBox("The node is deleted""Singly Linked List"MB_ICONINFORMATION);
                    
    deleted true;
                    break;
                }
                
                if ( 
    currentPtr->next == NULL )
                {
                    
    prevPtr->next NULL;
                    
    delete currentPtr;
                    
    MessageBox("The node is deleted""Singly Linked List"MB_ICONINFORMATION);
                    
    deleted true;
                    break;
                }

                
    prevPtr->next currentPtr->next;
                
    delete currentPtr;
                
    MessageBox("The node is deleted""Singly Linked List"MB_ICONINFORMATION);
                
    deleted true;
                break;
            }
        
    prevPtr currentPtr;
        
    currentPtr currentPtr ->next;
        }

        if ( 
    deleted == false )
            
    MessageBox("The node does not exist or the list is empty""Singly Linked List"MB_ICONEXCLAMATION );
        
    }

    void CSinglyLinkedListintDlg::OnAddAfter() 
    {
        
    // TODO: Add your control notification handler code here
        
    }

    void CSinglyLinkedListintDlg::OnAddBefore() 
    {
        
    // TODO: Add your control notification handler code here
        
    }

    void CSinglyLinkedListintDlg::OnSize() 
    {
        
    // TODO: Add your control notification handler code here
        
    NodecurrentPtr firstPtr;
        
    int count=0;

        while( 
    currentPtr != NULL )
        {
            
    count++;
            
    currentPtr currentPtr -> next;
        }
        
        
    sizeDLG.m_size count;
        
    sizeOfList count;
        
    sizeDLG.DoModal();

        
    }

    void CSinglyLinkedListintDlg::OnIsEmpty() 
    {
        
    // TODO: Add your control notification handler code here
        
    if ( firstPtr == NULL )
            
    MessageBox("The list is empty");
        else if ( 
    firstPtr != NULL )
            
    MessageBox("The list is not empty");
    }

    void CSinglyLinkedListintDlg::OnSwap() 
    {
        
    // TODO: Add your control notification handler code here
        
    }

    void CSinglyLinkedListintDlg::OnInList() 
    {
        
    // TODO: Add your control notification handler code here
        
    }

    void CSinglyLinkedListintDlg::OnGetIndex() 
    {
        
    // TODO: Add your control notification handler code here
        
    }

    void CSinglyLinkedListintDlg::OnPrint() 
    {
        
    // TODO: Add your control notification handler code here
        
    NodecurrentPtr firstPtr;
        
    printDLG.DoModal();

        while( 
    currentPtr != NULL )
        {
            
    /*
            .
            .
            .
            */
            //cout << currentPtr->DATA << endl;
            
    currentPtr currentPtr->next;
        }

        

    }

    void CSinglyLinkedListintDlg::OnAbout() 
    {
        
    // TODO: Add your control notification handler code here
        
    aboutDLG.DoModal();
        
    }







    So, what I want is: How can I create the print function so the user can see the list ?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Have a text box where you output everything.

    Also I would suggest you don't give the screen shots of the resource editor or the dialog as that does not help or at least to me.
     
  3. domain

    domain New Member

    Joined:
    May 1, 2007
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    First of all, thank you Mr.Shabbir for being with us and for the quick reply :)
    secondly, I know how to connect an integer data member ( say: int m_data ) with the test box, but as you know there are many nodes in the list. I'm just saying that if you could please give me an example?

    and can I connect an array with one text box ?
    &
     
  4. domain

    domain New Member

    Joined:
    May 1, 2007
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    Just for being clear, if I click on the print button, then a dialog is appears with one big text box and the nodes are listed in it like this:

    10 -> 2 -> 3 -> 95

    So, how can I do that ?
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Have the string concatenate and then do the SetWindowText
     
  6. domain

    domain New Member

    Joined:
    May 1, 2007
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    I didn't understand any word from your reply Mr.shabbir because I'm new at VC++ :(
    Could you please type the code that do this:

    Have the string concatenate and then do the SetWindowText
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Its nothing related to VC++. It something that you do in C or C++. You will output all the thing using printf and instead of doing that have them concatenate into a string then set that text to the text box text using the API SetWindowText
     
  8. domain

    domain New Member

    Joined:
    May 1, 2007
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    You are not helping me Mr.Shabbir ! at least explain to me in coding
     
  9. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    I am not sure if you know C-C++ programming or not. Do you know what is sprintf / sscanf ?
     
  10. domain

    domain New Member

    Joined:
    May 1, 2007
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    I studied C++ not C, I guess (sprintf / sscanf) are in C language ?
     
  11. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    In C++ also you can append the strings. Just append the complete string you wish to show to the user when print button is clicked and then display that string in the text box.

    Something like
    Code:
    string szTemp;
    szTemp = First Node Content;
    szTemp += Second Node Content;
    TextBox.SetWindowText(szTemp);
     
  12. domain

    domain New Member

    Joined:
    May 1, 2007
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    I wrote something like your code :

    PHP:

    Node
    currentPtr firstPtr;
        
    CString contents("");

        if ( 
    currentPtr != NULL )
        {
            while( 
    currentPtr -> next != NULL )
            {
                
    CString temp("");
                
    temp.Format("%i"currentPtr->DATA );

                
    contents += temp;
                
    contents += " -> ";
                
    currentPtr currentPtr->next;
            }

            
    contents =+ currentPtr -> DATA;

            
    printDLG.m_content contents;
            
    UpdateData(TRUE);
            
    printDLG.DoModal();
        }

    But the final result ( when I execute the program ) like this:
    ـ
    or
    ؟؟
     
  13. domain

    domain New Member

    Joined:
    May 1, 2007
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    ًWoOoOoOoW !!
    I want to dance now !!! the program now is 100% complete, I knew the problem with the previous code:

    PHP:

        
    // TODO: Add your control notification handler code here
        
    NodecurrentPtr firstPtr;
        
    CString contents("");

        if ( 
    currentPtr != NULL )
        {
            while( 
    currentPtr -> next != NULL )
            {
                
    CString temp("");
                
    temp.Format("%i"currentPtr->DATA );

                
    contents += temp;
                
    contents += " -> ";
                
    currentPtr currentPtr->next;
            }
            
    CString temp("");
            
    temp.Format("%i"currentPtr -> DATA );
            
    contents += temp;

            
    printDLG.m_content contents;
            
    UpdateData(TRUE);
            
    printDLG.DoModal();
        }
        else
            
    MessageBox("The list is empty" );

     
  14. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Finally I could explain you. :D
     
  15. domain

    domain New Member

    Joined:
    May 1, 2007
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    Thank you Mr.Shabbir for the help :)
     
  16. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    My pleasure.
     

Share This Page