Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command in PRG file to add picture 2

Status
Not open for further replies.

michel392

Programmer
Dec 17, 2001
54
BR
I have converted an old FoxPro 2.0 program to Visual FoxPro 6.0. Now I want the program to show a picture (.BMP,GIF orJPG) in the screen as it executes. Is it possible to add a command or a group of commands to show a picture in screen (in a .PRG file), without having to use a FORM ?

Michel
 
Michel,
Sure, here a routine that is part of a web service that puts todays Dilbert strip on my screen each morning.
Code:
FUNCTION DisplayDilbert()

IF FILE(ADDBS(SYS(2023)) + "Dilbert.gif")
   IF TYPE("_screen.imgDilbert") = "O" AND !ISNULL(_screen.imgDilbert)
      _screen.RemoveObject("imgDilbert")
   ENDIF
   _screen.AddObject("imgDilbert", "image")
   _screen.imgDilbert.Picture = ADDBS(SYS(2023)) + "Dilbert.gif"
   *adjust as necessary to put in lower right corner
   _screen.iMGDILBERT.Top = (_screen.height - _screen.iMGDILBERT.height) - 2
   _screen.iMGDILBERT.Left= (_screen.width - _screen.iMGDILBERT.width) - 2
   _screen.imgDilbert.Visible = .T.   
ENDIF
Adjust the Top and Left calculation to put it where you want it. Using other properties you could also stretch it.

Rick
 
Rick:

I used the function you provided but I do not see the picture being displayed.
See bellow the program I used the funcion.

Michel


* GRAFICO1.PRG
SET TALK OFF
DEFINE WINDOW TelaPadrao IN DESKTOP;
FROM 0,0 TO 47,100;
FONT 'Courier New',12

ACTIVATE WINDOW TelaPadrao
@ 4, 10 SAY "Hello world ! I am Dilbert !"

* Displaying Dilbert (I saved a picture Dilbert.gif in C:\WINDOWS\TEMP
* and in the directory where I saved this program)
* ---------------
DO DisplayDilbert
* ---------------
ok=SPACE(1)
@ 20,10 SAY &quot;Type <enter> to exit this program &quot; GET ok
READ

DEACTIVATE WINDOW TelaPadrao

RETURN



FUNCTION DisplayDilbert()

IF FILE(ADDBS(SYS(2023)) + &quot;Dilbert.gif&quot;)
IF TYPE(&quot;_screen.imgDilbert&quot;) = &quot;O&quot; AND !ISNULL(_SCREEN.imgDilbert)
_SCREEN.REMOVEOBJECT(&quot;imgDilbert&quot;)
ENDIF
_SCREEN.ADDOBJECT(&quot;imgDilbert&quot;, &quot;image&quot;)
_SCREEN.imgDilbert.PICTURE = ADDBS(SYS(2023)) + &quot;Dilbert.gif&quot;
*adjust as necessary to put in lower right corner
_SCREEN.imgDilbert.TOP = (_SCREEN.HEIGHT - _SCREEN.imgDilbert.HEIGHT) - 2
_SCREEN.imgDilbert.LEFT= (_SCREEN.WIDTH - _SCREEN.imgDilbert.WIDTH) - 2
_SCREEN.imgDilbert.VISIBLE = .T.
ENDIF

*Adjust the Top and Left calculation to put it where you want it. Using other properties you could also stretch it.

 
Or you can use:

_screen.Picture = 'WhatEver.BMP'

Dave S.
 
Michel,
This code put's it on the desktop not in the current window. Try it with just this code in you main program:
Code:
* GRAFICO1.PRG
SET TALK OFF

* Displaying Dilbert  (I saved a picture Dilbert.gif in C:\WINDOWS\TEMP 
* and in the directory where I saved this program)
* ---------------
DO DisplayDilbert
* ---------------

RETURN
<DisplayDilbert function>
Note: Dave is right his code will work, you just have a bit more control over the image object in _Screen.

Rick
 
I haven't got a solution using the answers above ! Maybe it is not clear to me.
I want the picture (.JPG,.BMP, etc) to appear in a screen (or even in a printing - but not in a VFP Report: I use only commands in a .PRG)
&quot;Now I want the program to show a picture (.BMP,GIF or JPG) in the screen as it executes. Is it possible to add a command or a group of commands to show a picture in screen (in a .PRG file), without having to use a FORM ?&quot;
Michel


 
HI
in your prg add the code..

_screen.Picture = &quot;myBmp.bmp&quot;


This command will show your myBMP.BMP as a picture in the screen. Now this is your first step. You will realise, you hav started in the right way.

