Using Win32 functions in Visual FoxPro Image Gallery
Device Context
..msdn
ChangeDisplaySettings
CreateCompatibleDC
CreateDC
DeleteDC
DeleteObject
EnumDisplayDevices
EnumDisplaySettings
GetDC
GetDeviceCaps
GetObject
GetObjectType
ReleaseDC
SelectObject
Code examples:
Bitmap Class for Visual FoxPro application
Converting twips to pixels and vice versa
Copying picture of the active form to the Clipboard using Enhanced Metafile API functions
Creating a clipping region from the path selected into the device context of a form
Creating a window using CreateWindowEx function
Displaying animated images on FoxPro form with BitBlt and StretchBlt functions
Displaying bitmap using the AlphaBlend function
Displaying the associated icons and descriptions for files and folders
Drawing a rectangle using Windows regular edges and borders
Drawing a window caption using the DrawCaption routine
Drawing cursors for the classes defined by the system (preregistered): BUTTON, EDIT, LISTBOX etc.
Drawing icons associated with the VFP main window
Drawing standard Windows icons
Drawing Windows frame controls using the DrawFrameControl function
Drawing Windows predefined bitmaps using the LoadBitmap functions
Form Magnifier
GDI+ fun: roach-infested desktop
GDI+: Color Transparency
GDI+: copying to the Clipboard (a) image of active FoxPro window/form, (b) image file
GDI+: Creating thumbnails to preview images in a directory
GDI+: how to make VFP controls visually shake and shudder
GDI+: saving image of FoxPro form to graphics file (BMP, GIF, JPG, PNG, TIF)
GDI+: Scrolling through large image using the mouse
GDI+: sending image of FoxPro form to printer
How to change the name and the size of the font in the MessageBox dialog
How to copy the image of a form to the Clipboard using Bitmap API functions
How to display picture stored in enhanced-format metafile (*.emf)
How to find which fonts Windows uses for drawing captions, menus and message boxes
How to make a VFP form fading out when released (GDI version)
How to make a VFP form fading out when released (GDI+ version)
How to play AVI file on the _screen
How to print a bitmap file
How to print FoxPro form
How to print FoxPro form -- II
How to print picture stored in enhanced-format metafile (*.emf)
How to put a horizontal text scrolling on the form (a news line)
How to put a vertical text scrolling on the form (a movie cast)
How to view icons stored in executable files (Icon Viewer)
How to view icons stored in executable files (Icon Viewer) - II
Obtaining the bounding rectangle for the specified device context
Placing an arbitrary rectangular area of main VFP window on the Clipboard
Placing On-screen Alert on top of all windows
Printing text on the client area of the main VFP window
Printing text on the main VFP window
Printing text with the Escape function
Reading metrics for the currently selected font
Retrieving graphic capabilities of your display
Splash Screen for the VFP application
Storing content of the Clipboard to a bitmap file
Storing screen shot of a form to bitmap file
Storing screen shot of a form to enhanced metafile (*.emf)
Subclassing CommandButton control to create BackColor property
Using Font and Text functions
Using FrameRgn for displaying system colors
Using GetNearestColor
Using the DrawText function
Using the GradientFill function
Using the LoadImage function to have a bitmap file loaded and displayed on VFP main window
Vertical Label control
GDI+: how to make VFP controls visually shake and shudder

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
Shuddering control may appear a good way to get user`s immediate attention. For example, when Purchase Order form opens, and the shipping date is not entered or overdue, the textbox hosting this value may start vibrate and thus can be easily spotted by the user.

It starts with creating a sequence of frames and storing them in memory. Each frame is an image of the control rotated by a certain small angle. When a shaking time comes, the actual control becomes hidden and a timer starts drawing frames upon its location. In this way, an illusion is created of the control shaking with the amplitude fading in a few seconds.

flash demoflash demoSee a short demo displaying a form with several controls

Adobe Flash Player is required to view this demo.

Note that the demo is slower and less dynamic comparing to the actual form appearance.

See also:
  • Placing On-screen Alert on top of all windows
  • Flashing caption of a VFP application in the Windows task bar using FlashWindowEx
  • Scrolling text on the form horizontally (a newsreel)
  • Scrolling text on the form vertically (a movie cast)
  • Playing AVI on _screen
  • Displaying animated images
  • Form Magnifier
  •  
    SET PROCEDURE TO gdiplus ADDITIVE
     
    PUBLIC oForm As Tform
    oForm = CREATEOBJECT("Tform")
    oForm.Visible=.T.
    * end of main
     
    DEFINE CLASS Tform As Form
        Width=400
        Height=250
        Autocenter=.T.
        Caption="GDI+ Test Form"
        Picture="C:\windows\Gone Fishing.bmp"
     
        ADD OBJECT Text1 As TextBox WITH Left=10, Top=10,;
        Width=160, Height=24, Value=DATETIME()
     
        ADD OBJECT lst1 As ListBox WITH Left=10, Top=50,;
        Width=120, height=150
     
        ADD OBJECT check1 As CheckBox WITH Left=200, Top=12,;
        Autosize=.T., Backstyle=0, FontBold=.T.,;
        Caption="Use Local Settings"
     
        ADD OBJECT edit1 As EditBox WITH Left=150, Top=50,;
        Width=220, Height=150, Value=VERSION()+CHR(13)+SYS(0)
     
        ADD OBJECT cmd As CommandButton WITH Left=10, Top=210,;
        Width=80, Height=27, Caption="Buzz"
     
        ADD OBJECT buzz As Tbuzzer
        buzzindex=0
     
    PROCEDURE lst1.Init
        WITH THIS
            .AddItem("Sunday")
            .AddItem("Monday")
            .AddItem("Tuesday")
            .AddItem("Wednesday")
            .AddItem("Thursday")
            .AddItem("Friday")
            .AddItem("Saturday")
            .ListIndex=3
        ENDWITH
     
    PROCEDURE Click
        THIS.buzz.StopBuzzing
     
    PROCEDURE cmd.Click
        ThisForm.buzzindex = ThisForm.buzzindex + 1
        IF ThisForm.buzzindex > ThisForm.ControlCount
            ThisForm.buzzindex=1
        ENDIF
        LOCAL oCtrl
        oCtrl = ThisForm.Controls[ThisForm.buzzindex]
        IF LOWER(oCtrl.Name) $ "text1;lst1;check1;edit1;"
            ThisForm.buzz.buzz(oCtrl)
        ENDIF
    ENDDEFINE
     
    DEFINE CLASS Tbuzzer As Custom
    #DEFINE SRCCOPY 0xCC0020
    #DEFINE SM_CXSCREEN 0
    #DEFINE SM_CYSCREEN 1
    #DEFINE SM_CYCAPTION 4
    #DEFINE SM_CXFRAME 32
    #DEFINE SM_CYFRAME 33
     
        gdiplus=NULL
        hGraphics=NULL
        hBackground=NULL
        ctrl=NULL
        hWindow=0  && HWND of the form
        frames=NULL
     
        maxangle=7  && degree
        secondspercycle=5
        TimerInterval=15  && ms
        starttime=0
     
        absctrlleft=0
        absctrltop=0
        leftmargin=0
        rightmargin=0
        topmargin=0
        bottommargin=0
        bmpwidth=0
        bmpheight=0
     
        ADD OBJECT tm As Timer WITH Interval=0
     
    PROCEDURE Init
        THIS.declare
        THIS.gdiplus = CREATEOBJECT("gdiplusinit")
        THIS.frames = CREATEOBJECT("Tframes")
     
    PROCEDURE Destroy
        THIS.StopBuzzing
        THIS.frames.ReleaseFrames
        THIS.frames=NULL
        THIS.gdiplus=NULL
     
    PROCEDURE tm.Timer
        THIS.Parent.OnTimer
     
    PROCEDURE StartBuzzing
        WITH THIS
            .hGraphics = CREATEOBJECT("graphics", .hWindow)
            .starttime = GetTickCount()
            .tm.Interval = THIS.TimerInterval
        ENDWITH
     
    PROCEDURE StopBuzzing
        THIS.tm.Interval=0
     
        IF NOT ISNULL(THIS.hBackground)
            THIS.RestoreBackground
            THIS.hBackground=NULL
        ENDIF
        IF NOT ISNULL(THIS.hGraphics)
            THIS.hGraphics=NULL
        ENDIF
        IF NOT ISNULL(THIS.ctrl)
            THIS.ctrl.Visible=.T.
        ENDIF
     
    PROCEDURE RestoreBackground
        IF NOT ISNULL(THIS.ctrl)
            THIS.hGraphics.drawimage(THIS.hBackground,;
                THIS.ctrl.left-THIS.leftmargin+1,;
                THIS.ctrl.top-THIS.topmargin+1,;
                THIS.bmpwidth, THIS.bmpheight)
        ENDIF
     
    PROCEDURE Buzz(oControl As Control)
        IF VARTYPE(m.oControl) = "O"
            THIS.StopBuzzing
            THIS.PrepareBuzzing(oControl)
        ENDIF
        THIS.StartBuzzing
     
    PROCEDURE PrepareBuzzing(oControl As Control)
        THIS.frames.ReleaseFrames
     
        THIS.ctrl = oControl
        THIS.hWindow = ThisForm.HWND
        THIS.GetAbsCoords
     
        LOCAL ctrlBitmap As gdibitmap, hdc
        hdc = GetWindowDC(THIS.hWindow)
     
        * saving an image of the control (rectangle area)
        ctrlBitmap = CREATEOBJECT("gdibitmap",;
            THIS.ctrl.Width, THIS.ctrl.Height)
        WITH ctrlBitmap
            .graphics.GetDC
            = BitBlt(.graphics.hdc, 0,0, .imgwidth, .imgheight,;
                m.hdc, THIS.absctrlleft,THIS.absctrltop, SRCCOPY)
            .graphics.ReleaseDC
        ENDWITH
     
        * saving the background image while the control is hidden
        THIS.ctrl.Visible=.T.
        = INKEY(0.1)  && a small delay is required
        THIS.hBackground = CREATEOBJECT("gdibitmap",;
            THIS.bmpwidth, THIS.bmpheight)
        WITH THIS.hBackground
            .graphics.GetDC
            = BitBlt(.graphics.hdc, 0,0,;
                THIS.bmpwidth, THIS.bmpheight,;
                m.hdc, THIS.absctrlleft-THIS.leftmargin+1,;
                THIS.absctrltop-THIS.topmargin+1, SRCCOPY)
            .graphics.ReleaseDC
        ENDWITH
     
        = ReleaseDC(THIS.hWindow, m.hdc)
     
        LOCAL nAngle, oMatrix As gdimatrix, oFrame As Tframe
     
        * creating a sequence of frames displaying the control
        * rotated by a specified angle
        FOR nAngle=-THIS.maxangle TO THIS.maxangle STEP 0.05
            oMatrix = CREATEOBJECT("gdimatrix")
            WITH oMatrix
                * centering the axis of rotation
                .Translate(THIS.bmpwidth/2, THIS.bmpheight/2)
                .Rotate(m.nAngle)
            ENDWITH
     
            oFrame = THIS.frames.AddFrame(THIS.bmpwidth,;
                THIS.bmpheight, m.nAngle)
     
            WITH oFrame.bitmap
                * drawing the background
                .graphics.drawimage(THIS.hBackground, 0,0)
                * applying rotation transformation
                .graphics.SetTransform(oMatrix)
                * drawing the control
                .graphics.drawimage(m.ctrlBitmap,;
                    THIS.leftmargin-THIS.bmpwidth/2,;
                    THIS.topmargin-THIS.bmpheight/2)
            ENDWITH
        NEXT
     
    PROCEDURE OnTimer
        LOCAL nElapsedTime
        nElapsedTime = (GetTickCount() - THIS.starttime)/1000
     
        IF nElapsedTime > THIS.secondspercycle
            THIS.starttime = GetTickCount()
            RETURN
        ENDIF
     
        * calculating the amplitude, fading from 1 to zero
        LOCAL nArgument, nAngle
        nArgument = ((6/(nElapsedTime+3))-1) * SIN(120*nElapsedTime)
        nAngle = nArgument * THIS.maxangle
        THIS.DrawImage(m.nAngle)
     
    PROCEDURE DrawImage(nAngle)
    * draws a frame specified by angle
        LOCAL oFrame As Tframe
        oFrame = THIS.frames.GetFrameByAngle(m.nAngle * 1000)
        THIS.hGraphics.drawimage(oFrame.bitmap,;
            THIS.ctrl.left-THIS.leftmargin+1,;
            THIS.ctrl.top-THIS.topmargin+1,;
            THIS.bmpwidth-2, THIS.bmpheight-2)
     
    PROCEDURE GetAbsCoords
    * calculates coordinates and margins for the frames
    * displaying rotated control
        LOCAL oCtrl As Control, nLeft, nTop
        oCtrl = THIS.ctrl
        nLeft = oCtrl.Left
        nTop = oCtrl.Top
     
        DO WHILE oCtrl.Parent <> ThisForm
            IF TYPE("oCtrl.Parent.Left") = "N"
                nLeft = nLeft + oCtrl.Parent.Left
                nTop = nTop + oCtrl.Parent.Top
            ENDIF
            oCtrl = oCtrl.Parent
        ENDDO
     
        LOCAL nCaptionHeight, nFrameWidth, nFrameHeight
        nCaptionHeight = GetSystemMetrics(SM_CYCAPTION)
        nFrameWidth = GetSystemMetrics(SM_CXFRAME)
        nFrameHeight = GetSystemMetrics(SM_CYFRAME)
     
        THIS.absctrlleft = m.nLeft + m.nFrameWidth
        THIS.absctrltop = m.nTop + m.nCaptionHeight + m.nFrameHeight
     
        STORE 5 TO THIS.leftmargin, THIS.rightmargin,;
            THIS.topmargin, THIS.bottommargin
     
        THIS.bmpwidth=THIS.ctrl.Width + THIS.leftmargin + THIS.rightmargin
        THIS.bmpheight=THIS.ctrl.Height + THIS.topmargin + THIS.bottommargin
     
    PROCEDURE declare
        DECLARE INTEGER GetSystemMetrics IN user32 INTEGER nIndex
        DECLARE INTEGER GetWindowDC IN user32 INTEGER hWindow
        DECLARE INTEGER ReleaseDC IN user32 INTEGER hwindow, INTEGER hdc
        DECLARE INTEGER GetTickCount IN kernel32
     
        DECLARE INTEGER BitBlt IN gdi32;
            INTEGER hDestDC, INTEGER x, INTEGER y,;
            INTEGER nWidth, INTEGER nHeight, INTEGER hSrcDC,;
            INTEGER xSrc, INTEGER ySrc, INTEGER dwRop
     
    ENDDEFINE
     
    DEFINE CLASS Tframes As Collection  && collection of frames
     
    PROCEDURE Destroy
        THIS.ReleaseFrames
     
    PROCEDURE AddFrame(nWidth, nHeight, nAngle)
        LOCAL obj As Tframe
        obj = CREATEOBJECT("Tframe", nWidth, nHeight, nAngle)
        THIS.Add(obj)
        obj=NULL
    RETURN THIS.GetLastFrame()
     
    PROCEDURE ReleaseFrames
        DO WHILE THIS.Count > 0
            THIS.Remove(1)
        ENDDO
     
    FUNCTION GetLastFrame() As Tframe
    RETURN THIS.GetFrame(THIS.Count)
     
    FUNCTION GetFrame(nIndex) As Tframe
    RETURN IIF(BETWEEN(m.nIndex, 1,THIS.Count), THIS.Item(m.nIndex), NULL)
     
    FUNCTION GetFrameByAngle(nAngle As Number) As Tframe
        LOCAL nIndex, nDiff, nMinDiff, nResult
        nMinDiff=999
        nResult=1
     
        FOR nIndex=1 TO THIS.Count
            nDiff = ABS(THIS.Item(nIndex).angle - m.nAngle)
            IF nDiff < m.nMinDiff
                nMinDiff = m.nDiff
                nResult = m.nIndex
                IF m.nMinDiff <= 5
                    EXIT
                ENDIF
            ENDIF
        NEXT
    RETURN THIS.GetFrame(m.nResult)
     
    ENDDEFINE
     
    DEFINE CLASS Tframe As Relation
        angle=0  && rotation angle
        bitmap=NULL  && gdibitmap
     
    PROCEDURE Init(nWidth, nHeight, nAngle)
        THIS.bitmap = CREATEOBJECT("gdibitmap", m.nWidth, m.nHeight)
        THIS.angle = m.nAngle * 1000  && to eliminate decimals
     
    ENDDEFINE
     
     
     

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    8119 bytes  
    Created: 2007-03-11 12:19:56  
    Modified: 2007-03-22 09:40:55  
    Visits in 7 days: 83  
    Listed functions:
    BitBlt
    GetSystemMetrics
    GetTickCount
    GetWindowDC
    ReleaseDC
    Printer friendly API declarations
    My comment:
    The code is based on custom GDI+ class. Download the class module first and save it in gdiplus.prg file.

    Math function similar to this is used to form a shaking pattern for control.
    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-2013 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.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (50.16.17.90)
    2.03 hrs.Example: 'How to create non-blocking Winsock server'
    Language: 'C++'
     Example: 'How to block the PrintScreen key'
    3.3 hrs.Examples
    Page 12
     Example: 'Downloading files from the FTP server using InternetReadFile'
    3.76 hrs.Function: 'GdipCreateFromHDC'
     Example: 'Sending email messages with Simple MAPI'
    4.74 hrs.Function: 'SHRegOpenUSKey'
    Function group: 'Registry'
    8.49 hrs.Example: 'Winsock: retrieving the host information corresponding to a network address'
     
    Function group: 'Atom'
    10.57 hrs.Function: 'RegCreateKeyEx'
    Function group: 'Registry'
    Google
    Advertise here!