|
putting it in a struct might be faster for the actual call, since you only have to pass the address of the struct (if you're passing by reference). but you still have to put the stuff in the struct, which will probably take just as long as putting the stuff on the stack.
i only put things in structs when the parameter list itself gets too long for easy reading (somewhere around 8 or 10 items).
-c
<font size=-2>
o(int O){putchar(O);}main(){float l[8],O,I=.05;char _;for(l[6]=15;l[6]<':';o
(10),l[5]=-'$'*I+l[6]++*I)for(l[7]=-5;l[7]<'@';l[4]=-'('*I+l[7]++*I,o(_?'?':':'))for
(*l=O=0,_=1;++_&&((l[2]=*l**l)+(l[3]=O*O)<4);O=*l*O+l[5]+O**l,*l=l[2]-l[3]+l[4]);}</font>
|
|
|
|
|
In fact, for readability a structure will be preferable particulary if there are no hint about what each parameters are:
f(true, false, true, true, true);
Looking at this code it's hard to know what the third parameter means (and it is easy to swap parameters by errors).
As mentionned in another answer, 7 parameters are generally what is considered as a maximum for readability...
Structures or classes also allows to set parameters to default values. If everything is inline and a good compiler is used, the compiler should be able to remove useless initialisation.
Structures or classes (I prefer classes with private members), also allows to easily add a parameter, have default options or compute parameters.
Also if most parameters are optional and different subset are used depending on the context, different constructors can be provided.
Finally as someone else said, if the function is called only from a few places it will be simpler (faster) to pass all those parameters than to define a structure (or a class). But if the code is often used, a better design is in order. The best solution is to make a class with all the data private and inline accessor as this will greatly simplify maintenance if you need additional parameters (or you want to remove obsolete parameters).
Philippe Mori
|
|
|
|
|
I'm trying to take a user input string and then use it like an already declared var. Any idea on how I can do this?
Ex. Users enters myvarX then I use this string to access the variable myvarX.
Thanks for any help.
Jim
|
|
|
|
|
As far as I know this is not possible in C
but you can still declare a std::map<string, some_type="">
and use it, but I think it's not you wanted
|
|
|
|
|
Use a scripting language like Tcl. (You can embed a Tcl interpreter in your Windows app).
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I've never programmed in Tcl, could you give me an idea of how this would be done?
Thanks
|
|
|
|
|
I am looking for some code to draw a minimize to tray button on the caption bar of my window. If any one could help that would be great.
Kurt
|
|
|
|
|
|
There is an article at this other site.
Regards
Thomas
Finally with Sonork id: 100.10453 Thömmi
Disclaimer: Because of heavy processing requirements, we are currently using some of your unused brain capacity for backup processing. Please ignore any hallucinations, voices or unusual dreams you may experience. Please avoid concentration-intensive tasks until further notice. Thank you.
|
|
|
|
|
|
When framework creates a childwindow of an MDI FrameWnd
I'd like childwnd to be maximized. How to achive it ?
thx in adv.
|
|
|
|
|
When you create your application I think at 4th step you can set it in checkbox.
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
In a dialog based application, I draw a rectangle with
CRectTracker. But when i close a sub-window, the part of the drawed rectangle (the part of the covered) also disappeared. Why ?
The following is my code:
BOOL CMYDlg::PreTranslateMessage(MSG* pMsg)
{
switch (pMsg->message)
{
case WM_LBUTTONDOWN:
{
if (pMsg->hwnd == GetSafeHwnd())
{
CPoint pt;
pt.x = GET_X_LPARAM(pMsg->lParam);
pt.y = GET_Y_LPARAM(pMsg->lParam);
if(GetAsyncKeyState(VK_SHIFT) < 0)
{
CRect re(pt, pt);
CRectTracker rt(re, CRectTracker::solidLine | CRectTracker::resizeOutside);
if (rt.TrackRubberBand(this, pt, TRUE))
{
CDC* pDC = GetDC();
rt.Draw(pDC);
CSetRect dlg;
dlg.m_rectleft = rt.m_rect.left;
dlg.m_rectright = rt.m_rect.right;
dlg.m_recttop = rt.m_rect.top;
dlg.m_rectbottom = rt.m_rect.bottom;
if(dlg.DoModal() == IDOK)
{
OnSaveRectInfo(dlg.m_rectleft, dlg.m_rectright, dlg.m_recttop,dlg.m_rectbottom);
}
}
return TRUE;
}
break;
default: break;
}
return CDialog::PreTranslateMessage(pMsg);
}
xyz
|
|
|
|
|
IMHO, you are doing far too much work in PreTranslateMessage. if you want to handle a mouse down event, override the appropriate function (OnButtonDown, i think); if you want to paint something, override OnPaint. PreTranslateMessage isn't supposed to be used as a place to do Win32-style message loop programming.
-c
<font size=-2>
o(int O){putchar(O);}main(){float l[8],O,I=.05;char _;for(l[6]=15;l[6]<':';o
(10),l[5]=-'$'*I+l[6]++*I)for(l[7]=-5;l[7]<'@';l[4]=-'('*I+l[7]++*I,o(_?'?':':'))for
(*l=O=0,_=1;++_&&((l[2]=*l**l)+(l[3]=O*O)<4);O=*l*O+l[5]+O**l,*l=l[2]-l[3]+l[4]);}</font>
|
|
|
|
|
I'm trying to get the profiler working ( again ! )on my project but as usual with the profiler, it does not work very well ...
any idea why I get this error ?
PREP : fatal error PRF1011: cannot open file c:\project\my_project\full_profile_release\my_project.pbo
and from MSDN, prf1011 doesn't give more info ...
who/what is supposed to generate that file ? isn't supposed to be automatic when
started from the IDE ?
I also tried using the shell ( cmd ) to run the profile ( with the ftime.bat ) but , bummer, it doesn't work ....
any ideas
Thanks.
Max.
|
|
|
|
|
Have you enabled generating the map file on your release build?
If i remember right, the initial PREP phase requires the .map files to generate the .pbi which PROFILE processes to create the .pbo files. Finally, PREP is run again with the /M switch to consolidate all the .pbo files into a single .pbt file.
I've played with the command line version a while ago & this is the template FTIME.bat that i used to get it to work.
PREP /OM /FT /EXC nafxcwd.lib /INC File1.cpp /INC File2.cpp MyApp
if errorlevel == 1 goto done
PROFILE MyApp
if errorlevel == 1 goto done
PREP /M MyApp
if errorlevel == 1 goto done
PLIST /ST /T MyApp >MyApp.txt
:done
Chen Venkataraman
|
|
|
|
|
Hi all
In my application I'm having two toolbars.
When I create second one, framework inserts it in new row, but I want it
to be placed on the right of the first one.
I tried to use DockControlBar() providing lpRect parameter, but it makes no difference.
Of course I can drag second toolbar with mouse, but I don't know how to do this
programatically.
Thx in advance
|
|
|
|
|
|
I am trying to automate an application which contains tabular data. This data when sent to a Word application manages to push the table onto the next page, but not in PowerPoint. I end up having a huge table which cannot be viewed entirely in a single slide.
Is there any way to make the automation controller smart enough to split the table during export?
Does anyone have any other solution?
|
|
|
|
|
Does anybody knows how to change text label (caption) of the radio buttons ?
Good sample will be very nice to see .. !
thanks a lot !
|
|
|
|
|
Suppose you have a radio button (id is IDC_RADIO1) and another radio button (IDC_RADIO2). You could code something like this:
void CMyTestDlg::ChangeCaption()
{
CWnd* pWnd = GetDlgItem(IDC_RADIO1);
pWnd->SetWindowText("Choice_001");
pWnd = GetDlgItem(IDC_RADIO2);
pWnd->SetWindowText("Choice_002");
}
Maxwell Chen
|
|
|
|
|
GetDlgItem(IDC_RADIO_WHATEVER)->SetWindowText("New Label");
|
|
|
|
|
Thanks a lot !
it works perfect .
And another one question - how can i to show / hide Radio buttons elements on the dialog ?
thank you !
|
|
|
|
|
GetDlgItem(IDC_RADIO_BUTTON)->ShowWindow(false);
I think this is the way I normally do it.
Best Regards
Søren Madsen
Denmark
|
|
|
|
|
Hello!
I'm trying to record a metafile under Gdi+ somehow into MEMORY, but all the constructors for Gdiplus::Metafile require a filename!
There is however one constructor which allows the metafile to be recorded into an IStream interface. I was thinking that perhaps such an object could be written that would stream the data into a memory buffer via an IStream interface.
<br />
Metafile::Metafile(IStream* stream, HDC referenceHdc, Rect& frameRect, MetafileFrameUnit frameUnit, EmfType type, WCHAR* description)<br />
<br />
Creates a Metafile object for recording to an IStream interface.<br />
Does anyone know how this is possible? Perhaps some atl / com code? I need this for a Visual C++ 6.0 Mfc app.
Thanx a bunch! I really appreciate your help .
Cheers,
swinefeaster
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|