I am still suggesting you are doing this all wrong but I can fix this problem if you really are manually drawing the list. To me it sounds like the listbox should be a child within some other window and you are just trying to do this in some crazy manual way. If it was child it would draw itself when needed with zero code needed from you. However if you are manually doing it you could try this Copy all the code in the WM_PAINT function of your listbox and place it inside a function like so
void PaintMyList (HWND Handle_of_ListBox, HDC Dc)
{
// Paste your current list box WM_PAINT code here
}
Now replace the PaintStruct stuff and simply us the HDC passed on the interface and use Handle_of_ListBox where you need a handle .. okay check it all compiles. So we are clear all you are using from the PaintStruct is the DC and the DC you are to use is declared on that function interface so you can remove all references to the PaintStruct. Now use a variant you posted above with the one call change
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC_of_MainWindow = BeginPaint(hwnd, &ps);
Draw_From_FRONT_BUFFER_To_MainWindow();
PaintMyList(Handle_of_ListBox, ps.hdc); // <=== Now the list paints on the DC from the paintstruct
EndPaint(hwnd, &ps);
return 0;
}
break;
In vino veritas