Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Win32 (http://www.go4expert.com/forums/win32/)
-   -   Could I have some help with drawing ?( MFC ) (http://www.go4expert.com/forums/i-help-drawing-mfc-t4360/)

domain 19May2007 00:02

Could I have some help with drawing ?( MFC )
 
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:
http://my.mail299.googlepages.com/pic_project_01.gif


Resource View:
http://my.mail299.googlepages.com/pic_project_02.gif


Files View:
http://my.mail299.googlepages.com/pic_project_03.gif


Class View:
http://my.mail299.googlepages.com/pic_project_04.gif


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


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

PHP Code:



// 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 ?

shabbir 19May2007 09:52

Re: Could I have some help with drawing ?( MFC )
 
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.

domain 19May2007 18:31

Re: Could I have some help with drawing ?( MFC )
 
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 ?
&
Quote:

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

domain 19May2007 18:33

Re: Could I have some help with drawing ?( MFC )
 
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 ?

shabbir 19May2007 22:10

Re: Could I have some help with drawing ?( MFC )
 
Have the string concatenate and then do the SetWindowText

domain 20May2007 00:59

Re: Could I have some help with drawing ?( MFC )
 
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

shabbir 20May2007 09:46

Re: Could I have some help with drawing ?( MFC )
 
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

domain 20May2007 13:09

Re: Could I have some help with drawing ?( MFC )
 
You are not helping me Mr.Shabbir ! at least explain to me in coding

shabbir 20May2007 13:28

Re: Could I have some help with drawing ?( MFC )
 
I am not sure if you know C-C++ programming or not. Do you know what is sprintf / sscanf ?

domain 20May2007 13:49

Re: Could I have some help with drawing ?( MFC )
 
I studied C++ not C, I guess (sprintf / sscanf) are in C language ?


All times are GMT +5.5. The time now is 05:45.