Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to ping a remote site using ICMP API calls
How to control Adobe Reader 9.0 (SDI mode) from VFP application
Creating a console window for Visual FoxPro application
How to convert a bitmap file to monochrome format (1 bpp)
Using FoxTray ActiveX control: System Tray Icon and menu attached to VFP form
How to copy the image of a form to the Clipboard using Bitmap API functions
Terminating all running applications from a VFP program
Dragging files from Explorer window and dropping them on FoxPro control (requires VFP9)
Detecting changes in connections to removable drives (VFP9)
Moving shortcut to a specified position on the Windows Desktop
Passing data records between VFP applications via the Clipboard
Reading and setting system access privileges for the current process
Compressing and decompressing files with Windows API Runtime Library routines
How to prevent users from accessing the Windows Desktop and from switching to other applications
How to make a VFP form fading out when released (GDI version)
How to view icons stored in executable files (Icon Viewer) - II
GDI+: reading and writing metadata in JPEG and TIFF files
How to display Windows On-Screen Keyboard
Bitmap Class for Visual FoxPro application
Finding out if the current user is the Guest account
How to print a bitmap file
How to print FoxPro form -- II
Placing On-screen Alert on top of all windows
Reading the structure of VFP main menu
How to activate Windows Calculator

User rating: 10/10 (2 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Versions:
click to open
Before you begin:
This code sample explains how to programmatically open an instance of Windows Calculator.

PUBLIC frm
frm = CreateObject("Tform")
frm.Visible = .T.

DEFINE CLASS Tform As Form
#DEFINE WM_QUIT 18
#DEFINE SW_SHOWNORMAL 1
    Width=400
    Height=200
    Caption="Activate Windows Calculator"

    ADD OBJECT cmdShow As CommandButton WITH;
        Caption="Show Calc", Height=24, Width=100,;
        Top=5, Left=10

    ADD OBJECT cmdHide As CommandButton WITH;
        Caption="Hide Calc", Height=24, Width=100,;
        Top=5, Left=112

PROCEDURE Init
    THIS.declare

PROCEDURE Destroy
    THIS._hide

PROCEDURE cmdShow.Click
    ThisForm._show

PROCEDURE cmdHide.Click
    ThisForm._hide

PROCEDURE _show
    LOCAL hWindow
    hWindow = FindWindow(Null, "Calculator")

    IF IsWindow(hWindow)=0
        = WinExec("calc.exe", SW_SHOWNORMAL)
        DOEVENTS
        hWindow = FindWindow(Null, "Calculator")
*        = SetParent(hWindow, _vfp.HWnd)
    ENDIF

    IF IsWindow(hWindow) <> 0
        = SetForegroundWindow(hWindow)  
*        = SetParent(hWindow, _vfp.HWnd)
        THIS.PasteNumber(PI())
    ENDIF

PROCEDURE _hide
    LOCAL hWindow
    hWindow = FindWindow(Null, "Calculator")
    IF IsWindow(hWindow) <> 0
        = PostMessage(hWindow, WM_QUIT, 0,0)
    ENDIF

PROCEDURE PasteNumber(cNumber)
#DEFINE WM_KEYDOWN 0x0100
#DEFINE WM_KEYUP 0x0101
#DEFINE VK_CONTROL 0x11
#DEFINE KEYEVENTF_EXTENDEDKEY 1
#DEFINE KEYEVENTF_KEYUP 2

    LOCAL hWindow
    hWindow = FindWindow(Null, "Calculator")

    IF hWindow <> 0
        * stores the number in the Clipboard
        STORE TRANSFORM(m.cNumber) TO _cliptext

        * makes Calculator the foreground window
        = SetForegroundWindow(hWindow)

        * simulates CTRL+V keystroke
        = keybd_event(VK_CONTROL, 0, 0, 0)
        = keybd_event(VkKeyScan(ASC("V")), 0, 0, 0)
        = keybd_event(VkKeyScan(ASC("V")), 0, KEYEVENTF_KEYUP, 0)
        = keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)
    ENDIF

PROTECTED PROCEDURE declare
    DECLARE INTEGER SetForegroundWindow IN user32;
        INTEGER hWindow

    DECLARE INTEGER IsWindow IN user32 INTEGER hWindow

    DECLARE INTEGER FindWindow IN user32;
        STRING lpClassName, STRING lpWindowName

    DECLARE INTEGER WinExec IN kernel32;
        STRING lpCmdLine, INTEGER nCmdShow

    DECLARE INTEGER PostMessage IN user32;
        INTEGER hWindow, INTEGER Msg,;
        STRING @wParam, INTEGER lParam

    DECLARE keybd_event IN user32;
        SHORT bVk, SHORT bScan, INTEGER dwFlags,;
        INTEGER dwExtraInfo

    DECLARE SHORT VkKeyScan IN user32 INTEGER ch

    DECLARE INTEGER SetParent IN user32;
        INTEGER hWndChild,;
        INTEGER hWndNewParent

ENDDEFINE

User rating: 10/10 (2 votes)
Rate this code sample:
  • ~
2452 bytes  
Created: 2001-07-12 12:00:00  
Modified: 2009-12-28 21:59:15  
Visits in 7 days: 99  
Listed functions:
FindWindow
IsWindow
keybd_event
PostMessage
SetForegroundWindow
SetParent
VkKeyScan
WinExec
Printer friendly API declarations
My comment:
Btw, you can use the SetParent function to make the main VFP window (_screen.hWnd or _vfp.hWnd) the parent window for the Calculator. In that case the calculator window becomes confined in the main VFP window.
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.


Copyright 2001-2017 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.6.36), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (54.146.5.196)
8 sec.Solution: 'ContextMenu ActiveX Control'
19 sec.Function: 'RemoveDirectoryTransacted'
Function group: 'File Management'
1.02 min.Example: 'Retrieving information specific to the current Time Zone'
1.17 min.Function: 'DrawIcon'
1.3 min.Function: 'mmioRead'
Function group: 'Windows Multimedia'
1.45 min.Example: 'How to retrieve adapter information for the local computer (including MAC address)'
1.6 min.Example: 'How to retrieve information about a cache entry (Internet Explorer)'
1.73 min.Example: 'Reading and setting explicit Application User Model ID for the current process (Win7)'
1.88 min.Function: 'AVIStreamLength'
Function group: 'Windows Multimedia'
2.58 min.
Function group: 'Windows Sockets 2 (Winsock)'
Google
Advertise here!