windows的消息循環

發表于:2013-06-21來源:Csdn作者:terrycanny點擊數: 標簽:windows
GetMesssge函數的返回值可非零、零或-1,應避免如下代碼出現: [cpp] view plaincopyprint? while (GetMessage( lpMsg, hWnd, 0, 0))

  GetMesssge函數的返回值可非零、零或-1,應避免如下代碼出現:

  [cpp] view plaincopyprint?

  while (GetMessage( lpMsg, hWnd, 0, 0))

  {

  TranslateMessage(&Msg);

  DispatchMessage(&Msg);

  }

  while (GetMessage( lpMsg, hWnd, 0, 0))

  {

  TranslateMessage(&Msg);

  DispatchMessage(&Msg);

  }

  -1返回值的可能性表示這樣的代碼會導致致命的應用程序錯誤。

  可修改為:

  [cpp] view plaincopyprint?

  while(GetMessage(&Msg, NULL, 0, 0) > 0)

  {

  TranslateMessage(&Msg);

  DispatchMessage(&Msg);

  }

  while(GetMessage(&Msg, NULL, 0, 0) > 0)

  {

  TranslateMessage(&Msg);

  DispatchMessage(&Msg);

  }

  或

  [cpp] view plaincopyprint?

  BOOL bRet;

  while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)

  {

  if (bRet == -1)

  {

  // handle the error and possibly exit

  }

  else

  {

  TranslateMessage(&msg);

  DispatchMessage(&msg);

  }

  }

原文轉自:http://blog.csdn.net/terrycanny/article/details/8622492

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97