Picture Control Not Reseting Right

M

matt

I use the following code in OnInitDialog for a secondary window opened
in the main window by hitting DoModal():

P_Icons[0] = IDI_BACK;
HICON hIcon1 = (HICON)
::LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(P_Icons[0]),IMAGE_ICON,38,41,LR_DEFAULTCOLOR);
m_hole_1.SetIcon(hIcon1);
UpdateData(FALSE);

This works the first time through, and the picture control's icon is
change periodically. However, when the window is destroyed (hitting
the OnOk button), and the window is re-created again from the main
window with DoModal again, the picture control shows the icon that was
last assigned before the window was last deleted, even though every
time this window is created, in its OnInitDialog, I specifically
assign it the same starting icon! How can this code be essentially
ignored in OnInitDialog?

To make things stranger, if I use the following line to load the icon
(instead of the one above), things work:

HICON hIcon1 = (HICON)
::LoadImage(NULL,P_Icons[0],IMAGE_ICON,38,41,LR_LOADFROMFILE);
m_hole_1.SetIcon(hIcon1);
UpdateData(FALSE);

Anyone have a clue what's going on? Is the first parameter in
LoadImage correct?

Thanks,

JM
 
A

Alf P. Steinbach

I'll answer the C++ related parts, the windowing stuff is off-topic here.


* (e-mail address removed) (matt) schriebt:
I use the following code in OnInitDialog for a secondary window opened
in the main window by hitting DoModal():

P_Icons[0] = IDI_BACK;
HICON hIcon1 = (HICON)

This is a C cast.

Do you know which of the following,

static_cast
const_cast
reinterpret_cast

it corresponds to in this case?

If not then you're in trouble.

As a newbie, never use C casts.


::LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(P_Icons[0]),IMAGE_ICON,38,41,LR_DEFAULTCOLOR);

Here you're using "magic numbers", 38 and 41.

Those will always get you into trouble.



Anyone have a clue what's going on? Is the first parameter in
LoadImage correct?

This is a FAQ:

<url: http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9>

By the nature of the question the FAQ isn't and cannot be complete, so
after _studying_ what the FAQ has to say on this question, also look around.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top