But if you want the picture to be controlled more to your choice.. Rick has shown how to add the object as a code and the object is for showing an image file.

If you have used.. DEFINE WINDOW command in your codes.. then..

DEFINE WINDOW myWIN FROM 0,0 TO 25,80 NAME myWin

by using NAME myWin.. you can add the forms properties to the window.. such as..
myWin.Picture = myBmpFile.bmp

If you activate your window myWin.. you can see the picture in your myWin now.

:)

:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Ramani,

Despite of the fact I received from you all a lot of help,
I did not got the result I want yet !
Bellow is my entire program, and it did nor work (I do not see the Dilbert picture !)

The picture Dilbert.bmp is in the same directoty as this program is.
Michel


* GRAFICO1.PRG

SET TALK OFF
DEFINE WINDOW TelaPadrao IN DESKTOP;
FROM 0,0 TO 47,100;
NAME 'TelaPadrao';
FONT 'Courier New',12

* Displaying Dilbert (the Dilbert.bmp picture is in the
* same directory where I saved this program)
* ---------------
DO DisplayDilbert
* ---------------

TelaPadrao.Picture = 'Dilbert.bmp'

ACTIVATE WINDOW TelaPadrao
@ 4, 10 SAY &quot;Hello world ! I am Dilbert !&quot;

_screen.Picture = 'Dilbert.bmp'

ok=SPACE(1)
@ 20,10 SAY &quot;Type <enter> to exit this program &quot; GET ok
READ

DEACTIVATE WINDOW TelaPadrao

RETURN




FUNCTION DisplayDilbert()

IF FILE(ADDBS(SYS(2023)) + &quot;Dilbert.bmp&quot;)
IF TYPE(&quot;_screen.imgDilbert&quot;) = &quot;O&quot; AND !ISNULL(_SCREEN.imgDilbert)
_SCREEN.REMOVEOBJECT(&quot;imgDilbert&quot;)
ENDIF
_SCREEN.ADDOBJECT(&quot;imgDilbert&quot;, &quot;image&quot;)
_SCREEN.imgDilbert.PICTURE = ADDBS(SYS(2023)) + &quot;Dilbert.bmp&quot;
*adjust as necessary to put in lower right corner
_SCREEN.imgDilbert.TOP = (_SCREEN.HEIGHT - _SCREEN.imgDilbert.HEIGHT) - 2
_SCREEN.imgDilbert.LEFT= (_SCREEN.WIDTH - _SCREEN.imgDilbert.WIDTH) - 2
_SCREEN.imgDilbert.VISIBLE = .T.
ENDIF
 
michel392,
You've really got three things going on here.
1) DO DisplayDilbert - This expects the .BMP file in your temp directory (SYS(2023)) not the current directory. This will display a single copy of the picture as a separate object on the screen in the lower right hand corner (if the file exists!).

2) You are setting your WINDOW TelaPadrao PICTURE to the .BMP and by default the picture will be &quot;tiled&quot; (repeated multiple times) in the background of this window.

3) _screen.Picture = 'Dilbert.bmp' will also place a tiled copy of the image all over the background of the screen!

What is it you really want to do? All three of these work for me in VFP 6 SP5, VFP 7.0 SP1 and VFP 8.0 (beta).

Rick

 
Rick,

I just want, after activating a window (Window TelaPadrao, in the example), to have a single picture (Dilbert.bmp) to be displayed in the right top corner of the screen.

Like a logo of a firm in a screen, for example 'Dilbert Company' is the name of the firm and Dilbert.bmp its logo displayed in the screen.

I don't want to use a form to to this, I want to write commands to display what I want (name of the firm and a logo picture).

Thanks,
Michel
 
You can use something like:
@ 0, 150 SAY 'SomeBitmap.BMP' BITMAP
-or-
@ 0, WCOLS() - WidthOfBitmap SAY 'SomeBitmap.BMP' BITMAP
Dave S.
 
Michel,
This works for me:
Code:
* GRAFICO1.PRG

SET TALK OFF
DEFINE WINDOW TelaPadrao IN DESKTOP;
    FROM 0,0 TO 47,100;
    NAME 'TelaPadrao';
    FONT 'Courier New',12

* Displaying Dilbert (the Dilbert.bmp picture is in the
* same directory where I saved this program)
* ---------------
DO DisplayDilbert
* ---------------

** TelaPadrao.Picture = 'Dilbert.bmp' 

ACTIVATE WINDOW TelaPadrao
@ 4, 10 SAY &quot;Hello world ! I am Dilbert !&quot;

** _screen.Picture = 'Dilbert.bmp' 

ok=SPACE(1)
@ 20,10 SAY &quot;Type <enter> to exit this program &quot; GET ok
READ

