×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Cut, Copy, Paste to a Top Level Form & No Menu

Cut, Copy, Paste to a Top Level Form & No Menu

Cut, Copy, Paste to a Top Level Form & No Menu

(OP)
Hi,

How do I add cut, copy, and paste functionality to a single page VFP9 app that only uses a top level form. I do have a main.prg that starts it up. No menu of any kind.

Thanks,
Stanley

RE: Cut, Copy, Paste to a Top Level Form & No Menu

Take a look at the Help for SYS(1500).

For example:

CODE -->

SYS(1500, '_MED_PASTE', '_MEDIT') 

Similarly for Cut, Copy, etc.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Cut, Copy, Paste to a Top Level Form & No Menu

That is to programmatically paste, but that's not the problem of stynlyn, I think.

First of all realize that even such usually system wide available hotkeys for copy, cut and paste are no longer available, if you don't have any menu at all. You don't have to now add a menu to your own top level form, it is enough if those menu items are defined in a context menu, even if you never ACTIVATE it.

In the end, to save you some steps in generating a shortcut menu:

CODE

DEFINE POPUP copypaste SHORTCUT RELATIVE FROM MROW(),MCOL()
DEFINE BAR _med_copy OF copypaste PROMPT "\<Copy" ;
	KEY CTRL+C, "Ctrl+C" ;
	MESSAGE "Copies the selection onto the Clipboard"
DEFINE BAR _med_paste OF copypaste PROMPT "\<Paste" ;
	KEY CTRL+V, "Ctrl+V" ;
	MESSAGE "Pastes the contents of the Clipboard"
DEFINE BAR _med_cut OF copypaste PROMPT "Cut (<\X)" ;
	KEY CTRL+X, "Ctrl+X" ;
	MESSAGE "Removes the selection and places it onto the Clipboard" 

If you want to create this from scratch you create a menu via VFP "new" toolbar. You get there by picking New->Menu->new file->shortcut. Then to add system menu items click "Insert Bar" and yo get a choice of all system menu item sorted by menus and you can also sort it by prompt, so you find Copy in C, Paste in P, etc. You might add more than copy, paste, and cut to make more such things available. To be very clear, you don't define these items by hand and need to lookup the menu constants like _med_copy, the list of items to pick from by using "Insert Bar" will know all these constants and is your valuable time saver.

It's not a bad idea to also enable the user to use a context menu when he right clicks on your form controls, which offers options viable for that control, like these is viable for textboxes, comboboxes in combo style (not in dropdown list style), editboxes, and in general whereever a selection of text can be made in a control.

You could even design mjultiple context menus, at best one individual shortcut menu per control on your form. Actually that's a step to conform to Windows UI pepople rarely do in a VFP application, though if it would be more commonly done this wold naturally put such menu items where they belong to be. A strategy would be that activation of a control releases the current shortcut menu and defines the one for that control without activating it, as that's done by the user by a rightclick, but the options should be available also by hotkey definitions.

Just think of that everytime you do a rightclick on any application on anything and find valuable options you could use in that context there, even if the same things can be done without using the context menu. There's also no reason to not use a context menu, if you're a keyboard user, as ther is that button with a paper sheet and some lines, well no, it's not a paper sheet it symbolizes a context menu.

Chriss

RE: Cut, Copy, Paste to a Top Level Form & No Menu

One way of incorporating this as a general way of context menus in your application:

1. Design all base classes (It's a well known and mostly ignored general advice to do)
2. In all your control base classes add a method "definecontextmenu"
3. In the Gotfocus event do

CODE

This.definecontextmenu() 
4. In the rightclick event do

CODE

This.definecontextmenu()
ACTIVATE POPUP context 
The reason you don't just ACTIVATE POPUP context, but also redefine the context menu is that you don't want to show it at the position the mouse was when activating the control, but at the current mouse position MROW(),MCOL(). I know you could also define a popup once and the MOVE POPUP context TO MROW(),MCOL(), but in general, believe me, your context menu will contain items in context of the current state of the application and that control and you will also want to vary more things than just the position, like having some items and not others. So overall defining the context menu at GotFocus to have the hotkey usability is one thing and defining it at the time of the rightclick is another thing that'll pay off long term.

In the definecontextmenu method you can define your individually needed context menu. At minimum for copy&paste functionality:

CODE

DEFINE POPUP context SHORTCUT RELATIVE FROM MROW(),MCOL()
DEFINE BAR _med_copy OF context PROMPT "\<Copy" ;
	KEY CTRL+C, "Ctrl+C" ;
	MESSAGE "Copies the selection onto the Clipboard"
DEFINE BAR _med_paste OF context PROMPT "\<Paste" ;
	KEY CTRL+V, "Ctrl+V" ;
	MESSAGE "Pastes the contents of the Clipboard"
DEFINE BAR _med_cut OF context PROMPT "Cut (<\x)" ;
	KEY CTRL+X, "Ctrl+X" ;
	MESSAGE "Removes the selection and places it onto the Clipboard" 

Doing it that way, you have it quite automatic aside from the actual context menu definition in each control. And even this would not mean you have to individually program every controls definecontextmenu, this code could be the default in all base control classes, so you only override this with an individual menu when you have some more specific items you want to offer to the user.

Chriss

RE: Cut, Copy, Paste to a Top Level Form & No Menu

And even if you decide against the context menu implementation in your application, just define one POPUP once at startup, never activate it, and the items with a hotkey definition work throughout all of your application.

Chriss

RE: Cut, Copy, Paste to a Top Level Form & No Menu

(OP)
Hi,

Quote (Mike)


Take a look at the Help for SYS(1500).

Quote (Chris)


That is to programmatically paste, but that's not the problem of stynlyn, I think.

Chris is correct as I attempted something similar, and the help specifically says...

Quote (VFP Help)


User-defined menu items and disabled system menu items cannot be activated with SYS(1500).

I could never get it to work, and since I have no menus, then read this help article, I gave up on that and asked here.

The needed functionality is the same as for any other windows app. Select the text, then cut or copy or paste over the selected.

Chris's reply will do it and actually has more power and at the individual control level. I didn't need that much power, just simple cut, copy, and paste.

For now, "scope creep" solved my need for this as I went away from the Top Level form as Desktop, to a plain form within the _Screen object with a custom menu made for the app that does a lot more than cut, copy, paste.

Thanks Chris as I can see using your suggestion for other functions as well via the context menu.

Stanley

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close