WM_INITDIALOG 和 WM_NOTIFY 代码段。
HWND hTabCtrl = nullptr;
HWND hCurrentTab = nullptr;
HWND hTab1 = nullptr;
LRESULT CALLBACK WINPROC(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
hTabCtrl = GetDlgItem(hWnd, IDC_TAB1);
g_hWnd = hWnd;
ShowWindow(hTab1, SW_SHOW);
switch(uMsg)
{
case WM_INITDIALOG:
{
//hInstance = 0; // Useless?
INITCOMMONCONTROLSEX ix;
ix.dwSize = sizeof(INITCOMMONCONTROLSEX);
ix.dwICC = ICC_TAB_CLASSES|ICC_UPDOWN_CLASS;
InitCommonControlsEx(&ix);
//ShowWindow(hTabCtrl, SW_SHOW);
TCITEM ti;
memset(&ti, 0, sizeof(ti));
ti.mask = TCIF_TEXT;
ti.pszText = L"Basic Options";
ti.cchTextMax = 255;
TabCtrl_InsertItem(hTabCtrl,0,&ti); //
ti.pszText = L"Antis";
TabCtrl_InsertItem(hTabCtrl,1,&ti);
TabCtrl_SetCurSel(hTabCtrl,0);
hTab1 = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DLG2), /*handle of the tab control*/ hTabCtrl, (DLGPROC)GeneralDlgPrc);
break;
}
// Macro so you don't need the crazy styled cast.
case WM_NOTIFY:
{
switch( ( ( LPNMHDR ) lParam) -> code )
{
case TCN_SELCHANGE:
{
if( TabCtrl_GetCurSel( ( ( LPNMHDR ) lParam) -> hwndFrom ) == 0 )
{
ShowWindow( hTab1, SW_SHOW );
}
else
{
}
break;
}
}
}
我试过这样,它没有出现。它覆盖了选项卡边框之一,因此它应该存在,但它在表单控件上不可见。
这是屏幕截图: http: //puu.sh/1yt1b
编辑:它有效,但位置错误,我应该手动设置位置吗?