原因:使用GetDlgItem()函数时需要先判断指针然后才可以使用。
错误代码:
//重新建一个线程,查询帧同步
DWORD WINAPI SCsync_Thread(LPVOID Lparam)
{
CTABPAGE1 * ppPage = (CTABPAGE1 *)Lparam;;// 创建指针指向当前类
ULONG SYNC;
char SSync[];
while()
{
ppPage->ReadReg(hDev, 0x08, &SYNC, );//该地址读取出来低八位是同步信息
memcpy(SSync,&SYNC,*sizeof(char));
if (SSync[] == )//说明已经同步
{
ppPage->GetDlgItem(IDC_STATIC_SCsync_green)->ShowWindow(SW_SHOW);//显示绿灯
ppPage->GetDlgItem(IDC_STATIC_SCsync_Red)->ShowWindow(SW_HIDE);
}
else
{
ppPage->GetDlgItem(IDC_STATIC_SCsync_Red)->ShowWindow(SW_SHOW);//显示红灯
ppPage->GetDlgItem(IDC_STATIC_SCsync_green)->ShowWindow(SW_HIDE);
}
} }
加上判断指针之后的正确的代码:
//重新建一个线程,查询帧同步
DWORD WINAPI SCsync_Thread(LPVOID Lparam)
{
CTABPAGE1 * ppPage = (CTABPAGE1 *)Lparam;;// 创建指针指向当前类
ULONG SYNC;
char SSync[];
while()
{
ppPage->ReadReg(hDev, 0x08, &SYNC, );//该地址读取出来低八位是同步信息
memcpy(SSync,&SYNC,*sizeof(char));
if (SSync[] == )//说明已经同步
{
if (ppPage->GetDlgItem(IDC_STATIC_SCsync_green))
ppPage->GetDlgItem(IDC_STATIC_SCsync_green)->ShowWindow(SW_SHOW);//显示绿灯
if (ppPage->GetDlgItem(IDC_STATIC_SCsync_Red))
ppPage->GetDlgItem(IDC_STATIC_SCsync_Red)->ShowWindow(SW_HIDE);
}
else
{
if (ppPage->GetDlgItem(IDC_STATIC_SCsync_Red))//判断之后才能使用该指针
ppPage->GetDlgItem(IDC_STATIC_SCsync_Red)->ShowWindow(SW_SHOW);//显示红灯
if (ppPage->GetDlgItem(IDC_STATIC_SCsync_green))
ppPage->GetDlgItem(IDC_STATIC_SCsync_green)->ShowWindow(SW_HIDE);
}
} }