|
I don't know if this will help, but i was tying to rewrite into C code, my program in Matlab.
I used the Matlab compiler to run my code in C, but it does not generate a proper C code as i want.
That'i is why at some points the syntax may look weird.
F.K
|
|
|
|
|
Well, it helps to understand the queer syntax.
First of all, if you want to initialize a variable, use 0(zero) instaed of NULL. NULL should only be used for pointers, meaning not available memory. It may or may not coincide with being zero.
A variable is not a function. in your sample trl_value was used as a function trl_value(length(.....)), this function was then given a value, and never stored. Two errors at once.
A function cannot assigned a value, it is returning one! And a variable cannot be a function.
You may of course have a function with the same name like a variable, but this is bad manners, and not shown in your sample code.
So I think the best is, you just make clear what the code should perform. and write a plain simple text(file) in your local language, and try to translate this one into C.
Rounding in C/C++:
One of many methods
<br />
VariableRounded = (long)(VariableToBeRounded+0.5);<br />
Works mathematically correct only for positive values.
So try to use the floor or ceiling finctions instead. Still issues with signs.
G. Steudtel
|
|
|
|
|
Be more specific. What errors are you talking about (i.e., compiler, linker, run-time)?
There are different ways of rounding a number, depending on the intent. You can use ceil(), floor(), or you can add 0.5 to the number and cast away the exponent, leaving just the mantissa.
|
|
|
|
|
2nd question first...
double d,e = 5.731;
d = floor (e); // = 5
d = ceil (e); // = 6
d = fmod (e, 1.0); // = 0.731
d = fmod (e, 2.0); // = 1.731
As for the 1st question:
a) You don't give us the error messages. If there are loads, the first few will do.
Chances are, error 10-99 are follow ons from errors 1 - 9.
b) You have two '#include's at the beginning, but you don't give the preprocessor
and filenames to actually include...
c) There are a LOT of file scope (global) variables here. Not the best programming
example. If it works, then OK, but don't take too many tips from it.
Iain.
|
|
|
|
|
I have a dialog with 6 spin controls on it. The controls are populated with a random number in the OnInitDialog method. Once one of the spin controls is increased I would like to turn off the other 5 so that they can't be changed. If the original control was then later decreased then I need to turn on the all of the controls again so that they may be changed.
I have tried to do this the VScroll message handler but it seems that the buddy window is updated before or independant of this message handler.
Thanks for the help,
-Eric
|
|
|
|
|
You might be able to lock out the buddy changing by looking at EN_UPDATE (or is it EN_CHANGE...)
Alternatively, turn off the buddying on the other controls with UDM_SETBUDDY (NULL) and re-
connect them when your changed spinner goes back to its initial value.
Iain.
|
|
|
|
|
Iain,
Thanks for the help. I have used the EN_CHANGE message for each edit control and then I turned off the other spin controls if one was increased. The problem is that when the user clicks up again it will turn them all back on again. Here is a snippet of my code. Any ideas? I want to be able to only increase one of the 6 spin controls then turn off the rest. If the users then decreases the one spin control by one then it needs to turn the other controls back on again.
<br />
void CMyDialog::OnChangeEditOne()<br />
{<br />
if(!bFirstRun)<br />
{<br />
if(!bOne)<br />
{<br />
m_cTwo.EnableWindow(FALSE);<br />
m_cThree.EnableWindow(FALSE);<br />
m_cFour.EnableWindow(FALSE);<br />
m_cFive.EnableWindow(FALSE);<br />
m_cSix.EnableWindow(FALSE);<br />
m_cOk.EnableWindow(TRUE);<br />
bOne = TRUE;<br />
}<br />
else<br />
{<br />
m_cTwo.EnableWindow(TRUE);<br />
m_cThree.EnableWindow(TRUE);<br />
m_cFour.EnableWindow(TRUE);<br />
m_cFive.EnableWindow(TRUE);<br />
m_cSix.EnableWindow(TRUE);<br />
m_cOk.EnableWindow(FALSE);<br />
bOne = FALSE;<br />
}<br />
}<br />
else<br />
bFirstRun = FALSE;<br />
}<br />
Thanks again.
-Eric
|
|
|
|
|
Iain,
Thanks for the help. I have used the EN_CHANGE message for each edit control and then I turned off the other spin controls if one was increased. The problem is that when the user clicks up again it will turn them all back on again. Here is a snippet of my code. Any ideas? I want to be able to only increase one of the 6 spin controls then turn off the rest. If the users then decreases the one spin control by one then it needs to turn the other controls back on again.
<br />
void CMyDialog::OnChangeEditOne()<br />
{ <br />
if(!bFirstRun)<br />
{<br />
if(!bOne)<br />
{<br />
m_cTwo.EnableWindow(FALSE);<br />
m_cThree.EnableWindow(FALSE);<br />
m_cFour.EnableWindow(FALSE);<br />
m_cFive.EnableWindow(FALSE);<br />
m_cSix.EnableWindow(FALSE);<br />
m_cOk.EnableWindow(TRUE);<br />
bOne = TRUE;<br />
}<br />
else<br />
{<br />
m_cTwo.EnableWindow(TRUE);<br />
m_cThree.EnableWindow(TRUE);<br />
m_cFour.EnableWindow(TRUE);<br />
m_cFive.EnableWindow(TRUE);<br />
m_cSix.EnableWindow(TRUE);<br />
m_cOk.EnableWindow(FALSE);<br />
bOne = FALSE;<br />
}<br />
}<br />
else<br />
bFirstRun = FALSE;<br />
}<br />
Thanks again.
-Eric
|
|
|
|
|
Hi
I want to dynamic load # buttons.
Like if i have one employee, i only show 1 'Remove' button next to his information.
But when there are 10 employees, i want to see 10 buttons at the correct place.
How can i make a copy of that button and place it somewhere else?
Greetings
jens
|
|
|
|
|
|
Hi David
Ok but the ID given to that CButton needs to be changing, i would make it something like
IDC_BUTTONREMOVENR1
IDC_BUTTONREMOVENR2
...
How can i now use the same code for IDC_BUTTONREMOVENR1 & the others?
Let's assume i have written the correct code for the 1st button on click. But can i use that code now for the other buttons too and how so?
Greetings
Jens
|
|
|
|
|
I don't know what your design is, but I would think an acceptable solution would be to put the employees in a list control with checkboxes in the first "column." Then you would only require one Remove button. Does that make sense?
If that violates your design, you can use something like:
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
//}}AFX_MSG_MAP
ON_COMMAND_RANGE(IDC_BUTTONBASE, IDC_BUTTONBASE + 4, OnRemove)
END_MESSAGE_MAP()
CButton *pRemoveButtons[5];
for (int x = 0; x < 5; x++)
{
pRemoveButtons[x] = new CButton;
pRemoveButtons[x]->Create(..., IDC_BUTTONBASE + x);
}
void CMyDlg::OnRemove(UINT nID)
{
TRACE("You clicked on Remove button #%d\n", nID - IDC_BUTTONBASE);
}
|
|
|
|
|
I think that ON_CONTROL_RANGE would probably be a little simpler to use here, rather than ON_COMMAND_RANGE.
|
|
|
|
|
Whether you provide the BN_CLICKED notification code in the macro or the handler function, I don't see that one is any easier to use than the other.
|
|
|
|
|
Does any one know how to access the help button on a property sheet? I'm trying to use the resource editor, but all it lets me access are the individual pages. Thanks,
Ralf.
ralf.riedel@usm.edu
|
|
|
|
|
hi RalfPeter
You can't access the help button on the property sheet because you can't see the form, and that's pretty ennoying.
Doesn't it work when you add 'OnHelp' (message map) @ header file propsheet?
afx_msg void OnHelp();
void CMyPropSheet::OnHelp()
{
AfxMessageBox("onhelp");
}
Hope this works.
Just Modified
I fixed the problem by not using the standard help button but i created the button myself.
OnInitDialog:
CRect rect, tabrect;
//Get button sizes and positions
GetDlgItem(IDOK)->GetWindowRect(rect);
GetTabControl()->GetWindowRect(tabrect);
ScreenToClient(rect);ScreenToClient(tabrect);
int iWidth = rect.Width();
rect.left = tabrect.left;
rect.right = tabrect.left + iWidth;
m_ButtonHelp.Create("&Help",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE|WS_TABSTOP, rect, this, IDC_BUTTON_HELP);
//add IDC_BUTTON_HELP in RESOURCE.H yourself!!
m_ButtonHelp.SetFont(GetFont());
This creates the button + positions it correctly.
Then work with the previous code to catch the onclick.
Greetings
Jens
|
|
|
|
|
Exactly what do you mean by "access the help button?" Are you wanting to respond to the clicking of the Help button? As the property sheet is not based on a dialog template (like the property pages are), you obviously won't be able to alter it via the resource editor. The OK, Cancel, Apply and Help buttons are created dynamically.
See if the MSDN article Q132715 is of any help.
|
|
|
|
|
In my base class I have this (the base class is pure-virtual)
class CBase
{
protected:
bool m_bEnable;
public:
bool EnableMe( bool bEnable ) = 0;
}
and in each derived class, I have
bool DerivedClass::EnableMe( bool bEnable )
{
m_bEnable = bEnable;
}
would it be better to have :
class CBase
{
protected:
bool m_bEnable;
public:
bool EnableMe( bool bEnable ) { bEnable = bEnable;};
}
bool DerivedClass::EnableMe( bool bEnable )
{
CBase::EnableMe(bEnable);
}
Thanks,
Max.
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
Hi,
it depends on the use of the class.
If you want to impement a interface class, then the pure virtual class should be used.
Keep in mind, that you cannot create instances (aka variables) of this class. Those classes can only be accessed by pointers.
You may write a function body for a pure virtual function, which may be called by any derived class. Resulting in a combination of your to proposals.
G. Steudtel
|
|
|
|
|
Hi,
I have a project that compile with the c2664 error.
error C2664: 'test' : cannot convert parameter 4 from 'void (int,float [],float [])' to 'void (__cdecl *)(int,float [],float [])'
None of the functions with this name in scope match the target type
// functions prototypes
void funcv (int n,float x[],float f[]);
void test (float x[], int n, int *check,
void (*vecfunc) (int, float [], float []));
How can I correct the functions prototypes to get a correct compilation ?
Thanks,
Claude
|
|
|
|
|
You haven't provided enough information. The compiler is not complaining about the prototypes. Show us the code snippet that calls the offending function (i.e., funcv, test).
|
|
|
|
|
Hi,
The function test is called like this:
CBroydn Broydn;
Broydn.test(x,N,&check,funcv);
I have to add that this code was working when I was utilizing thes functions inside a DLL.
Now I want to get out this code from the DLL. and I get this compile error c2664.
Thanks,
Claude
|
|
|
|
|
A hint might be the fact, that the compiler complains about converting a void parameter to a __cdecl function pointer returnig void. Looks to me, that the function prototype of 'funcv' is different. Probably of type pascal or samoething like that.
G. Steudtel
|
|
|
|
|
Show the protypes for funcv.
I think to use class methods as function pointers, you need to make the method static.
Jason Henderson My articles
"The best argument against democracy is a five-minute conversation with the average voter." - Winston Churchill
|
|
|
|
|
The interface IShellDispatch,has an updated interface named IShellDispatch2.
How to invoke IShellDispatch2 and all the members method.
Swarup
|
|
|
|