Click here to Skip to main content
16,010,650 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Text Processing Pin
Nick Parker24-Nov-01 1:54
protectorNick Parker24-Nov-01 1:54 
GeneralEnumPrinters function Pin
Brett G.22-Nov-01 16:49
Brett G.22-Nov-01 16:49 
QuestionHow to display a bitmap of 24 bits correctly?? Pin
Leesen22-Nov-01 16:23
Leesen22-Nov-01 16:23 
AnswerRe: How to display a bitmap of 24 bits correctly?? Pin
Christian Graus22-Nov-01 16:38
protectorChristian Graus22-Nov-01 16:38 
GeneralRe: How to display a bitmap of 24 bits correctly?? Pin
Leesen22-Nov-01 16:48
Leesen22-Nov-01 16:48 
GeneralRe: How to display a bitmap of 24 bits correctly?? Pin
Christian Graus22-Nov-01 17:21
protectorChristian Graus22-Nov-01 17:21 
GeneralSorting the CStringArray Pin
Tili22-Nov-01 15:11
Tili22-Nov-01 15:11 
GeneralRe: Sorting the CStringArray Pin
Christian Graus22-Nov-01 16:42
protectorChristian Graus22-Nov-01 16:42 
Another reason MFC containers suck hard. STL containers do this stuff with ease.

Here's some code from MSDN - why they couldn't build it in is beyond me. If you *must* use MFC containers, then this is how to do it:


/*
 * Compile options needed: /MT
 */ 

#include <afx.h>
#include <iostream.h>
#include <afxcoll.h>

class CSortStringArray : public CStringArray {
public:
   void Sort();
private:
   BOOL CompareAndSwap(int pos);
};
void CSortStringArray::Sort()
{
   BOOL bNotDone = TRUE;

   while (bNotDone)
   {
      bNotDone = FALSE;
      for(int pos = 0;pos < GetUpperBound();pos++)
         bNotDone |= CompareAndSwap(pos);
   }
}
BOOL CSortStringArray::CompareAndSwap(int pos)
{
   CString temp;
   int posFirst = pos;
   int posNext = pos + 1;

   if (GetAt(posFirst).CompareNoCase(GetAt(posNext)) > 0)
   {
      temp = GetAt(posFirst);
      SetAt(posFirst, GetAt(posNext));
      SetAt(posNext, temp);
      return TRUE;

   }
   return FALSE;
}
void main()
{
   CSortStringArray sortArray;

   sortArray.Add(CString("Zebra"));
   sortArray.Add(CString("Bat"));
   sortArray.Add(CString("Apple"));
   sortArray.Add(CString("Mango"));

   for (int i = 0; i <= sortArray.GetUpperBound(); i++)
      cout << sortArray[i] << endl;

   sortArray.Sort();
   cout << endl;

   for (int j = 0; j <= sortArray.GetUpperBound(); j++)
      cout << sortArray[j] << endl;
} 




Christian

After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now

GeneralRe: Sorting the CStringArray Pin
Jon Hulatt22-Nov-01 22:29
Jon Hulatt22-Nov-01 22:29 
GeneralRe: Sorting the CStringArray Pin
Tili23-Nov-01 7:23
Tili23-Nov-01 7:23 
GeneralRe: Sorting the CStringArray Pin
Christian Graus23-Nov-01 10:21
protectorChristian Graus23-Nov-01 10:21 
GeneralRe: Sorting the CStringArray Pin
Alvaro Mendez23-Nov-01 11:53
Alvaro Mendez23-Nov-01 11:53 
GeneralCDialog Return Value Pin
Matt Newman22-Nov-01 11:53
Matt Newman22-Nov-01 11:53 
GeneralRe: CDialog Return Value Pin
Christian Graus22-Nov-01 12:11
protectorChristian Graus22-Nov-01 12:11 
GeneralRe: CDialog Return Value Pin
Matt Newman22-Nov-01 12:15
Matt Newman22-Nov-01 12:15 
GeneralComparing the contents of DC's Pin
Member 2362222-Nov-01 11:29
Member 2362222-Nov-01 11:29 
GeneralRe: Comparing the contents of DC's Pin
Christian Graus22-Nov-01 12:13
protectorChristian Graus22-Nov-01 12:13 
GeneralRe: Comparing the contents of DC's Pin
Member 2362222-Nov-01 18:23
Member 2362222-Nov-01 18:23 
GeneralRe: Comparing the contents of DC's Pin
Christian Graus22-Nov-01 19:25
protectorChristian Graus22-Nov-01 19:25 
GeneralDisabled 256-color toolbar buttons Pin
Erik Hammar22-Nov-01 11:06
Erik Hammar22-Nov-01 11:06 
GeneralRe: Disabled 256-color toolbar buttons Pin
Andrew Peace22-Nov-01 14:47
Andrew Peace22-Nov-01 14:47 
GeneralRe: Disabled 256-color toolbar buttons Pin
Rashid Thadha22-Nov-01 22:38
Rashid Thadha22-Nov-01 22:38 
GeneralCopying a HBITMAP to a different HBITMAP Pin
Chambers22-Nov-01 10:14
Chambers22-Nov-01 10:14 
GeneralRe: Copying a HBITMAP to a different HBITMAP Pin
Christian Graus22-Nov-01 10:39
protectorChristian Graus22-Nov-01 10:39 
GeneralRe: Copying a HBITMAP to a different HBITMAP Pin
Chambers22-Nov-01 10:58
Chambers22-Nov-01 10:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.