|
template<class Pred>
void sort(greater<T> pr);
So you want the predicate reversed, surely?
std::list theList
// function object, a bit more 'STL-style'
class CMyBaseClassGreater {
public:
bool operator()(CMyBaseClass* pFirst, CMyBaseClass* pSecond)
{
return *pFirst > *pSecond;
}
}
theList.sort(CMyBaseClassGreater());
std::sort won't work on a list, as it needs random access iterators, which list doesn't provide. You have to use std::list::sort().
|
|
|
|
|
Thanks for the info. I actually got as far as figuring out the function object, but still couldn't get it to compile. I kept getting C2664 errors, complaining that it couldn't convert the function object to the proper type. Such as:
error C2664: 'void __thiscall std::list<class CMyClass*,class std::allocator<class CMyClass*> >::sort(struct std::greater<class CMyClass *>)' : cannot convert parameter 1 from 'struct ObjectComp' in 'struct std:greater<class CMyClass*>'
From digging through dejanews, I ran across a couple of threads that suggested that SP4 breaks template behavior of list::sort. Basically saying that the code snippet suggested works fine on gcc and Dinkumware's STL etc., but not on MSVC SP4. Is this possible? One day I will grow to like the STL
|
|
|
|
|
Thanks for the suggestion but that is something that I had tried until I realized that you can't use the sort algorithm for a list container. The example you showed only works for random access containers.
Thanks
|
|
|
|
|
You can sort using any predicate function. Here are some examples from code I am working with:
struct greater_magnitude
{
bool operator()(const CTFARect& x, const CTFARect& y) const {
return (fabs(x.Value()) > fabs(y.Value()));
}
};
std::list<CTFARect> m_lstRects;
...
m_lstRects.sort(greater_magnitude());
In your case, you'd define struct my_comparison_predicate with member bool my_comparison_predicate::operator()(const CTFARect *x, const CTFARect * y) const after my example above.
But to use this, you have to fix some bugs in the Microsoft standard C++ library.
Look at Dunkumware's list of bug fixes for the VC++ standard library. Edit the standard library headers in "Program Files\Microsoft Visual Studio\vc98\include" to implement the fixes on the Dinkumware page.
Then, you must edit the file "list" thus to allow the use of predicates:
*** list Tue Jun 27 23:50:23 2000
--- list.original Mon Jun 15 05:00:00 1998
***************
*** 281,288 ****
erase(_F++);
else
++_F; }
!
! template<class _Pr1> void remove_if(_Pr1 _Pr)
{iterator _L = end();
for (iterator _F = begin(); _F != _L; )
if (_Pr(*_F))
--- 281,288 ----
erase(_F++);
else
++_F; }
! typedef binder2nd<not_equal_to<_Ty> > _Pr1;
! void remove_if(_Pr1 _Pr)
{iterator _L = end();
for (iterator _F = begin(); _F != _L; )
if (_Pr(*_F))
***************
*** 297,304 ****
erase(_M);
else
_F = _M; }
!
! template<class _Pr2> void unique(_Pr2 _Pr)
{iterator _F = begin(), _L = end();
if (_F != _L)
for (iterator _M = _F; ++_M != _L; _M = _F)
--- 297,304 ----
erase(_M);
else
_F = _M; }
! typedef not_equal_to<_Ty> _Pr2;
! void unique(_Pr2 _Pr)
{iterator _F = begin(), _L = end();
if (_F != _L)
for (iterator _M = _F; ++_M != _L; _M = _F)
***************
*** 321,328 ****
_Splice(_L1, _X, _F2, _L2);
_Size += _X._Size;
_X._Size = 0; }}
!
! template<class _Pr3> void merge(_Myt& _X, _Pr3 _Pr)
{if (&_X != this)
{iterator _F1 = begin(), _L1 = end();
iterator _F2 = _X.begin(), _L2 = _X.end();
--- 321,328 ----
_Splice(_L1, _X, _F2, _L2);
_Size += _X._Size;
_X._Size = 0; }}
! typedef greater<_Ty> _Pr3;
! void merge(_Myt& _X, _Pr3 _Pr)
{if (&_X != this)
{iterator _F1 = begin(), _L1 = end();
iterator _F2 = _X.begin(), _L2 = _X.end();
***************
*** 349,362 ****
{_A[_I].merge(_X);
_A[_I].swap(_X); }
if (_I == _MAXN)
! _A[_I - 1].merge(_X);
else
{_A[_I].swap(_X);
if (_I == _N)
++_N; }}
while (0 < _N)
merge(_A[--_N]); }}
! template<class _Pr3> void sort(_Pr3 _Pr)
{if (2 <= size())
{const size_t _MAXN = 15;
_Myt _X(allocator), _A[_MAXN + 1];
--- 349,362 ----
{_A[_I].merge(_X);
_A[_I].swap(_X); }
if (_I == _MAXN)
! _A[_I].merge(_X);
else
{_A[_I].swap(_X);
if (_I == _N)
++_N; }}
while (0 < _N)
merge(_A[--_N]); }}
! void sort(_Pr3 _Pr)
{if (2 <= size())
{const size_t _MAXN = 15;
_Myt _X(allocator), _A[_MAXN + 1];
***************
*** 368,374 ****
{_A[_I].merge(_X, _Pr);
_A[_I].swap(_X); }
if (_I == _MAXN)
! _A[_I - 1].merge(_X, _Pr);
else
{_A[_I].swap(_X);
if (_I == _N)
--- 368,374 ----
{_A[_I].merge(_X, _Pr);
_A[_I].swap(_X); }
if (_I == _MAXN)
! _A[_I].merge(_X, _Pr);
else
{_A[_I].swap(_X);
if (_I == _N)
|
|
|
|
|
Hi,
I create a simple MFC App, with a toolbar. After that I try the following code to disable one of the buttons:
CToolBarCtrl &tb = m_wndToolBar.GetToolBarCtrl();
tb.EnableButton(ID_FILE_SAVE, false);
Why is the button not disabled?
If works fine if I try to disable a menuitem, but I cannot figure out how to disable a toolbar button...
I have also tried to send the message directly (TB_ENABLEBUTTON) but that won't work either...
TIA,
- Anders
|
|
|
|
|
MFC uses message maps to enable and disable things. Sounds like you're fighting with MFC over whether it should or shouldn't be neabled.
If there are no handlers for the message, it's automatically disabled. If you do have a handler, then you need to handle the ON_UPDATE_CMD_UI messages and call pCmdUI->Enable(FALSE).
|
|
|
|
|
Thanks a lot, it works
- Anders
|
|
|
|
|
Hi,
I have a CDialog which has a menu. In that menu, I have a popup-menu that contains my last opened files, like the last opened project in the Visual Studio. This works
wonderful when I start my program, but I have a problem with the update on that MRU lis during the run-time. Ususally, the current opened filename is on the top of that list.
When you choose that 3rd file in that list, usually, it will be moved up the the first position. And yes, it does so, the only problem is that the menu-item-text doesn't seems to
get updated with the new name, since I don't get the filename that is written there, I get the last opened file instead. How can I force my program to update the item text of
that menu??????
Thanx,
Grit
|
|
|
|
|
Hi i believe some people from this newsgroup have obtained wincap 32 from microsoft sdk and i was wondering has anyone obatined this project and made alterations to it such that it can be compiled by Visual c++ complier and can work in win 95? If anyone has already successful in doing so , can you emailed your wincap project to me ?
|
|
|
|
|
Hello,
A few months ago I posted a message that I encounter problems with the String Table in Visual Studio Pro C++ V6.00. So far I did'nt receive any suggestion. I like to repeat my question.
The problem is that if the String Table has to have more than 300 string items, one particular string form the string table appears unwanted in the message box to prompt for a save operation at closing the child window.
Can sombody give some advice how to remediate this problem ?
thanks.
|
|
|
|
|
isn't you problem you resource string number conflict with mfc text(s)?
(try look into your resource.h IDS_ and compare with AFX_IDS_ into afxres.h and similar files)
me one time happened this - i wanted to get over one mfc text and wizard for my next new strings used next
numbers in "mfc system text index range"
if you creating new resource and select id from existing and modify it (f.e select IDS_TEXT and change to IDS_TEXT2)
wizard will keep the same number (#define) for both cases
t!
|
|
|
|
|
Your hints to inspect AFX_IDS_... are most welcome. In my String Table only a few AFX_IDS_... are present as AFX_IDS_APP_TITLE 57344 to AFX_IDS_PREVIEW_CLOSE 61445.
I see in the properties table of a string item in the String Table that there exist an AFX_IDS_ASKTOSAVE ID but I don't known how I can open the afxres.h file. I don't find such a file in my project. I find only include staements. Please can you tell me how I get access to the afxres.h file.
I struggle with this problem for a long time.
|
|
|
|
|
afxres.h you can find into your devstudio instalation
(something like program files/.../mfc/include)
when i look into there is f.e. AFX_IDS_SAVEFILE 0xf001 (and anothers)
try to change id of by you critical text (resource.h) what appears in save question and rebuild all
when situation changes problem is with resource id
|
|
|
|
|
Hi Everyone,
I'm using a DIALOG with some buttons to play sounds (wav/mp3) with DirectX.
it has it's own CSound class which holds all the interfaces and such. In that
class I have a IMediaEventEx, which I used to call the 'SetNotifyWindow'
function, with as param the GetSafeHwnd() from the dialog, and a WM_USER+1
for the message.
My Problem is that my dialog never receives the Msg. Is this because it's a dialog??
Thanks!
Stefan
|
|
|
|
|
Any article or book available for "How to write Network(like client-server communication )programs using Visual C++ -step by step approach"?
|
|
|
|
|
How about Ralph Davis' "Win32 Network Programming". Addison Wesley. ISBN 0-201-48930-9
|
|
|
|
|
I've defined following classes (standart example):
A
/ \
B C
\ /
D
B and C are virtually inherit A.
But following code failed at compile time:
A* pa = new B();
B* pb;
pb = (B*)pa;
How can I resolve such error?
|
|
|
|
|
This sort of thing requires either a reinterpret cast if you are CERTAIN that pa will always be an actual instance of a B, or you need to enable RTTI and use dynamic_cast.
|
|
|
|
|
Thanks. It very helps me.
|
|
|
|
|
I can capture the screen and copy it into a bitmap and can anyone suggest how i can save this into a file ? If i save my captured screen into a DIB and how can i save into a file? Anyway , which will be a better option for win98 - save into DIB or bitmap?
|
|
|
|
|
This code works fine in our project
void WriteBmpToFile(HBITMAP hBmp)
{
BITMAP Bmp;
BITMAPINFOHEADER BmpInfoHeader;
BITMAPINFO * pBmpInfo;
BYTE * pData;
::GetObject(hBmp, sizeof(Bmp), &Bmp);
memset(&BmpInfoHeader, 0, sizeof(BmpInfoHeader));
BmpInfoHeader.biSize = sizeof(BmpInfoHeader);
BmpInfoHeader.biWidth = Bmp.bmWidth;
BmpInfoHeader.biHeight = Bmp.bmHeight;
BmpInfoHeader.biPlanes = 1;
BmpInfoHeader.biBitCount = 24;
pBmpInfo = (BITMAPINFO * )&BmpInfoHeader;
int nSize = Bmp.bmWidth * Bmp.bmHeight * 3;
pData = (BYTE*)malloc(nSize);
HDC hDC = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
::GetDIBits(hDC, hBmp, 0, Bmp.bmHeight, pData, pBmpInfo, DIB_RGB_COLORS);
::DeleteDC(hDC);
int file = _lcreat("file.bmp", 0);
if (file != -1)
{
BITMAPFILEHEADER hdr;
hdr.bfType = 0x4d42;
hdr.bfSize = (sizeof(BITMAPFILEHEADER) + sizeof(BmpInfoHeader) + nSize);
hdr.bfReserved1 = 0;
hdr.bfReserved2 = 0;
hdr.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BmpInfoHeader);
_lwrite(file, (const char*)&hdr, sizeof(hdr));
_lwrite(file, (const char*)&BmpInfoHeader, sizeof(BmpInfoHeader));
_lwrite(file, (const char*)pData, nSize);
_lclose(file);
}
free(pData);
}
|
|
|
|
|
If you want to write DIB with different color depth, don't forget to write palette between header and color data
|
|
|
|
|
int nSize = ( Bmp.bmWidth * 3 + 3 ) / 4 * 4 * Bmp.bmHeight;
|
|
|
|
|
Hey Feng !! That book of yours ever going to be published ?
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
Christain.
It's going to be printed tomorrow (Nov/30).
|
|
|
|
|