codingdir logo sitemap sitemap |
Home
PHP
C#
C++
ANDROID
JAVA
JAVASCRIPT
PYTHON

from C++ how do I type a string to my desktop or word document on my computer (not window)


By : , Category : c++

try using SendInput

SendInput on MSDN

    INPUT ip;

    // Set up a generic keyboard event.
    ip.type = INPUT_KEYBOARD;
    ip.ki.wScan = 0; // hardware scan code for key
    ip.ki.time = 0;
    ip.ki.dwExtraInfo = 0;

    // Press the "A" key
    ip.ki.wVk = 0x41; // virtual-key code for the "a" key
    ip.ki.dwFlags = 0; // 0 for key press
    SendInput(1, &ip, sizeof(INPUT));

    // Release the "A" key
    ip.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
    SendInput(1, &ip, sizeof(INPUT));
ReLated :

Try with

$contents = str_replace('$[Client name]', $username, $contents);

first add the dll of Microsoft.Office.Interop.Word to your references then add this header file:

using Microsoft.Office.Interop.Word;

and use the following code:

Word.Application ap = new Word.Application(); 
Document document = ap.Documents.Open(@"C:TestNewDocument.docx);

You can use the NetworkListManager APIs to find if a network is connected to the internet. The example below does both that and checks to see if the network is free. You can just remove the Cost related code:

HRESULT GetFreeInternetInterface(_Out_ GUID* pInterfaceGuid)
{
    bool fCoInitialized = false;
    HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
    if (SUCCEEDED(hr))
    {
        fCoInitialized = true;
        CComPtr<INetworkListManager> pNetworkListManager; 
        hr = pNetworkListManager.CoCreateInstance(__uuidof(NetworkListManager));
        if (SUCCEEDED(hr))
        {
            CComPtr<IEnumNetworkConnections> pNetworkConnections;
            hr = pNetworkListManager->GetNetworkConnections(&pNetworkConnections);

            bool fFound = false;
            while (SUCCEEDED(hr))
            {
                CComPtr<INetworkConnection> pNetworkConnection;
                hr = pNetworkConnections->Next(1, &pNetworkConnection, nullptr);
                if (hr == S_OK)
                {
                    CComPtr<INetworkConnectionCost> pNetworkConnectionCost;
                    hr = pNetworkConnection.QueryInterface(&pNetworkConnectionCost);

                    if (SUCCEEDED(hr))
                    {
                        NLM_CONNECTIVITY nlmConnectivity = NLM_CONNECTIVITY_DISCONNECTED;
                        DWORD dwCost = NLM_CONNECTION_COST_UNKNOWN;
                        if (SUCCEEDED(pNetworkConnection->GetConnectivity(&nlmConnectivity)) &&
                            (nlmConnectivity & (NLM_CONNECTIVITY_IPV4_INTERNET | NLM_CONNECTIVITY_IPV6_INTERNET)) != 0 &&
                            SUCCEEDED(pNetworkConnectionCost->GetCost(&dwCost)) &&
                            dwCost == NLM_CONNECTION_COST_UNRESTRICTED &&
                            SUCCEEDED(pNetworkConnection->GetAdapterId(pInterfaceGuid)))
                        {
                            fFound = true;
                            break;
                        }
                    }
                }
                else hr = E_NOINTERFACE;
            }

            if (SUCCEEDED(hr) && !fFound)
                hr = E_NOINTERFACE;
        }
    }
    if (fCoInitialized) CoUninitialize();
    return hr;
}

Once you have the interface GUID and IP Helper APIs to get the interface type. Here is some code I had that looks for non-cellular networks. You can take it and modify it to do what you need:

BOOL GetAdapterAddresses(
    _Out_ PIP_ADAPTER_ADDRESSES * ppIAA
    )
{
    *ppIAA = NULL;

    DWORD len = 0;
    DWORD flags = GAA_FLAG_SKIP_ANYCAST|GAA_FLAG_SKIP_MULTICAST|GAA_FLAG_SKIP_DNS_SERVER;
    if (GetAdaptersAddresses(AF_UNSPEC, flags, NULL, NULL, &len) != ERROR_BUFFER_OVERFLOW)
        return FALSE;

    PIP_ADAPTER_ADDRESSES pIAA = (PIP_ADAPTER_ADDRESSES)LocalAlloc(LPTR, len);
    if (pIAA) {
        GetAdaptersAddresses(AF_UNSPEC, flags, NULL, pIAA, &len);
        *ppIAA = pIAA;
        return TRUE;
    }
    return FALSE;
}

bool IsNonCellularIfType(
    _In_ IFTYPE IfType
    )
{
    return // Ignore Loopback and WWAN
        IfType != IF_TYPE_SOFTWARE_LOOPBACK &&
        IfType != IF_TYPE_WWANPP &&
        IfType != IF_TYPE_WWANPP2;
}

DWORD GetNonCellularIfIndex(
    )
{
    DWORD IfIndex = (DWORD)(-1);
    PIP_ADAPTER_ADDRESSES pIAA;
    if (GetAdapterAddresses(&pIAA)) {
        PIP_ADAPTER_ADDRESSES pIAAList = pIAA;
        while (pIAA) {
            // Look for Non-Cellular interface
            if (pIAA->OperStatus == IfOperStatusUp &&
                IsNonCellularIfType(pIAA->IfType)) {
                PIP_ADAPTER_UNICAST_ADDRESS_LH pUnicastAddr = pIAA->FirstUnicastAddress;
                // Look through all unicast addresses for valid IPv4 or IPv6 addresses
                while (pUnicastAddr) {
                    LPSOCKADDR pAddr = pUnicastAddr->Address.lpSockaddr;
                    if (pAddr->sa_family == AF_INET) {
                        if (!IN4_IS_ADDR_LINKLOCAL(&((SOCKADDR_IN *)pAddr)->sin_addr)) {
                            IfIndex = pIAA->IfIndex;
                            break;
                        }
                    }
                    else if (pAddr->sa_family == AF_INET6) {
                        if (!IN6_IS_ADDR_LINKLOCAL(&((SOCKADDR_IN6 *)pAddr)->sin6_addr)) {
                            IfIndex = pIAA->IfIndex;
                            break;
                        }
                    }
                    pUnicastAddr = pUnicastAddr->Next;
                }
                // No need to keep looking any more?
                if (IfIndex != (DWORD)(-1))
                    break; // while (pIAA)
            }
            pIAA = pIAA->Next;
        }

        LocalFree(pIAAList);
    }
    return IfIndex;
}

I was able to find a solution.

Here is the code -

Dim objWord2 As Object
Set objWord2 = CreateObject("Word.Application")
objWord2.Visible = True
objWord2.Documents.Open "C:UserskmccormaDesktopFRONTCOVER.doc"

'Iterate round a list of names
For Each itm In arrNames

    Dim rngStory As Word.Range

    'Iterate through all story types in the current document
    For Each rngStory In ActiveDocument.StoryRanges
      'Iterate through all linked stories
      Do

        Dim strText As String

        ' Get the text from the current TextBox
        strText = rngStory.Text

        'Check if the current text box contains the string you are looking for
        If InStr(1, strText, "SearchText") Then

            'Overwrite the text in the TextBox
            rngStory.Text = itm

        End If

        'Get next linked story (if any)
        Set rngStory = rngStory.NextStoryRange
      Loop Until rngStory Is Nothing
    Next

    If itm & "X" <> "X" Then
        ActiveDocument.SaveAs ("C:UserskmccormaDesktopFrontCover" & itm & ".doc")
    End If

Next itm
Comments


Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © codingdir.com All Rights Reserved .