Click here to Skip to main content
16,012,110 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to change the background color of AfxControlBar*, CToolBar's parent window ? Pin
Paresh Chitte25-Feb-08 17:22
Paresh Chitte25-Feb-08 17:22 
GeneralRe: How to change the background color of AfxControlBar*, CToolBar's parent window ? Pin
SandipG 27-Feb-08 22:46
SandipG 27-Feb-08 22:46 
GeneralRe: How to change the background color of AfxControlBar*, CToolBar's parent window ? Pin
Paresh Chitte28-Feb-08 17:27
Paresh Chitte28-Feb-08 17:27 
Questionhow to generate several Gaussian function according to different sigm Pin
gentleguy25-Feb-08 14:30
gentleguy25-Feb-08 14:30 
QuestionParallel Port Polling Pin
GlenET25-Feb-08 10:21
GlenET25-Feb-08 10:21 
GeneralRe: Parallel Port Polling Pin
Mark Salsbery25-Feb-08 11:04
Mark Salsbery25-Feb-08 11:04 
GeneralRe: Parallel Port Polling Pin
GlenET26-Feb-08 7:21
GlenET26-Feb-08 7:21 
GeneralRe: Parallel Port Polling Pin
Mark Salsbery26-Feb-08 7:51
Mark Salsbery26-Feb-08 7:51 
A window timer will need a window, so the view class is a better place to implement that type of timer.

For better timer resolution, and without a window, you can use a multimedia timer.
timeBeginPeriod()/timeSetEvent()/timeKillEvent()/timeEndPeriod() are the multimedia timer
functions you'd need.  A multimedia timer can periodically call a callback function or set/signal
an event - way more flexible than a window timer. 

Note that multimedia timer events/callbacks occur on a different thread, so if in response to the
timer you need to mess with UI, you'll need to synchronize access to UI/GDI with the app's UI thread.

Here's an example...
<font color="Green">// add to CMyDocumentClass class</font>
UINT wTimerRes = 0;
MMRESULT mmTimerId = 0;
static void CALLBACK MyTimerProc(UINT, UINT, DWORD_PTR dwUser, DWORD_PTR, DWORD_PTR);
void StartTimer();
void StopTimer();


<font color="Green">// Implement timer methods in class implementation...</font>

CMyDocumentClass::CMyDocumentClass()
{
    UINT wTimerRes = 0;
    MMRESULT mmTimerId = 0;
}

void CMyDocumentClass::StartTimer()
{
    TIMECAPS tc;
    if (::timeGetDevCaps(&tc, sizeof(TIMECAPS)) == TIMERR_NOERROR) 
    {
        <font color="Green">// Try for 1ms resolution - accept best</font>
        wTimerRes = min(max(tc.wPeriodMin, 1), tc.wPeriodMax);
        ::timeBeginPeriod(wTimerRes); 

        <font color="Green">// Set periodic 100ms timer</font>
        mmTimerId = ::timeSetEvent(100, wTimerRes, &CMyDocumentClass::MyTimerProc, (DWORD_PTR)this, 
                                                        TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
    }
}

void CMyDocumentClass::StopTimer()
{
    if (mmTimerId)
    {
        ::timeKillEvent(mmTimerId);
        mmTimerId = 0;
        ::timeEndPeriod(wTimerRes);
        wTimerRes = 0;
    }
}

void CALLBACK CMyDocumentClass::MyTimerProc(UINT, UINT, DWORD_PTR, DWORD_PTR, DWORD_PTR)
{
    CMyDocumentClass *pThis = (CMyDocumentClass *)dwUser;

   <font color="Green">// do something on timer</font>
}








Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

Generallistview item height Pin
Jim Crafton25-Feb-08 8:19
Jim Crafton25-Feb-08 8:19 
GeneralRe: listview item height Pin
Dr. Emmett Brown25-Feb-08 10:26
Dr. Emmett Brown25-Feb-08 10:26 
GeneralRe: listview item height Pin
David Crow25-Feb-08 11:30
David Crow25-Feb-08 11:30 
GeneralRe: listview item height Pin
Michael Dunn25-Feb-08 12:43
sitebuilderMichael Dunn25-Feb-08 12:43 
Generalconstructor / destructor in template class Pin
act_x25-Feb-08 7:33
act_x25-Feb-08 7:33 
GeneralRe: constructor / destructor in template class Pin
CPallini25-Feb-08 7:38
mveCPallini25-Feb-08 7:38 
GeneralRe: constructor / destructor in template class Pin
act_x25-Feb-08 7:52
act_x25-Feb-08 7:52 
GeneralRe: constructor / destructor in template class Pin
David Crow25-Feb-08 7:41
David Crow25-Feb-08 7:41 
QuestionAdding trend-line to MSCHART in C++ Pin
Member 343670325-Feb-08 5:33
Member 343670325-Feb-08 5:33 
GeneralGet m_nIDHelp of active dialog from CMainFrame in MDI application Pin
ptr_Electron25-Feb-08 5:21
ptr_Electron25-Feb-08 5:21 
GeneralRe: Get m_nIDHelp of active dialog from CMainFrame in MDI application Pin
Dr. Emmett Brown25-Feb-08 5:30
Dr. Emmett Brown25-Feb-08 5:30 
GeneralRe: Get m_nIDHelp of active dialog from CMainFrame in MDI application Pin
ptr_Electron25-Feb-08 23:15
ptr_Electron25-Feb-08 23:15 
GeneralHide the dilog in dialog based application. Pin
vicky0000025-Feb-08 3:18
vicky0000025-Feb-08 3:18 
GeneralRe: Hide the dilog in dialog based application. Pin
Maxwell Chen25-Feb-08 3:23
Maxwell Chen25-Feb-08 3:23 
GeneralRe: Hide the dilog in dialog based application. Pin
vicky0000025-Feb-08 17:54
vicky0000025-Feb-08 17:54 
GeneralRe: Hide the dilog in dialog based application. Pin
Maxwell Chen25-Feb-08 3:36
Maxwell Chen25-Feb-08 3:36 
AnswerRe: Hide the dilog in dialog based application. Pin
Rajkumar R25-Feb-08 3:52
Rajkumar R25-Feb-08 3:52 

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.