|
The best way is not to use C style file handling, but use C++, with iostreams, and write stream handlers for your struct.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I believe he asked if he could do it that way, not a better way to do it.
Try this way...
<br />
#include "stdio.h"
<br />
struct XYZSTRUCT<br />
{<br />
int n1;<br />
double d1;<br />
char c[25];<br />
};<br />
<br />
XYZSTRUCT xyzItem;<br />
int nItemsRead = 0;<br />
<br />
FILE* f = fopen("MyFile.xyz", "rb");<br />
if (f)<br />
{<br />
itemsRead = fread(&xyzItem, sizeof(XYZSTRUCT), 1, f);<br />
fclose(f);<br />
}<br />
if (itemsRead < 1)<br />
{<br />
}<br />
Of course, Christian might be right about his claim that IOstreams are better, but sometimes, something quick and dirty like this are called for.
Keep in mind that you should stick with standard C++ types and not use MFC types when you're doing it this way.
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi all,
I am fixing some defects in a huge code base, There's a function, say, func1 ()in which after even a long investigation, I am unable to find which function of the code base calls this function..
I there any way to find this out..This code has got multiple threads..can somebody suggest any free tool which can show the function call stack or any other means of finding this out..
Thanks,
Shiva P
|
|
|
|
|
one tool will do both of these things for you. It's from Microsoft and it's called Visual Studio. It will search for the function call across an entire project ( actually, Microsoft Windows is also worth checking out, it'll search all the text within a directory structure for you ), and if you put a breakpoint in your function and run in debug mode, you'll be able to see a call stack.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
if you want to do it programmatically, You can try looking at StackWalk
msdn online has This[^] to say about it
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
"Philosophy is a study that lets us be unhappy more intelligently."
-Anon.
|
|
|
|
|
Can you not set a breakpoint in func1() , and then check the call stack once the breakpoint has been reached?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
hi all i need help
i can get the Thread current process but i don't know how to get the information of the window was created by the Thread like (window caption, control in that window....) the same Spy++ tool of VS when we click the Thread(Ctrl+T) button on toolbar.
Thank so much
|
|
|
|
|
MSDN: EnumThreadWindows Function
The EnumThreadWindows function enumerates all nonchild windows associated with a thread by passing the handle to each window, in turn, to an application-defined callback function. EnumThreadWindows continues until the last window is enumerated or the callback function returns FALSE. To enumerate child windows of a particular window, use the EnumChildWindows function.
|
|
|
|
|
I'm currently working on a project using RichEditView and I have run into a small but very destructive problem. How do I draw text in the view? I have tried OnDraw and even OnPaint but neither function is called by the program. Please help this poor noob before he kills his computer.
|
|
|
|
|
CRichEditCtrl &ctrl = GetRichEditCtrl();
ctrl.SetWindowText(_T("This is my text!"));
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi there,
I have a group of three checkboxes. When I click on CheckBox2, a dialog box appears asking for user input. What it's suppose to do is when a user cancels a selection it should default to the first checkbox by making a call to CheckRadioButton. It does default but once the user clicks away from the application, the dialog box reappears as if the function to open up the dialog box is called once again. I isolated the problem and found that its the CheckRadioButton() that performs the recursive calls. How can I stop it from doing that? Thanks.
void CCheckBox::OnCheckBox2
{
CMyDialog dlg;
int nRet = -1;
nRet = dlg.DoModal();
// Handle the return value from DoModal
switch ( nRet )
{
case -1:
AfxMessageBox("Dialog box could not be created!");
break;
case IDOK:
{
..code...
break;
}
case IDABORT:
{
OnCheckBox1();
break;
}
case IDCANCEL:
{
OnCheckBox1();
break;
}
default:
break;
};
}
void CCheckBox::OnCheckBox1()
{
CheckRadioButton(IDC_RADIO1, IDC_RADIO3, IDC_RADIO1); //problem lies here
}
|
|
|
|
|
elephantstar wrote:
...when a user cancels a selection...
Cancels what selection?
elephantstar wrote:
...once the user clicks away from the application...
Closes the application, or puts focus on another application?
elephantstar wrote:
CheckRadioButton(IDC_RADIO1, IDC_RADIO3, IDC_RADIO1);
While I don't think it is related to the problem, are the values for IDC_RADIO1 , IDC_RADIO2 , and IDC_RADIO3 contiguous?
Why are you using CheckRadioButton() with checkboxes and not radio buttons?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
-When the user selects cancel (CASE IDCANCEL) in the popup dialog box, it would call OnCheckBox1() to check the first radio button. The first button is the default selection.
-Puts focus on another application.
-The radio button values are contiguous. The buttons are radio buttons not checkboxes. Sorry to confuse you with the names.
|
|
|
|
|
elephantstar wrote:
-When the user selects cancel (CASE IDCANCEL) in the popup dialog box, it would call OnCheckBox1() to check the first radio button. The first button is the default selection.
Blake's suggestion is definitely the cleanest. Assign each of the radio buttons a CButton member variable (e.g., m_btnRadio1, m_btnRadio2, m_btnRadio3). Something like:
void CCheckBox::OnCheckBox1( void )
{
m_btnRadio2.SetCheck(BST_UNCHECKED);
m_btnRadio3.SetCheck(BST_UNCHECKED);
}
void CCheckBox::OnCheckBox2( void )
{
CMyDialog dlg;
int nReturn;
nReturn = dlg.DoModal();
if (IDABORT == nReturn || IDCANCEL == nReturn)
m_btnRadio1.SetCheck(BST_CHECKED);
else
m_btnRadio1.SetCheck(BST_UNCHECKED);
m_btnRadio3.SetCheck(BST_UNCHECKED);
}
void CCheckBox::OnCheckBox3( void )
{
m_btnRadio1.SetCheck(BST_UNCHECKED);
m_btnRadio2.SetCheck(BST_UNCHECKED);
}
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I did as you suggested but there's a problem. The second radio button does not uncheck so I inserted m_btnRadio2.SetCheck(BST_UNCHECKED) when nReturn is either IDABORT or IDCANCEL. The recursion appears once again. Why is that? I grouped the buttons such that the first button has group property checked while the other two does not. What is going on?
|
|
|
|
|
I would manually check or uncheck the OTHER radio or checkbox buttons in a handler for a particular button. You are getting recursed because the handler for button 1 is calling a function that will try to UNCHECK buttons 2 and three and CHECK button 1 AGAIN. As a result, your button 1 OnCheckBox1 is getting called from itself.
If you want these three items to be mutualy exclusive, you should try to use radio buttons, and not check boxes. If you group them properly and make them all automatic, you won't even need such a handler to 'set' them in your code. Windows will do it automatically.
If you insist on following your current path, you should do the following instead:
void CCheckBox::OnCheckBox1()
{
// button 1 will check or uncheck itself
// uncheck button 2
CButton* pButton = (CButton*)GetDlgItem(IDC_RADIO2);
pButton->SetCheck(0);
// uncheck button 3
pButton = (CButton*)GetDlgItem(IDC_RADIO3);
pButton->SetCheck(0);
}
void CCheckBox::OnCheckBox2()
{
// uncheck button 1
CButton* pButton = (CButton*)GetDlgItem(IDC_RADIO1);
pButton->SetCheck(0);
// button 2 will check or uncheck itself
// uncheck button 3
pButton = (CButton*)GetDlgItem(IDC_RADIO3);
pButton->SetCheck(0);
}
similarly for button 3.
|
|
|
|
|
Sorry to confuse you. These buttons are radio buttons and they are contiguous and grouped properly. It's just giving me problems with the CheckRadioButton in OnCheckBox1().
|
|
|
|
|
In that case, I would not bother with the call to 'set' the radio buttons in the radio button handler. They should be toggling on and off properly on their own.
Your call is just redundant - so redundant, it actually recurses on itself.
|
|
|
|
|
So then what was wrong with my initial code? All I want to do is call CheckRadioButton to check the first button when the user cancels the dialog box selection in OnCheckBox2().
|
|
|
|
|
elephantstar wrote:
So then what was wrong with my initial code?
I'm not sure, but this code snippet works for me:
void CT9Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_RADIO1, m_btnRadio1);
DDX_Control(pDX, IDC_RADIO2, m_btnRadio2);
DDX_Control(pDX, IDC_RADIO3, m_btnRadio3);
}
BEGIN_MESSAGE_MAP(CT9Dlg, CDialog)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
END_MESSAGE_MAP()
BOOL CT9Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_btnRadio1.SetCheck(BST_CHECKED);
return TRUE;
}
void CT9Dlg::OnRadio1()
{
}
void CT9Dlg::OnRadio2()
{
CMyDialog dlg;
if (IDCANCEL == dlg.DoModal())
{
m_btnRadio1.SetCheck(BST_CHECKED);
m_btnRadio2.SetCheck(BST_UNCHECKED);
}
}
void CT9Dlg::OnRadio3()
{
}
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I have the exact same setup, but the button in its event handler function does not like to uncheck itself (ie. m_btnRadio2.SetCheck(BST_UNCHECKED);) This is what causes the recursion and it recursivelly calls OnRadio2() about four times. I tried to test this on OnRadio1() by doing the following:
void CT9Dlg:OnRadio1()
{
MessageBox("Hello");
m_btnRadio1.SetCheck(BST_UNCHECKED); //recursive calls
m_btnRadio2.SetCheck(BST_CHECKED);
m_btnRadio3.SetCheck(BST_UNCHECKED);
}
OnRadio1() is repeately called because of that line of code. I just don't understand it. Should the group properties for each radio button be checked or just the first in the group? This bug is really bugging me.....
|
|
|
|
|
elephantstar wrote:
Should the group properties for each radio button be checked or just the first in the group?
Yes. The three radio buttons must also be next to each other in the Z-order.
elephantstar wrote:
This bug is really bugging me
If you can package the project up fairly small and still be able to reproduce the problem, feel free to send it to me and I'll take a look.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
My question is simple enough, I have project that I have been working on for probably 1 and a half years. It is written in C++ and is a fully fucntional RAM/memory searcher capable of searching for floats, ints, bytes , etc in RAM. I was curious as to WHERE I would have to go, to sell this project. By sell I meant give away the rights, and source code. I am looking for a site that allows one to sell their source codes/rights to it. If anyone knows any, please tell me.
|
|
|
|
|
www.download.com comes to mind, while www.tucows.com is another.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Im loading a menu from a resource with LoadMenu and then i insert an extra item using InsertMenuItem, this item has a bitmap, which causes the menu to be extended on the left, adding room for the bitmap. However, now the little arrows on the right that indicates submenus are drawn over the texts. Ive tried making the new item longer than all preexisting items and then everything looks okay. So my guess is that somewhere the width of the menu is precomputed and it doesnt get updated correctly when the extra room for the bitmap is added.
The documentation tells me to call DrawMenuBar(HWND) after changing a menu, but my menu is for a contextmenu not a window.
What am i doing wrong?
|
|
|
|