BitBlt() in Child Wnd's OnPoint() failed.

Hi all,

I have created a window(without title bar) class with image manipulating functionalities. Just I want to show this window as part of another window, that is with in a window just like controls.

I know to display as a separate window. But I just want to show as part of parent window, like a control.

I hope my question is clear.
I am using Visual Studio 2005.

:)
Purusothaman A


Answer this question

BitBlt() in Child Wnd's OnPoint() failed.

  • ShaneShowers

    Thank you viorel.

    But I am not yet clear.
    Is it simply enough to pass parent window as parameter and specify WS_CHILD style to a class derived from CWnd/CDialog
    Will this embed my CWnd/CDialog derived class's object into another window

    Can u show me a small example (pseudo)code snippet

    Sorry for asking more.
    Because I already tried, could not get desired result, displayed as a seperate window.

    :)
    Purusothaman A

  • Chandrakanttt

    Use SetParent(HWND hChild, HWND hParent). You have to be careful because the new parent window have to send all the necessary messages to the child window in order for this to work properly. Additionally, your child window will disappear from the task bar because it behaves now as a child control.

  • neotom

    I think you should create your window with WS_CHILD style, but without styles specific to separate windows. When you create it with CreateWindow function, specify the parent window as a parameter. The proper place for creating child controls is the handler for WM_CREATE or WM_INITDIALOG notifications.

     

    I hope this helps.


  • Dan_Brownlow

    I would try without parent "CWnd::OnPaint();". I hope this helps.


  • droujav

    Thanks Viorel.

    It works!

    :)
    Purusothaman A

  • sandyJ

    child CWnd, got shown in dialog box as a child control.

    myCWnd.h file:
    ============
    #pragma once


    // myCWnd

    class myCWnd : public CWnd
    {
    HBITMAP hBmp;
    CBitmap ObjBmp;
    DECLARE_DYNAMIC(myCWnd)

    public:
    myCWnd();
    virtual ~myCWnd();
    afx_msg void OnPaint();

    protected:
    DECLARE_MESSAGE_MAP()
    };

    myCWnd.cpp file
    ==============
    // myCWnd.cpp : implementation file
    //

    #include "stdafx.h"
    #include "myCWnd.h"


    // myCWnd

    IMPLEMENT_DYNAMIC(myCWnd, CWnd)

    myCWnd::myCWnd()
    {
    CString sBmpImgPath = "D:\\temp\\sujith_1.bmp";
    hBmp = (HBITMAP)::LoadImage(NULL, sBmpImgPath, IMAGE_BITMAP, 100, 100, LR_LOADFROMFILE | LR_CREATEDIBSECTION);

    if(!hBmp)
    MessageBox("Img Loading Failed.");
    else
    ObjBmp.Attach(hBmp);
    }

    myCWnd::~myCWnd()
    {
    }


    BEGIN_MESSAGE_MAP(myCWnd, CWnd)
    ON_WM_PAINT()
    END_MESSAGE_MAP()



    // myCWnd message handlers
    afx_msg void myCWnd::OnPaint()
    {
    CWnd::OnPaint();

    if(hBmp)
    {
    CPaintDC dc(this);
    CDC memDC;

    memDC.CreateCompatibleDC(&dc);
    memDC.SelectObject(&ObjBmp);

    dc.BitBlt(10, 10, 100, 100, &memDC, 0, 0, SRCCOPY);
    }
    }

    Declaration in Dialog's header file:
    ==========================
    myCWnd obj;

    from Dialog's OnInitDialog()
    ======================
    obj.Create(NULL, "Sample", WS_VISIBLE|WS_VSCROLL|WS_CHILD|WS_BORDER, CRect(100,100,200,200), this, 132422);

    myCWnd's OnPaint gets called.
    BitBlt() returned 1.
    but no out put.
    I verified that image loading is always successfull.
    And MessageBox() in myCWnd's constructor never displayed.

    I am using Visual Studio 2005.
    Pls point out me where I am wrong.

    Waiting for valuable suggestions.

    Thankyou.

    :)
    Purusothaman A


  • BitBlt() in Child Wnd's OnPoint() failed.