偶想改变 记事本 的背景色
先是打开一个空白的记事本然后 用 FindWindow 和 GetDC 分别得到其 窗口句柄 和 设备句柄
然后该如何呢?    偶用 CreateSolidBrush 创建了一个蓝色的刷子
    可是用 Rectangle 只是在记事本中画了一个空白的黑框矩形
    其中并没有用蓝色填充,而且这个框在刷新后就没有了。如何让它一直存在并且是蓝心的,谢谢。

解决方案 »

  1.   

    重载OnPaint消息映射函数,加入填充处理。
      

  2.   

    计事本一刷新你画的东西肯定没有了,除非你装钩子拦截他的paint事件.至于为什么没填充蓝色应该是你程序的问题
      

  3.   

    偶用 FillRect 了,没反应... 汗
    哪位可以帮我写一个成功置色的代码,刷新问题先不谈,谢谢。
      

  4.   

    以下是偶的源代码,虽然是Masm32的语法,但和C的大同小异,最重要的是
    看看偶的 Api 用得对不对,很简单的几条代码,帮偶看看吧,谢谢!!
    .386 
    .model flat,stdcall 
    option casemap:none WinMain proto :DWORD,:DWORD,:DWORD,:DWORD include \masm32\include\windows.inc 
    include \masm32\include\user32.inc 
    includelib \masm32\lib\user32.lib 
    include \masm32\include\kernel32.inc 
    includelib \masm32\lib\kernel32.lib
    include \masm32\include\gdi32.inc
    includelib \masm32\lib\gdi32.libRGB macro red,green,blue
    xor eax,eax
    mov ah,blue
    shl eax,8
    mov ah,green
    mov al,red
    endm.DATA 
    WinName db "未定标题 - 记事本",0
    MsgBoxCaption  db "HoHo",0 
    MsgFormat      db '%d',0
    szBuffer       db 64 dup(?)
    TestString db "i love you",0
    rect RECT <0,0,500,500>                        <---初始化结构.DATA? 
    hWnd HINSTANCE ? 
    ps PAINTSTRUCT <>
    hdc HDC ?
    rushnew HBRUSH ?.CODE 
    start: 
        invoke FindWindow,NULL,addr WinName
        mov hWnd,eax
        invoke GetDC,hWnd
        mov hdc,eax
        RGB 255,0,0
        invoke CreateSolidBrush,eax
        invoke wsprintf, addr szBuffer, addr MsgFormat,eax
        invoke MessageBox, NULL, addr szBuffer, addr MsgBoxCaption, MB_OK 
        mov rushnew,eax
        invoke SelectObject,hdc,addr rushnew
        invoke Rectangle,hdc,0,0,500,500                
        invoke FillRect,hdc,addr rect,rushnew
        invoke ExitProcess,eax END start
      

  5.   

    不考虑刷新问题,测试成功:
    #include "stdafx.h"int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
      // TODO: Place code here.
    HWND hWnd = FindWindow(NULL, "未定标题 - 记事本"); //注意记事本窗口的标题
    if (hWnd == NULL) return 0;
    hWnd = FindWindowEx(hWnd, NULL, "Edit", NULL);
    if (hWnd == NULL) return 0;
    HDC hDC = GetDC(hWnd);
    RECT rt;
    GetClientRect(hWnd, &rt);
    FillRect(hDC, &rt, (HBRUSH)GetStockObject(BLACK_BRUSH));
    DeleteDC(hDC);
    return 0;
    }
      

  6.   

    如果要一直保持背景色,我觉得只能用hook,SetWindowLong也是不行的。