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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Put a text message in a window created in the desktop

Status
Not open for further replies.

PatMcLaughlin

Programmer
Dec 10, 2010
97
US
I am sure this is easy for most but I have spent an hour reading and searching to no avail. I have defined a window in the desktop with the Title of "File in Progress". Now I want to have it display a file name (already defined in the program as (lcOrigName)) in the window when this file is being processed. When the program moves to the next file to process, I want to change the window to display the new file name etc. My window is there, and defined as follows:
Code:
DEFINE WINDOW FileInProcess FROM 6,80 TO 10,115 IN DESKTOP TITLE 'File In Progress' DOUBLE FONT 'Courier', 16 STYLE 'BI' NOCLOSE ;

Now how do I get the text in it?
 
The right answer is "Don't do that." In VFP, there's no reason to ever DEFINE WINDOW.

Using the Form Designer, create a form and put a textbox or editbox in it. Give it the title you want (by setting the form's Caption property). Add a custom method that set's the value of the textbox/editbox.

Then, when you want this form to appear, use DO FORM with the NAME clause so you can hold onto a reference to the form. When you want to update the textbox/editbox, use that reference to call the method you added, passing the string you want to display as a parameter.

Now that I think about it, since you don't want the user to be able to change the value, you could use a label, and have the method set its Caption.

Tamar
 
Do you mean create a Label and send it to my window... At which point it appears I could "Modify Label" when it changes.
 
Pat, colleague,
No offense, but you're still thinking by the FPD categories. What Tamar meant is - place a Label object on your form object and modify its Caption property dynamically at run-time.
HTH.


Regards,

Ilya
 
What Tamar & Ilya are saying is:

1. Create a VFP FORM
2. Using the VFP FORM Tools, drop a Label object onto it.

Then in the Label object's Caption property, you can put the text you need.
Note - one way this can be done if the Form is passed a memory variable containing the desired text and then in the Form's Init Method, you would so something like:

ThisForm.lblDisplayText.Caption = cThisText

Also note that you could do the same type of thing with a Text object (make it ReadOnly) instead of a Label object, but the cThisText assignment would then be something like:

ThisForm.txtDisplayText.Value = cThisText

You might want to look over the Creating a Form Manually at the VFP tutorial site:
Good Luck,
JRB-Bldr
 
Here's a quick manual message window example...

Code:
**** create the message window and display it...
oMsg = CREATEOBJECT('desktopwindow')
oMsg.SHOW()

**** update the displayed message
oMsg.NewMessage('Your message text here....')
Code:
DEFINE CLASS desktopwindow AS FORM
  SCALEMODE =3
  TOP=45
  LEFT=35
  HEIGHT=80
  WIDTH=200
  CONTROLBOX=.T.
  KEYPREVIEW=.F.
  MAXBUTTON=.F.
  MINBUTTON=.F.
  BORDERSTYLE=2
  BORDERWIDTH=16
  DESKTOP=.F.
  ICON=_SCREEN.ICON
  WINDOWTYPE=0
  SHOWWINDOW=0
  ALWAYSONTOP=.F.
  AUTOCENTER = .T.
  LOCKSCREEN=.F.
  CLOSABLE=.T.
  titlebar = 0
  WINDOWSTATE=0

  ADD OBJECT lblMessage AS LABEL

  PROCEDURE INIT
  WITH THIS.lblMessage
    .FONTNAME = 'Tahoma'
    .FONTSIZE = 10
    .FONTBOLD = .T.
    .ALIGNMENT = 2
    .WORDWRAP = .T.
    .FORECOLOR = RGB(0,0,0)
    .BACKSTYLE = 0
    .CAPTION = []
    .VISIBLE = .T.
    .HEIGHT = 80
    .WIDTH = 200
    .TOP = 0
    .LEFT = 0
  ENDWITH
  ENDPROC

  PROCEDURE REFRESH
  THIS.lblMessage.WIDTH = THIS.WIDTH
  THIS.lblMessage.HEIGHT = THIS.HEIGHT
  ENDPROC

  PROCEDURE NewMessage
  LPARAMETERS pcText
  IF PCOUNT() > 0 .AND. TYPE('pcText') = 'C'
    THIS.lblMessage.CAPTION = pcText
  ENDIF
  THIS.REFRESH()
  ENDPROC
ENDDEFINE


Andy Snyder
SnyAc Software Services Hyperware Inc. a division of AmTech Software
 
Pat,

One point to add to the good advice you've already been given:

Make sure your form is modeless (that it, its WindowType property is 0). This is essential. If it wasn't modeless, your file operation would stop and wait until the user closed the form, which is not what you want.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
if you just want to give the user an impression of the file being processed, why noy use
WAIT WINDOW "your text" NOWAIT AT 20,30
 
Jack... using the WAIT WINDOW method is the quick and painless way to accomplish that but it also doesn't create a persistent message display window. Any movement of the mouse or a keyboard action removes the message. The display window example I gave is a persistent, modeless message window that has to be closed by the program when the programmer decides to close it.

Andy Snyder
SnyAc Software Services Hyperware Inc. a division of AmTech Software
 
The other thing about Wait Window is it totally "outs" an application as being a Foxpro application. That isn't necessarily a bad thing, but in some environments you wouldn't want to advertise it.
 
Andy, if one is processing quickly a lot of files you can put the wait window in the loop. So it is rebuilded every time again. Keystrokes and mouse movements don't matter anymore. I used it a lot. It's very easy and better than nothing.
 
You can add noclear and when done or at the end of the logic issue window clear i.e.

wait window "Processing level 1" noclear
statements...

wait window "Processing level 2" noclear

statements

window clear

You can add other options to 'wait windows' statement as mentioned in the earlier posts.

This is not a nice way to place messages as forum members expressed. But to answer your question here is the code -

define window winPrice from 10,50 to 30,90 close float title "Your Title of the Message"
activate window winPrice
@ 12,12 say "InProgress Step 1"
statements .....
@ 12,12 say "InProgress Step 2"
deactivate window winPrice

 
Another way to consider getting a persistent message box is to use MessageBox().

An example of using might be:
Code:
cMessageBoxTitle = <Whatever you want>

mcMessageTitle = cMessageBoxTitle
mcMessageText = <Your message text here>

* --- Now define which button(s) you want on the window ---
* --- OK Button Only ---
*nDialogType = 0 + 48 + 0
*  0 = OK Button Only
*  48 = Exclamation mark icon
*  0 = First button is default
* --- Yes/No Buttons ---
nDialogType = 4 + 32 + 256
*  4 = Yes and No buttons
*  32 = Question mark icon
*  256 = Second button is default

nAnswer = MESSAGEBOX(mcMessageText, nDialogType, mcMessageTitle)

* --- If you want to do something ---
* --- based on the user's button click do the following ---
* --- If you just want to use an OK button, maybe skip the following ---
IF nAnswer = 6
   * --- YES Button Clicked ---
   <Do something>
ELSE
   * --- YES Button NOT Clicked ---
   <Do something else>
ENDIF  && IF nAnswer = 6

Good Luck,
JRB-Bldr
 
Jack.... "better than nothing"... as you can see above I have offered a solution that is quite a bit better than nothing. In my early days programming with VFP and with FP 2.6 I used the wait window but I outgrew that a long time ago.

Andy Snyder
SnyAc Software Services Hyperware Inc. a division of AmTech Software
 
JRB-Bldr, surely MessageBox() is the last thing you would want in a processing loop? The user would have to constantly hit Enter to allow the processing to resume. (I suppose you could keyboard the Enter key programmatically, but then the message would be constantly flashing on and off, which is not nice.)

Personally, I think the best option is to use a modeless form, containing a suitable set of labels and/or shapes that can be updated periodically. It's a simple solution, and you can make it completely generic.

I don't often use a Wait window because .... I don't know; somehow, it's not very Windows-like. But that's just a personal opinion.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Well, you don't have to use KEYBOARD. Just pass the fourth parameter, the timeout. :)

But I agree it's the wrong way to go. Messagebox() is OK for accepting a response from a user when the application cannot proceed without that response. Of course, if the user response is *required* then the timeout is useless, which just rubs in the point that messagebox() is probably the wrong function here.
 
Mike - you are correct. I guess that I did not ready the original post carefully enough.

Yes, the Messagebox() approach would put up a window with a message, but to leave it, would take user interaction to click on a button.

I guess that I got caught up in trying to offer ALL alternatives to PatMcLaughlin instead of offering the best, applicable method to meet the specifics of their need.

Now I want to have it display a file name (already defined in the program as (lcOrigName)) in the window when this file is being processed. When the program moves to the next file to process, I want to change the window to display the new file name etc.

Far better would be WAIT WINDOW, to just show which file was being processed at the particular moment in time.

Good Luck,
JRB-Bldr
 
First and foremost, I want to thank everyone for your efforts and posts! Although you are all in agreement that I need to create a form to do this, I have spent 6 hours using what you have said and even copying and pasting the code to a new program trying to get a window to pop up and change the label. When I copied the code into the new document, and ran it using the debugger, I could step it to produce the window about 1 in 5 tries without any changes in between. I could change its size and color with the same regularity. (I changed it to red to make it stand out on my desktop and moved it up on the screen to assure it was not covered by other windows.) I finally gave up and went back and made the current window wider and printed the file name into it clearing the window and rewriting the FileName each time I changed files. It is not what I wanted but it is reliable. So thanks again from a dummy!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top