Solved

VFP 7.0 application background picture

Posted on 2010-08-15
17
1,841 Views
Last Modified: 2012-06-27
Hello,

In a VFP 7.0 application, when the main menu loads up, is there a way to define a 'background' picture / wall paper that would persist thru the application.?
The application that loads up now, has the main menu at the top and the entire scree is BLANK. I would like the company logo or some picture and color in the back and this has to remain till the user exists back to the OS.
Thanks in advance
0
Comment
Question by:shahjagat
  • 6
  • 5
  • 4
  • +1
17 Comments
 
LVL 41

Assisted Solution

by:pcelba
pcelba earned 40 total points
ID: 33441337
You may specify background picture for each window in VFP. The main VFP window isn't an exception:

_screen.Picture = '<Your picture name and path>'

To remove background picture simply set this property to empty string
_screen.Picture = ""
0
 

Author Comment

by:shahjagat
ID: 33441441
But how can I get a picture on the 'Main Menu Window'.  The 'Main menu' is where all the screen and other option exit into and I would like some kind of a picture in the main menu.  

I guess I dont know where I can place the _screen.picture since the Menu desginer has no place for me specify the picture.  If I place it in the program that loads the menu, the picture dissappears as soon as the menu loads up.

0
 
LVL 41

Expert Comment

by:pcelba
ID: 33441458
Each menu is defined in a window or in form, so place the picture to the form in which the menu appears.

0
 
LVL 41

Expert Comment

by:pcelba
ID: 33441464
Of course, you cannot use _screen if the _screen isn't the form in which is the menu defined.

Does your app use some Top level form?
0
 

Author Comment

by:shahjagat
ID: 33441502
I dont have a top level form.
I have a Main.prg calling the shots.  It calls the Splash screen which is displayes for few seconds and in the destroy event it loads the menu.

0
 
LVL 41

Expert Comment

by:pcelba
ID: 33441525
OK, that probably could mean the main VFP window is the _screen.

Are you able to check _screen.picture value when the picture "disappears" ? The screen surface could also be covered by some other window, of course. What is the _screen.ActiveForm after the menu creation?

0
 

Author Comment

by:shahjagat
ID: 33441632
I created a top level form and could manage to get the Menu in the toplevel form with pictures in the back like how I was wanting.

However when I run any menu option it creates another window (blank - no colors) and runs in that window. When I exit the option, the blank empty window remains open.

0
 
LVL 41

Expert Comment

by:pcelba
ID: 33441650
You have to understand I don't see your code, so I may just guess the blank window is created by your code and it has no picture property set.

VFP does not create any window or form if you don't create and execute appropriate code.

If you need background picture displayed on each form then you have to create such form from a form class which has this picture defined or you have to set picture property each time the new form is created.

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 45 total points
ID: 33443420
What do you mean by "when I exit the option"? When you close the form that is called when you choose a menu item? And then that form stays open? Then you're having a problem in that form with it's release, but that has nothing to do with colors, has it?

It's quite easy like pcelba said, there's the _screen which typically is the main window of any foxpro app that has no top level form and with setting _screen.picture you set a background picture. It's not limited to _screen, each form has a .picture property you can set to a background picture.

Bye, Olaf.
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33443459
If you're using old code like DEFINE WINDOW / SHOW WINDOW you'll have blank white windows, these kind of windows are deprecated, you use forms in Visual Foxpro.

Still you can give such froms a backgroiund picture too, if you use the NAME clause of the Window command.

Bye, Olaf.
DEFINE WINDOW test1 FROM 0,0 to 10,10 NAME test2

test2.picture = Home()+"fox.bmp"

Show Window test1



* test1 is the name of the window in regard to window commands, 

* while test2 is the object name, with which you can access

* form proerties of the window, like picture.

Open in new window

0
 
LVL 2

Assisted Solution

by:FEOX
FEOX earned 40 total points
ID: 33443471
Try adding the attached snippet to your code.

To show the background image, add this code (should be part of your start-up routine):

  MAIN_HomeDir = "<folder where MAIN.BMP, MAIN.JPG or MAIN.GIF resides>"
  Do MAINBMP_Start

To hide the background image, add this code (should be part of your clean-up routine before QUIT):

  Do MAINBMP_End

