show_keys.cpp

本文介绍了一个简单的Windows应用程序示例,展示了如何使用Win32 API进行窗口注册、创建及消息处理等基本操作,并针对不同Windows版本进行了适配。

  name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-5572165936844014&dt=1194442938015&lmt=1194190197&format=336x280_as&output=html&correlator=1194442937843&url=file%3A%2F%2F%2FC%3A%2FDocuments%2520and%2520Settings%2Flhh1%2F%E6%A1%8C%E9%9D%A2%2FCLanguage.htm&color_bg=FFFFFF&color_text=000000&color_link=000000&color_url=FFFFFF&color_border=FFFFFF&ad_type=text&ga_vid=583001034.1194442938&ga_sid=1194442938&ga_hid=1942779085&flash=9&u_h=768&u_w=1024&u_ah=740&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="336" scrolling="no" height="280" allowtransparency="allowtransparency"> 
#include <windows.h> 
#include "Show_Keys.h"


#if defined (WIN32)
 #define IS_WIN32 TRUE
#else
 #define IS_WIN32 FALSE
#endif

#define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
#define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
#define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32

HINSTANCE hInst;   // current instance

LPCTSTR lpszAppName  = "MyApp";
LPCTSTR lpszTitle    = "My Application";

BOOL RegisterWin95( CONST WNDCLASS* lpwc );

int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                      LPTSTR lpCmdLine, int nCmdShow)
{
   MSG      msg;
   HWND     hWnd;
   WNDCLASS wc;

   // Register the main application window class.
   //............................................
   wc.style         = CS_HREDRAW | CS_VREDRAW;
   wc.lpfnWndProc   = (WNDPROC)WndProc;      
   wc.cbClsExtra    = 0;                     
   wc.cbWndExtra    = 0;                     
   wc.hInstance     = hInstance;             
   wc.hIcon         = LoadIcon( hInstance, lpszAppName );
   wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
   wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
   wc.lpszMenuName  = lpszAppName;             
   wc.lpszClassName = lpszAppName;             

   if ( IS_WIN95 )
   {
      if ( !RegisterWin95( &wc ) )
         return( FALSE );
   }
   else if ( !RegisterClass( &wc ) )
      return( FALSE );

   hInst = hInstance;

   // Create the main application window.
   //....................................
   hWnd = CreateWindow( lpszAppName,
                        lpszTitle,   
                        WS_OVERLAPPEDWINDOW,
                        CW_USEDEFAULT, 0,
                        CW_USEDEFAULT, 0, 
                        NULL,             
                        NULL,             
                        hInstance,        
                        NULL              
                      );

   if ( !hWnd )
      return( FALSE );

   ShowWindow( hWnd, nCmdShow );
   UpdateWindow( hWnd );        

   while( GetMessage( &msg, NULL, 0, 0) )  
   {
      TranslateMessage( &msg );
      DispatchMessage( &msg ); 
   }

   return( msg.wParam );
}


BOOL RegisterWin95( CONST WNDCLASS* lpwc )
{
   WNDCLASSEX wcex;

   wcex.style         = lpwc->style;
   wcex.lpfnWndProc   = lpwc->lpfnWndProc;
   wcex.cbClsExtra    = lpwc->cbClsExtra;
   wcex.cbWndExtra    = lpwc->cbWndExtra;
   wcex.hInstance     = lpwc->hInstance;
   wcex.hIcon         = lpwc->hIcon;
   wcex.hCursor       = lpwc->hCursor;
   wcex.hbrBackground = lpwc->hbrBackground;
   wcex.lpszMenuName  = lpwc->lpszMenuName;
   wcex.lpszClassName = lpwc->lpszClassName;

   // Added elements for Windows 95.
   //...............................
   wcex.cbSize = sizeof(WNDCLASSEX);
   wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName,
                            IMAGE_ICON, 16, 16,
                            LR_DEFAULTCOLOR );
   
   return RegisterClassEx( &wcex );
}

LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
   switch( uMsg )
   {
      case WM_KEYDOWN :
           {
              char szName[31];
              HDC  hDC;

              InvalidateRect( hWnd, NULL, TRUE );
              UpdateWindow( hWnd );

              hDC = GetDC( hWnd );

              GetKeyNameText( lParam, szName, 30 );
              TextOut( hDC, 10, 10, szName, lstrlen( szName ) );

              ReleaseDC( hWnd, hDC );
           }
           break;

      case WM_COMMAND :
              switch( LOWORD( wParam ) )
              {
                 case IDM_ABOUT :
                        DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
                        break;

                 case IDM_EXIT :
                        DestroyWindow( hWnd );
                        break;
              }
              break;
     
      case WM_DESTROY :
              PostQuitMessage(0);
              break;

      default :
            return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
   }

   return( 0L );
}


