|
If you are using Visual C++ you can use the macro _countof(x) which returns the size of the specified array. In your case you have to write i < _countof(a)
|
|
|
|
|
I actually am using VC++, thanks for your answer!
|
|
|
|
|
You are welcome! 
|
|
|
|
|
What's wrong with asking the compiler how big the array is - it knows, it bunged the thing on the stack for you:
template <typename T, std::size_t N>
std::size_t sizeof_array( T (&)[N] )
{
return N;
}
Most decent compilers (VC++2003, 2005, 2008 and 2010, gcc 3.3 onwards) will inline that to a constant. You can extend it a bit...
template <typename T, std::size_t N>
T *beginning_of_array( T (&a)[N] )
{
return a;
}
template <typename T, std::size_t N>
T *end_of_array( T (&a)[N] )
{
return &a[ N ];
}
which means you can get away from using indexes entirely and start using algorithms to do the sort of thing you're doing in your example:
int main()
{
std::string a[] = { "One", "Two", "Three" };
std::copy( beginning_of_array( a ), end_of_array( a ), std::ostream_iterator<std::string>( std::cout, "\n" ) );
}
From there you're not far away from using overloaded functions to come up with a generic way of handling different aggregates of things.
Cheers,
Ash
|
|
|
|
|
Hi,
I am using default scrollbar for window. In OnSize i am calling SetScrollInfo() function whenever i am resizing the window. But in some situation the scrollbar is getting hidden, if i reduce or increase the size again scrollbar is becoming visible again. I checked the min and max position values but they are correct.
|
|
|
|
|
Are you also resetting your scroll ranges in your paint routine? You need to do this in order to take account of the current client window size and the amount of information you can display relative to the amount of information available. Remember that these values can change just by using a different size font for text or zooming an image.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Thanks a lot, it worked after doing the changes suggested by you.
|
|
|
|
|
You're welcome.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Hello Friends
I am creating a application using GDI/PLus to save tiff as multiPage.
I got the Image object And tried
Image img;
img.save(..,..);
And its working fine
Then I used
img.saveAdd(..,..)
to add other images.but its not working.
And It is accepting one parameter as EncoderParameter which is having option to set multi Frame as I think as I found tht type in c#.
Do anyone is having idea how can I add image as MultiPage.
Thanks In Advance.
Regards
Yogesh
|
|
|
|
|
Hi,
Lets say, I am having Vendor dll and it is non-unicode.
I want to use this dll in my Application and it is unicode.
DLL is built using SDK functions such way that I cannot make is Unicode, same with Application it cannot build without unicode (frame work dependencies). Both of them are using CString.
Is there any way possible by which I can use this dll in my application without changing their nature?
Please let me know if further clarification needed.
Thanks in advance.
|
|
|
|
|
It should be easy enough. Just make sure when calling the vendor supplied DLL to use explicit specialisations of CStringT e.g. CStringT< char, ChTraitsCRT<char> > . It might be a good idea to use a typedef for this.
Oh, one other thing - make sure that around including the header for the library TCHAR is defined as char and not wchar_t or the functions won't link properly.
Cheers,
Ash
PS: Looks like there are already typedefs in MFC for this sort of thing. Have a look in Alain's answer below for their names!
modified on Thursday, October 28, 2010 8:28 AM
|
|
|
|
|
Hi,
From VS2003 the MFC (or ATL) CString classes are specializations of CStringT : see http://msdn.microsoft.com/en-us/library/5bzxfsea(VS.71).aspx[^]
Explicitly use CStringW for your framework related code and CStringA for interaction with your DLL.
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Hi,
I am sure the "file.exe" is not running. But when I tried to re-build the exe file. VS 2008 gives this error.
Please help.
Thanks,
|
|
|
|
|
can you rename the file? if not, it is locked by some process.
can you delete the file? if so, doing that could solve it.
|
|
|
|
|
Yes, I can rename and delete it. But it is painful to delete the EXE file for every build.
Do you have any other solution?
I guess it is caused by the windows 7 security.
Thanks,
|
|
|
|
|
I haven't encountered such situation on Win7 yet. If you can delete it, the EXE isn't executing any more (as it would when you had some non-main thread that goes on while not being marked background).
Here is one work-around idea: add a pre-build step to your Visual project, deleting the EXE with a DOS-like command, which you enter somewhere in the project's settings dialog.
|
|
|
|
|
I'm now coding with VC++2008.
I wanna show 2 dialogs at the same time.
So how to achieve it?
Thanks in advance.
In fact I've tried the following:
BOOL CDlg1::OnInitDialog()
{
...
dlg2.Create(IDD_DIALOG2, this);
dlg2.ShowWindow(SW_SHOW);
...
}
But this doesn't work.
|
|
|
|
|
|
A dialog, i.e. a window shown as modal, by definition is unique within a process, as it grabs you, your mouse and keyboard until you dismiss it.
If you want two dialogs, you need two processes.
Or you switch to modeless windows, which aren't dialogs at all. But then other forms of the same process could also be brought to the foreground and operated on.
|
|
|
|
|
Luc Pattyn wrote: If you want two dialogs, you need two processes.
This isn't true. It's possible and quite common for a modal dialog to have a button (or some other mechanism) which brings up another "nested" (not nested in a parent-child sense) modal dialog. Both dialogs are modal and shown at the same time although while the nested one exists the parent one is disabled.
Steve
|
|
|
|
|
You're right of course, however that still leaves only one accessible dialog, not what the OP wants.
|
|
|
|
|
define dlg2 as a member varibale of CDlg1.
CDlg2 * m_pDlg2;
BOOL CDlg1::OnInitDialog()
{
m_pDlg2 = new CDlg2();
m_pDlg2->Create(IDD_DIALOG2, this);
m_pDlg2->ShowWindow(SW_SHOW);
}
void CDlg1::OnDestroy()
{
CDialog::OnDestroy();
if(m_pDlg2)
delete m_pDlg2;
m_pDlg2 = NULL;
}
modified on Thursday, October 28, 2010 4:17 AM
|
|
|
|
|
Why bother using new and delete and the pointer m_pDlg2 ? In general I'd lose the new and delete (and in this case the OnDestroy handler too) and embed CDlg2 directly:
class CDlg1 :
{
CDlg2 m_Dlg2;
};
BOOL CDlg1::OnShowOtherDialog()
{
m_Dlg2.Create(IDD_DIALOG2, this);
m_Dlg2.ShowWindow(SW_SHOW);
}
Steve
|
|
|
|
|
Good advice,
en,, I prefer to use pointer..
|
|
|
|
|
I prefer to avoid using the heap when it's not necessary: It's faster, safer and helps minimise heap fragmentation.
Steve
|
|
|
|