将位图图像加载到按钮

时间:2014-04-30 11:36:21

标签: c++ visual-c++ mfc

我正在研究遗留应用程序,我在一个对话框中添加了一个按钮(Switch / pushlike),我希望将位图图像添加到那个,获取引用的是getdlgitem(id)但是这里这个函数也要求hwnd对象, 在搜索我之前发现的代码时,他们使用了以下三个函数

environ_control->dialwindow
environ_get_active_dialogue()
environ_get_ActiveWindow()

传递到hwnd的地方,他们都没有为我工作,

我试过这样的

CButton* pButton = (CButton*)GetDlgItem(environ_get_active_dialogue(),IDD_BTN_CUSTOMRANDC );
pButton->SetBitmap((HBITMAP)Bmp1);

它在第二行提供调试断言失败,请帮助,功能代码是

SYMBOLIC JOB_PSNUP::nup_init_nup_dialog( void )

{

    int arrTabs[8];

arrTabs[0] = 6;
arrTabs[1] = 28;
arrTabs[2] = 61;
arrTabs[3] = 97;
arrTabs[4] = 137;
arrTabs[5] = 179;
arrTabs[6] = 218;

// Reset information about Preview area
m_hwndPreview = NULL;
m_hdcPreview  = NULL;
m_rFront.top = m_rFront.bottom = m_rFront.left = m_rFront.right = 0;
m_rBack.top = m_rBack.bottom = m_rBack.left = m_rBack.right = 0;
CBitmap Bmp1, Bmp2;


m_bSetOrderMode = FALSE;
m_iCurrOrder    = 1;

environ_set_dlg_item_text_win( IDD_SNAME, "<click on page>" );

CDataExchange dx(CWnd::FromHandle(environ_get_active_dialogue()), FALSE);
ELX_INT BtnIndex;
comm->m_pXPBtn[BtnIndex = comm->GetIndexForNewBtn()] = new ECXPStyleButton;
comm->m_pXPBtn[comm->GetIndexForNewBtn()] = new ECXPStyleButton;

comm->initXPBtn(comm->m_pXPBtn[BtnIndex+0], IDD_NUMOVEUP,   &dx, IDB_MOVEUP,   "Move up");
comm->initXPBtn(comm->m_pXPBtn[BtnIndex+1], IDD_NUMOVEDOWN, &dx, IDB_MOVEDOWN, "Move down");



ECListCtrl* pListCtrl = comm->InitECListCtrl(IDD_NULIST, _T("Order,70;Side,50;Number,60;H.Offset,60;V.Offset,60;Constant,60;Forms,50"));    
pListCtrl->GetHeaderCtrl()->EnableWindow(FALSE);
comm->state.enSortBy2 = SORT_DOC_BY_NAME_ASC;

environ_set_resource_object_state( 0, IDD_NUCURRORDER, OBJECT_STATE_DISABLED, FALSE );
environ_set_resource_object_state( 0, IDD_NUORDERLAB, OBJECT_STATE_DISABLED, FALSE );

environ_message_handler( ENVIRON_LBSET_TAB_STOPS, (void*)IDD_NULIST, (void*)(&arrTabs));
environ_message_handler( ENVIRON_LBSET_HEXTENT, (void*)IDD_NULIST, (void*)(1000) );

comm->dial.dial_stack_fake[0] = '\0';
environ_set_string_into_resource_object( 0, IDD_NUHOFFSET, comm->dial.dial_stack_fake,  FALSE );


Bmp1.LoadBitmapA(IDB_BUTTON_ON);
Bmp2.LoadBitmapA(IDB_BUTTON_OFF);
if( environ_is_object_selected( 0, IDD_BTN_CUSTOMRANDC ))
{
    CButton* pButton = (CButton*)GetDlgItem(environ_get_active_dialogue(),IDD_BTN_CUSTOMRANDC );
    pButton->SetBitmap((HBITMAP)Bmp2);  
}
else
{
    CButton* pButton = (CButton*)GetDlgItem(environ_get_active_dialogue(),IDD_BTN_CUSTOMRANDC );
    pButton->SetBitmap((HBITMAP)Bmp1);  
}




// Total number of partitions
environ_set_dlg_item_int_win( IDD_NUTOTNUM, m_iTotal );

// On Back side
if( m_enPaperDuplex == JOB_SIMPLEX )
{
    environ_set_resource_object_state( 0, IDD_NUFRONTNUMLAB, OBJECT_STATE_HIDDEN, FALSE );

    environ_set_resource_object_state( 0, IDD_NUFRONTNUM, OBJECT_STATE_HIDDEN, FALSE );
    environ_set_resource_object_state( 0, IDD_NUBACKNUMLAB, OBJECT_STATE_HIDDEN, FALSE );
    environ_set_resource_object_state( 0, IDD_NUBACKNUM, OBJECT_STATE_HIDDEN, FALSE );
    environ_set_resource_object_state( 0, IDD_NUFRONTLAB, OBJECT_STATE_HIDDEN, FALSE );
    environ_set_resource_object_state( 0, IDD_NUBACKLAB, OBJECT_STATE_HIDDEN, FALSE );

    environ_set_dlg_item_text_win( IDD_NUTOTNUMLAB, "&Number of Partitions:" );
}
else
{
    environ_set_dlg_item_int_win( IDD_NUFRONTNUM, m_iOnFront );
    environ_set_dlg_item_int_win( IDD_NUBACKNUM, m_iOnBack );
}

// Offset units
comm->job_prop->jobprop_get_unit_name( comm->formdef.props.units, FALSE/*TRUE*/, comm->state.workstring ); // SMP
environ_set_dlg_item_text_win( IDD_UNITSTR0, comm->state.workstring );
environ_set_dlg_item_text_win( IDD_UNITSTR1, comm->state.workstring );


if( comm->job_config.flag.auto_offset_paper_partitions )
{
    environ_set_resource_object_on_or_off( 0, IDD_NUAUTOOFFSET, TRUE );
}

// List of Partitions
nup_fill_list();


m_NupDialExit = USER_CANCEL;
return( 0 );
}

1 个答案:

答案 0 :(得分:0)

采用两个参数的GetDlgItem版本返回HWND,而不是CWnd *。因此将它投射到CButton *是不正确的。而是使用GetDlgItem(IDD_BTN_CUSTOMRANDC)。