HDC undefined value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi ,
I am migrating from VC 6.0 to VC 7.0 with ( windows Control Lib
option in vc dot net ) where I want to draw an image using StretchDIBits. I
am not able to get the HDC of the Window.
I tried using get_handel() which gives undefined value.
Any help regarding this will be great.

Thanx in Advance,
G.Girish
 
Is it a WinForms application? I have done this before:

void MyControl::OnPaint(PaintEventArgs^ e)
{
HDC dc = static_cast<HDC>(static_cast<void*>(e->Graphics->GetHdc()));
try
{
unmanaged_function(dc);
}
finally
{
e->Graphics->ReleaseHdc(static_cast<IntPtr>(dc));
}
Panel::OnPaint(e);
}

Tom
 
Hi Tamas,
Thank you for your reply,
I tried as you said but still I am getting that HDC is undefined.The
Graphics object (e->Graphics) also does not contains any value .Please look
in to my code .

private: System::Void Form1_Paint(System::Object * sender,
System::Windows::Forms::PaintEventArgs * e)
{
HDC dc=(HDC)e->Graphics->GetHdc().ToPointer();
HDC dc1 = static_cast<HDC>(static_cast<void*>(e->Graphics->GetHdc()));
}
G.Girish
 
The only differences I see is that Tamas is overriding Control::OnPaint
(which is recommended if you inherrit) while Girish is handling the Form's
paint event.

I have written a similar code in C++CLI and it works - for controls and
forms; for events and overrides.

Can you send a callstack when your Form1_Paint method is called?

Marcus
 
Back
Top