⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tabcontrol.cpp

📁 控件得用法总结
💻 CPP
字号:
#include "stdafx.h"
#include "TabControl.h"
#include "resourceppc.h"

TabControl::TabControl()
{
}
TabControl::~TabControl()
{
}

LRESULT TabControl::_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	 LRESULT lResult = 0;
    TabControl* pThis = (TabControl *) GetWindowLong(hWnd, GWL_USERDATA);

    switch (uMsg)
    {
		case WM_LBUTTONDBLCLK:
			MessageBox(pThis->m_hWnd,L"dfd",L"dfdf",0);
			switch(LOWORD(wParam))
			{
				case IDC_TREE1://选择树形结构
					switch (HIWORD(wParam))
					{
						
					}
				break;
				default:
					break;
			}
			break;
		case WM_INITDIALOG:
			pThis = (TabControl *)lParam;
			pThis->m_hWnd = hWnd;
			SetWindowLong(hWnd, GWL_USERDATA, (LONG)pThis);

			SHMENUBARINFO shmbi;   
            shmbi.cbSize = sizeof(shmbi);
            shmbi.hwndParent = hWnd;
            shmbi.dwFlags = SHCMBF_EMPTYBAR;
            SHCreateMenuBar(&shmbi);

			SHINITDLGINFO shidi;
			shidi.dwMask = SHIDIM_FLAGS;
			shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
			shidi.hDlg = hWnd;
			SHInitDialog(&shidi);
			break;

        case WM_COMMAND:
            lResult = pThis->OnCommand(HIWORD(wParam), LOWORD(wParam), (HWND) lParam);
            break;

        case WM_PAINT:
			pThis->OnPaint();
            break;
        default:
            return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }

    return lResult;
}

LRESULT TabControl::OnPaint()
{
	LPPAINTSTRUCT pps;
	/*BeginPaint(this->m_hWnd,pps);
	HWND TabhWnd=GetDlgItem(this->m_hWnd,IDC_TABControl);

	TCITEM tcItem;
	tcItem.mask = TCIF_TEXT;
	tcItem.pszText = _T("Tab #1");
	tcItem.cchTextMax=100;
	
	

	TabCtrl_InsertItem(TabhWnd,0,&tcItem);

	TCITEM tcItem1;
	tcItem1.mask=TCIF_TEXT;
	tcItem1.pszText=_T("Tab#2");
	TabCtrl_InsertItem(TabhWnd,1,&tcItem1);
	

	CreateWindow(L"BUTTON",L"选择", WS_VISIBLE, 100,  40, 40, 20, TabhWnd, NULL , NULL, NULL);*/

///////////////////创建imagelist
	//HIMAGELIST himlIcons;  // handle to new image list 
	//HICON hicon;           // handle to icon 
 //
 //   

 //   // Create a masked image list large enough to hold the icons. 
	//himlIcons = ImageList_Create(32, 32, ILC_MASK, 1, 0); 
 //
 //   // Load the icon resources, and add the icons to the image list. 
	//hicon = LoadIcon(hinst, MAKEINTRESOURCE(IDI_ICON1)); 
 //   ImageList_AddIcon(himlIcons, hicon); 
//////////////////////////////////////////////////


	//tree cotrols
	HWND TreeHwnd=GetDlgItem(this->m_hWnd,IDC_TREE1);

	TVITEM tvitem;
	tvitem.mask=TVIF_TEXT|TVIF_IMAGE;
	tvitem.pszText=L"节点一";
	tvitem.cChildren=1;
	

	TVINSERTSTRUCT tss;
	tss.hParent=TVI_ROOT;
	tss.hInsertAfter=TVI_FIRST;
	tss.item=tvitem;
	HTREEITEM htitem= TreeView_InsertItem(TreeHwnd,&tss);
	
	TVITEM tvitem1;
	tvitem1.mask=TVIF_TEXT;
	tvitem1.pszText=L"节点1.1";
	tvitem1.cChildren=1;

	TVINSERTSTRUCT tss1;
	tss1.hInsertAfter=TVI_FIRST;
	tss1.hParent=htitem;
	tss1.item=tvitem1;
	HTREEITEM htitemChiled= TreeView_InsertItem(TreeHwnd,&tss1);

	TVITEM tvitem11;
	tvitem11.mask=TVIF_TEXT;
	tvitem11.pszText=L"节点1.1.1";
	tvitem11.cChildren=0;

	TVINSERTSTRUCT tss11;
	tss11.hInsertAfter=TVI_SORT;
	tss11.hParent=htitemChiled;
	tss11.item=tvitem11;
	TreeView_InsertItem(TreeHwnd,&tss11);

	SetWindowLong(TreeHwnd, GWL_STYLE, GetWindowLong(TreeHwnd, GWL_STYLE) | TVS_HASBUTTONS|TVS_CHECKBOXES|TVS_HASLINES);//树形控件前面加上checkbox
	SendMessage(TreeHwnd,TVM_EXPAND,(WPARAM)htitemChiled,0);


	HWND CheckHwnd=GetDlgItem(this->m_hWnd,IDC_CHECK1);
	CheckDlgButton(this->m_hWnd,IDC_CHECK1,1);//设置checkbutton被选中
	int i=IsDlgButtonChecked(this->m_hWnd,IDC_CHECK1);
	TCHAR checkValue[255];
	GetDlgItemText(this->m_hWnd,IDC_CHECK1,checkValue,255);
	SendMessage(CheckHwnd,WM_GETTEXT,255,(LPARAM)checkValue);

	EndPaint(this->m_hWnd,pps);
	
	return S_OK;
}

LRESULT TabControl::OnCommand(WORD wNotifyCode, WORD wID, HWND hwndCtrl)
{
	HWND TreeHwnd=GetDlgItem(this->m_hWnd,IDC_TREE1);
	switch (wID)
	{
	case IDC_TABControl:
		switch (wNotifyCode)
		{
			
		default:
			break;

		}
		break;
	case IDC_TREE1://选择树形结构
		switch (wNotifyCode)
		{
		case WM_LBUTTONDBLCLK:
			SendMessage(TreeHwnd,TVM_GETITEM,0,0);
			break;
		}
		break;
	default:
		break;
	}
	return S_OK;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -