views:

217

answers:

1

I have a small application which embeds webbrowser controls. In that application I have created a popup class. This popup is used to display server generated error messages.

I want to be able to resize the popup to suit the message. This is so a short message is not contained in an oversize form and a large message is not in an undersized form.

Rather than send a width and height I would like to calculate the dimensions on the fly. I also did not want to visibly resize the form, that is just plain ugly.

Everything I try fails :(

This is what I thought should work

create the form
move it offscreen by setting its left position to -1000
show the form (offscreen)
write the contents to the webrowser ctl
get the width and height after it renders
hide the form
resize the form to fit the above width and height
center it onscreen
show the form

That should work just great, except the webbrowser control refuses to render, therefore I can't get the client width and height

Does anyone know how this can be done?

DC

+1  A: 

I have solved the issue I was having. it was a timing one.

the problem was I was writing content to the webbrowser control. And then attempting to read the width and height. but the control hadn't rendered and so I was not getting those parameters.

I realised this early in the piece so I instead put the resize code in the ondocumentcomplete event. sadly what I didn't realise was this event is not called when you write directly to the document. somehow I managed to convince myself it wasn't being called because the control was hidden. that was not the case.

So once I managed to figure that out I put a message pump in after I called the write function and before I called the show function. the message pump looped around until the control returned complete (checks the readystate flag)

PopUp->Write(text.c_str());
while (!PopUp->Complete() && ProcessMessages()){ ; }
popup_ctlDownloadComplete(0);

now when the DownloadComplete event is called manually, the document has rendered and I can get the width and height.

The code above could cause an infinite loop if there is an error so I have added a counter to kill it should that happen. just not shown for brevity and clarity.

Oh and the code is legacy code not managed code

DC

DeveloperChris