Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 通过不同的过程设置RichEdit的文本颜色_Python_C_Winapi_User Interface_Win32gui - Fatal编程技术网

Python 通过不同的过程设置RichEdit的文本颜色

Python 通过不同的过程设置RichEdit的文本颜色,python,c,winapi,user-interface,win32gui,Python,C,Winapi,User Interface,Win32gui,我试图从不同的过程中为richedit控件(类RichEdit20W)中的特定单词设置背景色和前景色。我使用python调用了以下C代码,但失败了(SendMessage返回0)。如果我将SCF_SELECTION更改为SFC_ALL或0,它会起作用,但遗憾的是,它不符合我的需要,因为我只需要将更改应用于控件中的部分文本 代码如下: #include <Windows.h> #include <stdio.h> #include <limits.h> #inc

我试图从不同的过程中为richedit控件(类RichEdit20W)中的特定单词设置背景色和前景色。我使用python调用了以下C代码,但失败了(SendMessage返回0)。如果我将SCF_SELECTION更改为SFC_ALL或0,它会起作用,但遗憾的是,它不符合我的需要,因为我只需要将更改应用于控件中的部分文本

代码如下:

#include <Windows.h>
#include <stdio.h>
#include <limits.h>
#include <Richedit.h>

__declspec(dllexport) LRESULT SetColour(HWND hWnd, COLORREF textColor, COLORREF bgColor)
{
    CHARRANGE cr;
    cr.cpMin = 3;
    cr.cpMax = 8;

    CHARFORMAT2 cf;
    cf.cbSize = sizeof(cf);
    cf.dwMask = CFM_COLOR | CFM_BACKCOLOR;
    cf.crTextColor = textColor;
    cf.crBackColor = bgColor;

    DWORD   dwPID;
    HANDLE  hProcess;
    LPVOID  pRemoteCR;
    LPVOID  pRemoteCF;
    SIZE_T  zWritten;
    LRESULT lResult;

    GetWindowThreadProcessId(hWnd, &dwPID);
    hProcess = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, dwPID);
    //  Allocate memory on the target process & write the CHARFORMAT2 structure there
    pRemoteCR = VirtualAllocEx(hProcess, NULL, sizeof cr, MEM_COMMIT, PAGE_READWRITE);
    WriteProcessMemory(hProcess, pRemoteCR, &cr, sizeof cr, &zWritten);
    SendMessage(hWnd, EM_EXSETSEL, 0, (LPARAM)pRemoteCR);
    VirtualFreeEx(hProcess, pRemoteCR, 0, MEM_RELEASE);

    pRemoteCF = VirtualAllocEx(hProcess, NULL, sizeof cf, MEM_COMMIT, PAGE_READWRITE);
    WriteProcessMemory(hProcess, pRemoteCF, &cf, sizeof cf, &zWritten);
    lResult = SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)pRemoteCF); // SCF_SELECTION
    VirtualFreeEx(hProcess, pRemoteCF, 0, MEM_RELEASE);

    return lResult;
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD dwReason,LPVOID lpvReserved)
{
    return TRUE;
}
#包括
#包括
#包括
#包括
__declspec(dllexport)LRESULT SETCOLOR(HWND HWND,COLORREF textColor,COLORREF bgColor)
{
CHARRANGE cr;
cr.cpMin=3;
cr.cpMax=8;
CHARFORMAT2 cf;
cf.cbSize=sizeof(cf);
cf.dwMask=CFM|U颜色| CFM|U背景色;
cf.crTextColor=textColor;
cf.crBackColor=bgColor;
德沃德·德皮德;
处理hProcess;
LPVOID-pRemoteCR;
LPVOID-pRemoteCF;
书写的大小;
LRESULT LRESULT;
GetWindowThreadProcessId(hWnd和dwPID);
hProcess=OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_OPERATION,FALSE,dwPID);
//在目标进程上分配内存&在那里写入CHARFORMAT2结构
pRemoteCR=VirtualAllocEx(hProcess,NULL,cr的大小,MEM\u COMMIT,PAGE\u READWRITE);
WriteProcessMemory(hProcess、pRemoteCR和cr、cr大小和ZWRITED);
SendMessage(hWnd,EM_exsetel,0,(LPARAM)pRemoteCR);
VirtualFreeEx(HProces、pRemoteCR、0、MEM_发布);
pRemoteCF=VirtualAllocEx(hProcess,NULL,sizeof cf,MEM\u COMMIT,PAGE\u READWRITE);
WriteProcessMemory(hProcess、pRemoteCF、&cf、sizeof cf、&zwrite);
lResult=SendMessage(hWnd,EM_SETCHARFORMAT,(WPARAM)SCF_SELECTION,(LPARAM)pRemoteCF);//SCF_SELECTION
VirtualFreeEx(HProces、pRemoteCF、0、MEM_发布);
返回lResult;
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL、DWORD dwReason、LPVOID lpvReserved)
{
返回TRUE;
}