LRESULT CALLBACK About( HWND hDlg,          
                        UINT message,       
                        WPARAM wParam,      
                        LPARAM lParam)
{
   switch (message)
   {
       case WM_INITDIALOG:
               return (TRUE);

       case WM_COMMAND:                             
               if (   LOWORD(wParam) == IDOK        
                   || LOWORD(wParam) == IDCANCEL)   
               {
                       EndDialog(hDlg, TRUE);       
                       return (TRUE);
               }
               break;
   }

   return (FALSE);
}

编译时出现以下问题:/home/lfm/ros2_ws/src/realsense-ros/realsense2_camera/src/base_realsense_node.cpp: In member function ‘void realsense2_camera::BaseRealSenseNode::setupFilters()’: /home/lfm/ros2_ws/src/realsense-ros/realsense2_camera/src/base_realsense_node.cpp:232:76: error: ‘rotation_filter’ is not a member of ‘rs2’; did you mean ‘spatial_filter’? 232 | sh_back(std::make_shared<NamedFilter>(std::make_shared<rs2::rotation_filter>(std::vector< rs2_stream >{ RS2_STREAM_DEPTH, RS2_STREAM_COLOR, RS2_STREAM_INFRARED }), _parameters, _logger)); | ^~~~~~~~~~~~~~~ | spatial_filter /home/lfm/ros2_ws/src/realsense-ros/realsense2_camera/src/base_realsense_node.cpp:232:92: error: no matching function for call to ‘make_shared<<expression error> >(std::vector<rs2_stream>)’ 232 | e_shared<NamedFilter>(std::make_shared<rs2::rotation_filter>(std::vector< rs2_stream >{ RS2_STREAM_DEPTH, RS2_STREAM_COLOR, RS2_STREAM_INFRARED }), _parameters, _logger)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/11/memory:77, from /opt/ros/humble/include/librealsense2/hpp/rs_types.hpp:18, from /opt/ros/humble/include/librealsense2/rs.hpp:8, from /home/lfm/ros2_ws/src/realsense-ros/realsense2_camera/src/../include/base_realsense_node.h:17, from /home/lfm/ros2_ws/src/realsense-ros/realsense2_camera/src/base_realsense_node.cpp:15: /usr/include/c++/11/bits/shared_ptr.h:875:5: note: candidate: ‘template<class _Tp, class ... _Args> std::shared_ptr<_Tp> std::make_shared(_Args&& ...)’ 875 | make_shared(_Args&&... __args) | ^~~~~~~~~~~ /usr/include/c++/11/bits/shared_ptr.h:875:5: note: template argument deduction/substitution failed: /home/lfm/ros2_ws/src/realsense-ros/realsense2_camera/src/base_realsense_node.cpp:232:92: error: template argument 1 is invalid 232 | e_shared<NamedFilter>(std::make_shared<rs2::rotation_filter>(std::vector< rs2_stream >{ RS2_STREAM_DEPTH, RS2_STREAM_COLOR, RS2_STREAM_INFRARED }), _parameters, _logger)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/lfm/ros2_ws/src/realsense-ros/realsense2_camera/src/base_realsense_node.cpp: In member function ‘void realsense2_camera::BaseRealSenseNode::imu_callback(rs2::frame)’: /home/lfm/ros2_ws/src/realsense-ros/realsense2_camera/src/base_realsense_node.cpp:522:71: error: ‘class rs2::motion_frame’ has no member named ‘get_combined_motion_data’ 522 | auto combined_motion_data = frame.as<rs2::motion_frame>().get_combined_motion_data(); | ^~~~~~~~~~~~~~~~~~~~~~~~ /home/lfm/ros2_ws/src/realsense-ros/realsense2_camera/src/rs_node_setup.cpp: In member function ‘void realsense2_camera::BaseRealSenseNode::CalibConfigReadService(realsense2_camera_msgs::srv::CalibConfigRead_Request_<std::allocator<void> >::SharedPtr, realsense2_camera_msgs::srv::CalibConfigRead_Response_<std::allocator<void> >::SharedPtr)’: /home/lfm/ros2_ws/src/realsense-ros/realsense2_camera/src/rs_node_setup.cpp:618:68: error: ‘class rs2::auto_calibrated_device’ has no member named ‘get_calibration_config’; did you mean ‘get_calibration_table’? 618 | res->calib_config = _dev.as<rs2::auto_calibrated_device>().get_calibration_config(); | ^~~~~~~~~~~~~~~~~~~~~~ | get_calibration_table /home/lfm/ros2_ws/src/realsense-ros/realsense2_camera/src/rs_node_setup.cpp: In member function ‘void realsense2_camera::BaseRealSenseNode::CalibConfigWriteService(realsense2_camera_msgs::srv::CalibConfigWrite_Request_<std::allocator<void> >::SharedPtr, realsense2_camera_msgs::srv::CalibConfigWrite_Response_<std::allocator<void> >::SharedPtr)’: /home/lfm/ros2_ws/src/realsense-ros/realsense2_camera/src/rs_node_setup.cpp:632:48: error: ‘class rs2::auto_calibrated_device’ has no member named ‘set_calibration_config’; did you mean ‘set_calibration_table’? 632 | _dev.as<rs2::auto_calibrated_device>().set_calibration_config(req->calib_config); | ^~~~~~~~~~~~~~~~~~~~~~ | set_calibration_table gmake[2]: *** [CMakeFiles/realsense2_camera.dir/build.make:90:CMakeFiles/realsense2_camera.dir/src/base_realsense_node.cpp.o] 错误 1 gmake[2]: *** 正在等待未完成的任务.... gmake[2]: *** [CMakeFiles/realsense2_camera.dir/build.make:118:CMakeFiles/realsense2_camera.dir/src/rs_node_setup.cpp.o] 错误 1 gmake[1]: *** [CMakeFiles/Makefile2:159:CMakeFiles/realsense2_camera.dir/all] 错误 2 gmake: *** [Makefile:146:all] 错误 2 --- Failed <<< realsense2_camera [16.8s, exited with code 2]
07-31
Starting >>> armor_detector Starting >>> image_extractor Starting >>> image_subscriber_cpp Starting >>> image_subscriber_pkg Starting >>> show_img Traceback (most recent call last):[armor_detector:cmake - 0.7s] [image_extractor:cmake - 0.7s] [image_subscriber_cpp:cmake - 0.6s] ... File "<string>", line 1, in <module> File "/home/lizhuo/.local/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 268, in run_setup exec(code, g) File "<string>", line 23 'image_subscriber' = 'image_subscriber_pkg.image_subscriber:main', ^^^^^^^^^^^^^^^^^^ SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='? --- stderr: image_subscriber_pkg Traceback (most recent call last): File "/usr/lib/python3/dist-packages/colcon_core/executor/__init__.py", line 91, in __call__ rc = await self.task(*args, **kwargs) File "/usr/lib/python3/dist-packages/colcon_core/task/__init__.py", line 93, in __call__ return await task_method(*args, **kwargs) File "/usr/lib/python3/dist-packages/colcon_ros/task/ament_python/build.py", line 51, in build setup_py_data = get_setup_data(self.context.pkg, env) File "/usr/lib/python3/dist-packages/colcon_core/task/python/__init__.py", line 20, in get_setup_data return dict(pkg.metadata[key](env)) File "/usr/lib/python3/dist-packages/colcon_ros/package_augmentation/ros_ament_python.py", line 57, in getter return get_setup_information( File "/usr/lib/python3/dist-packages/colcon_python_setup_py/package_identification/python_setup_py.py", line 249, in get_setup_information _setup_information_cache[hashable_env] = _get_setup_information( File "/usr/lib/python3/dist-packages/colcon_python_setup_py/package_identification/python_setup_py.py", line 296, in _get_setup_information result = subprocess.run( File "/usr/lib/python3.10/subprocess.py", line 526, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['/usr/bin/python3', '-c', 'import sys;from contextlib import suppress;exec("with suppress(ImportError): from setuptools.extern.packaging.specifiers import SpecifierSet");exec("with suppress(ImportError): from packaging.specifiers import SpecifierSet");from distutils.core import run_setup;dist = run_setup( \'setup.py\', script_args=(\'--dry-run\',), stop_after=\'config\');skip_keys = (\'cmdclass\', \'distclass\', \'ext_modules\', \'metadata\');data = { key: value for key, value in dist.__dict__.items() if ( not key.startswith(\'_\') and not callable(value) and key not in skip_keys and key not in dist.display_option_names )};data[\'metadata\'] = { k: v for k, v in dist.metadata.__dict__.items() if k not in (\'license_files\', \'provides_extras\')};sys.stdout.buffer.write(repr(data).encode(\'utf-8\'))']' returned non-zero exit status 1. --- Failed <<< image_subscriber_pkg [0.81s, exited with code 1] Aborted <<< show_img [0.79s] Aborted <<< image_extractor [8.06s] Aborted <<< image_subscriber_cpp [8.09s] Aborted <<< armor_detector [9.24s] Summary: 0 packages finished [10.4s] 1 package failed: image_subscriber_pkg 4 packages aborted: armor_detector image_extractor image_subscriber_cpp show_img 2 packages had stderr output: armor_detector image_subscriber_pkg Command '['/usr/bin/python3', '-c', 'import sys;from contextlib import suppress;exec("with suppress(ImportError): from setuptools.extern.packaging.specifiers import SpecifierSet");exec("with suppress(ImportError): from packaging.specifiers import SpecifierSet");from distutils.core import run_setup;dist = run_setup( \'setup.py\', script_args=(\'--dry-run\',), stop_after=\'config\');skip_keys = (\'cmdclass\', \'distclass\', \'ext_modules\', \'metadata\');data = { key: value for key, value in dist.__dict__.items() if ( not key.startswith(\'_\') and not callable(value) and key not in skip_keys and key not in dist.display_option_names )};data[\'metadata\'] = { k: v for k, v in dist.metadata.__dict__.items() if k not in (\'license_files\', \'provides_extras\')};sys.stdout.buffer.write(repr(data).encode(\'utf-8\'))']' returned non-zero exit status 1.
08-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值