locked
Image Background for Child Window RRS feed

  • Question

  • I am very unused to windows development. I am trying to display a background image with Windows C++. I have the following code..

    //in wndproc

    case WM_CTLCOLOREDIT: if ((HWND)lParam == hRuleText) { hdc = (HDC)wParam; SetTextColor(hdc, RGB(255,0,255)); SetBkMode(hdc, TRANSPARENT);

    //(Edited to:) InvalidateRect(hRuleText, NULL, FALSE); return (LRESULT)g_rule_brush; } return DefWindowProc(hWnd, message, wParam, lParam); break;

    //in startup

    ...

    hOverlord = CreateWindowW(szWindowClassOverlord, szWindowTitleOverlord,
                    WS_OVERLAPPEDWINDOW,
                    CW_USEDEFAULT, 0, 600, 500, NULL, NULL, hInstanceOverlord, NULL);
        if(hOverlord == NULL)
        {
            Message(L"Could not create text label.");
            return false;
        }

    ...

    //uses loadimage LOADBITMAP(g_rule_bmp, L"./Images/ruletext_bg.bmp") g_rule_brush = CreatePatternBrush((HBITMAP)g_rule_bmp);

    //thought i might of needed to select the brush here but is used directly?

    //note deletes everything in destructor

    ...

    hRuleText = CreateWindowW(L"edit", L"", WS_CHILD | WS_VISIBLE | WS_DLGFRAME | ES_LEFT | ES_MULTILINE |
    ES_WANTRETURN | ES_AUTOVSCROLL,
            50, 170, 451, 135, hOverlord, (HMENU)ID_RULE_TEXT, GetModuleHandle(NULL), NULL);
    //note same image size as given in window
        if (hRuleText == NULL)
        {
            Message(L"Could not create text label.");
            return false;
        }

    I have two problems..

    a) The background image renders in the window child box but isn't rendered from 0,0 so it creates an repeated image.
    Image (it renders from some midpoint) - the HBRUSH passes the background bitmap brush for rendering. Don't know how to tell it to render the image in the proper place.

    Edit: The window pos coords for rendering this as based on the parent window and I need to change this to the client window but don't know how? - then again could just render a full image of the parent window but very annoying to update anything on it and will have problems I am sure.

    <strike>b̶)̶ ̶W̶h̶e̶n̶ ̶d̶e̶l̶e̶t̶i̶n̶g̶ ̶c̶h̶a̶r̶a̶c̶t̶e̶r̶s̶ ̶t̶h̶e̶y̶ ̶a̶r̶e̶ ̶s̶t̶i̶l̶l̶ ̶d̶i̶s̶p̶l̶a̶y̶e̶d̶ ̶(̶a̶s̶ ̶I̶ ̶s̶e̶t̶ ̶t̶h̶e̶ ̶b̶a̶c̶k̶g̶r̶o̶u̶n̶d̶ ̶o̶f̶ ̶t̶h̶e̶ ̶t̶e̶x̶t̶ ̶
    t̶o̶ ̶
    t̶r̶a̶n̶s̶p̶a̶r̶e̶n̶t̶ ̶b̶u̶t̶ ̶s̶t̶i̶l̶l̶ ̶w̶a̶n̶t̶ ̶t̶h̶a̶t̶ ̶f̶u̶n̶c̶t̶i̶o̶n̶a̶l̶i̶t̶y̶ ̶b̶u̶t̶ ̶o̶b̶v̶i̶o̶u̶s̶l̶y̶ ̶w̶i̶t̶h̶ ̶t̶h̶e̶ ̶c̶h̶a̶r̶a̶c̶t̶e̶r̶s̶ ̶b̶e̶i̶n̶g̶ ̶
    d̶e̶l̶e̶t̶e̶d̶ ̶a̶l̶s̶o̶)̶.̶
    </strike>

    ^ I have sorted the second item by adding ~ InvalidateRect(hRuleText, NULL, FALSE); into case WM_CTLCOLOREDIT: as edited above.




    Wednesday, September 17, 2014 10:22 AM