|
A NULL child already indicates no child/sub-items are available for that particular item though...?
Like a windows drop down menu...what kinda data structure would that require...?
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I have no idea what you're on about.
STL is a religeon. Enquiries to Reverend Christian Graus
|
|
|
|
|
while (item)
{
// use the other members
item = item.Child;
}
Make item a POINTER to an ITEM, and use NULL to specify the bottom item. Otherwise you need a data memeber or magic number combination to show the end of the line. If it's a loop ( the last item points to the first ) then it's like this
ITEM item = (whatever)
ITEM item2 = item
while(true)
{
//deal with item
item = item.Child;
if (&item == &item2)
break;
}
so where-ever you start, when you end up at the beginning, you break.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Hey Christian...thanx for the reply...
Your correct about the pointer assumption...i'm actually using JScript to develope a menu in DHTML with unlimited children popup's...
Each AppendMenuItem() basically takes as parameters
Caption, Parent, CommandID and adds them to the array as needed.
If i'm to create a menu from a array I fail to see how the above would create all the popups and items in each...I have tried the above before and i'm obviosuly missing a important link...
File Edit View
New Undo History ->>> Object1
Open Redo --------- Object2
Save Wireframe Object3
Solid
In order to create all the popups I would need to iterate the array and when the end of a division was reached i'd need to stop and start back where I began, no...?
I'm thinking I need some nLevel variable to track my last known position...perhaps an array of nLevels...?
How does the code above allow me to find an item with a particular caption...?
Sorry for not getting it or repeating questions...
Thanx!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
OK - that changes things a LOT. Your orignal model cannot work, because it does not allow multiple children of one parent. I *do* know that you can have arrays in JScript, so one way would be for an ITEM to store an array of children, if it's empty, then it's an end item, otherwise it contains the children of that item.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Christian Graus wrote:
OK - that changes things a LOT.
I was afraid of that.
Arrays are possible in JScript so are custom struct's sorta.
function MENU_ITEM(Caption, Parent, CommandID)
{
this.Caption = Caption;
this.Parent = Parent;
this.CommandID = CommandID;
this.Child = new Array();
}
var MenuItems = new Array();
var nItems = MenuItems.length;
MenuItems[nItems] = new MENU_ITEM("File", null, null);
MenuItems[nItems].Child = new MENU_ITEM("MRU1", "File", 1000);
MenuItems[nItems+1].Child = new MENU_ITEM("MRU2", "File", 2000);
MenuItems[nItems+2].Child = new MENU_ITEM("MRU3", "File", 3000);
The above is what I am trying to accomplish and have almost got it...
a Menubar is created with only a File item and it has 3 children MRU list...how do I iterate the array above, considering children can have children and so on...
thats whats confusing the heck outta me...i'm so lost on how to set up the loop...
Would I use 2 nested for loops or a while loop...?
Can you suggest any other approach/structure to managing drop down menus...?
Thanx again!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hockey wrote:
how do I iterate the array above, considering children can have children and so on...
Recursion
A function needs to take an ITEM, then it needs to iterate through the array of items in it something like this
RecurseThroughMenu(ITEM item)
{
foreach (ITEM i in item.Child)
{
// add item i to the menu under 'item'
if (i.Child.length > 0)
RecurseThroughMenu(i)
}
}
This is not meant to be any particular language, just give you the idea how to do it
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Christian Graus wrote:
This is not meant to be any particular language, just give you the idea how to do it
foreach IMO says Perl is your friend...
ASP has something similar to I think.
Anyways...I appreciate your help...i'm still gonna have to invest a lot of time into fully understanding whats going on, but i'll get it eventually.
Thanx for your time.
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I'm doing a Windows Paint-like application. I draw on the screen by capturing every mouse button-downs and moves, and then SetPixel(), the line drawn will be broken and I guess the Windows does not process the messages fast enough so some MouseMove do not react to every point the mouse moves. How does Windows Paint do that drawing on the screen without breaking? What should I do to smooth it?
|
|
|
|
|
I believe you are partially right. I think windows does not miss a message, but WM_MOUSEMOVE is not sent for every pixel your mouse is over.
Anyway use CDC::LineTo
Best regards,
Alexandru Savescu
|
|
|
|
|
davilism wrote:
How does Windows Paint do that drawing on the screen without breaking?
Probably it just connects the points with line segments. Depending on the speed of mouse movement, the line will be more or less jagged.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Hi,
I´m running in a big trouble, my control shows an enhanced metafile, and I have seen that Ms Word 2000, and CComControlBase::IDataObject_GetData(...), creates an ooold Windows 3.1 metafile to make the image for printing and for design mode... ( aaah !, so still using Windows 3.1 ooold code !!!!!, and you can see in the MSDN that Win 3.1 metafiles are obsolote, and please don´t use it ((( ).
The problem that I have, is that my enhanced metafile uses some funtions that are not compatible with the old Win 3.1 metafiles, and nothing ( or some things but not all), is shown ...
Do you know any solution, or workaround for this problem ?, thanks for you help, greetings
Braulio
|
|
|
|
|
I have a socket used to receive UDP packet in my program, the main thread respons to the FD_WRITE and FD_READ message, and sets flags, then calls up another thread to do some receivefrom and sendto operation.
The program goes fine in normal LAN, then I changed the environment to 802.11b Wireless LAN, the program becomes very unstable, sometimes it acts
like "dead", and I was forced to kill it.
Can you suggest any possible reasons for the problem?
Here is how I created the socket, did I miss something?
if (!AfxSocketInit())
{
AfxMessageBox("AfxSocketInit error!", MB_OK | MB_ICONERROR);
return FALSE;
}
m_bSocketCreated = false;
m_Socket = socket( AF_INET, SOCK_DGRAM, 0);
if( m_Socket != INVALID_SOCKET )
{
m_Address.sin_family = AF_INET;
m_Address.sin_port = htons(25556);
m_Address.sin_addr.S_un.S_addr = htonl( INADDR_ANY);
i = bind(m_Socket, (struct sockaddr*)&m_Address, sizeof(m_Address));
if( i != SOCKET_ERROR )
{
int j = 1;
i = setsockopt(m_Socket, SOL_SOCKET, SO_DONTROUTE, (char*)&j, sizeof(int) );
i |= setsockopt(m_Socket, SOL_SOCKET, SO_BROADCAST, (char*)&j, sizeof(int) );
if( i != SOCKET_ERROR )
{
ULONG tmp = 1;
i = ioctlsocket( m_Socket, FIONBIO, &tmp);
if( i != SOCKET_ERROR )
{
i = WSAAsyncSelect(m_Socket, m_hWnd, UWM_SOCKET_NOTIFY, FD_READ | FD_WRITE);
if( i != SOCKET_ERROR )
{
m_bSocketCreated = true;
}
}
}
}
}
if( m_bSocketCreated == false )
{
AfxMessageBox("Create socket error!", MB_OK | MB_ICONERROR);
}
|
|
|
|
|
Does your test machine have interfaces for both regular and wireless LAN? If so, maybe Winsock is having some trouble routing the messages.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
But isn't socket programming for WLAN different between socket programming for LAN??
or it was only maybe IrDA socket programming which was different,...
Rickard Andersson@Suza Computing
ICQ#: 50302279 (Add me!)
E-mail: nikado@pc.nu
I'm from the winter country SWEDEN!
|
|
|
|
|
Rickard Andersson wrote:
But isn't socket programming for WLAN different between socket programming for LAN??
eeks... I hope not much. Because I wanna port some programms to WLAN, as soon as I can afford one. Sorry for interupting.
|
|
|
|
|
No, UDP/IP or TCP/IP sockets should work the same no matter what the physical network layer is.
|
|
|
|
|
WLAN is slower and more unreliable than wired LAN. Does your program work properly if datagrams are lost in transmission?
|
|
|
|
|
In 2K/XP therу is an option like "hide underlined letters for keyboard navigation until I press Alt Key". I'm interesting to know, which message is sent to controls when Alt pressed and controls redraw.
(sorry for bad english)
|
|
|
|
|
I believe it's WM_SYSKEYDOWN
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Hi all
I have encountered a mysterious problem. When i tried to pass the CString argument, the compiler gives me the following error
ompiling...
Assignment3_question1Doc.cpp
e:\documents and settings\administrator\my documents\st2\mfc programming\assignment3_question1\assignment3_question1doc.h(23) : error C2629: unexpected 'class CString ('
Generating Code...
Compiling...
Assignment3_question1View.cpp
e:\documents and settings\administrator\my documents\st2\mfc programming\assignment3_question1\assignment3_question1doc.h(23) : error C2629: unexpected 'class CString ('
Generating Code...
Error executing cl.exe.
Assignment3_question1.exe - 3 error(s), 0 warning(s)
This is my class definition:
class Group
{
public:
Group(CString &t1, CString &t2, CString &t3, CString &t4)
{
team.Add(t1);
team.Add(t2);
team.Add(t3);
team.Add(t4);
}
CString GetTeam(int i)
{
return team.GetAt(i);
}
void PutResult(int t1, int s1, int t2, int s2)
{
}
void GetLadder()
{
}
private:
CStringArray team;
int res[4][4];
};
and this is how i used it
Group groupA(CString("France"), CString("Uruguay"), CString("Denmark"),CString("Senegal"));
and this is the MSDN says:
Compiler Error C2629
unexpected 'token ('
A syntax error made the statement ambiguous.
This error can be caused by mixing declaration and expression syntax.
The following is an example of this error:
class B
{
B( &B );
B( B& );
};
Note: I have inclulded the "Group.h" in the Document repository. This is a SDI , MFC application.
COuld you please enlighten me see where i went wrong. I have asked this couple of time but it sill give me the error.
Cheers.
|
|
|
|
|
Forget CString ("France"), just use "France". The conversion is implicit. I'm not sure, but I think pass by reference might be part of the problem ( although usually a great idea, I just have a feeling about it this time ). If you're going to pass bt reference as an optimisation, it's an excellent idea to make them const where-ever you don't intend to modify them.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Also CString implements reference counting and passing an object and not a reference will not produce much overhead at all.
Best regards,
Alexandru Savescu
|
|
|
|
|
tcuong,
Here is your code compiled in a Visual C++ console app with MFC support. I named the app 'Team'. The code works as you wrote it...
#include "stdafx.h"
#include "Team.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CWinApp theApp;
using namespace std;
class Group
{
public:
Group(CString &t1, CString &t2, CString &t3, CString &t4)
{
team.Add(t1);
team.Add(t2);
team.Add(t3);
team.Add(t4);
}
CString GetTeam(int i)
{
return team.GetAt(i);
}
void PutResult(int t1, int s1, int t2, int s2)
{
}
void GetLadder()
{
}
private:
CStringArray team;
int res[4][4];
};
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
CString strHello;
strHello.LoadString(IDS_HELLO);
cout << (LPCTSTR)strHello << endl << endl;
Group groupA(CString("France"), CString("Uruguay"), CString("Denmark"),CString("Senegal"));
int i;
for(i = 0; i < 4; i++)
cout << (LPCTSTR)groupA.GetTeam(i) << endl;
cin >> i;
}
return nRetCode;
} The unexpected 'token (' error you are getting is a syntax error in your code ahead of the Group groupA(...) stuff. Try commenting out the Group groupA(...) line and see if the error moves to another line of code. If it does you definitely have a syntax error somewhere else. Email me your code if you still can't get it.
Good luck...
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
I have a application that has serval CScrolledViews called.
There are plenty of good examples of how to add TabCtls to
the CMainFrame and I did that, But the "tabs" are on the
outside of my documents! How do I get them inside my documents
as the first "widget" inside the doc?
|
|
|
|
|