Re: using SetBitmap

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jeff Partch (jeffp_at_mvps.org)
Date: 11/01/04


Date: Mon, 1 Nov 2004 13:36:00 -0600


"hilla hartman" <hillah@gmail.com> wrote in message
news:87877a19.0411011116.56e730b4@posting.google.com...
> Hi,
> I wrote a program that is a dialog box and has a callback function. In
> the callback function i need to change a picture that is in the dialog
> box.
> Since the Callback function isnt in the same class as the dialog box i
> cant use -(CStatic*) GetDlgItem( IDC_IMAGE);
> and have to use - (CStatic*) GetDlgItem(g_hwnd, IDC_IMAGE);
> In the first case it works... In the second case (which is what i
> actually need) it throws an exception.
> the code looks like this -
>
> hBitmap = (HBITMAP)::LoadImage( NULL, "c:\\tactix.bmp", IMAGE_BITMAP,
> 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
>
> pImage = (CStatic*) GetDlgItem(g_hwnd, IDC_IMAGE);
> if (pImage != NULL)
> pImage->SetBitmap( hBitmap);

I suspect that GetDlgItem is returning an HWND...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxreference/dialogboxfunctions/getdlgitem.asp

...you can't cast an HWND to a CStatic*, but you might could use...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cwnd.3a3a.fromhandle.asp

...and cast that CWnd* to a CStatic*. Or you might could just use
SendMessage and...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/staticcontrols/staticcontrolreference/staticcontrolmessages/stm_setimage.asp

-- 
Jeff Partch [VC++ MVP]


Relevant Pages

  • [PULL] typesafe callbacks for kthread and stop_machine
    ... * because any other types will not be cast, they will cause a warning as ... the return type of the callback function ...
    (Linux-Kernel)
  • Re: Weird malloc behaviour
    ... A printf argument corresponding to a %p format specification must ... A printf argument involving sizeof must be cast to the correct ... When dereferencing the parameter of a callback function, ... defining and initializing a local pointer of the correct type and ...
    (comp.lang.c)
  • Re: API misunderstands VB function that returns a variant...?
    ... SetTimer runs a callback function after N seconds elapsed. ... HWND hwnd, ... Public Function TimerFunc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal ... idEvent As Long, ByVal dwTime As Long) As Long ...
    (microsoft.public.vb.winapi)
  • Re: SetTimer with no form?
    ... > VOID CALLBACK HeimdallTimerProc(HWND hwnd, UINT message, UINT_PTR ... From the MSDN docs for SetTimer: ... When you specify a TimerProc callback function, ...
    (microsoft.public.win32.programmer.kernel)
  • Re: EnumChildWindows make application crash
    ... i have initialized the hWnd to the CFrameWnd's handle. ... Yes, it's crash in EnumFunc. ... Put a break in the callback function and step in to ...
    (microsoft.public.vc.mfc)