zoukankan      html  css  js  c++  java
  • 简单的窗口内容自动填充

    /****************************************************************************
    设置剪贴板文本
    ****************************************************************************/
    bool SetClipBoardText(const TCHAR* text, HWND hWnd)
    {
        assert(hWnd);
        //打开剪贴板
        if (!::OpenClipboard(hWnd))
            return false;
        //empties the clipboard and frees handles to data in the clipboard
        if (!EmptyClipboard())
        {
            CloseClipboard();
            return false;
        }
        //get text length
        int len = _tcslen(text);
        //After SetClipboardData is called, the system owns the object identified by the hMem parameter. 
        //The application can read the data, but must not free the handle or leave it locked. If the 
        //hMem parameter identifies a memory object, the object must have been allocated using the 
        //GlobalAlloc function with the GMEM_MOVEABLE and GMEM_DDESHARE flags. 
        HANDLE hClip = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (len + 1)*sizeof(TCHAR));
        if (hClip == NULL)
        {
            CloseClipboard();
            return false;
        }
        //locks a global memory object and returns a pointer to the first byte of the object's memory block
        TCHAR* pBuf = (TCHAR*)GlobalLock(hClip);
        if (pBuf == NULL)
        {
            GlobalFree(hClip);
            CloseClipboard();
            return false;
        }
    
        memcpy(pBuf, text, len*sizeof(TCHAR));
        pBuf[len] = NULL;
    
        GlobalUnlock(hClip);
        if (NULL == SetClipboardData(CF_TEXT, hClip))
        {
            GlobalFree(hClip);
            CloseClipboard();
            return false;
        }
    
        CloseClipboard();
        return true;
    }
    
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        //设置类名和窗口名
        HWND hWnd = ::FindWindow(L"ClassName",L"WindowName");
    
        if (NULL != hWnd)
        {
            ::SetForegroundWindow(hWnd);
            //RECT rc;
            //::GetWindowRect(hWnd, &rc);
            //::SetCursorPos(rc.left + 257, rc.top + 281);
            //257 + (281<<16)效果同上面三句,设置坐标,坐标可以由spy++获得
            ::SendMessage(hWnd, WM_LBUTTONDOWN,0, 257 + (281<<16));
            SetClipBoardText(_T("2433453"),hWnd);
            ::SendMessage(hWnd, WM_PASTE, 0, 0);
        }
        system("pause");
        return 0;
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    notes: the architecture of GDB
    How systems researchers build systems
    spark1.1.0源码阅读-executor
    spark1.1.0源码阅读-taskScheduler
    spark1.1.0源码阅读-dagscheduler and stage
    akka简单示例-2
    环境安装与项目配置
    安装zsh
    linux mysql 密码修改
    django-debug-toolbar 安装及配置 django性能监控及调试
  • 原文地址:https://www.cnblogs.com/ggzone/p/4786424.html
Copyright © 2011-2022 走看看