when the form is activated:

case WM_ACTIVATE:
                {
                    if (wParam==WA_INACTIVE)
                    {
                        SetWindowText(inst->hwnd,"unactivated");
                        FormActivated = NULL;
                    }
                    else
                    {
                        SetWindowText(inst->hwnd,"activated");
                        FormActivated = inst->hwnd;
                    }

                    return 0;
                }
                break;

when i create the timer:

case WM_CREATE:
                {
                    if(WindowMain == NULL || WindowMain ==GetDesktopWindow())
                    {
                         WindowMain = HandleWindow;
                    }
                    SetTimer(inst->hwnd,JoystickTimer,150,NULL);
                    SetTimer(inst->hwnd,KeyBoardTimer,150,NULL);
                    SendMessage((HWND)lParam , WM_CREATE, wParam, lParam);
                }
                break;

so why the WM_TIMER isn't activated? why i get invalid handle?

WPARAM MessageLoop()
{
    MSG msgEvents;
    while(GetMessage(&msgEvents, NULL, 0, 0) > 0)
    {
        if (!IsDialogMessage(FormActivated, &msgEvents))
        {
           TranslateMessage(&msgEvents);
           DispatchMessage(&msgEvents);
        }
    }
    return msgEvents.wParam;
}

Off-topic:

SendMessage((HWND)lParam , WM_CREATE, wParam, lParam);

WHAT?!.. are you trying to accomplish here?

confused: if i minimizate the form, why the timer is working?
(i know these, because after restaure the form, the image is changed)
seems that i must give up on SetTimer() or i realy have 1 problem with FormActivated and/or message loop

i found the problem:

case WM_PAINT:
            {
                return 0;
            }
            break;

how these return value on WM_PAINT message can 'stop' the timer?

Did you initialize WindowMain to NULL when you created it? If not, then it contained arbitrary data from the stack and it would not be NULL in your test in the WM_CREATE switch.

This question has already been answered. Start a new discussion instead.