what can i use instead SetTimer()?

May 10, 2016 at 11:46pm
i'm trying using the SetTimer() it's good, but for deferent delay between frames it's a big problem... instead a Multimedia Timers, is there another timer that i can use?
May 11, 2016 at 10:57am
If you want to change the delay use KillTimer():

https://msdn.microsoft.com/en-us/library/windows/desktop/ms644903%28v=vs.85%29.aspx

and then SetTimer() again.

By the way: a timer with a period of 10ms and below makes little sense for a gui (it just keeps the gui busy). The user will see changes only when the delay is 200ms and more.
May 11, 2016 at 11:08am
i'm so sorry, but the SetTimer()(using animated gif's, but diferent delay between frames) is very instable :(
i only get problems :(
May 13, 2016 at 7:40am
I don't think that SetTimer() is instable. You have a problem else where.

Following suggestion:

Create a thread per animation. As soon as the animation changes send a message to the gui and make the update to window.
May 17, 2016 at 2:18pm
yes you have right. but theres 1 timer that 'stops' when the form wins the focus. that timer just change the form icon:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void SetIcon(image &imgIcon)
        {
            if(hWindowIcon!=NULL)
                DestroyIcon(hWindowIcon);
            if(hWindowIconBig!=NULL)
                DestroyIcon(hWindowIconBig);
            hWindowIcon =CopyIcon((HICON)imgIcon);
            hWindowIconBig =CopyIcon((HICON)imgIcon);
            //DrawHICONtoHDC(NULL, (HICON)imgIcon,100,100);
            if(hWindowIcon!=NULL)
            {
                SendMessage( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)(HICON)hWindowIcon);//if i don't use  these line
            }

            if(hWindowIconBig!=NULL)
            {
                SendMessage( hwnd, WM_SETICON, ICON_BIG, (LPARAM)(HICON)hWindowIconBig );
            }
        }

see these on DrawHICONtoHDC():
1 - if i use it,the icon is changed;
2 - NULL is a HDC, so it's wrong... i just did these for not draw it.
but what you think?
May 18, 2016 at 11:56am
DestroyIcon() before you set the new icon is certainly a problem and may lead to undefined behavior. Move that after the SendMessage() is done.

Plus: It is always allowed to use DestroyIcon() / CopyIcon(). See:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms648063%28v=vs.85%29.aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/ms648058%28v=vs.85%29.aspx
May 18, 2016 at 12:02pm
but it's wrong, i think, move the DestroyIcon() after SendMessage(), because it's selected to window, right?
Last edited on May 18, 2016 at 12:03pm
May 18, 2016 at 12:27pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
void SetIcon(image &imgIcon)
        {

auto tmp_wi = hWindowIcon;
auto tmp_wib = hWindowIconBig;

            if(hWindowIcon!=NULL)
                DestroyIcon(hWindowIcon);
            if(hWindowIconBig!=NULL)
                DestroyIcon(hWindowIconBig);

            hWindowIcon =CopyIcon((HICON)imgIcon);
            hWindowIconBig =CopyIcon((HICON)imgIcon);
            //DrawHICONtoHDC(NULL, (HICON)imgIcon,100,100);
            if(hWindowIcon!=NULL)
            {
                SendMessage( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)(HICON)hWindowIcon);//if i don't use  these line
            }

            if(hWindowIconBig!=NULL)
            {
                SendMessage( hwnd, WM_SETICON, ICON_BIG, (LPARAM)(HICON)hWindowIconBig );
            }

            if(tmp_wi!=NULL)
                DestroyIcon(tmp_wi);
            if(tmp_wib!=NULL)
                DestroyIcon(tmp_wib);
        }


The next issue is whether it is correct at all to destroy these icons. Remember that there are circumstances where it is not allowed to destroy them.
May 18, 2016 at 12:35pm
thanks for all. i have 1 question: why the hWindowIcon hWindowIconBig and aren't destroyed?
i can do it on desctructor.. but tell me
May 18, 2016 at 1:12pm
They are destroyed (line 26/28). Just make sure that the window doesn't access any data from the icon when you destroy it. Hence destroy the icon after it is removed from the window (with WM_SETICON).
May 18, 2016 at 1:17pm
thanks for all
May 18, 2016 at 1:23pm
correct me 1 thing: before destroy a timer\multithread or something like that, is the best use the wait functions and CreateEvent() and SetEvent() first?
May 19, 2016 at 10:35am
This cannot be answered. It depends entirely on the purpose of the event.
May 19, 2016 at 7:06pm
thanks for all.. realy thanks
Topic archived. No new replies allowed.