Click here to Skip to main content
16,005,290 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to change background color on toolbar Pin
ElizabethC6-Aug-03 8:24
ElizabethC6-Aug-03 8:24 
GeneralMACROS. Pin
WREY6-Aug-03 8:12
WREY6-Aug-03 8:12 
GeneralRe: MACROS. Pin
Larry Antram6-Aug-03 8:19
Larry Antram6-Aug-03 8:19 
GeneralRe: MACROS. Pin
WREY6-Aug-03 9:02
WREY6-Aug-03 9:02 
GeneralRe: MACROS. Pin
Larry Antram6-Aug-03 9:24
Larry Antram6-Aug-03 9:24 
GeneralRe: MACROS. Pin
WREY6-Aug-03 10:19
WREY6-Aug-03 10:19 
GeneralRe: MACROS. Pin
Larry Antram6-Aug-03 10:40
Larry Antram6-Aug-03 10:40 
GeneralRe: MACROS. Pin
Larry Antram6-Aug-03 10:53
Larry Antram6-Aug-03 10:53 
It looks like you might be wanting to run something once, if so you could do it like this:

class MyClass
{
protected:
   BOOL m_bFirstTime;
   
public:
   MyClass()
     : m_bFirstTime( TRUE )
   {
   }
   
   void MyFunction()
   {
      if( m_bFirstTime )
      {
          // do something here only the first time this function is called
   
          m_bFirstTime = FALSE;
      }
   }
};
Although, in real world apps it would be better to structure the class something like this:

class MyClass
{
protected:
   BOOL m_bInitialized;
  
public:
   MyClass()
     : m_bInitialized( FALSE )
   {
   }
  
   virtual ~MyClass()
   {
      UnInitialize();
   }
  
   BOOL Initialize()
   {
      BOOL bResult = FALSE;
      {
         // TODO: do whatever initialization is required, and if
         // it succeeds set the following values to indicate it
   
         m_bInitialized = TRUE;
         bResult = TRUE;
      }
      return bResult;
   }
  
   void UnInitialize()
   {
      if( m_bInitialized )
      {
          // TODO: clean up
  
          m_bInitialized = FALSE;
      }
   }
    
   BOOL MyFunction()
   {
       BOOL bResult = FALSE;
       {
          if( m_bInitialized )
          {
             // TODO: do something that required initialization
             // and set bResult to TRUE if it succeeded
   
             bResult = TRUE;
          }
       }
       return bResult;
   }
};
Or if you aren't using classes, and you want to be bad, you could do something like this:

void MyFunction()
{
   static v_bFirstTime = TRUE;
   
   if( v_bFirstTime )
   {
      // do something here only the first time this function is called
   
      v_bFirstTime = FALSE;
   }
}
Or this:

static g_bFirstTime = TRUE;
   
void MyFunction()
{
   if( g_bFirstTime )
   {
      // do something here only the first time this function is called
   
      g_bFirstTime = FALSE;
   }
}

GeneralRe: MACROS. Pin
WREY6-Aug-03 12:01
WREY6-Aug-03 12:01 
GeneralProblem with Passing ofstream to DLL Pin
DionChen6-Aug-03 8:04
DionChen6-Aug-03 8:04 
QuestionHow to use SetWindowSubclass Pin
krosswindz6-Aug-03 7:50
krosswindz6-Aug-03 7:50 
GeneralBITMAP Structures Pin
colormyiris6-Aug-03 7:28
colormyiris6-Aug-03 7:28 
GeneralRe: BITMAP Structures Pin
David Crow6-Aug-03 7:33
David Crow6-Aug-03 7:33 
GeneralCFileDialog with custom activeX Pin
sdfdsfa6-Aug-03 7:22
sdfdsfa6-Aug-03 7:22 
GeneralEditbox and checkbox control questions Pin
Binayak6-Aug-03 7:14
Binayak6-Aug-03 7:14 
GeneralRe: Editbox and checkbox control questions Pin
Brian Delahunty6-Aug-03 7:22
Brian Delahunty6-Aug-03 7:22 
QuestionTree Control : How to get selected Item while Capturing single click event? Pin
Binayak6-Aug-03 6:08
Binayak6-Aug-03 6:08 
AnswerRe: Tree Control : How to get selected Item while Capturing single click event? Pin
Rage6-Aug-03 6:38
professionalRage6-Aug-03 6:38 
GeneralRe: Tree Control : How to get selected Item while Capturing single click event? Pin
Binayak6-Aug-03 6:53
Binayak6-Aug-03 6:53 
GeneralChallenge folks!!! This can't really be that hard!?!?? :( Pin
Tommy Svensson6-Aug-03 5:45
Tommy Svensson6-Aug-03 5:45 
GeneralRe: Challenge folks!!! This can't really be that hard!?!?? :( Pin
Michael Dunn6-Aug-03 7:41
sitebuilderMichael Dunn6-Aug-03 7:41 
GeneralRe: Challenge folks!!! This can't really be that hard!?!?? :( Pin
Tommy Svensson6-Aug-03 10:20
Tommy Svensson6-Aug-03 10:20 
GeneralRe: Challenge folks!!! This can't really be that hard!?!?? :( Pin
Tommy Svensson6-Aug-03 23:03
Tommy Svensson6-Aug-03 23:03 
General"ignore all default librairies" problem Pin
alfith6-Aug-03 5:34
alfith6-Aug-03 5:34 
Questionhow to display greek characters Pin
LESUR6-Aug-03 5:08
LESUR6-Aug-03 5:08 

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.