Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

IFLOGM Dialogs & Images

andrew_4619
Honored Contributor III
495 Views

I was wanting to have some buttons on windows dialogs  that have images rather than text. In the resource editor a button has Options Bitmap true/false and also  Icon true/false  under 'Appearance'. I have spend the last 30 minutes looking at MSDN for a clue on how to use these and failed. Which makes me even less hopeful for Fortran...

Has anyone got any experiance and tips on if this,  is it possible and if so what needs to be set where and how?

0 Kudos
3 Replies
andrew_4619
Honored Contributor III
495 Views

I found some clues in this code snippet  so It will have a play and see what I can do:

[cpp]HANDLE hbitmap=LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BITMAP1),IMAGE_BITMAP,32,32,LR_DEFAULTCOLOR);

HWND button=CreateWindow("BUTTON","Test button",BS_BITMAP | WS_VISIBLE | WS_CHILD,10,10,34,34,hwnd,NULL,hThisInstance,NULL);

SendMessage(button,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)hbitmap);[/cpp]

0 Kudos
Neels
New Contributor II
495 Views

There are some examples on the Xeffort page.

0 Kudos
andrew_4619
Honored Contributor III
495 Views

I have never delved into xeffort though I believe there is some very useful stuff there.  I made a simple fortran routine to apply a bitmap resource to a dialog button resource which seems to work (I haven't tried to break it yet....). It was quite simple to do, the problem is finding information what you need to do....  I have attached  some souce which might help others:

[fortran]

subroutine set_button_image(dlg_hwnd,Button_ID,BITMAP_ID,BM_width,BM_height) !apply bitmap to dialog button
!unsure of limitations (e.g. BM bigger than button etc), limited testing
use ifwin, only : handle, LoadImage, GetModuleHandle, MAKEINTRESOURCE,LR_DEFAULTCOLOR, NULL,&
IMAGE_BITMAP, GetDlgItem, BM_SETIMAGE, LRESULT, SENDMESSAGE, word
integer(handle), intent(in) :: dlg_hwnd !handle of dialog
integer(4),intent(in) :: Button_ID !resouce ID to apply bitmap to,resource needs accept bitmap .true. in dialog editor
integer(4),intent(in) :: BITMAP_ID !resouce ID of the bitmap
integer(handle),intent(in) :: BM_width, BM_height !size in pixel of bitmap (size we want but only tested with want=actual)
integer(handle) :: button_hwnd, hbitmap_hwnd
integer(lresult) :: lres
integer(word) :: bmid !is is an integer(2)
bmid = BITMAP_ID !note integer(4) to (2)
! note, bitmap_width & height are MSDN type wparam > uint_ptr > handle (wparam not defined if ifwin)
! get the handle of the button and bitmap and then sendmessage to button
button_hwnd = GetDlgItem(dlg_hwnd, Button_ID)
!HANDLE WINAPI LoadImage(_In_opt_ HINSTANCE hinst,_In_ LPCTSTR lpszName,_In_ UINT uType,_In_ int cxDesired,
! _In_ int cyDesired,_In_ UINT fuLoad);
hbitmap_hwnd = LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(BMID),IMAGE_BITMAP,BM_width,BM_height,LR_DEFAULTCOLOR)
!LRESULT WINAPI SendMessage(_In_ HWND hWnd,_In_ UINT Msg,_In_ WPARAM wParam,_In_ LPARAM lParam);
Lres = SendMessage(button_hwnd,BM_SETIMAGE,IMAGE_BITMAP,hbitmap_hwnd)
end subroutine[/fortran]

0 Kudos
Reply