Results 1 to 40 of 40

Thread: Load image into STATIC control Win32

Threaded View

  1. #12

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Exclamation Re: Load image into STATIC control Win32

    Hi Lavolpe,

    Regarding that click event:
    You mean like this ?
    Code:
        'Create memory dc and draw image on it.
        hdc = GetDC(hForm)
        hMemDC = CreateCompatibleDC(hdc)
        hMemBMP = CreateCompatibleBitmap(hdc, lPicWidth, lPicHeight)
    
        'store original memory bitmap.    
        hOriginalBitmap = SelectObject(hMemDC, hMemBMP)
    
        Call BitBlt(hMemDC, 0, 0, lPicWidth, lPicHeight, hdc, lLeft, lTop, SRCCOPY)
    
        'create new StdPicture object from the memory bitmap.
        Set oPic = CreateStdPicture(hMemBMP)
    
        'load newly created picture onto the static control.
        If Not oPic Is Nothing Then
            Call SendMessage(hStatic, STM_SETIMAGE, IMAGE_BITMAP, ByVal oPic.handle)
        End If
    
        'restore original memory bitmap and cleanup. 
        hMemBMP = SelectObject(hMemDC, hOriginalBitmap)
        Call DeleteObject(hMemBMP)
        Call DeleteDC(hMemDC)
        ReleaseDC hForm, hdc
    You are deleting hMemBmp therefore "Call SendMessage(hStatic, STM_SETIMAGE, IMAGE_BITMAP, ByVal hMemBMP)" fails. In addition, you have those 2 lines reversed. You should first put back the original bitmap, then delete the DC. If your intentions were to actually delete hMemBMP, then you would do that too.
    I deleted the memory bitmap before SendMessage because I already had the bitmap secured in the
    StdPicture Object but even if I don't delete hMemBMP, calling SendMessage(hStatic, STM_SETIMAGE, IMAGE_BITMAP, ByVal hMemBMP) doesn't work ... The whole thing only works via a StdPicture object which still begs the question why.



    You probably need to call UpdateWindow API on the static hWnd? Refreshing the form likely does nothing because a form is not going to know to refresh an API-generated window you created. The form does not know that window exists.
    Makes sense, but calling UpdateWindow on the static control hwnd doesn't seem to have any effect nor does InvalidateRect or RedawWindow... I had already tested them all.

    The only way the static control gets displayed is if I don't set the WS_VISIBLE style bit and only if I call the ShowWindow API on it's hwnd after SendMessage, not before !!!! weird
    Last edited by JAAFAR; Oct 4th, 2020 at 01:00 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width