sendmessage与POSTMESSAGE的区别??如何接收SENDMESSAGE的消息 - C++ Builder / Windows SDK/API
我的程序是这样的
HWND hWnd; UINT uiDataMsgNo=0x444; UINT uiReConnectMsg=0x555; UINT uiDisconnectMsg=0x666;void __fastcall TMain::FormCreate(TObject *Sender){ int ret,i; Application->OnMessage = AppMessage;}//----------------------void __fastcall TMain::InitGDW(){ try { int ret=-1; hWnd=Main->Handle; } catch(...) { }}//------------------------------------------------------void __fastcall TMain::FormShow(TObject *Sender){ PageControl1->ActivePage=TabSheet1; Main->InitGDW();}//----------------------void __fastcall TMain::AppMessage(tagMSG &Msg, bool &Handled){ // char pchPlate[30];//[OUT]车牌号码 char pchTime[20];//[OUT]车辆抓拍时间,格式为:yyyyMMddHHmmss BYTE pByteBinImage[280];//[OUT]车牌二值图 BYTE pBytePlateJpeg[200*1024];//[OUT]车牌JPEG图 UINT dwPlateJpegSize=5*1024;//[OUT]车牌JPEG图的大小 BYTE pByteCarJpeg[200*1024];//[OUT]近景车辆JPEG图 UINT dwCarJpegSize=100*1024;//[OUT]近景车辆JPEG图的大小 FILE *fp; int ret=-1; try { switch(Msg.message) { case 0x444: ret = GDW_GetVehicleInfo2AD( pchPlate, pchTime, pByteBinImage, pBytePlateJpeg, dwPlateJpegSize, pByteCarJpeg, dwCarJpegSize); if(ret==0||ret==1) { TestEdit64->Text=Trim( String(pchPlate)); GDWLbl->Caption="车牌识别成功!"; SpeedButton1->Click(); } else { GDWLbl->Caption="车牌识别失败!"+IntToStr(ret); } //显示过车时间 // SetDlgItemText(IDC_EDIT_T,""); // str = pchTime; // SetDlgItemText(IDC_EDIT_T,str); if(ret==0) //显示近景图 try { fp = fopen("near.jpg", "w+"); fwrite(pByteCarJpeg, dwCarJpegSize, 1, fp); fclose(fp); Image7->Picture->LoadFromFile("near.jpg"); // m_picnear.LoadFromFile("C:\\near.jpg"); //显示车牌JPEG fp = fopen("plate.jpg", "w+"); fwrite(pBytePlateJpeg, dwPlateJpegSize, 1, fp); fclose(fp); Image8->Picture->LoadFromFile("plate.jpg"); // m_plate.LoadFromFile("C:\\plate.jpg"); //显示二值图 GDW_WriteBinBmp("bin.bmp",pByteBinImage);//注意:此接口也已在动态库中,可直接调用 // Image8->Picture->LoadFromFile("bin.bmp"); // m_bin.LoadFromFile("C:\\bin.bmp"); } catch(...) { } try { } catch(...) { } /* //显示近景图 fp = fopen("C:\\near.jpg", "w+"); fwrite(pByteCarJpeg, dwCarJpegSize, 1, fp); fclose(fp); // Image7->Picture->LoadFromFile("C:\\near.jpg"); // m_picnear.LoadFromFile("C:\\near.jpg"); //显示车牌JPEG fp = fopen("C:\\plate.jpg", "w+"); fwrite(pBytePlateJpeg, dwPlateJpegSize, 1, fp); fclose(fp); // Image8->Picture->LoadFromFile("C:\\plate.jpg"); // m_plate.LoadFromFile("C:\\plate.jpg"); //显示二值图 GDW_WriteBinBmp("C:\\bin.bmp",pByteBinImage);//注意:此接口也已在动态库中,可直接调用 // m_bin.LoadFromFile("C:\\bin.bmp"); */ break; case 0x555: break; case 0x666: break; } } catch(...) { // }}void __fastcall TMain::Button9Click(TObject *Sender){ PostMessage(hWnd,0x444,0,0); //SendMessage(hWnd,0x444,0,0);}
// 也不一定需要// 你嫌那样麻烦的话,直接重载MainForm的WndProc函数// 在这个窗口的窗口过程中处理所有的消息,处理时根据id来区分// 就是直接在MainForm的头文件中声明下这个函数// 一般是 void __fastcall TMainForm::WndProc(TMessage& Msg) ;
[解决办法]