MFC CPP A problem with putting picture in picture control on load

I got MFC app and I wanted to upload a picture using those 3 lines:

cbitmap_.LoadBitmap(IDB_BITMAP1);
picture_control_.SetBitmap((HBITMAP)cbitmap_.Detach());
UpdateData(FALSE);

When I did it on the main Dialog it worked. I tried to use it on a second Dialog that I open and it doesnt work on load. If I use it with a button on the second dialog it works as well… Where in the cpp file of the second dialog should I paste that code?

Thank you !

Answer

Final initialization of controls in a dialog is commonly done in response to the WM_INITDIALOG message. It is sent by the system after all controls have been created, but before the dialog is displayed. The CDialog class provides the virtual OnInitDialog member you can override in a derived implementation.

The call to UpdateData(FALSE) is not required either way. Assuming that picture_control_ is of type CStatic and properly attached to the control with a call to DDX_Control from the DoDataExchange implementation.