Using Win32 functions in Visual FoxPro Image Gallery
URL Monikers
..msdn
CreateURLMonikerEx
FindMediaType
IsValidURL
ObtainUserAgentString
URLDownloadToCacheFile
URLDownloadToFile
UrlMkGetSessionOption
Code examples:
Yet another modal dialog: now HTML-based
Yet another modal dialog: now HTML-based

User rating: 9/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
Before you begin:
The ShowHTMLDialog displays modal dialog that is functionally similar to the dialogs created by MessageBox and TaskDialog functions.


A very attractive feature of this dialog is its HTML-based content. The window title, and whole client part of the dialog are defined strictly in HTML terms. This is like a miniature IE window.
#DEFINE URL_MK_LEGACY 0
#DEFINE URL_MK_UNIFORM 1
DO declare

LOCAL cDlgDefinitionFile, cUrl, nUrlMoniker, cFeatures,;
    cArguments, cOutput, cDlgReturn

* the dialog definition is stored in local HTML file
cDlgDefinitionFile=LOWER(FULLPATH("dlgdefinition.html"))
IF NOT FILE(m.cDlgDefinitionFile)
    DO CreateDlgDefinitionFile WITH m.cDlgDefinitionFile
ENDIF

* create URL Moniker from the Url
cUrl=ToUnicode("file://" + m.cDlgDefinitionFile)
nUrlMoniker=0
IF CreateURLMonikerEx(0, cUrl, @nUrlMoniker, URL_MK_UNIFORM) <> 0
    RETURN  && failed
ENDIF

* ShowHTMLDialog input parameteres
cFeatures=ToUnicode("dialogWidth:340px;dialogHeight:130px;center:1;")
cArguments=ToUnicode("")
cOutput=REPLICATE(CHR(0), 256)
cDlgReturn=""

IF ShowHTMLDialog(_screen.HWnd, m.nUrlMoniker,;
        m.cArguments, m.cFeatures, @cOutput) = 0
    nAddr=buf2dword(SUBSTR(cOutput,9,4))
    IF m.nAddr <> 0
        cDlgReturn=FromUnicode( Mem2Str(nAddr) )
    ENDIF
ENDIF
? cDlgReturn
* end of main

PROCEDURE CreateDlgDefinitionFile(cFilename)
    LOCAL cHtml

* the HTML code is converted to base64 only because
* it is meant to be properly displayed on this web page;
* otherwise no need to do that
TE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J0biIgaWQ9
ImJ0bkNhbmNlbCIgdHlwZT0iU3VibWl0IiB2YWx1ZT0i
Q2FuY2VsIj4gDQo8L2Rpdj4NCjxzY3JpcHQgZm9yPSJi
dG5PayIgZXZlbnQ9Im9uY2xpY2siPg0KCXdpbmRvdy5y
ZXR1cm5WYWx1ZT0iQWdyZWUiOw0KCXdpbmRvdy5jbG9z
ZSgpOw0KPC9zY3JpcHQ+DQo8c2NyaXB0IGZvcj0iYnRu
Q2FuY2VsIiBldmVudD0ib25jbGljayI+DQoJd2luZG93
LnJldHVyblZhbHVlPSJEaXNhZ3JlZSI7DQoJd2luZG93
LmNsb3NlKCk7DQo8L3NjcmlwdD4NCjwvYm9keT4=
ENDTEXT

    * converting back from base64 to normal text
    cHtml=STRCONV(m.cHtml,14)

    * saving to HTML file
    TRY
        SET SAFETY OFF
        STRTOFILE(m.cHtml, m.cFilename)
    CATCH
    FINALLY
        SET SAFETY ON
    ENDTRY

PROCEDURE declare
    DECLARE INTEGER CreateURLMonikerEx IN urlmon;
        INTEGER pMkCtx, STRING szURL,;
        INTEGER @ppmk, LONG dwFlags

    DECLARE INTEGER ShowHTMLDialog IN mshtml;
        INTEGER hwndParent, INTEGER pMk, STRING pvarArgIn,;
        STRING pchOptions, STRING @pvarArgOut

    DECLARE RtlMoveMemory IN kernel32 As MemToStr;
        STRING @, INTEGER, INTEGER

FUNCTION buf2dword(cBuffer)
RETURN Asc(SUBSTR(cBuffer, 1,1)) + ;
    BitLShift(Asc(SUBSTR(cBuffer, 2,1)),  8) +;
    BitLShift(Asc(SUBSTR(cBuffer, 3,1)), 16) +;
    BitLShift(Asc(SUBSTR(cBuffer, 4,1)), 24)

FUNCTION ToUnicode(cStr)
RETURN STRCONV(cStr+CHR(0), 5)

FUNCTION FromUnicode(cStr)
RETURN STRTRAN(STRCONV(cStr, 6), CHR(0), "")

FUNCTION Mem2Str(nBaseAddr As Number)
#DEFINE BUFFER_SIZE 16
#DEFINE EMPTY_BUFFER REPLICATE(CHR(0), BUFFER_SIZE)
* reads Unicode string from specified memory address

    IF nBaseAddr = 0
        RETURN ""
    ENDIF

    LOCAL nCurAddr, cResult, cBuffer, nPos
    nCurAddr=nBaseAddr
    cResult=""

    DO WHILE .T.
        cBuffer = EMPTY_BUFFER
        = MemToStr(@cBuffer, nCurAddr, BUFFER_SIZE)
        nPos = AT(CHR(0)+CHR(0), cBuffer)

        IF nPos > 0
            cResult = cResult + SUBSTR(cBuffer, 1, nPos)
            RETURN cResult
        ELSE
            cResult = cResult + cBuffer
            nCurAddr = m.nCurAddr + BUFFER_SIZE
        ENDIF
    ENDDO

User rating: 9/10 (2 votes)
Rate this code sample:
  • ~
4147 bytes  
Created: 2009-12-09 16:16:35  
Modified: 2009-12-10 13:26:39  
Visits in 7 days: 112  
Listed functions:
CreateURLMonikerEx
ShowHTMLDialog
Printer friendly API declarations
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-2018 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.39), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (54.82.78.213)
14 sec.Function: 'waveInOpen'
Function group: 'Windows Multimedia'
25 sec.Function: 'CreateEllipticRgn'
Function group: 'Region'
36 sec.Function: 'InetIsOffline'
Function group: 'Shell Functions'
51 sec.Example: 'Using the FindMediaType function'
1.03 min.Function: 'SendMessage'
Function group: 'Message and Message Queue'
1.23 min.Function: 'GetPriorityClass'
Function group: 'Process and Thread'
1.47 min.Function: 'CeEnumDBVolumes'
Function group: 'Remote Application Programming (RAPI)'
1.67 min.Function: 'UpdateResource'
Function group: 'Resource'
1.83 min.Function: 'FindClose'
Function group: 'File Management'
2.03 min.Example: 'Class library providing access to the System Registry'
Google
Advertise here!