The idea behide the code is to create a non-Desktop Form (MainBmpWin) with an Image (MainImg) who follows the size of the main window.  The snippet also includes a feature that automatically sets the BackColor to the RGB color of the image's upper-left pixel.  Feel free to improvise the code.
*******************************************************************
* SHOW/HIDE MAINBMP:
*******************************************************************
#define MAINBMP_BMPFILE "main.bmp"
#define MAINBMP_JPGFILE "main.jpg"
#define MAINBMP_GIFFILE "main.gif"

PROC MAINBMP_Start
* Desc: Activates the Calendar

** MODULE VARS::

  ** CREATE MAINBMP:
  PUBLIC MainBmp
  MainBmp = CREATEOBJECT("MainBmpWin")

  IF (TYPE("MainBmp.MainImg.Picture") == "C")
    _SCREEN.LockScreen  = .T.                && Do not animate screen.
    MainBmp.Top         = -MainBmp.Height*2  && Hide Offscreen to hide maximize animation.
    MainBmp.Visible     = .T.
    MainBmp.BackColor   = _SCREEN.BackColor  && Use Main Windows Background Color
    MainBmp.WindowState = 2                  && Maximized
    _SCREEN.LockScreen  = .F.
  ENDIF

RETURN
* End of MAINBMP_Start

PROC MAINBMP_End
* Desc: Deactivates the Calendar

  IF (TYPE("MainBmp.MainImg.Picture") == "C")
    MainBmp.Release
    RELEASE MainBmp
  ENDIF

RETURN
* End of MAINBMP_End

*******************************************************************
* MODULE CLASSES:
*******************************************************************
DEFINE CLASS MainBmpWin AS Form

  ** ORIGINAL DIMENSION:
  Width  = 540
  Height = 250
  Top    = 0
  Left   = 0

  ** WINDOW CHARACTERISTICS:
  BorderStyle = 0    && No Border
  ControlBox  = .F.
  MaxButton   = .F.
  MinButton   = .F.
  TitleBar    = 0    && No Title Bar

  ** Background Color Set?
  BGColorSet  = .F.

