现在的位置: 首页 > 自动控制 > 工业·编程 > 正文

程序控制控件事件触发

2012-09-09 22:05 工业·编程 ⁄ 共 829字 ⁄ 字号 暂无评论

  1. 代码控制tab切换

m_tab.SetCurSel(1);

NMHDR h;
h.code = TCN_SELCHANGE;
h.idFrom = IDC_TABCTRL;
h.hwndFrom = m_tab.m_hWnd; // tab控件的句柄

::SendMessage(m_hWnd, WM_NOTIFY, (WPARAM)IDC_TABCTRL, (LPARAM)&h);

// m_hWnd为包含tab控件的对话框

2. treectrl选项切换

NMTREEVIEW tv;
memset((void*)&tv,0,sizeof(tv)); 
tv.hdr.hwndFrom = m_hWnd; 
tv.hdr.idFrom = ::GetClassLong(m_hWnd,GWL_ID);
tv.hdr.code = TVN_SELCHANGED; 
tv.action = TVN_SELCHANGED; 
tv.itemNew.hItem = hCurItem;
::SendMessage(pReceiverDlg->m_hWnd,WM_NOTIFY,(WPARAM)tv.hdr.idFrom,(LPARAM)&tv);

//pReceiverDlg->m_hWnd为包含tree控件的对话框

3. listctrl

NM_LISTVIEW listmsg;

memset(&listmsg, 0, sizeof(NM_LISTVIEW));

listmsg.hdr.hwndFrom = ::GetDlgItem(m_hWnd, IDC_LISTCTRL);

listmsg.hdr.code=NM_CLICK;

listmsg.hdr.idFrom=IDC_LISTCTRL;

listmsg.iItem = x; listmsg.iSubItem=y;

::SendMessage(m_hWnd, WM_NOTIFY, listmsg.hdr.idFrom,(LPARAM)&listmsg);

//m_hWnd为IDC_LISTCTRL的父窗口

给我留言

留言无头像?