|
Hello
See the code in C++ for linked list implementation of a queue.
<code> #include <iostream.h>
#include <stdlib.h>
#include <process.h>
#include <conio.h>
#include <dos.h>
struct queuelist
{
int intData;
int valid;
struct queuelist* next;
};
struct queuelist *head, *tail;
class CNode
{
private:
struct queuelist* queue;
public:
int AddToQueue(int);
int PopFromQueue();
int DeleteQueue();
void DisplayQueue();
};
void menu();
void menu()
{
textcolor(WHITE);
cout<<" Queue Manipulation Menu"<<endl;
cout<<"........................"<<endl<<endl;
cout<<"1. Add member to queue."<<endl;
cout<<"2. Extract next member."<<endl;
cout<<"3. Delete whole queue."<<endl;
cout<<"4. Help"<<endl;
cout<<"5. Display queue contents."<<endl;
cout<<"6. Quit."<<endl;
}
void main()
{
clrscr();
int data;
int option;
CNode node;
while(1)
{
menu();
cout<<"OPTION: ";
cin>>option;
cout<<endl;
switch(option)
{
case 1:
cout<<"Member: ";
cin>>data;
if(node.AddToQueue(data)==-1)
cout<<"Could not add.."<<endl;
else
cout<<"Added.."<<endl;
break;
case 2:
int pop=0;
clrscr();
cout<<"Extract next member."<<endl;
pop = node.PopFromQueue();
if(pop!=-1)
cout<<node.PopFromQueue();
break;
case 3:
clrscr();
node.DeleteQueue();
break;
case 4:
cout<<"Under Construction."<<endl;
break;
case 5:
clrscr();
cout<<"Queue Contents."<<endl;
node.DisplayQueue();
break;
case 6:
exit(0);
default:
textcolor(RED);
cout<<"Invalid Option.."<<endl;
break;
}
}
getch();
}
int CNode::AddToQueue(int data)
{
struct queuelist* q;
struct queuelist* temp;
q = head;
if(q == NULL)
{
cout<<"First member in queue."<<endl;
temp = (struct queuelist*)malloc(sizeof(struct queuelist));
if(temp == NULL)
{
textcolor(RED);
cout<<"Not enough memory. Stopping..."<<endl;
return -1;
}
else
{
temp->intData = data;
temp->next=NULL;
temp->valid=1;
q->next = temp;
head = temp;
tail = temp;
q = temp;
}
}
else
{
while(q->next!=NULL) q=q->next;
temp = (struct queuelist*)malloc(sizeof(struct queuelist));
if(temp == NULL)
{
textcolor(RED);
cout<<"Not enough memory. Quitting..."<<endl;
return -1;
}
else
{
temp->intData = data;
temp->next=NULL;
q->next = temp;
q = q->next;
q->valid = 1;
tail = q;
}
}
return 1;
}
void CNode::DisplayQueue()
{
struct queuelist* queue;
queue = head;
if(queue == NULL || queue->valid != 1)
{
textcolor(RED);
cout<<"Empty Queue";
}
else
{
while(queue != NULL)
{
if(queue->next!=0)
cout<<"||"<<queue->intData<<"|"<<queue->next;
else
cout<<"||"<<queue->intData<<"|NULL||->";
queue = queue->next;
}
}
cout<<endl;
}
int CNode::PopFromQueue()
{
int tempdat=0;
struct queuelist* queue;
struct queuelist* prev;
queue = head;
if(queue->valid !=1)
{
textcolor(RED);
cout<<"Queue Exhausted. No members."<<endl;
return -1;
}
else
{
queue = head;
prev = queue;
queue = queue->next;
head = queue;
}
tempdat = prev->intData;
prev->next=NULL;
free(prev);
return tempdat;
}
int CNode::DeleteQueue()
{
struct queuelist* prev;
queue = head;
while(queue!=NULL)
{
prev = queue;
queue = queue->next;
queue->valid=0;
free(prev);
}
return 1;
}</code>
Bye,
Sreekanth Muralidharan
|
|
|
|
|
Much better, but still shows confusion.
Now you have C and C++ mixed all up together in a Frakeinstineon (the monster) kind of way.
You need to know a little more about C programing and for C++ programing I recommend the Bruce Eckel series of books, since he is good at explaning it. Also, Bruce Eckel has a web-site that has copies of his books in electronic form that you can download (recomend purchasing them though).
After reading you bio and seeing how well you did, I have decided to write my version and will send it to you (when finished).
Mean while:
1) queuelist is still a node.
2) CNode is not a node it represents the list.
3) The fuctions that require a return value do not return a success value.
4) The getch() function will never be reached, because you are still using exit() to exit from the program.
typedef struct tagNode
{
struct tagNode* pNext;
int intData;
} NODE;
static NODE* g_pHead;
int AddNode(int intData);
int DisplayList();
int DeleteNode();
void DeleteAll();
class CIntList
{
struct NODE
{
struct NODE* pNext;
int intData;
};
NODE* m_pHead;
public:
int AddNode(int intData);
int DisplayList();
int DeleteNode();
void DeleteAll();
CIntList() : m_pHead(NULL) {}
~CIntList() { DeleteAll(); }
};
Good Luck!
INTP
|
|
|
|
|
I'm working with MFC42 (the one that came with VS6). Is there any way to gray out buttons in the toolbar which have a handler ?
I have got a base class for all my dialog boxes, which handles the messages. So every dialog box has got a function which handles the Toolbar messages altough the handler doesn't do anything useful. The users want the buttons with unuseful handlers grayed out, so i have to do this programmatically.
Any ideas ?
All the label says is that this stuff contains chemicals "... known to the State of California to cause cancer in rats and low-income test subjects." Roger Wright http://www.codeproject.com/lounge.asp?select=965687&exp=5&fr=1#xx965687xx
|
|
|
|
|
Every ToolbUtton must have A ID .
via Using these Function you can disable them
let Button id you want to disable is ID_BUTTON1
then here is little piece of Code.
CButton *But=(CButton*)this->GetDlgItem(ID_BUTTON1);<br />
<br />
if(But)<br />
{<br />
But->EnableWindow(FALSE);<br />
}
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
You should implement the <a href="http://msdn.microsoft.com/library/en-us/vclib/html/_mfc_on_update_command_ui.asp">ON_UPDATE_COMMAND_UI</a> [<a href="http://msdn.microsoft.com/library/en-us/vclib/html/_mfc_on_update_command_ui.asp" target="_blank" title="New Window">^</a>] handler for your button's control ID and then call pCmdUI->Enable( false ) in that handler.
--
Affordable Windows-based CMS: www.zeta-producer.de/enu
|
|
|
|
|
I do create a CListCtrl (yes, really this is no voting joke! ) with the WS_BORDER style inside a control and later put it into a dialog box by code, too.
The problem is that the control that I create by hand has a 1 pixel black border on XP but not the 1 pixel blue border (i.e. the Windows XP themed border) when being dropped visually on a dialog box.
Question: Can anyone tell me how to acchieve the themed version when creating a control programatically?
Thanks!
--
Affordable Windows-based CMS: www.zeta-producer.de/enu
|
|
|
|
|
Got it myself :
The Control does not have the WS_BORDER style but rather the extended WS_EX_CLIENTEDGE style. Then it looks correctly.
--
Affordable Windows-based CMS: www.zeta-producer.de/enu
|
|
|
|
|
Hi guys ...
I have two questions for you:
1. How can i detect if SP1, or SP2 is installed on a machine(and if is the final release, not beta)
and is there any way to know if the OS is in "Safe Mode" ?
2. I have to install some files from my app, but they are protected by Windows File Protection. Is there any way
to install them? [w/o copying them from safe mode]
Thanks ...
|
|
|
|
|
I this Can help you out
OSVERSIONINFO
The OSVERSIONINFO data structure contains operating system version information. The information includes major and minor version numbers, a build number, a platform identifier, and descriptive text about the operating system. This structure is used with the GetVersionEx function.
<br />
typedef struct _OSVERSIONINFO{ <br />
DWORD dwOSVersionInfoSize; <br />
DWORD dwMajorVersion; <br />
DWORD dwMinorVersion; <br />
DWORD dwBuildNumber; <br />
DWORD dwPlatformId; <br />
TCHAR szCSDVersion[ 128 ]; <br />
} OSVERSIONINFO ;
AND
lAST pARAMETER
szCSDVersion
Windows NT/2000/XP: Contains a null-terminated string, such as "Service Pack 3", that indicates the latest Service Pack installed on the system. If no Service Pack has been installed, the string is empty.
Windows 95/98/Me: Contains a null-terminated string that indicates additional version information. For example, " C" indicates Windows 95 OSR2 and " A" indicates Windows 98 Second Edition
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
Hi every body.
How i'am program same MSN Messenger when has user login.
a program stay in system tray popup dialog message same
MSN Messanger or Norton Antivirus
Thank you.
|
|
|
|
|
My error!
First time!i choice Two.m_cbodata is Two.
Second time!i choice One.m_cbodata is Two.
When i choice ,my Combo Box data is not change.
I don't know what happen.
pls help me.
My code is following......
//MyView.h
public:
//{{AFX_DATA(CMyView)
CString m_cbodata;
//}}AFX_DATA
//MyView.cpp
void Click()
{
UpdateData(TRUE);
if (m_cbodata=="One")
{
AfxMessageBox("One");
}
if (m_cbodata=="Two")
{
AfxMessageBox("Two");
}
}
|
|
|
|
|
i found my error!!!
i change following code!!!!
//MyView.cpp
if (0==m_ctrldevice.GetCurSel( ))
{
AfxMessageBox("One");
}
if (1==m_ctrldevice.GetCurSel( ))
{
AfxMessageBox("Two");
}
|
|
|
|
|
how about this:
CString str;
str.Format("%d",m_ctrldevice.GetCurSel() + 1);
AfxMessageBox(str);
this will display a messagebox with "1","2", or whatever the cursel is.
If I write code in my sleep, does that make me brilliant, or just a lazy programmer?
My articles
www.stillwaterexpress.com
BlackDice - the programmer formerly known as bdiamond
|
|
|
|
|
Hi !
I'm facing many problems (app crashs) when my app is compiled in release mode (problems I don't have in debug mode). I noticed that removing some const_cast improved the situation.
This makes me wonder : am I allowed to use const_cast ? How can I spot the situations where const_cast should be avoided ? If const_cast is dangerous, why is it provided ?
Thanks for your enlightment !
Jerome
|
|
|
|
|
hian So Jerome BAck!!!!
so any way here you's Answer,As MSDN states that,i have maked sentence bold which might be causing problem in your program
pointer to any object type or a pointer to a data member can be explicitly converted to a type that is identical except for the const, volatile, and __unaligned qualifiers. For pointers and references, the result will refer to the original object. For pointers to data members, the result will refer to the same member as the original (uncast) pointer to data member. Depending on the type of the referenced object, a write operation through the resulting pointer, reference, or pointer to data member might produce undefined behavior.
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
Hi everybody,
Currently i am thinking how to program a PC Booking/Reservation System for an office of 100 PCs where user login is controled by Windows Active Directory.
I have little idea about AD login control, anybody can tell me where to start?
Thanks
JW
DJ
|
|
|
|
|
well.....i had a doubt earlier regarding how i can access data from different classes.....i got the answer.....though that exactly didnt solve my answer.....
u c i am making a dialog box.....that is to load a picture.....and upon moving the mouse upon it.....it is supposed to change the pictures......(bacially these pics are frames of a volume control).....what i have done is that i have loaded the pics.....into the dc memory(and made it compactible).....so by bitblt it displays.....it workz as well.....
my problem is.....i have many such controls......so i have derived a class from the Cstatic class and by using the concept of subclassing.....i can get the mouse controls for the particular control.....
but to bitblt it i have to call the variable that pointz to the frame of that picture......but i have declared the variables that hold the frames of this in the main CXyzDlg::OnInitDialog() .....how do i access this variables from th derived class THAT I HAVE CREATED?????
PLEASE HELP!!!!!!
|
|
|
|
|
could you be more specific, even give some code exemple and point out the error
|
|
|
|
|
ok......
this os what i have declared in the CXyzDlg.h
<br />
CSize m_size;<br />
CSize m_size1;<br />
<br />
CPoint m_pt;<br />
CDC m_dcMem;
CDC m_dcMempotI[32];
<br />
HBITMAP m_hBmpOld;
HBITMAP m_hBmpNew;
BITMAP m_bmInfo;
<br />
BITMAP m_bmInfo1; <br />
<br />
this is what i have added in the CXyzDlg::OnPaint()......here i have called the variables that points to the picture in the dc memory
<br />
void CCreamzDlg::OnPaint() <br />
{<br />
if (IsIconic())<br />
{<br />
CPaintDC dc(this);
<br />
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);<br />
<br />
int cxIcon = GetSystemMetrics(SM_CXICON);<br />
int cyIcon = GetSystemMetrics(SM_CYICON);<br />
CRect rect;<br />
GetClientRect(&rect);<br />
int x = (rect.Width() - cxIcon + 1) / 2;<br />
int y = (rect.Height() - cyIcon + 1) / 2;<br />
<br />
dc.DrawIcon(x, y, m_hIcon);<br />
}<br />
else<br />
{<br />
<br />
<br />
CPaintDC dc(this);<br />
dc.BitBlt(offsetx,offsety,m_size.cx+50,m_size.cy+50,&m_dcMem, 2, 0,SRCCOPY);<br />
<br />
dc.BitBlt(offsetx1,offsety1,m_size1.cx,m_size1.cy,&m_dcMempotI[m_i], -14, -13,SRCCOPY);<br />
<br />
dc.BitBlt(offsetx2,offsety2,m_size1.cx,m_size1.cy,&m_dcMempotI[m_j], -14, -13,SRCCOPY);<br />
CDialog::OnPaint();<br />
<br />
<br />
}<br />
}<br />
<br />
the code that i am showing here is the one that works.......that is the one that doesnot use subclassing.....
i need subclassing feature coz the only action that i can get with a ststic control is just the event "On Clicked()"....but i need the mousemove function as well in the static window....so for that i derive a class from the base class CStatic....and add the mouse movements into it(subclassing).....the problem is that even in this derived class i have put in the WM_PAINT message as well....so that it can be automatically updated.....and thatz when the problem arises.....
i am not able to call the
dc.BitBlt(offsetx2,offsety2,m_size1.cx,m_size1.cy,&m_dcMempotI[m_j], -14, -13,SRCCOPY);
coz inside it the the derived class the variable : ,&m_dcMempotI , m_j ,offsetx2,offsety2,m_size1 are not defined...
what do i do....
if i were to put the dcmemory variable in a class....each time i create an object....a lot of memory is taken...coz all the frames of the volume controls get created again and again.....but tere is a need only for one.....
i hope u understood the prob.....
this is what i had written in the CXyzDlg::OnInitDialog()
in this there are three static windowz that i have created (one background bitmap,two controlz bitmap)
with the variables m_st1 ,.m_st3 ,m.st4 respectively being the static variables linked to the static windows.
<br />
BOOL CCreamzDlg::OnInitDialog()<br />
{<br />
CDialog::OnInitDialog();<br />
<br />
<br />
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);<br />
ASSERT(IDM_ABOUTBOX < 0xF000);<br />
<br />
CMenu* pSysMenu = GetSystemMenu(FALSE);<br />
if (pSysMenu != NULL)<br />
{<br />
CString strAboutMenu;<br />
strAboutMenu.LoadString(IDS_ABOUTBOX);<br />
if (!strAboutMenu.IsEmpty())<br />
{<br />
pSysMenu->AppendMenu(MF_SEPARATOR);<br />
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);<br />
}<br />
}<br />
<br />
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
<br />
m_i=0;<br />
m_j=0;<br />
m_check=FALSE;<br />
<br />
<br />
m_DragOn=FALSE;<br />
<br />
<br />
CClientDC dc(this);<br />
m_dcMem.CreateCompatibleDC( &dc );<br />
<br />
sourcex=sourcey=0;<br />
<br />
<br />
m_hBmpNew = (HBITMAP) LoadImage(<br />
AfxGetInstanceHandle(),
"c:\\mm.bmp",
IMAGE_BITMAP,
0,
0,
LR_CREATEDIBSECTION|LR_LOADFROMFILE); <br />
<br />
if( m_hBmpNew == NULL )<br />
{<br />
AfxMessageBox("Load Image Failed");<br />
}<br />
<br />
else {<br />
<br />
<br />
m_st1.GetClientRect( &rectStaticClient );<br />
rectStaticClient.NormalizeRect();<br />
m_size.cx=rectStaticClient.Size().cx;<br />
m_size.cy=rectStaticClient.Size().cy;<br />
m_size.cx = rectStaticClient.Width();
m_size.cy = rectStaticClient.Height();
<br />
m_st1.ClientToScreen( &rectStaticClient );<br />
ScreenToClient( &rectStaticClient);<br />
<br />
m_pt.x = rectStaticClient.left;<br />
m_pt.y = rectStaticClient.top;<br />
GetObject( m_hBmpNew , sizeof(BITMAP), &m_bmInfo );<br />
VERIFY(m_hBmpOld = (HBITMAP)SelectObject(m_dcMem, m_hBmpNew ) );<br />
offsetx= m_pt.x;<br />
offsety=m_pt.y; <br />
}<br />
<br />
<br />
m_dcMempotI[0].CreateCompatibleDC( &dc );<br />
<br />
strcpy(m_filename,"E:\\projectz_infoz\\minimax_potz\\modified\\pot1\\pot");<br />
_itoa( 0, m_charz, 10 );<br />
strcat(m_filename,m_charz);<br />
strcat(m_filename,".bmp");<br />
<br />
<br />
m_hBmpNew = (HBITMAP) LoadImage(<br />
AfxGetInstanceHandle(),
m_filename,
IMAGE_BITMAP,
0,
0,
LR_CREATEDIBSECTION|LR_LOADFROMFILE); <br />
<br />
if( m_hBmpNew == NULL )<br />
{<br />
AfxMessageBox("Load Image Failed");<br />
}<br />
<br />
else {<br />
m_st3.GetClientRect( &rectStaticClient );<br />
rectStaticClient.NormalizeRect();<br />
m_size1.cx=rectStaticClient.Size().cx;<br />
m_size1.cy=rectStaticClient.Size().cy;<br />
m_size1.cx = rectStaticClient.Width();
m_size1.cy = rectStaticClient.Height();
<br />
m_st3.ClientToScreen( &rectStaticClient );<br />
ScreenToClient( &rectStaticClient);<br />
<br />
m_pt.x = rectStaticClient.left;<br />
m_pt.y = rectStaticClient.top;<br />
GetObject( m_hBmpNew , sizeof(BITMAP), &m_bmInfo );<br />
VERIFY(m_hBmpOld = (HBITMAP)SelectObject(m_dcMempotI[0], m_hBmpNew ) );<br />
offsetx1= m_pt.x;<br />
offsety1=m_pt.y; <br />
}<br />
<br />
<br />
for(m_i=1;m_i<=31;m_i++)<br />
{<br />
<br />
m_dcMempotI[m_i].CreateCompatibleDC( &dc );<br />
<br />
strcpy(m_filename,"E:\\projectz_infoz\\minimax_potz\\modified\\pot1\\pot");<br />
_itoa( m_i, m_charz, 10 );<br />
strcat(m_filename,m_charz);<br />
strcat(m_filename,".bmp");<br />
<br />
<br />
m_hBmpNew = (HBITMAP) LoadImage(<br />
AfxGetInstanceHandle(),
m_filename,
IMAGE_BITMAP,
0,
0,
LR_CREATEDIBSECTION|LR_LOADFROMFILE); <br />
<br />
if( m_hBmpNew == NULL )<br />
{<br />
AfxMessageBox("Load Image Failed");<br />
}<br />
<br />
else {<br />
GetObject( m_hBmpNew , sizeof(BITMAP), &m_bmInfo );<br />
VERIFY(m_hBmpOld = (HBITMAP)SelectObject(m_dcMempotI[m_i], m_hBmpNew ) );<br />
}<br />
<br />
}
<br />
m_i=0;<br />
<br />
<br />
<br />
m_st4.GetClientRect( &rectStaticClient1 );<br />
rectStaticClient.NormalizeRect();<br />
m_size1.cx=rectStaticClient.Size().cx;<br />
m_size1.cy=rectStaticClient.Size().cy;<br />
m_size1.cx = rectStaticClient.Width();
m_size1.cy = rectStaticClient.Height();
<br />
m_st4.ClientToScreen( &rectStaticClient1 );<br />
ScreenToClient( &rectStaticClient1);<br />
<br />
m_pt.x = rectStaticClient1.left;<br />
m_pt.y = rectStaticClient1.top;<br />
offsetx2= m_pt.x;<br />
offsety2=m_pt.y; <br />
<br />
<br />
<br />
return TRUE;
}<br />
<br />
please get me a solution......anyone....
if anyone has got a bettr way of doing this without subclassing.....that is also ok as well....
HELP!!!!!
|
|
|
|
|
hi all,
I want to Right Click on the different static Controls..(Labels,..)
How to do that using Visual C++?
Can anybody please help me?
Thanks in advance..
|
|
|
|
|
...
hi there...
this is how i do it....
well.....first derive a class say "CMystatic"from the base class CStatic class using the 'ADD CLASS' option in the wizard.....
after u do this.....
again take the wizard....then take the "message maps option" and in that select the class name that u have just derived (here called as CMystatic) from the "class name" combo box......
then.....in the messages option select the WM_LBUTTONDOWN.....by doubleclicking on this the wizard automatically loads the handler responsible when the left button is clicked on the static control.....
if have still doubt check up.....
Create your own controls - the art of subclassing
By Chris Maunder .....which iz a very informative topic available in code project .....
cheerz....
|
|
|
|
|
hi....;)
if u want right click......after subclassing....just select the "WM_RBUTTONDOWN"......there ar numerous other types u can handle when u subclass......
best of luck..
cheerz
|
|
|
|
|
I am building a dialog based application (MFC) showing complex tebular data, say different form of grids. I did not find any grid to fullfill my needs. so i put a numer of msflex grids (15 grids) set their properties to give look and feel i want, but it caused an anoying problem.
The size of resource templete file .rc is 12MB but changing size and properties of grid/dialog to get desired look causes the size of .rc file upto 200 MB, the computer nearly dies while compilation may be due to large size of .rc file, dialog also contains 3 bitmap images the total size of iamges is just 615KB (so the BMP's are not the problem)
I want to ask that;
1. Is their any limitation on the resources in an application/ dialog?
2. Limitation on Number of controls that can be placed on dialog?
3. Obviously 200MB .rc file is unacceptable, any compiler options; how to fix .rc files, I have regesigned the dialog but when the number of controls increases same problem reappears.
Please, Help.
|
|
|
|
|
Me too got the same prblm. ..
But once we delete the grids, the .RC file size will decrease.
Again we can add the grid.
But its safe to have backup of .RC file
It might be a bug in the ActiveX grid.
|
|
|
|
|
Thanks for ur Reply
Again we can add the grid.
Adding the grids back re-increases the the size of .rc file; problem reappears
It might be a bug in the ActiveX grid.
Any tool or method to ensure the safe usability of AX controls? so one can check the contols before using it.
MSFlex grid is Microsoft's product, it cant be buggy (maybe); ithink it is some other problem related to resource compiler about which i know nothing.
|
|
|
|
|