|
I came up with this, but I have't tried compiling it yet. What do you think?
CMyList::iterator iCurr;
CMyList::iterator iNext;
bool bMovedItem = true;
while (bMovedItem)
{
iCurr = myEntryList.begin();
iNext = iCurr + 1;
bMovedItem = false;
while (iCurr < myEntryList.end())
{
bool currSelected = (*iCurr)->mySelected;
bool nextSelected = (*iNext)->mySelected
if (!currSelected && currSelected != nextSelected)
{
myEntryList.reverse(iCurr, iNext);
bMovedItem = true;
}
iCurr++;
}
}
I'm certainly no STL expert (more accurately, I'm a rank beginner with a complete disdain for STL - grin).
------- signature starts
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
Please review the Legal Disclaimer in my bio.
------- signature ends
|
|
|
|
|
it might work
here's my top-of-the-head STL version:
bool operator < (const CListItem &a, const CListItem &b)
{
return (a.IsSelected && !b.IsSelected);
}
...
std::stable_sort(myList);
-c
Being just contaminates the void. --Robyn Hitchcock
|
|
|
|
|
Personally?
I would dump the list to a text file, exec the COMMAND.COM sort program and then read back in the text file.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
now that's exotic!
or... fire up an instance of Access, shoot the data into a special table, read it back with SQL, then pick the data out of the recordsets!
-c
Being just contaminates the void. --Robyn Hitchcock
|
|
|
|
|
I would try that but we're on CE...
------- signature starts
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
Please review the Legal Disclaimer in my bio.
------- signature ends
|
|
|
|
|
One solution would be to use stable_partition. This will reorder the list based on a predicate which returns true or false, without changing the relative order of any of the items in the same grouping.
The following example shows a simple implementation:
#include <iostream>
#include <list>
#include <algorithm>
#include <functional>
void PrintChar( char ch )
{
std::cout << "'" << ch << "'" << std::endl;
}
struct Partition : public std::unary_function< char, bool >
{
bool operator()( char ch )
{
return ( ch == 'B' || ch == 'E' || ch == 'F' );
}
};
int main(int argc, char* argv[])
{
std::list<char> myList;
myList.push_back( 'A' );
myList.push_back( 'B' );
myList.push_back( 'C' );
myList.push_back( 'D' );
myList.push_back( 'E' );
myList.push_back( 'F' );
std::cout << "before:" << std::endl;
std::for_each( myList.begin(), myList.end(), PrintChar );
std::stable_partition( myList.begin(), myList.end(), Partition() );
std::cout << "after:" << std::endl;
std::for_each( myList.begin(), myList.end(), PrintChar );
return 0;
}
Best regards,
John
|
|
|
|
|
I have been taked with creating a TCP/IP file server app that can impliment drag and drop functionality to explorer.
My problm is that the app lists only the file names and attributes, that it is passed without a refrence to the original location. I need to be able to get the target of a drag and drop opperation onto the explorer window, so I can pass that target back to the calling app.
I've spent countless hours trying to figure out how to get the drop target on the drag opperation to explorer without any success.
Any help would be greatly appreciated.
Life is like a warm bath, the longer you're in the more wrinkled you get.
|
|
|
|
|
Is there a way to hook a window (SetWindowsHookEx) without using a DLL. So I can hook CreateWindow, that it doesn't send WM_CREATE before I want it to?
Thanks in advance,
Sjoerd
LPCSTR Dutch = "Double Dutch "
|
|
|
|
|
You only need a DLL if the hook is to be a system wide hook. A hook that is limited to the scope of the current process can keep its code within the application.
Beyond that, I'm not sure that I understand what you are trying to do with WM_CREATE.
|
|
|
|
|
Oliver Daniel wrote:
You only need a DLL if the hook is to be a system wide hook. A hook that is limited to the scope of the current process can keep its code within the application.
Thanks for this
Oliver Daniel wrote:
Beyond that, I'm not sure that I understand what you are trying to do with WM_CREATE.
CreateWindow does automatically send a WM_CREATE. But right under there, I call SetWindowLong, to change te Window proc. There, the WM_CREATE has to be handled. So, if I hook into the process, I can change the Window proc, before WM_CREATE has been sent.
Sjoerd van Leent
LPCSTR Dutch = "Double Dutch "
|
|
|
|
|
I've created a standard server for small LAN apps using class CAsyncSocket(in Visual C++ 6.0). The maximum number of active clients is 1996. Now this is not a problem cause this ain't a Web server but after the clients disconnect themselves (even all) the server doesn't accept ever again clients. This server worked just fine in Windows 98 SE (but restrincting me to 46 clients). In Win 98 i've conneted and disconnected arround of 7000 clients (150 times * 46 maximum allowed active connections) to see if crashes and it didn't happend. So what the hell is wrong with Windows XP ? It was supposed to be Better but ...
If anyone can answer to my question please reply at my email address.
Codu'
|
|
|
|
|
Probably a bug in your software that doesn't show up on the 9x platform. Like I just told someone else, 9x and NT/W2K/XP execute programs very differently. Hidden bugs can crop up when you switch from one platform to another.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Hi
Does anyone know how can I disable the activation of the screensaver from Visual C++? I tried the SendInput() function to simulate mouse movement but it doesn't work
Please help me
Thankx
Jancsi
xxx
|
|
|
|
|
Look at the SystemParameterInfo function and the SPI_SETSCREENSAVEACTIVE parameter
|
|
|
|
|
Had a type that should be SystemParametersInfo
|
|
|
|
|
How do you get the value of an unnamed key value? In regedit it is diaplayed as "(Default)". I've tried
RegQueryValueEx(hKey,
"(default)", 0, &type,
(unsigned char*)buf, &bufsize)
but it returns 2. I've also tried to RegEnumKey() and it gets the key name ok, but it just refuses to get the value.
|
|
|
|
|
just set lpSubKey to NULL:
RegQueryValueEx(hKey,
NULL, 0, &type,
(unsigned char*)buf, &bufsize)
|
|
|
|
|
Could someone please explain what exactly shows the printing progress (status) bar, and how it is updated? I currently am using the following code, which does not have this progress bar..
void CDisplayPrintTemplate::BatchPrintPage()
{
DOCINFO di;
CPrintInfo printInfo;
CSCTaxDoc* pDoc = (CSCTaxDoc*)GetDocument();
CDC dc;
CRect draw_area;
ASSERT_VALID(pDoc);
CPrintDialog dlg(FALSE);
if (dlg.DoModal() == IDCANCEL)
return;
dc.Attach(dlg.GetPrinterDC());
dc.m_bPrinting = TRUE;
printInfo.m_bDirect = TRUE;
printInfo.m_rectDraw.left = 0;
printInfo.m_rectDraw.right = dc.GetDeviceCaps(HORZRES);
printInfo.m_rectDraw.top = 0;
printInfo.m_rectDraw.bottom = dc.GetDeviceCaps(VERTRES);
dc.DPtoLP(&printInfo.m_rectDraw);
draw_area = printInfo.m_rectDraw;
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = pDoc->GetPathName();
di.lpszOutput = NULL;
dc.StartDoc(&di);
OnPreparePrinting(&printInfo);
OnBeginPrinting(&dc, &printInfo);
for (printInfo.m_nCurPage = 1 ; printInfo.m_nCurPage <= printInfo.GetMaxPage() ; printInfo.m_nCurPage++)
{
OnPrepareDC(&dc, &printInfo);
dc.StartPage();
OnPrepareDC(&dc, &printInfo);
OnPrint(&dc, &printInfo);
dc.EndPage();
printInfo.m_rectDraw = draw_area;
}
OnEndPrinting(&dc, &printInfo);
dc.EndDoc();
VERIFY(dc.DeleteDC());
dc.Detach();
}
thanks for the help!
-dz
|
|
|
|
|
I have a very small application which should be using very little memory but according to the Task Manager the memory usage increases over time. Now of course this is a memory leak so I changed all the stack buffers to heap ones and made sure to free them at the end of each function so I know that the memory is being freed.
I also use a whole bunch of MessageBox's and a couple of GetDlgItem's.
Now figuring I'm an idiot I decided to take all of my buffer variables and instead of allocating them on the heap I decided to do so on the stack (aka not call malloc and use char[x] instead).
Again the memory usage still rises (by about 4KB mind you [if the task manager can be believed... most of my memory allocation is of the single MAX_PATH and _MAX_FNAME chunks).
Now thinking it could be from pass by value allocation I made sure and passed all my buffers by reference and yet it still rises.
(eg MessageBox(MainWindow,(char*)&buffer,"cannot open item",0);)
My last shot in the dark is maybe MessageBox is creating the leak by when clicking OK the message box is not freed by Windows or something. I know that's a stretch but I can't think of anything else.
Are there any tools out there that I can use to determine where memory is being allocated and find possible leaks? (mind you I'm using char*'s and straight Win32SDK (aka no mfc)). Can anyone suggest what I can look for next?
This is driving me absolutely batty.
Sean
|
|
|
|
|
grab a 14 day trial of Purify . it will spot most leaks in your app.
-c
Being just contaminates the void. --Robyn Hitchcock
|
|
|
|
|
Well I did that and it stated I had no leaks in the application.
Maybe I'm just trusting the Task Manager when I shouldn't be.
Sean
|
|
|
|
|
if you're on NT/2K/XP, you can try calling _heapmin somewhere in your app. sometimes that will force the OS to minimize your app's heap (really free'ing memory you think you've already free'd, but which the OS hasn't given back to the general pool). sometimes it has no effect at all...
-c
Being just contaminates the void. --Robyn Hitchcock
|
|
|
|
|
Anyone here knows of a site that has the details of how to convert
wstring to strings and vice versa in STL. Apparently, there are a
couple of different ways of doing this. I am not sure if VC6 supports
them, but anyhow, i would appreciate any hints.
thanks
|
|
|
|
|
|
I'm writing a data server. In which, I have a Server, which has methods: FirstPage, PrevoiusPage, NextPage, LastPage, Insert, Delete. One page is 20 rows set in the server.
In the client, I have a client rowset class, which will cache all the rows it fetched so far. Say, invoke server's FirstPage to get 1st 20 rows, call Nextpage to get the NextPage, and so on. All the rows got will put in internal cache in client rowset, and navigation (first, prev, next, last) are so far so good. However, when i do insert in 10th row in client side, i created an instance, and invoke server side's Insert too. However, I'm not sure WHICH PLACE the ROW WILL be. Therefore, I can't synchronize the rowset. Can anyone tell me if there's any standard for insert positioning, and how to synchronize it ?
I've to finish it pretty soon, or i'll be fired. Please help me.
|
|
|
|