|
Thanks for replying. Your suggestion provided the solution!!
William
Fortes in fide et opere!
|
|
|
|
|
Yes your right of course. I shouldn't try answering questions before my first coffee or two of the day.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Why do you actually declare class inside another class?
I've always wondered why.
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
Interests: C++, ADO, SQL, Winsock, 0s and 1s
|
|
|
|
|
Usually for some information-hiding reason. For example, you might need to store data in a POD (Plain Old Data) structure in order to store it to and from some binary file format. However, you don't want users of your class to access this directly.
Normally you'd put the declaration in an implementation file, but you might want to have a member variable of that type. To do this, the structure must be declared in the header, so you put it in a private area of the header.
At other times, you might want a parameter class. You might have a method on one class that requires a large number of parameters, many of which are optional (which probably means you've overloaded the method too heavily, but sometimes it's necessary). The Refactoring people suggest that you should replace the large number of parameters with a single parameter of a class type.
The class is only used in this one method, so to avoid polluting the namespace, you declare the parameter class inside the class in which it's used (obviously here you would declare it public or protected , depending on the scope of the method that uses it as a parameter.
|
|
|
|
|
In my case, I'm doing it for a little of the second reason you gave and a third for encapsulation (meaning, the inner structure provides a kind of specialized service for the outter structure, which the outter structure assigns to it as a sort of "black box" requirement).
That "black box" requirement, has an interface which the outter structure uses, but which ANY other class or structure can use, which makes the usefullness of the inner structure "portable".
William
Fortes in fide et opere!
|
|
|
|
|
hy, to instatiate the embedded struct you must do this:
MajorStruct::MinorStruct minStruct;
greets
andreas
|
|
|
|
|
Thank you for your answer. It was a good answer, and I appreciate it.
William
Fortes in fide et opere!
|
|
|
|
|
I'm using WSAEventSelect() to register events, FD_READ, FD_WRITE, etc to handle in my program. I have a section of code like:
WSAEnumNetworkEvents(pConnect->m_oSkt, *pwsaEvents, &wsaNetEvent)
if((wsaNetEvent.lNetworkEvents & FD_READ) &&
wsaNetEvent.iErrorCode[FD_READ_BIT] == 0)
{
// do stuff
}
:
:
I get an FD_ACCEPT event on the server as I expect and an FD_WRITE on the client as I expect, but when I call send() on the client, I get wsaNetEvent.lNetworkEvents == 0 on the server. I don't understand why it would equal 0. Under what conditions would it equal 0? Any help would be appreciated.
Thanks,
melinda
|
|
|
|
|
I implemented a control (derived from CWnd) that implements a context menu. When the user selects something from the menu, the picture covering the whole control changes.
The picture is stored in an offscreen buffer and WM_PAINT only repaints the portion uncovered. I capture which item was chosen from the context menu right there with TrackPopupMenu and the TPM_RETURNCMD flag.
The problem is that when the pop-up context menu is disappearing it leaves some of itself on the control. The portion left behind is not of the same shape everytime.
While debugging I found this:
If, after a full control repaint (invalidating the whole control), I pop and hide the menu without any change to the control, the menu invalidates the area it was covering (let's call this Area A) and produces the artifact. From then on (as long as I don't issue a full control repaint), when I pop and hide the menu, it invalidates ONLY the area of itself that intersects with the area it 1st covered (Area A), making this new area Area A, and produces the artifact in this area only. So, if I pop and hide the menu making the intersection empty, it in fact doesn't invalidate anything and the artifact is not produced; Area A becomes empty and from then on there is no artifact until I invalidate the whole control, beginning this process again.
Note that the artifact does not cover all of Area A. As an example the artifact would be in the middle of Area A, which means WM_PAINT actually painted some of it (above and below).
Another fact is that if I delay the full control repaint for, let's say, 1 second, the artifact is not produced. But I don't want to delay anything.
If I move another window over the artifact, producing a WM_PAINT, it clears the artifact away.
I think the pop-up menu is somehow painting MY control's DC at the same time (as in concurrent threads) as my WM_PAINT. If this is the case, is there a way to prevent this?
Please help me! Any light on the issue will be greatly appreciated.
|
|
|
|
|
|
Registry hives are not kept in one central location. It's going to depend on whether it's for a user (HKCU), or the machine (HKLM), and which OS it is running on (Windows 9x uses different locations than Windows NT/2000).
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
There is a RegQueryInfoKey function, but from the documentation I can't tell if it would give you what you want right off hand.
You could also try RegSaveKey. It saves the key info to a file and you could read the file afterward. Still not sure if it will save the path though.
"It is better to remain silent and be thought a fool than to open one's mouth and remove all doubt." - Abraham Lincoln
|
|
|
|
|
Hi,
Im having problem with the Rich Edit Control in MDI Applications (Derived from CFormView).
What happens is that the Application compiles and executes good, but when I open a new DialogBox window (with a RichEdit Control on it).The application fails to initialize the DialogBox.
"What" n "How" do i Fix this.
Plz Help.
bye
raheel
|
|
|
|
|
I think the problem is that you haven't registered the Rich Edit control.
When Windows creates a dialog box, it looks up the window class names in the dialog resource against the list of window classes registered for the process (registered with RegisterClass ). If it can't find one, it fails the dialog creation.
To get the Rich Edit control registered, call AfxInitRichEdit before creating this dialog. In your InitInstance override is probably a good place.
|
|
|
|
|
Hello ,
I have created Regualr dll file using shared MFC dll . In dll file I have
defined one function which is called by pascal/vb/vc++ program .The
program works fine as expected .The function displays the simple dialog box
with "OK" & "CANCEL" button .
But when I add the ActiveX control to DLL file , even without adding any member for activeX control , the program fails .I have just put the control box using control pallete in dialog editor as we add normal button .
What is the problem with ActiveX control . What are the settings I need
to do in order to use ActiveX control in the DLL project .
U can check the proplem by simply creating the project as below :
Steps which I followed are explained below :
1. Create DLL project using MFC AppWizard(DLL) , give the name as "sample" .
2. On the second step , keep all default setting .i.e "Regular DLL using shared MFC DLL"
Note the the option for "Automation" & "Winows Socket " are kept as unchecked .
2. Say ok , the application frame work is generated .
Now u can simply insert one dialog , with dialog ID as "IDD_DIALOG1" .
Don't add anything to the dialog .Using the claas wizard , add the class
for dialog , give the name as "Cmydialog" & base class class is "CDialog".
Don't add any control or variable to the dialog . Just leave it as it is .
Then in the sample.cpp file of ur project add the code as shown below.
include the file "mydialog.h" .
The logic in the calldlg function is self explainatory. It just shows message box
with the value passed by the calling function . Then it creates the the dialog &
just display it .
CSampleApp theApp;
BOOL CSampleApp::InitInstance()
{
AfxOleInitModule();
AfxEnableControlContainer();
return CWinApp::InitInstance();
}
void _stdcall calldlg(int x)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
int j;
j=x;
CString str;
str.Format("The value is %d ",j);
MessageBox(0,str,"title",0);
static Cmydialog pt;
static int flag= 0;
if(flag==0)
{
pt.Create(IDD_DIALOG1,AfxGetMainWnd());
flag=1;
}
pt.ShowWindow(SW_SHOW);
}
In the "sample.h" file add the declaration function for InitInstance() since we have
overriden it in the sample.cpp file .
Then add the "calldlg" i.e name of the function in the "sample.def" define file .
Compile it . The sample.dll file is created without any error .
Now just to check it , create client application using MFC . Create simple dialog
based application name "Testsample".
Add one button with id "IDC_TEST" & in the handler of that button call the
function "calldlg" in the dll file . The code is shown below :
void CTestsampleDlg::OnTest()
{
// TODO: Add your control notification handler code here
int p=2;
HMODULE hMod1;
PF pf1={0};
hMod1 = LoadLibrary("c:\\sample\\debug\\sample.dll");
pf1 = (PF)GetProcAddress(hMod1,"calldlg");
pf1(p);
}
just add the following in Testsampledlg.cpp in the very beginning only
typedef void (_stdcall * PF)(int);
Now compile the project & run it . It works without any problem .
Now just open the dll project , add the Microsoft Flex Grid Control with
"Project|add to the project|controls & componants" . Say insert ,
The Flex Grid control is added to the control pallete .The required classes
are also added to the project .
Now just put the flex grid control on ur dialog i.e IDD_DIALOG1 in our case .
Don't add any thing to the grid control as well as to the dialog .
Just compile it . It compiles without any error .
Now try to test it . U will see the Assertion error
What is the problem here with the activeX control now .
Please try it .
thanks & regards ,
Bhalchandra
|
|
|
|
|
I need help finishing up my project. I am really close I think.
I need to pass a binary tree in a treeNode::output to the List::insertNode to be inserted into a linked list. I've exhausted all ideas I can come up with and just dont see the light.
Thanks, here is the code I have.
<pre>#include <iostream>
#include <string>
#include "List.h"
using namespace std;
class treeNode
{
string name;
treeNode *smaller, *bigger;
friend class List;
public:
treeNode(string newName="", treeNode *newSmaller=NULL, treeNode *newBigger=NULL)
{
name=newName;
smaller=newSmaller;
bigger=newBigger;
}
void add(string newName)
{
if(newName<name)
{
if(smaller==NULL)
smaller=new treeNode(newName);
else
smaller->add(newName);
}
if(newName>name)
{
if(bigger==NULL)
bigger=new treeNode(newName);
else
bigger->add(newName);
}
}
void output(treeNode *name,List &l)
{
if(smaller!=NULL)
smaller->output(name,l);
l.insertNode(l);
if(bigger!=NULL)
bigger->output(name,l);
}
};
void main()
{
List l;
treeNode t;
string newName;
int howMany;
cin >> howMany;
for(int i=0; i<howMany; ++i)
{
cin >> newName;
t.add(newName);
//l.insertNode(treeNode *t);
}
//t.output(t);
//l.outputList(cout);
}</pre>
|
|
|
|
|
If List::insertNode takes a treeNode* parameter, you probably need to write
l.insertNode( &t ); It isn't clear to me what you're doing.
Normally I wouldn't recommend writing your own list and tree classes; the C++ standard library includes std::list and std::map or std::set for that.
|
|
|
|
|
But you have not indicated what specific problem you are having. I'm assuming you have single-stepped through each line of code using the debugger. If not, that would be a good place to start. Simply putting the code together, running the program, and noting the output, does not indicate whether your program is doing the right or wrong thing.
Are items added to the tree as expected? Can you traverse the tree in prefix, infix, and postfix order? Does changing your code to the following help:
void output(treeNode *name, List &l)
{
if (smaller != NULL)
output(smaller, l);
cout << name << endl;
if (bigger != NULL)
output(bigger, l);
}
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Yes, that is very similar to what my teacher told me to do, if not identical. I was too much of a bonehead to not write it down though, thinking I could remember a couple simple parameters. I was wrong.
Sorry my thread was so vague. I will try to be more specific next time.
Thank you.
|
|
|
|
|
How do programs like window washer accomplish this. Do they go low level or hi level and just zero a file?
Wouldn't it make sense to just encrypt a file with a random password then delete it...?
Just cursious
I'm drinking triples, seeing double and acting single
|
|
|
|
|
I heard they overwrite it twice just to make sure any residual magnetism is destroyed.
|
|
|
|
|
|
JWood wrote:
residual magnetism is destroyed
Ahhh I wondered why they did that...Window washer does it like 30 times....I couldn't figure out why...
Interesting
I'm drinking triples, seeing double and acting single
|
|
|
|
|
Indeed, the default behavior of the shred command on many Unix systems is to overwrite the file 25 times (!!) with random data, with the option of adding a final overwrite with zeros in an attempt to hide the fact that shred was even used.
Note, however, that most programs like shred can only work at the file level -- filesystems which do not guarantee that overwritten bytes are written to the same place on disk will likely leave residual chunks of the data file behind in unallocated space.
Of course, probably the best way to keep that data from being recovered would probably be to overwrite it with random data many time, zero it, delete it, cause a head crash on the occupied sectors, then melt the platters
- Mike
|
|
|
|
|
Michael Imamura wrote:
cause a head crash on the occupied sectors, then melt the platters
I don't think i'll be going that far...
I'm drinking triples, seeing double and acting single
|
|
|
|
|