- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In april this year there was a discussion in the forum about setting an icon in the title bar of a simple dialog based windows application. The solution was to use the code:
hIcon = LoadImage(ghInstance, %val(MAKEINTRESOURCE(IDI_TITLEBAR_ICON)), IMAGE_ICON, &
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0);
if(hIcon /= 0) then
hr = SendMessage(dlg%hWnd, WM_SETICON, ICON_SMALL, hIcon);
end if
With this code I get multiple error messages.
Could someone post the code of a complete but simplified fortran windows application with the code implemented?
Many thanks,
Bruce
hIcon = LoadImage(ghInstance, %val(MAKEINTRESOURCE(IDI_TITLEBAR_ICON)), IMAGE_ICON, &
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0);
if(hIcon /= 0) then
hr = SendMessage(dlg%hWnd, WM_SETICON, ICON_SMALL, hIcon);
end if
With this code I get multiple error messages.
Could someone post the code of a complete but simplified fortran windows application with the code implemented?
Many thanks,
Bruce
Link Copied
9 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The code (probably) works OK; however, the problem lies in CVF's Win32 header files (DFWIN). Now, you didn't post which error messages you get. LoadImage is a particular problem; 5.0x didn't contain it, later versions did but there's also a conflict with a QuickWin function of the same name.
Don't know the present situation, however, you could write an interface of your own. Here's a snippet.
HTH
Jugoslav
Don't know the present situation, however, you could write an interface of your own. Here's a snippet.
!NOTE: Due to name collision with MSFLIB's LoadImage, and missing !declaration of LoadImage even from CVF6 headers, this function is !declared here as LoadImageA. !DEC$OBJCOMMENT LIB:"USER32.LIB" INTERFACE INTEGER(4) FUNCTION LoadImageA(hInst,lpszName,uType,cxDesired, & cyDesired,fuLoad) !DEC$ATTRIBUTES STDCALL, ALIAS : '_LoadImageA@24' :: LoadImageA INTEGER hInst INTEGER lpszName INTEGER uType INTEGER cxDesired INTEGER cyDesired INTEGER fuLoad END FUNCTION LoadImageA END INTERFACE
HTH
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is some code which works perfectly. It uses the LoadImage interface in USER32.F90. In versions prior to 6.5 (I think) you had to supply your own interface, but the 6.5+ upgrade now includes this function.
! Loads a file containing a bitmap in uncompressed Windows bitmap
! format, and returns a bitmap handle. Returns 0 if the load failed.
! note: ghIinstance for the main window is a global variable
INTEGER FUNCTION LoadBitmapFile (filename)
IMPLICIT NONE
CHARACTER(LEN=*), INTENT(IN) :: filename
INTEGER*4 :: handle
CHARACTER(LEN=200) :: fn
fn = filename
IF(LEN_TRIM(fn) == 0) THEN
LoadBitmapFile = 0
RETURN
END IF
CALL NullTerminateString(fn) ! adds a terminal null byte
handle = LoadImage (ghInstance, fn, IMAGE_BITMAP, 0, 0, &
LR_LOADFROMFILE)
IF (handle == 0) THEN
CALL WriteMsgLastError(WRITEMSG_WARNING, "LoadBitmapFile", &
"LoadImage")
LoadBitmapFile = 0
ELSE
LoadBitmapFile = handle
END IF
END FUNCTION LoadBitmapFile
! Loads a file containing a bitmap in uncompressed Windows bitmap
! format, and returns a bitmap handle. Returns 0 if the load failed.
! note: ghIinstance for the main window is a global variable
INTEGER FUNCTION LoadBitmapFile (filename)
IMPLICIT NONE
CHARACTER(LEN=*), INTENT(IN) :: filename
INTEGER*4 :: handle
CHARACTER(LEN=200) :: fn
fn = filename
IF(LEN_TRIM(fn) == 0) THEN
LoadBitmapFile = 0
RETURN
END IF
CALL NullTerminateString(fn) ! adds a terminal null byte
handle = LoadImage (ghInstance, fn, IMAGE_BITMAP, 0, 0, &
LR_LOADFROMFILE)
IF (handle == 0) THEN
CALL WriteMsgLastError(WRITEMSG_WARNING, "LoadBitmapFile", &
"LoadImage")
LoadBitmapFile = 0
ELSE
LoadBitmapFile = handle
END IF
END FUNCTION LoadBitmapFile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jugoslav, I already tried the interface you suggested but I get error messages about not recognizing the following:
- IMAGE_ICON
- SM_CXSMICON
- SM_CYSMICON
- WM_SETICON
- ICON_SMALL
It seems as if something has not been included, but I don't see what this could be. The Fortran version I use is 6.0A
Bruce
- IMAGE_ICON
- SM_CXSMICON
- SM_CYSMICON
- WM_SETICON
- ICON_SMALL
It seems as if something has not been included, but I don't see what this could be. The Fortran version I use is 6.0A
Bruce
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Bruce,
If you included DFWIN, and it still fails to compile, it simply ain't there. Here they are:
If you included DFWIN, and it still fails to compile, it simply ain't there. Here they are:
INTEGER,PARAMETER:: SM_CXSMICON = 49 INTEGER,PARAMETER:: SM_CYSMICON = 50 INTEGER,PARAMETER:: WM_SETICON = #80 INTEGER,PARAMETER:: ICON_SMALL = 0 INTEGER,PARAMETER:: ICON_BIG = 1 INTEGER,PARAMETER:: IMAGE_BITMAP = 0 INTEGER,PARAMETER:: IMAGE_ICON = 1 INTEGER,PARAMETER:: IMAGE_CURSOR = 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jugoslav, now I'm a bit closer to the solution I think, but I don't understand why my compiler doesn't find the parameters you posted. IMAGE_BITMAP is the only one my compiler does find. Do you know in which file these parameters should be listed?
There's one problem left: How do I get the correct value for ghInstance (= hInst in the interface)?
Bruce
There's one problem left: How do I get the correct value for ghInstance (= hInst in the interface)?
Bruce
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It can't find them because they aren't there :-). They are located in .f90 files located in C:Program FilesMicrosoft Visual StudioDFInclude. DFWINTY.f90 contains Win32 type definitions and parameters; the rest (the ones USEd by DFWIN.f90) are INTERFACEs to Win32 functions. It is usually a good idea to do a "Find in Files" in that directory before implementing a Win32 routine from help to take a look at Fortran interface. Alas, Microsoft is (hopefully was) faster in developing Win32 APIs than Compaq in updating their Fortran interfaces.
Steve, btw, I think that new DFWINs.f90 should be available for free download from Compaq's site. After all, MSDN is free for download.
As for hInstance, you can obtain it using hInstance=GetModuleHandle(NULL).
Steve, btw, I think that new DFWINs.f90 should be available for free download from Compaq's site. After all, MSDN is free for download.
As for hInstance, you can obtain it using hInstance=GetModuleHandle(NULL).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jugoslav,
MSDN isn't free for download - one pays a large sum to be an MSDN subscriber. You can view the documentation online, true. The only place I know of that MS updates its Win32 declarations is in Visual Studio service packs - just like we do in our updates. If you know of something else MS does, please provide me a pointer.
CVF 6.6 has completely new and retranslated API declarations, but they also use new compiler features, so can't be used by users of older versions. Now that we've got this automated translation method, we can keep up with MS much easier.
Steve
MSDN isn't free for download - one pays a large sum to be an MSDN subscriber. You can view the documentation online, true. The only place I know of that MS updates its Win32 declarations is in Visual Studio service packs - just like we do in our updates. If you know of something else MS does, please provide me a pointer.
CVF 6.6 has completely new and retranslated API declarations, but they also use new compiler features, so can't be used by users of older versions. Now that we've got this automated translation method, we can keep up with MS much easier.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That of hInstance I could have known: the same I use when presenting a bitmap in a control button.
It is still not working though. I don't get any error messages anymore, but the icon doesn't appear in the title bar.
Bruce
It is still not working though. I don't get any error messages anymore, but the icon doesn't appear in the title bar.
Bruce
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Finally: it's working !!!
Yugoslav, indeed I called the code from the same routine where I call DlgModal. When I put the code in a callback subroutine by dlginit, the icon appears in the title bar.
Many thanks !!!!
Bruce
Yugoslav, indeed I called the code from the same routine where I call DlgModal. When I put the code in a callback subroutine by dlginit, the icon appears in the title bar.
Many thanks !!!!
Bruce

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page