mfc >> Why I couldn't SetTimer in ListView

by WWVKaWFuV2Vp » Mon, 24 Jan 2005 11:05:01 GMT

I create new SDI project by AppWizard, at the final stage I modify the view
class from CView to CListview.
Everything is fine before I try to set a Timer in the ListView.
I simply call CWnd::SetTimer to start a timer, then use classwizard to
generate code to process WM_TIMER message
Here comes the code:
void CListView::OnTimer(UINT nIDEvent)
{
if (nIDEvent == 1)
{
....
}
CListView::OnTimer(nIDEvent);
}

But the I found the message WM_TIMER is been delivered only once,
then there are no more WM_TIMER after the first call to CListView::OnTimer.
I am totally puzzled, could anybody help me?


mfc >> Why I couldn't SetTimer in ListView

by Doug Harrison [MVP] » Mon, 24 Jan 2005 11:23:25 GMT






Assuming the "..." part isn't killing the timer, and the CListView::OnTimer
call is executed, I'd suspect that the latter is killing the timer. In
general, there's no need to call the base class OnTimer for timers created
in the derived class, and while you're diligently checking nIDEvent, there's
no guarantee the listview control itself does. In fact, listview creates a
couple of undocumented timers to manage the in-place edit controls it
creates; IIRC, they have IDs 42 and 43. So it definitely handles WM_TIMER,
but it may not be as diligent as you are in distinguishing its timers from
those created by subclasses.

I'd suggest trying:

if (nIDEvent == 1)
{
....
}
else
CListView::OnTimer(nIDEvent);

--
Doug Harrison
Microsoft MVP - Visual C++



mfc >> Why I couldn't SetTimer in ListView

by Jiangsheng[MVP/VC] » Mon, 24 Jan 2005 12:20:56 GMT

see KB Q200054 PRB: OnTimer() Is Not Called Repeatedly for a List Control


"Doug Harrison [MVP]" < XXXX@XXXXX.COM > : XXXX@XXXXX.COM ...





Why I couldn't SetTimer in ListView

by Doug Harrison [MVP] » Mon, 24 Jan 2005 12:44:09 GMT





I'm glad to see it's documented, but not so glad to see this misbehavior is
"by design". I knew this problem sounded familiar. Searching my own source
code, I found this (partial) comment:

// messages. Moreover, listview kills my timer when I call the base class
// version. I suppose I shouldn't have done that, but there's no excuse for
// listview to kill timers it didn't create.

Have you run across any documentation for the timer IDs listview uses? I
discovered the IDs for myself by using Spy++, but they really ought to be
documented.

--
Doug Harrison
Microsoft MVP - Visual C++


Why I couldn't SetTimer in ListView

by WWVKaWFuV2Vp » Mon, 24 Jan 2005 12:59:01 GMT

Thank you all, I had seen this KB and confirm it.






Why I couldn't SetTimer in ListView

by Alexander Grigoriev » Tue, 25 Jan 2005 12:14:52 GMT

Since the ID has the same width as the memory address, I suggest to use
either CWnd pointer for it, or an address of some data member.








Why I couldn't SetTimer in ListView

by Doug Harrison [MVP] » Wed, 26 Jan 2005 00:37:04 GMT





Not foolproof, but still a pretty nice idea. It has these desirable
properties:

1. It avoids small IDs, such as listview's magic 42 and 43, so won't
conflict with common practice.
2. As long as everyone uses the address of his own variable, people using
this method won't collide with one another.

--
Doug Harrison
Microsoft MVP - Visual C++


Similar Threads

1. Why I couldn't use this function?

Hello all:
   I create a single document,and a modelless dialog is called by menu,look:
void CSampleView::OnTest()
if(!D11.m_hWnd)
{
D11.Create(IDD_D11,this);
D11.ShowWindow(SW_SHOW);
}
and now I want to get the printer of dialog,look:
void CSampleView::OnLButtonDown(UINT nFlags, CPoint point)
{
CD11 *p=(CD11*)this->GetDlgItem(IDD_D11);
if(p) MessageBox("you");
else MessageBox("null");
}
but it always display "null",
I know I can use the variable "D11" to get the dialog's function and
member,but I want to know why I couldn't use this function GetDlgItem?
(Maybe I want to get the pointer in class CMainFrame or other class,should I
do)
Thank you very much.


2. Why couldn't reboot my PC?

3. Why couldn't change my IP?

hello all:
My OS is XP,and I use VC6,
First I create a raw socket,then set IP_HDRINCL,look:
m_skicmp=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP);
BOOL bopt=TRUE;
setsockopt(m_skicmp,IPPROTO_IP,IP_HDRINCL,(char*)&bopt,sizeof(bopt));

then I fill data in IP  and ICMP packet,but in the IP packet
the resourse IP isn't my local IP,I fill another IP,but when I
send the data:
sendto(m_skicmp,buf,sizeof(buf),0,(struct sockaddr*)&addrto,sizeof(struct 
sockaddr));
it displya error,the error number is 10004,
I want to know what I do if I replace the resource IP with another IP
in IP packet?


4. WHY WHY WHY WHY WHY WHY

5. Why does ListView.Sorting call RecreateHandle?

I'm impleneting a custom ListView with column sorting support and am
deciding whether to reuse the Sorting property to indicate direction
or create a new property.  The only drawback I see is that Sorting
calls RecreateHandle.

Why does it do this just to support sorting?  Would it be faster to do
a SendMessage to tell the Win32 control to sort the same way Sort()
does?

Thanks,

Sam

6. Question about ListView - resizing the last column: why does this work - CSharp/C#

7. couldn't load certificate from trusted people store on XP

Hi there,

I am writing a program which need to see the certificate in trusted
people store for security purpose. when I run the program, it says
"couldn't find the certificate in trusted people store ". I am using
VS2005 on XP sp2. I have imported a X509 certificate (c.pfx) into the
store on local machine account.

I wrote a small piece of code to see if the program can load cer from
the store but it returns 0. here under is the code:

System.Security.Cryptography.X509Certificates.X509Store theStore = new
System.Security.Cryptography.X509Certificates.X509Store("Trusted
People Store",StoreLocation.LocalMachine);
        theStore .Open(OpenFlags.ReadOnly);
        int count= theStore .Certificates.Count;
        string qq = string.Empty;

System.Security.Cryptography.X509Certificates.X509Certificate2Collection
ff = (X509Certificate2Collection)theStore .Certificates;
        foreach (X509Certificate2 rr in ff)
        {
            qq = rr.GetName();
        }
        x.Close();

Any idea?

Thanks!
Ron

8. Reg:Couldn't generate a report using Crystal Reports in .Net - CSharp/C#