PROC Init
* Desc: Initializes the image file.

  THIS.AddObject("MainImg","Image")
  DO CASE
    CASE (TYPE("THIS.MainImg.Picture") # "C")
    CASE (FILE(MAIN_HomeDir+MAINBMP_BMPFILE))
      THIS.MainImg.Picture = MAIN_HomeDir+MAINBMP_BMPFILE
    CASE (FILE(MAIN_HomeDir+MAINBMP_JPGFILE))
      THIS.MainImg.Picture = MAIN_HomeDir+MAINBMP_JPGFILE
    CASE (FILE(MAIN_HomeDir+MAINBMP_GIFFILE))
      THIS.MainImg.Picture = MAIN_HomeDir+MAINBMP_GIFFILE
    OTHERWISE
      THIS.RemoveObject("MainImg")
  ENDCASE

  PRIVATE RetVal
  RetVal = (TYPE("THIS.MainImg.Picture") = "C")
  IF (RetVal)
    THIS.MainImg.Stretch = 1
    THIS.Resize
    THIS.MainImg.Visible = .T.
  ENDIF

RETURN (RetVal)
ENDPROC
* End of Init

PROC Resize
* Desc: Resizes the image file.

  IF (TYPE("THIS.MainImg.Picture") = "C")
    THIS.LockScreen = .T.
    WITH THIS.MainImg
      .Top    = 0
      .Left   = 0
      .Width  = THISFORM.Width
      .Height = THISFORM.Height

      ** SET BG COLOR USING UPPER-LEFT POINT ON IMAGE:
      IF (.Visible .and. !THIS.BGColorSet)
        .Stretch = 2  && Stretch with Screen!
        n_RGB = THIS.Point(0,0)
        THIS.BackColor  = n_RGB
        THIS.BGColorSet = .T.
        .Stretch = 1  && Fit with Screen
      ENDIF

    ENDWITH
    THIS.LockScreen = .F.
  ENDIF

ENDPROC
* End of Reset

ENDDEFINE
* End of MainBmpWin

Open in new window

0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33452554
Ovecomplicated, but works ok, if you set Main_Homedir and call Mainbmp_start()

But there's little you need to do to show a streched picture, if that is the problem you have with the form or screen.picture property showing the picture tiled:

You don't need to create a form, you don't need to make the resize from a hidden position, you simply set the image visible at last (or the form)

Do that with thisform in the init() and each form will have that picture background.

Bye, Olaf.
Local loForm
loForm = _screen && (or another form, eg thisform)
with loForm
  .AddObject("imgbackground","image")
  with .imgbackground
    .ZOrder(loForm.Objects.Count-1)
    .picture = Home()+'FOX.BMP' && or any other picture
    .stretch = 2
    .width= loForm.width
    .height= loForm.height
    .visible =.t.
  endwith
endwith

Open in new window

0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33452561
With resizable forms you'll want to set the image anchor to 15, to resize with the form.

Bye, Olaf.
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33452585
If you have a base class all other forms in the app are parent classes of, you only need this in the base class, you could even do all that manually without code and other forms will inherit the background image.

Bye, Olaf.
0
 
LVL 2

Expert Comment

by:FEOX
ID: 33456018
I originally used a code similar to what you've shown, Olaf.  The problem with using the Main Window as the form containing the background image is that, with VFP 7.0, you can't trap the Resize Event of the Main Window and set the size of the image to follow that of the Main Window's.

The above class I've shared was borne out of the need to keep the background image aspect ratio intact (even when resized) and the background color blending with the image file's border (based on the image's upper left pixel color).  This can be handled by a maximized borderless form in the Main Window.

Some work-arounds were necessary to produce a seamless effect:

1. The need to get the upper-left pixel color of the image using Point(0,0) was necessary to get the image to blend with the background.  Unfortunately, that information is only available once the image is drawn.  That is why I used the first Resize event to capture this information (then never again for the succeeding resize events).

I tried using the Init Event for this, but for some reason, Point(0,0) does not show the correct color for the image's upper-left pixel (it seems that the Image has not been drawn yet during Init Event). After much testing, Point(0,0) works during the Resize Event... this prompted me to use Resize Event for both resizing the image and the one-time setting of the background window color.

2. Using stretch = 2 (stretched) ensures that Point(0,0) returns the color of the upper-left pixel of the image.  Using stretch = 1 (fit in window) keeps the aspect ratio of the image thus showing a good rendition (not distorted) of the company's logo and slogan.

All the above were done while LockScreen = .T. (no screen flickering occurs).

3. To raise a Resize Event, the window was maximized programmatically.  The only problem with this is the irritating maximize animation which prompted me to use the "hide offscreen" work-around.

The above class is what I used for my VFP 7.0 applications.  Clients have the option to change their background logo simply by changing the MAIN.BMP, MAIN.GIF or MAIN.JPG.  Thanks, Olaf for the comments.  Please feel free to revise, improve or use the above code.
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33458362
One of the complicated parts of your code:

    CASE (FILE(MAIN_HomeDir+MAINBMP_BMPFILE))
      THIS.MainImg.Picture = MAIN_HomeDir+MAINBMP_BMPFILE
    CASE (FILE(MAIN_HomeDir+MAINBMP_JPGFILE))
      THIS.MainImg.Picture = MAIN_HomeDir+MAINBMP_JPGFILE
    CASE (FILE(MAIN_HomeDir+MAINBMP_GIFFILE))
      THIS.MainImg.Picture = MAIN_HomeDir+MAINBMP_GIFFILE

Just make it one MAINPIC_PICFILE and let the customer set that to any type of pic allowed: BMP, JPG, JPEG, GIF, PNG and I think even ICO, TIF. You can also forget about the MAIN_HomeDir within the compiled exe, as long as pics are included within the exe the foxpro runtime looks for the file in the exe first anyway.

I see that within VFP7 you neither have anchoring (I'm sorryfor that part, forget anchor in VFP7), nor can you react to form or _screen resizes, but there is an FLL that introduces the binding to events even for VFP7:
http://www.sweetpotatosoftware.com/spsblog/CommentView,guid,f7644db8-b155-4d43-8216-4cfde233edb7.aspx

Besides that this only handles the _screen/main screen background, you need additional code like mine to cope with any form plus some resize code adjusting imgbackground width/height to form.width/height with each resize.

Bye, Olaf.
0
 

Author Closing Comment

by:shahjagat
ID: 33458895
Thanks Guys.  You have been of utmost help.  I managed to get the picture on the main screen. I initally did not go that route since I could nto figure out why it was replicating the pic so many times. But your code helped me and I got it working.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Join & Write a Comment

In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now