Author Topic: 请教:windows 7系统关闭时,ofw程序如何获取消息,并在获取到关机消息的同时执行某条特定语句  (Read 4893 times)

JSVSTX

  • Newbie
  • *
  • Posts: 17
最近在折腾系统关机的时候,通过ofw程序给单片机发送一条指令(serial.writeBytes(bytesHexToWater,10);)第一尝试如下, 不被响应:
if (SetConsoleCtrlHandler(PHANDLER_ROUTINE(CTRL_SHUTDOWN_EVENT),true))
{
   serial.writeBytes(bytesHexToWater,10);
}
第二尝试如下:

LRESULT CALLBACK WindowProc(UINT message, WPARAM wParam, LPARAM lParam){
   // TODO: Add your specialized code here and/or call the base class
   testApp getAppClass;
   if ( message ==  WM_QUERYENDSESSION ) //Windows关机消息
   {
      getAppClass.serial.writeBytes(getAppClass.bytesHexToWater,10);
      cout<<"just comeHere everytimes"<<endl;
      return false;
   }
   //return WindowProc(message, wParam, lParam);
   cout<<"just comeHere everytimes"<<endl;
}

ofw程序直接走不到这片代码之中,至于自带的exit(),exitApp()均没有使用成功。。。鉴于某初学无术,百思不得解,特发此贴,敬请各位高人走过路过顺便看看,不吝赐教,指点一二,小生感激不尽!

vinjn

  • Moderator 版主
  • Hero Member
  • *****
  • Posts: 587
ofw is based on glut
glut has its own WindowProc
In order to let ofw use your WindowProc, you need to let ofw know it.

For details, plz refer to this ofw topic
http://forum.openframeworks.cc/index.php?topic=22.msg2098#msg2098


vinjn

  • Moderator 版主
  • Hero Member
  • *****
  • Posts: 587
不管我有没有解决你的问题,都应该回一声吧

JSVSTX

  • Newbie
  • *
  • Posts: 17
不管我有没有解决你的问题,都应该回一声吧
老大,不好意思。我最近比较忙,上hudo的比较少。问题后来我找到了lib里面的设置,添加了系统关机指令到MSG里面,同时执行关闭程序进程指令,最后通过析构函数达到了目的的。非常感谢您的帮助。

Tags: