Forum Jump

Select Group :
Select Forum :
Sorted By :
Sort Order :
From The :
 
Thread Tools  Search this thread 
jaeger0
Total Points:
710
Status Points:
210
Brown Belt
June 23, 2009 5:48 AM PDT
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 ?
Paul Curtis
Total Points:
2,390
Status Points:
1,890
Brown Belt
June 23, 2009 12:01 PM PDT
Rate
 
#1
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:\somepath\somefile.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



onkelhotte
Total Points:
2,900
Status Points:
2,400
Brown Belt
June 24, 2009 12:53 AM PDT
Rate
 
#2
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


jaeger0
Total Points:
710
Status Points:
210
Brown Belt
June 25, 2009 3:31 PM PDT
Rate
 
#3 Reply to #1
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:\somepath\somefile.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




mavlik
Total Points:
440
Status Points:
390
Green Belt
June 25, 2009 4:01 PM PDT
Rate
 
#4 Reply to #3
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


Paul Curtis
Total Points:
2,390
Status Points:
1,890
Brown Belt
June 25, 2009 7:16 PM PDT
Rate
 
#5 Reply to #2
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





Intel Software Network Forums Statistics

8445 users have contributed to 31553 threads and 100398 posts to date.
In the past 24 hours, we have 10 new thread(s) 30 new posts(s), and 43 new user(s).

In the past 3 days, the most popular thread for everyone has been Lost in MKL The most posts were made to TBB on linux segfaulting The post with the most views is Hi,if you were using imsl yo

Please welcome our newest member nonamez