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

Saving bitmap in quickwin with saveimage_w

pennykate
Beginner
1,029 Views
I can save a completed image in the subroutine where it was created using a fixed filename. However, when I try to make it general, giving a filename in a dialog box after the image is completed (I haven't cracked menus yet) I get an error code out of saveimage_w. I have tried calling focusqq before saveimage_w but it does not help.
0 Kudos
6 Replies
Jugoslav_Dujic
Valued Contributor II
1,029 Views
I doubt that has anything to do with focus; rather, itlooks likean invalid file name.
What do you mean by "giving a filename in a dialog box"? Is it a standard "Save as" dialog box (GetSaveFileName) oryour customdialog? If the former, have in mind that SAVEIMAGE_W expects a "Fortran style" string (padded with blanks) while most APIs return "C style" strings (valid contents terminated with char(0), and the rest is garbage). Does perhaps the following work?:
iLen = INDEX(sFileName, CHAR(0))
IF (iLen.ne.0) sFileName = sFileName(1:iLen-1)
call SaveImage_W(sFileName...
Jugoslav
0 Kudos
pennykate
Beginner
1,029 Views
It worked! Thank you very much. I had not appreciated that the same format would not work for Open, Read, Write etc and for saveimage_w.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,029 Views
It works in OPEN? Actually, it shouldn't (more precisely, there's no guarantee in the Standard that it would, but CVF is certainly allowed to do it). Quick test...
Code:
Program OpenTest

character(20):: sFileName
integer::       i = 42

sFileName = "foo.txt"
open(11, file=sFileName, action="write")
write(11,*) i
close(11)

sFileName = "foo.txt"//char(0)//"garbage"
open(11, file=sFileName, action="read", status="old")
read(11,*) i
write(*,*) i
close(11)

End Program OpenTest
It does work indeed :-), i.e. it outputs "42"
Jugoslav
0 Kudos
pennykate
Beginner
1,029 Views
I now find I was asking the wrong question. It was pure coincidence that it worked after I put your suggestion in. I have two output files - a character file and a bitmap file. It worked when I saved just the bitmap file.
I have a custom dialog box toask forthe (character) input file name, and another toask for the names ofthe character and bitmap output files. If only one output file is named then it is created or overwritten correctly. If both are named then the character file is created or overwritten correctly. If a bitmap file is already present thenit is deleted (I found I could not write a new version without first deleting the old one) before calling the saveimage_w function. SaveImage_w returns an error code (-1), and the bitmap file is empty. If the character output file is not requested, SaveImage_w returns an error code of zero and the bitmap file is written correctly.
This is my first-ever Visual Fortran program, and it is based on bits from various sample programs.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,029 Views
It's pretty weird. Can you reproducethe problemon a minimal program? I don't know what to suggest -- sounds like gobbled memory or something.
Jugoslav
0 Kudos
pennykate
Beginner
1,029 Views
All the Windows-y stuff in my program is lifted from various sample programs.I don't know how much is essential and how much is just window-dressing, so I started removing stuff a bit at a time and re-running. I tried taking out the call to subroutine padstrfor, which came with the code I took from the mmplayer sample, and suddenlythewhole thingworked properly - but only if I also removed the code you gave me last week. This looked to me to be pretty harmless, so I was very surprised to find that it made a difference. I had wondered all along whether padstrfor was essential, but had not previously tried removing it to see what happened.
0 Kudos
Reply