display an image in a dialog box
I'm trying to display an image in a dialog. I have a specific image typ which I read from a file. So I tryed to
make a dialog by the use of a the "Picture Control", as type I guess to use "Bitmap" or is it "owner draw"
Have I to convert my image to bitmap, and generate a bitmap handle (somehow) However I have no Idea how I can do
that, I looked for several examples but could not find one.
Any Idea wwhere I can find information about that
problem ?
| |
Re: display an image in a dialog box
Here is a code fragment extracted from the WM_PAINT message handler within a window's proc function, which shows how to
read a background image from a windows bitmap (*.bmp) file and display the image centered in the window:
INTEGER :: rval, background_color
TYPE(T_PAINTSTRUCT) :: ps
TYPE(T_RECT) :: clientRect
INTEGER :: WndWidth, WndHeight
INTEGER :: imageWidth, imageHeight
INTEGER(HANDLE) :: hbitmapImage
INTEGER(HANDLE) :: hdcBitmap
INTEGER(HANDLE) :: hgdiobjectOld
CHARACTER(LEN=256) :: fname
fname = 'c:somepathsomefile.bmp'//CHAR(0) hbitmapImage = LoadImage (ghInstance, fname, IMAGE_BITMAP, 0, 0,
& LR_LOADFROMFILE)
rval = GetClientRect(hwnd, clientRect)
WndWidth = clientRect%right - clientRect%left
WndHeight = clientRect%bottom - clientRect%top
! create a device context for the current window rval = BeginPaint (hwnd, ps)
! Erase the background
CALL fill_rectangle (ps%hdc, background_color, clientRect)
! Draw the image
CALL GetBitmapSize (hbitmapImage, ps%hdc, imageWidth, imageHeight)
hdcBitmap = CreateCompatibleDC (ps%hdc)
hgdiobjectOld = SelectObject (hdcBitmap, hbitmapImage)
rval = BitBlt (ps%hdc, &
(WndWidth-imageWidth)/2, &
(WndHeight-imageHeight)/2, &
imageWidth, &
imageHeight, &
hdcBitmap, 0, 0, SRCCOPY)
! clean up
rval = SelectObject (hdcBitmap, hgdiobjectOld)
rval = DeleteDC (hdcBitmap)
rval = DeleteObject (hbitmapImage)
rval = EndPaint (hwnd, ps)
!==== seperate utility used in the above code ====
! Fills width and height with the dimensions, in pixels, of the
! bitmap specified by the bitmap handle, using the metrics of the
! provided device context.
SUBROUTINE GetBitmapSize (hbitmap, hDC, width, height)
IMPLICIT NONE
INTEGER(HANDLE), INTENT(IN) :: hbitmap
INTEGER(HANDLE), INTENT(IN) :: hDC
INTEGER, INTENT(OUT) :: width
INTEGER, INTENT(OUT) :: height
TYPE(T_BITMAPINFO) :: bitmapInfo
INTEGER :: rval
bitmapInfo%bmiHeader%biBitCount = 0
bitmapInfo%bmiHeader%biSize = SIZEOF(bitmapInfo%bmiHeader)
rval = GetDIBits (hDC, hbitmap, 0, 0, 0, LOC(bitmapInfo), & DIB_RGB_COLORS)
IF (rval == 0) THEN
! error
ELSE
width = bitmapInfo%bmiHeader%biWidth
height = bitmapInfo%bmiHeader%biHeight
END IF
END SUBROUTINE GetBitmapSize
| |
Re: display an image in a dialog box
To display a Bitmap on a button, you have to do the following: 1.) Import this
bitmap to your resource file (name is IDB_BITMAP) 2.) Set your IDC_BUTTON bitamp true 3.) Use the following
code
hInst=GetModuleHandle(NULL)
hBitmap=LoadBitmap(hInst,IDB_BITMAP)
l=SendMessage(GetDlgItem(dlg%hwnd,IDC_BUTTON),BM_SETIMAGE,IMAGE_BITMAP,hBitmap)
Markus
| |
Re: display an image in a dialog box
I could not find where fill_rectangle is defined,
in
which module is this subroutine defined ?
Here is a code fragment extracted from the WM_PAINT message handler within
a window's proc function, which shows how to read a background image from a windows bitmap (*.bmp) file and display the
image centered in the window:
INTEGER :: rval, background_color TYPE(T_PAINTSTRUCT) ::
ps TYPE(T_RECT) :: clientRect INTEGER :: WndWidth, WndHeight INTEGER :: imageWidth, imageHeight INTEGER(HANDLE) :: hbitmapImage INTEGER(HANDLE) :: hdcBitmap INTEGER(HANDLE) :: hgdiobjectOld CHARACTER(LEN=256) ::
fname
fname = 'c:somepathsomefile.bmp'//CHAR(0) hbitmapImage = LoadImage (ghInstance, fname,
IMAGE_BITMAP, 0, 0, & LR_LOADFROMFILE)
rval =
GetClientRect(hwnd, clientRect) WndWidth = clientRect%right - clientRect%left WndHeight = clientRect%bottom
- clientRect%top
! create a device context for the current window rval = BeginPaint (hwnd, ps)
! Erase the background CALL fill_rectangle (ps%hdc, background_color, clientRect)
! Draw the image CALL GetBitmapSize (hbitmapImage, ps%hdc, imageWidth, imageHeight) hdcBitmap = CreateCompatibleDC (ps%hdc) hgdiobjectOld = SelectObject (hdcBitmap, hbitmapImage) rval = BitBlt (ps%hdc, &
(WndWidth-imageWidth)/2, & (WndHeight-imageHeight)/2, & imageWidth, & imageHeight, & hdcBitmap, 0, 0, SRCCOPY)
! clean up rval = SelectObject
(hdcBitmap, hgdiobjectOld) rval = DeleteDC (hdcBitmap) rval = DeleteObject (hbitmapImage) rval =
EndPaint (hwnd, ps)
!==== seperate utility used in the above code ==== ! Fills width
and height with the dimensions, in pixels, of the ! bitmap specified by the bitmap handle, using the metrics of
the ! provided device context. SUBROUTINE GetBitmapSize (hbitmap, hDC, width, height) IMPLICIT
NONE INTEGER(HANDLE), INTENT(IN) :: hbitmap INTEGER(HANDLE), INTENT(IN) :: hDC INTEGER,
INTENT(OUT) :: width INTEGER, INTENT(OUT) :: height TYPE(T_BITMAPINFO)
:: bitmapInfo INTEGER :: rval
bitmapInfo%bmiHeader%biBitCount =
0 bitmapInfo%bmiHeader%biSize = SIZEOF(bitmapInfo%bmiHeader) rval = GetDIBits (hDC, hbitmap, 0, 0,
0, LOC(bitmapInfo), & DIB_RGB_COLORS)
IF (rval == 0) THEN
! error ELSE width = bitmapInfo%bmiHeader%biWidth height =
bitmapInfo%bmiHeader%biHeight END IF END SUBROUTINE GetBitmapSize
| |
Re: display an image in a dialog box
There is no function "fill_rectangle" but in Win32 SDK (or in MSDN) you
can find
function:
int FillRect( HDC hDC, // handle to device context CONST
RECT *lprc, // pointer to structure with rectangle HBRUSH hbr // handle to brush ); May be Mr.
Paul Curtis meant exactly this function?
And in unit "user32.f90" (user32.lib) you can find it declaration
interface !lib=user32.lib
integer(4) function FillRect (hDC ,lprc ,hbr )
!DEC$ IF DEFINED(_X86_)
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_FillRect@12' :: FillRect
!DEC$ ELSE
!DEC$ ATTRIBUTES STDCALL, ALIAS : 'FillRect' :: FillRect
!DEC$ ENDIF
!DEC$ ATTRIBUTES REFERENCE :: lprc
use dfwinty
integer hDC
type(T_RECT) lprc
integer hbr
end function FillRect
end interface
| |
Re: display an image in a dialog box
Sorry; using the Win32 API is facilitated by making a set of wrapper functions for common operations. Here is how you
fill a rectangle with a color:
RECURSIVE SUBROUTINE fill_rectangle (hdc, color, rect, edge)
IMPLICIT NONE
INTEGER(HANDLE), INTENT(IN) :: hdc
INTEGER, INTENT(IN) :: color
TYPE(T_RECT), INTENT(IN) :: rect
INTEGER, INTENT(IN), OPTIONAL :: edge
INTEGER(HANDLE) :: hbrush, hold
INTEGER :: rval
! these statements always go together,
! and this routine ensures that a brush
! resource is always destroyed after use
hbrush = CreateSolidBrush (color)
hold = SelectObject (hdc, hbrush)
rval = FillRect (hdc, rect, hbrush)
rval = SelectObject (hdc, hold)
rval = DeleteObject (hbrush)
IF (PRESENT(edge)) THEN
IF (edge == 1) rval = DrawEdge (hdc, rect, EDGE_SUNKEN, BF_RECT)
END IF
END SUBROUTINE fill_rectangle
| | |