此帖出自嵌入式系统论坛
最新回复
TO:nbcool
哦.知道了.
TO 大家:
另外通过前面各位高手的指导,我把我程序总体结构改了下,下面是主体代码,大家看看这会问题多不?还有个问题就是,我发现我程序死掉可能不是我程序的事.我这边把开发板打开 过了一个晚上,今天一看 也死掉了.现在我正研究是我内核定制的事,还是 硬件问题.不过还是请大家帮我看看下面程序的结构,以前感觉我这程序没什么问题了。 可是通过这个帖子,我发现我还有很多不足,希望各位能帮我多找点问题,我会努力改进的
DWORD WINAPI Thread_ReadPlayList(LPVOID lpParam)
{
HANDLE hFileHandle;
int nWidth,nHeight;
BOOL bRes;
DWORD dwReadByte;
int nTemp,nUsedLabelItem;
hFileHandle=CreateFile(PlayListPath,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_READONLY,NULL);
if(INVALID_HANDLE_VALUE==hFileHandle)
{MessageErrorBox(GetLastError(),L"Faile Open File");}
bRes=ReadFile(hFileHandle,&nWidth,sizeof(int),&dwReadByte,NULL);
if(FALSE==bRes)
{MessageErrorBox(GetLastError(),L"Read File");}
bRes=ReadFile(hFileHandle,&nHeight,sizeof(int),&dwReadByte,NULL);
if(FALSE==bRes)
{MessageErrorBox(GetLastError(),L"Read File");}
if(nWidth!=g_nScreenWidth||nHeight!=g_nScreenHeight)
{
//传送错误信息:节目列表错误,不是当前屏幕的节目列表
MessageBoxW(NULL,L"传输的节目列表文件错误",L"Error",MB_OK);
return 1;
}
while(!g_bStop)
{
bRes=ReadFile(hFileHandle,&nTemp,sizeof(int),&dwReadByte,NULL);
if(FALSE==bRes)
{MessageErrorBox(GetLastError(),L"Read File");}
if(0==dwReadByte)//文件结束
{
bRes=CloseHandle(hFileHandle);
if(FALSE==bRes)
MessageErrorBox(GetLastError(),L"CloseFile");
{//-----------
hFileHandle=CreateFile(PlayListPath,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_READONLY,NULL);
if(INVALID_HANDLE_VALUE==hFileHandle)
{MessageErrorBox(GetLastError(),L"Faile Open File");}
bRes=ReadFile(hFileHandle,&nWidth,sizeof(int),&dwReadByte,NULL);
if(FALSE==bRes)
{MessageErrorBox(GetLastError(),L"Read File");}
bRes=ReadFile(hFileHandle,&nHeight,sizeof(int),&dwReadByte,NULL);
if(FALSE==bRes)
{MessageErrorBox(GetLastError(),L"Read File");}
}//-----------
}
switch(nTemp)
{
case CLOCK_Type:
Thread_Switch_Clock_Type(hFileHandle);
continue;
break;
case PIC_Type:
Thread_Switch_Pic_Type(hFileHandle);
break;
case LABEL_Type:
Thread_Switch_Label_Type(hFileHandle,nUsedLabelItem);
continue;
break;
case NEWNODE:
Thread_Switch_NewNode(nUsedLabelItem);
case ENDNODE:
continue;
break;
}
}//}}}
//检查未释放资源,进行释放
return 1;
void MessageErrorBox(int nError,CString strError)
{
CString str;
str.Format(L"%d",nError);
MessageBoxW(NULL,str,strError,MB_OK);
}
void Thread_Switch_Clock_Type(HANDLE hFileHandle)
{
BOOL bRes;
DWORD dwReadByte;
g_pClockNode=(Arm_Clock_SetInfo *)malloc(sizeof(Arm_Clock_SetInfo));
if(g_pClockNode==NULL)
MessageErrorBox(-1,L"Malloc");
bRes=ReadFile(hFileHandle,g_pClockNode,sizeof(Arm_Clock_SetInfo),&dwReadByte,NULL);
if(FALSE==bRes)
{MessageErrorBox(GetLastError(),L"Read File");}
hClockFont=CreateFontIndirect(&g_pClockNode->logFont);
}
void Thread_Switch_Pic_Type(HANDLE hFileHandle)
{
BOOL bRes;
DWORD dwReadByte;
g_PlayNode.nType=PIC_Type;
if(g_PlayNode.pPointer)
free(g_PlayNode.pPointer);
g_PlayNode.pPointer=malloc(sizeof(Arm_Pic_SetInfo));
if(g_PlayNode.pPointer==NULL)
MessageErrorBox(-1,L"Malloc");
bRes=ReadFile(hFileHandle,g_PlayNode.pPointer,sizeof(Arm_Pic_SetInfo),&dwReadByte,NULL);
if(FALSE==bRes)
{MessageErrorBox(GetLastError(),L"Read File");}
g_PlayNode.PathName=
(TCHAR *)malloc(((Arm_Pic_SetInfo *)g_PlayNode.pPointer)->nPathLength*sizeof(TCHAR));
if(g_PlayNode.PathName==NULL)
MessageErrorBox(-1,L"Malloc");
bRes=ReadFile(hFileHandle,g_PlayNode.PathName,sizeof(TCHAR)*((Arm_Pic_SetInfo *)g_PlayNode.pPointer)->nPathLength,
&dwReadByte,NULL);
if(FALSE==bRes)
{MessageErrorBox(GetLastError(),L"Read File");}
PlayPic();
}
void Thread_Switch_Label_Type(HANDLE hFileHandle,int &nUsedLabelItem)
{
Arm_Label_Node *pLabel;
BOOL bRes;
DWORD dwReadByte;
if(NULL==g_pLabelNode)
{
g_pLabelNode=(Arm_Label_Node *)malloc(sizeof(Arm_Label_Node));
if(g_pLabelNode==NULL)
MessageErrorBox(-1,L"Malloc");
pLabel=g_pLabelNode;
}else
{
pLabel=g_pLabelNode;
while(NULL!=pLabel->next)
pLabel=pLabel->next;
pLabel->next=(Arm_Label_Node *)malloc(sizeof(Arm_Label_Node));
if(g_pLabelNode->next==NULL)
MessageErrorBox(-1,L"Malloc");
pLabel=pLabel->next;
}
pLabel->next=NULL;
pLabel->pArm_Label_SetInfo=(Arm_Label_SetInfo *)
malloc(sizeof(Arm_Label_SetInfo));
if(pLabel->pArm_Label_SetInfo==NULL)
MessageErrorBox(-1,L"Malloc");
bRes=ReadFile(hFileHandle,pLabel->pArm_Label_SetInfo,sizeof(Arm_Label_SetInfo),&dwReadByte,NULL);
if(FALSE==bRes)
{MessageErrorBox(GetLastError(),L"Read File");}
bRes=ReadFile(hFileHandle,pLabel->tContent,sizeof(TCHAR)*pLabel->pArm_Label_SetInfo->nContentLength,&dwReadByte,NULL);
if(FALSE==bRes)
{MessageErrorBox(GetLastError(),L"Read File");}
hLabelFont[nUsedLabelItem++]=CreateFontIndirect(&pLabel->pArm_Label_SetInfo->logFont);
}
void Thread_Switch_NewNode(int &nUsedLabelItem)
{
BOOL bRes;
Arm_Label_Node *pLabel;
nUsedLabelItem=0;
for(int i=0;inext;
free(g_pLabelNode->pArm_Label_SetInfo);
free(g_pLabelNode);
g_pLabelNode=pLabel;
}
if(NULL!=g_pClockNode)
free(g_pClockNode);
g_pClockNode=NULL;
g_pLabelNode=NULL;
}
void PlayPic()
{
CIImage mage;
CString strPath;
strPath=PicPathExtent;
strPath+=g_PlayNode.PathName;
mage.Draw(g_hIImageDC,0,0,g_nScreenWidth,g_nScreenHeight,strPath);
int i=0;
while(1)
{
BitBlt(g_hMiddleDC,0,0,i,g_nScreenHeight,g_hIImageDC,g_nScreenWidth-i,0,SRCCOPY);
SendMessage(g_hWnd,MSG_COPYSCREEN,0,0[color=#FF0000]);//这里用SendMessage,不用
//PostMessage,来解决
//一个时刻只有一个地方对HDC进行操作.(个人认
//为可以,如果有不妥请指出)[/color]
Sleep(5);
i++;
if(i>=g_nScreenWidth)
break;
}
}
LRESULT CLED_PlayerDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
switch(message)
{
case MSG_COPYSCREEN:
msg_CopyScreen();
break;
}
return CDialog::WindowProc(message, wParam, lParam);
}
void CLED_PlayerDlg::msg_CopyScreen()
{
Arm_Label_Node *pLabel;
HDC hdc=::GetDC(this->m_hWnd);[color=#FF0000]//注意:这里我是用API函数做的, 如果我用MFC 做
//CDC *dc=this->GetDC();dc->BitBlt(...);ReleaseDC(dc);
//的话 会有内存泄露不知道为什么,请指教[/color]
BitBlt(g_hTopDC,0,0,g_nScreenWidth,g_nScreenHeight,g_hMiddleDC,0,0,SRCCOPY);
pLabel=g_pLabelNode;
int nItem=0;
while(NULL!=pLabel)
{
DrawLabel(pLabel,nItem++);
pLabel=pLabel->next;
}
if(NULL!=g_pClockNode)
DrawClock(g_pClockNode);
BitBlt(hdc,0,0,g_nScreenWidth,g_nScreenHeight,g_hTopDC,0,0,SRCCOPY);
::ReleaseDC(this->m_hWnd,hdc);
}复制代码
程序可以说是顺序执行的了.....但我以后还要添加别的消息响应,所以还是把读文件放到了一个单独的线程里面.
详情
回复
发表于 2008-3-4 09:35
| ||
|
||
此帖出自嵌入式系统论坛
| ||
|
||
| |
|
|
| |
|
|
| |
|
|
| |
|
|
此帖出自嵌入式系统论坛
| ||
|
||
| |
|
|
此帖出自嵌入式系统论坛
| ||
|
||
| |
|
|
此帖出自嵌入式系统论坛
| ||
|
||
此帖出自嵌入式系统论坛
| ||
|
||
| |
|
|
此帖出自嵌入式系统论坛
| ||
|
||
此帖出自嵌入式系统论坛
| ||
|
||
此帖出自嵌入式系统论坛
| ||
|
||
此帖出自嵌入式系统论坛
| ||
|
||
| |
|
|
此帖出自嵌入式系统论坛
| ||
|
||
| |
|
|
EEWorld Datasheet 技术支持