Action is performed only after returning from function

103 views Asked by At

I got a little problem that i have some code written in a function that should display some pictures on a board, and i can see the pictures only after the whole function finishes. Here it is:

(in the following code, pictures is an array of PictureBoxes)

void static paint_path(ArrNode* node)
{
    list<int> head=(NG->game->getboard()).getcolored();
    int place=-1;
    while(head.size())
    {
        place=head.back();
        head.pop_back();
        if(node[place].color == white)
            pictures[place]->ImageLocation = "white-.bmp"; /*THIS LINE*/
        else if(node[place].color == black)
        {
            pictures[place]->ImageLocation = "black-.bmp"; /*AND THIS LINE*/
        }
    }
}

I need those 2 lines /THIS LINE/ /and THIS LINE/ to be performed in time, and not only after the function finishes. In fact, the pictures are really shown only after the function that called to a function that called to this function returns. Why is that?!

Thank you

EDIT

I progressed by including Windows.h in stdafx.h, and stdafx.h in Form1. Now, as ScottMcP-MVP suggested, i'm trying to use UpdateWindow(). I read that UpdateWindow() takes a variable of type HWND. So i defined the following in my function: (definition taken from another thread)

HWND hwnd = ::CreateWindowA("STATIC","dummy",WS_VISIBLE,0,0,100,100,NULL,NULL,NULL,NULL);
::SetWindowTextA(hwnd,"Window!");

and called UpdateWindow(hwnd);

But i keep getting an error:

Error 15 error LNK2028: unresolved token (0A00001D) "extern "C" int __stdcall UpdateWindow(struct HWND__ *)" (?UpdateWindow@@$$J14YGHPAUHWND__@@@Z) referenced in function "private: static void __clrcall GUI::Form1::paint_path(struct b_node *)" (?paint_path@Form1@GUI@@$$FCMXPAUb_node@@@Z) C:\...\GUI.obj

Any further help?

Thanks in advance

1

There are 1 answers

4
ScottMcP-MVP On

The reason for the delay is that while the function is executing the painting code is not executing. After the function returns message processing resumes, and will process WM_PAINT. You can call the UpdateWindow API to force an immediate paint during your function.