DEACTIVATE WINDOW TelaPadrao

RETURN




FUNCTION DisplayDilbert()

IF FILE(ADDBS(SYS(2023)) + &quot;Dilbert.bmp&quot;)
    IF TYPE(&quot;_screen.imgDilbert&quot;) = &quot;O&quot; AND !ISNULL(_SCREEN.imgDilbert)
        _SCREEN.REMOVEOBJECT(&quot;imgDilbert&quot;)
    ENDIF
    _SCREEN.ADDOBJECT(&quot;imgDilbert&quot;, &quot;image&quot;)
    _SCREEN.imgDilbert.PICTURE = ADDBS(SYS(2023)) + &quot;Dilbert.bmp&quot;
   *adjust as necessary to put in lower right corner
    _SCREEN.imgDilbert.TOP = (_SCREEN.HEIGHT - _SCREEN.imgDilbert.HEIGHT) - 2
    _SCREEN.imgDilbert.LEFT= (_SCREEN.WIDTH - _SCREEN.imgDilbert.WIDTH) - 2
   * change TOP to put in upper Right corner
 	 _SCREEN.imgDilbert.TOP = 0   
    _SCREEN.imgDilbert.VISIBLE = .T.
ENDIF
Rick
 
Rick,
Yes, the program worked fine in my computer too, but I need the picture to be displayed in the current window, not in desktop ! Thanks anyway, but please see Dave S. (DSummZZZ)'s simple solution above: it is all I need, and it has just one command ! (@ 0,150 SAY 'SomeBitmap.BMP' BITMAP)

Thanks,
Michel

 
Dave:

Yes, all I need is your simple solution (@ 0,150 SAY 'SomeBitmap.BMP' BITMAP). It worked fine.
Now, I am thinking higher: Is it possible to use that command in a printed report ? (Also, I write my reports using only commands: SET DEVICE TO PRINTER, @...SAY..., etc). I used the same command but only a small portion of the actual picture (Dilbet.bmp) was printed !

Thanks,
Michel
 
The problem you will run into with doing @...SAY on a report, is that the last line of whatever is printed may be farther down the page than where you want the next item printed. Like if the picture takes up 3 physical 'lines' on the report, and you have something like:
@ 1, 1 SAY m.Var1
@ 1,50 SAY 'MyBitMap.BMP' BITMAP
@ 2, 1 SAY m.Var2
@ 3, 1 SAY m.Var3

You will get an eject prior to lines 2 & 3 printing.
With that said, try adding SIZE and ISOMETRIC or STRETCH after BITMAP and you may get the desired result:

@ 1,50 SAY 'MyBitMap.BMP' BITMAP SIZE 10, 10 ISOMETRIC
-or-
@ 1,50 SAY 'MyBitMap.BMP' BITMAP SIZE 10, 10 STRETCH
Dave S.
 
Dave:
The command you provided above, for picture printing, works correctly.
I have not found help in the Visual FoxPro 6.0 on-line documentation for the command @ ... SAY &quot;anypic.BMP&quot; BITMAP, or even for @ ... SAY &quot;anypic.BMP&quot; BITMAP SIZE 10,10 ISOMETRIC.
How could I find this command syntax, in order I can understand its use in deep ?
Thanks,
Michel

 
Michel,
Buy a copy of the FoxPro for Windows documentation? While most of the FPD/FPW syntax still works in VFP, it's not documented because MS reserves the right to withdraw it's support in future versions of VFP. The question is always how long should the old code be supported when newer syntax will work? An image object also has size, position and stretch properties - you don't need to use this old syntax.

Rick

 
I would suggest you spend the time learning the 'new' ways of VFP objects instead of trying to understand the 'old' FoxPro syntax. Like Rick says, it isn't around any more except by a buying an old copy or having a licensed user paste it all for you. The example I showed was a 'quick and dirty' for an old app, but the time would be better spent during your conversion process, learning and using newer and I believe, better technologies.
Dave S.
 
Rick and Dave,
The problem with the report I am working now is its complex lay-out. I don't believe (I may be wrong) I can use the VFP Report Designer to create it with the lay-out I need.
Programmaticaly (writing all commands and using @...SAY's), I created the report from old FoxPro 2.0 code ! And with your help I put the picture in it.
But I will try to go ahead in the new world of Visual objects.
Thanks again,
Michel
 
I would be surprised if the report designer couldn't handle your requirements. Especially since you are using @...SAY's. You may need to take some of your code and put it in a UDF() for specail calcs, but a lot of things are easier to do with the report designer than hand coding.
Remember, we're still here!
Dave S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top