السلام عليكم
عملت برنامج باستخدام MFC يتعامل مع Linked List ، واريد ان اقوم بطباعة القائمة ، فماهي الطريقة المناسبة ؟ وياليت لو شرح بالتفصيل وشكراً :)
السلام عليكم
عملت برنامج باستخدام MFC يتعامل مع Linked List ، واريد ان اقوم بطباعة القائمة ، فماهي الطريقة المناسبة ؟ وياليت لو شرح بالتفصيل وشكراً :)
تم تعديل هذه المشاركة بواسطة مجلـد جديـد في 18 مايو 2007 في 02:13
مافيه ولا رد ؟!
أولاً : لم يمر على السؤال يوم كامل حتى تستعجل وتستغرب لعدم وجود ردود .
ثانياً : اليوم جمعة ولن تجد الكثيرين على النت ...
ثالثاً : صيغة السؤال توحي أنك لا تعلم الكثير عن MFC ... كم عدد الكتب ورقية أو إلكترونية التي لديك عن MFC ؟
أصبحت الأسئلة في هذا القسم مشابهه لقسم Visual Basic (رأي شخصي)
"First they ignore you, then they laugh at you, then they attack you, then you win"
===
اقتباسحُكَّامُـنَا إِنْ تَصَـدّوا لِلْحِمَــى اقْتَحَمُـوا ***** وَإِنْ تَصَدَّى لَـهُ المُسْتَعْمِـرُ انْسَحَبُـوا
هُمْ يَفْرشـُونَ لِجَيْـشِ الغَــزْوِ أَعْيُنَـهُـمْ ***** وَيَدَّعُــونَ وُثُـوبَـاً قَـبْـلَ أَنْ يَثِـبُــوا
الحَاكِمُـونَ و«وَاشُنْـطُـنْ» حُكُومَتُـهُـمْ ***** وَاللامِعُــونَ وَمَـا شَعَّـوا وَلا غَرَبُــوا
القَاتِلُـــونَ نُبُــوغَ الشَّـعْــبِ تَرْضِـيَـــةً ***** لِلْمُعْتَدِيــنَ وَمَـا أَجْـدَتْـهُـمُ الـقُــرَبُ
لَهُمْ شُمُـوخُ «المُثَنَّـى» ظَاهِـرَاً وَلَهُـمْ ***** هَـوَىً إِلَـى بَابَـك الخَرْمِـيّ يُنْتَسَـبُ
البردوني "أبو تمام وعروبة اليوم" 1971
===
اقتباسعبيد الهوى يحكمون البـلاد ***** ويحكمهــم كلّهـــم درهــــــمو تقتـادهـم شهـوة لا تنــام ***** وهـــم فـي جـهالتهــم نــــوّم
ففــي كـــلّ ناحيــة ظـالـــم ***** غبــــــيّ يسـلـّطــــه أظلـــم
أيا من شبعتم على جوعــنا ***** وجـــوع بنينـا ألـم تتخمـــوا ؟
ألم تفهموا غضبة الكادحين ***** على الظلـم ؟ لا بدّ أن تفهموا
البردوني "نحن و الحاكمون "
المشكلة يا اخي العزيز cipher ان بعض الاسئلة التي اضعها لا يقوم بالرد عليها الا واحد او اثنين بالكثير للاسف :(
وانا لدي جدول يجب ان ألتزم به :(
وبالفعل لا اعلم الكثير عن MFC فانا مبتدئ لكن لدي خبرة في البرمجه بال C++ .. وحتى تكون الصورة أوضح :
برنامج يتعامل مع Linked List : اضافة ، حذف ، كم عدد العناصر ، ... إلخ . وأريد ان اضع زر جديد لطباعة جميع العناصر بحيث يقوم بفتح Dialog جديد ويرسم فيه العناصر .
سؤالك عايز شرح أكتر علشان تلاقى حد يجاوبك....
. مشكلتك فى إنك مش عارف ترسم؟
. ولا مشكلتك إنك مش عارف ترسم إيه؟
. ولا مشكلتك إنك مش عارف تطلع القيم فى الشكل اللى إنت رسمته؟
سوف اقوم بشرح المشكلة حتى تتضح للجميع وارجو ان اجد الحل باسرع وقت .
اولاً: سوف اقوم بوضع صور للواجهة للبرنامج.
أ) صورة للواجهة الرئيسية :

طبعا كل Dialog اضع له class ، ما ادري اذا كانت هذه الطريقة صحيحة او لا ؟
ثانياً: صورة لل Workspace :
أ) File View :

ب) Resource View :

ج) Class View :

ثالثاً: الكود البرمجي لل SinglyLinkedListintDlg.cpp :
// 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;
Node* next;
};
Node::Node( int nd )
{
DATA = nd;
next = NULL;
}
Node::~Node()
{
next = NULL;
}
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
//$$$$$$$$$$$$$$$$$$$$$$$ Node Class $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
/*********************
**********************/
Node* firstPtr = 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(CDataExchange* pDX); // 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(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSinglyLinkedListintDlg dialog
CSinglyLinkedListintDlg::CSinglyLinkedListintDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSinglyLinkedListintDlg::IDD, pParent)
{
//{{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(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSinglyLinkedListintDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSinglyLinkedListintDlg, CDialog)
//{{AFX_MSG_MAP(CSinglyLinkedListintDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_BN_CLICKED(IDC_ADD_AFTER, OnAddAfter)
ON_BN_CLICKED(IDC_ADD_BEFORE, OnAddBefore)
ON_BN_CLICKED(IDC_SIZE, OnSize)
ON_BN_CLICKED(IDC_IS_EMPTY, OnIsEmpty)
ON_BN_CLICKED(IDC_SWAP, OnSwap)
ON_BN_CLICKED(IDC_IN_LIST, OnInList)
ON_BN_CLICKED(IDC_GET_INDEX, OnGetIndex)
ON_BN_CLICKED(IDC_PRINT, OnPrint)
ON_BN_CLICKED(IDC_ADD_FIRST, OnAddFirst)
ON_BN_CLICKED(IDC_ABOUT, OnAbout)
//}}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);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CSinglyLinkedListintDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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, (WPARAM) dc.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(x, y, m_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 (HCURSOR) m_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;
Node* newNode = new Node( newData );
if ( firstPtr != NULL )
{
newNode->next=firstPtr;
firstPtr=newNode;
}
else
firstPtr = newNode;
}
void CSinglyLinkedListintDlg::OnDelete()
{
// TODO: Add your control notification handler code here
Node* currentPtr = firstPtr;
Node* prevPtr = 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
Node* currentPtr = 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
Node* currentPtr = 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();
}..؟
هذا الموضوع مغلق.