this version corrects the errors I mentioned but not your problem:
#include <windows.h>
#include <tchar.h>
#include <stdlib.h>
#include <commctrl.h>
#include "res.h"
#define DLGLEN 20
#ifndef _countof /* not defined by Pelles C */
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
#endif
enum nTabDialogs
{
#define ITEM(x) x,
#include "tab.h"
#undef ITEM
NTABS
};
static HWND hTab = NULL; // Handle to tab control.
static HWND hTabDlg[NTABS] = {0}; // Array of handle to tab dialogs.
static TCHAR szTabDialogs [][DLGLEN] = // Tab title.
{
#define ITEM(x) _T(#x),
#include "tab.h"
#undef ITEM
};
static inline void MsgErr(LPCTSTR lpErrMessage)
{
MessageBox(NULL, lpErrMessage, _T("Error"), MB_OK);
}
static INT_PTR OnCommand(HWND hDlg, WPARAM wParam, LPARAM lParam)
{
switch (LOWORD(wParam))
{
case IDCANCEL:
SendMessage(hDlg, WM_CLOSE, 0, 0);
return TRUE;
case IDOK:
MsgErr(_T("LISTAGEM CERTA"));
return TRUE;
default:
return FALSE;
}
}
static INT_PTR CALLBACK Tab1_DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static TCHAR szBuffer[MAX_PATH];
switch(uMsg)
{
case WM_COMMAND:
if(HIWORD(wParam) == BN_CLICKED)
{
switch(LOWORD(wParam))
{
case IDC_BTN_TAB1_GET:
GetWindowText(GetDlgItem(hTabDlg[TAB1], IDC_EDT1), szBuffer, _countof(szBuffer));
break;
case IDC_BTN_TAB1_SHOWMESSAGE:
SendMessage(hTabDlg[TAB1], WM_COMMAND, MAKEWPARAM(IDC_BTN_TAB1_GET, BN_CLICKED),
(LPARAM)GetDlgItem(hTabDlg[TAB1], IDC_EDT1));
if(szBuffer[0] == '\0')
{
break;
}
MessageBox(NULL, szBuffer, _T("Hello!"), MB_OK);
}
}
return TRUE;
case WM_INITDIALOG:
ZeroMemory(szBuffer, sizeof szBuffer);
return TRUE;
default:
return FALSE;
}
}
static INT_PTR CALLBACK Tab2_DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_COMMAND: /* fall through */
case WM_INITDIALOG:
return TRUE;
default:
return FALSE;
}
}
static INT_PTR OnInitMainDialog(HWND hDlg, HINSTANCE l_Inst)
{
TCITEM tci =
{
.mask = TCIF_TEXT,
.iImage = -1,
.pszText = szTabDialogs[TAB1],
.cchTextMax = _countof(szTabDialogs[TAB1])
};
TCHAR szBuffer[MAX_PATH] = {0};
LPCTSTR szTabErr = _T("Can't create tab dialog.");
hTab = GetDlgItem(hDlg, IDC_TAB);
SendMessage(hTab, TCM_INSERTITEM, TAB1, (LPARAM)&tci);
tci.pszText = szTabDialogs[TAB2];
tci.cchTextMax = _countof(szTabDialogs[TAB2]);
SendMessage(hTab, TCM_INSERTITEM, TAB2, (LPARAM)&tci);
hTabDlg[TAB1] = CreateDialogParam(l_Inst, szTabDialogs[TAB1], hTab, Tab1_DlgProc, 0);
if(hTabDlg[TAB1] == NULL)
{
MsgErr(szTabErr);
SendMessage(hDlg, WM_CLOSE, 0, 0);
}
hTabDlg[TAB2] = CreateDialogParam(l_Inst, szTabDialogs[TAB2], hTab, Tab2_DlgProc, 0);
if(hTabDlg[TAB2] == NULL)
{
MsgErr(szTabErr);
SendMessage(hDlg, WM_CLOSE, 0, 0);
}
if(SetFocus(GetDlgItem(hTabDlg[TAB1], IDC_EDT1)) == NULL)
{
return TRUE;
}
return FALSE;
}
static INT_PTR CALLBACK MainDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_COMMAND:
return OnCommand(hDlg, wParam, lParam);
case WM_CLOSE:
EndDialog(hDlg, 0);
return TRUE;
case WM_INITDIALOG:
return OnInitMainDialog(hDlg, GetModuleHandle(NULL));
case WM_NOTIFY:
switch(((LPNMHDR)lParam)->code)
{
case TCN_SELCHANGE:
{
static int iTab = 0;
int iSelTab = SendMessage(hTab, TCM_GETCURSEL, 0, 0);
if(iTab != iSelTab)
{
/* assert(iTab < NTABS && iTab >= 0 && iSelTab < NTABS && iSelTab >= 0); */
ShowWindow(hTabDlg[iTab], SW_HIDE);
ShowWindow(hTabDlg[iSelTab], SW_SHOWNORMAL);
iTab = iSelTab;
}
if(iSelTab == TAB1)
{
SetFocus(GetDlgItem(hTabDlg[TAB1], IDC_EDT1));
}
return TRUE;
}
}
}
return FALSE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
INITCOMMONCONTROLSEX icex = {sizeof icex, ICC_TAB_CLASSES | ICC_STANDARD_CLASSES};
InitCommonControlsEx(&icex);
DialogBox(hInstance, _T("MainDialog"), NULL, MainDlgProc);
return 0;
}
tab.h
ITEM(TAB1)
ITEM(TAB2)