1 void CBitDlg::OnButton4() 
{CBitmap cb;
cb.LoadBitmap(IDB_BITMAP1);
this->m_pic.SetBitmap(cb); }
为什么本来有图的,执行完反而没有图,变成空白了??2如何在dialog中动态创建一个按钮,
void CBitDlg::OnButton5() 
{CreateWindow("BUTTON","你好",WS_CHILD|WS_WISIBLE,250,100,100,this,NULL,NULL,NULL);}
语法有问题吗?各参数在那里有说明的?如何创建?3dialog窗体中没有HWND怎么办?

解决方案 »

  1.   

    void CBitDlg::OnButton4() 
    {CBitmap cb;
    cb.LoadBitmap(IDB_BITMAP1);
    this->m_pic.SetBitmap(cb); }可能是因为cb是栈内对像,一会就被FREE掉了。
    试试把cb设成为类的成员变量
      

  2.   

    没装MSDN吗?  
      Platform SDK: Windows User Interface 
    CreateWindow
    The CreateWindow function creates an overlapped, pop-up, or child window. It specifies the window class, window title, window style, and (optionally) the initial position and size of the window. The function also specifies the window's parent or owner, if any, and the window's menu. To use extended window styles in addition to the styles supported by CreateWindow, use the CreateWindowEx function. HWND CreateWindow(
      LPCTSTR lpClassName,  // registered class name
      LPCTSTR lpWindowName, // window name
      DWORD dwStyle,        // window style
      int x,                // horizontal position of window
      int y,                // vertical position of window
      int nWidth,           // window width
      int nHeight,          // window height
      HWND hWndParent,      // handle to parent or owner window
      HMENU hMenu,          // menu handle or child identifier
      HINSTANCE hInstance,  // handle to application instance
      LPVOID lpParam        // window-creation data
    );
    Parameters
    lpClassName 
    [in] Pointer to a null-terminated string or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero. 
    If lpClassName is a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, provided that the module that registers the class is also the module that creates the window. The class name can also be any of the predefined system class names. For a list of system class names, see the Res section. lpWindowName 
    [in] Pointer to a null-terminated string that specifies the window name. 
    If the window style specifies a title bar, the window title pointed to by lpWindowName is displayed in the title bar. When using CreateWindow to create controls, such as buttons, check boxes, and static controls, use lpWindowName to specify the text of the control. When creating a static control with the SS_ICON style, use lpWindowName to specify the icon name or identifier. To specify an identifier, use the syntax "#num". dwStyle 
    [in] Specifies the style of the window being created. This parameter can be a combination of window styles, plus the control styles indicated in the Res section. 

    [in] Specifies the initial horizontal position of the window. For an overlapped or pop-up window, the x parameter is the initial x-coordinate of the window's upper-left corner, in screen coordinates. For a child window, x is the x-coordinate of the upper-left corner of the window relative to the upper-left corner of the parent window's client area. 
    If this parameter is set to CW_USEDEFAULT, the system selects the default position for the window's upper-left corner and ignores the y parameter. CW_USEDEFAULT is valid only for overlapped windows; if it is specified for a pop-up or child window, the x and y parameters are set to zero. y 
    [in] Specifies the initial vertical position of the window. For an overlapped or pop-up window, the y parameter is the initial y-coordinate of the window's upper-left corner, in screen coordinates. For a child window, y is the initial y-coordinate of the upper-left corner of the child window relative to the upper-left corner of the parent window's client area. For a list box, y is the initial y-coordinate of the upper-left corner of the list box's client area relative to the upper-left corner of the parent window's client area. 
    If an overlapped window is created with the WS_VISIBLE style bit set and the x parameter is set to CW_USEDEFAULT, the system ignores the y parameter. nWidth 
    [in] Specifies the width, in device units, of the window. For overlapped windows, nWidth is either the window's width, in screen coordinates, or CW_USEDEFAULT. If nWidth is CW_USEDEFAULT, the system selects a default width and height for the window; the default width extends from the initial x-coordinate to the right edge of the screen, and the default height extends from the initial y-coordinate to the top of the icon area. CW_USEDEFAULT is valid only for overlapped windows; if CW_USEDEFAULT is specified for a pop-up or child window, nWidth and nHeight are set to zero. 
    nHeight 
    [in] Specifies the height, in device units, of the window. For overlapped windows, nHeight is the window's height, in screen coordinates. If nWidth is set to CW_USEDEFAULT, the system ignores nHeight. 
    hWndParent 
    [in] Handle to the parent or owner window of the window being created. To create a child window or an owned window, supply a valid window handle. This parameter is optional for pop-up windows. 
    Windows 2000: To create a message-only window, supply HWND_MESSAGE or a handle to an existing message-only window. hMenu 
    [in] Handle to a menu, or specifies a child-window identifier depending on the window style. For an overlapped or pop-up window, hMenu identifies the menu to be used with the window; it can be NULL if the class menu is to be used. For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window. 
    hInstance 
    Windows 95/98: [in] Handle to the instance of the module to be associated with the window. 
    Windows NT/2000: This value is ignored. lpParam 
    [in] Pointer to a value to be passed to the window through the CREATESTRUCT structure passed in the lParam parameter the WM_CREATE message. If an application calls CreateWindow to create a multiple document interface (MDI) client window, lpParam must point to a CLIENTCREATESTRUCT structure. 
    Return Values
    If the function succeeds, the return value is a handle to the new window.If the function fails, the return value is NULL. To get extended error information, call GetLastError. This function typically fails for one of the following reasons: an invalid parameter value 
    the system class was registered by a different module 
    the WH_CBT hook is installed and returns a failure code 
    the window procedure fails for WM_CREATE or WM_NCCREATE 
    Res
      

  3.   

    to mahongxi(烤鸡翅膀)(色摸) :
    果然是这么回事,还问为什么点两次就有警告呢?10分以后给你
      

  4.   

    void CBitDlg::OnButton4() 
    {CBitmap cb;
    cb.LoadBitmap(IDB_BITMAP1);
    this->m_pic.SetBitmap(cb);
    cd.detach(); //加上这一句
    }