0

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

Community
  • 1
  • 1
Alaa M.
  • 4,961
  • 10
  • 54
  • 95

1 Answers1

1

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.

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15
  • OK i read about UpdateWindow and i found that i should include the file `Winuser.h` or `Windows.h`. But visual studio (2010) isn't letting me include them. I get errors. Any ideas? – Alaa M. Dec 06 '13 at 15:55
  • What language are you using? What GUI library are you using? What error do you get? – ScottMcP-MVP Dec 07 '13 at 01:19
  • Language C++ , GUI C++ , Errors when adding `Windows.h` : `error C2143: syntax error : missing ';' before 'constant' C:\...\include\windef.h` , `error C2059: syntax error : 'constant' C:...\include\windef.h` and some more. – Alaa M. Dec 07 '13 at 01:24
  • 1
    The UpdateWindow solution applies to C/C++ WinAPI apps. You appear to be using C++/CLI with the Winforms GUI library. Try adding a Winforms tag to your question in hopes of getting a more relevant answer. – ScottMcP-MVP Dec 07 '13 at 01:58