⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ew_vxworksadaptor.cpp

📁 基于Windml2.0的窗口系统原代码 , 以及和MFC CDC兼容的CDC
💻 CPP
字号:
#include "EW_VxWorksAdaptor.h"
#include "EW_VxWorksDrawInterface.h"
#include "CWMLHelp.h"
#include "cemgis.h"

WDOG_ID EW_VxWorksAdaptor::m_WatchDogId = NULL;

bool EW_VxWorksAdaptor::InitInstance()
{
	uglInitialize();	
          			
   	UGL_DEVICE_ID devId;
	UGL_EVENT_SERVICE_ID inputServiceId;
	uglDriverFind (UGL_DISPLAY_TYPE, 0, (UGL_UINT32 *)&devId); 
	uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&inputServiceId);    	
	uglInfo(devId, UGL_MODE_INFO_REQ, &m_modeInfo);
	
	//生成VxWorks画功能接口
    if(!m_pDraw)
        m_pDraw = new EW_VxworksDrawInterface(m_modeInfo.width , m_modeInfo.height);
        
        
	//初始化鼠标
	m_Mouse.Create(devId, 11  , 19, m_modeInfo.width / 2, m_modeInfo.height / 2);
	
	//创建事件处理器Id 
	m_eventRouterId = winEventRouterCreate (devId, inputServiceId);
	
	//创建应用程序环境
    m_appID = winAppCreate (m_eventRouterId, 100);
    
    //创建根窗口
    m_RootWindowId = winCreate (m_appID, 0, 0, m_modeInfo.width, m_modeInfo.height);
    winRootSet (m_eventRouterId, m_RootWindowId);
    uglDriverRegister (UGL_EVENT_ROUTER_TYPE, 0, (UGL_UINT32)m_eventRouterId);
    
	
	//调整Vxworks操作系统的轮转时间片是30时间片
	kernelTimeSlice(30);
	
	//向应用程序对象发送程序开始消息
    EW_Message Msg(EW_MSG_STARTUP);
    SendMsg(& Msg);

	//todo ...创建vxworks watch dog
    // create timer tick for stimulating EMGUI
//	if ((m_WatchDogId = wdCreate( )) != NULL){
//		wdStart (m_WatchDogId, 10000, (FUNCPTR)EW_VxWorksAdaptor::OnTimer(), 0);
//	} 
       
    //预置退出状态    
    m_bIsExit = false;
    
    return true;
}

//##ModelId=3F4E09F802BB
bool EW_VxWorksAdaptor::ExitInstance()
{
    EW_Message Msg(EW_MSG_HALT);
    SendMsg(& Msg);
        	
    if (m_pDraw){
        delete m_pDraw;
        m_pDraw = NULL;
    }
                   
    if (m_pAdaptor){    	
        delete m_pAdaptor;
        m_pAdaptor = NULL;
    }
    
    //释放基窗口
    winDestroy(m_RootWindowId);
    
    //释放地理信息对象
    CEMGIS *pEMGIS = GetCEMGIS();
	delete pEMGIS;
	
	
    //释放windml资源    
    winAppDestroy (m_appID);
	winEventRouterDestroy (m_eventRouterId);
    
    CWMLHelp::UnAllocColorClut();
	CWMLHelp::ReportRegisterClass();	
	
    uglDeinitialize();  
         
    return true;
}

//##ModelId=3F4E09F8031F
bool EW_VxWorksAdaptor::Execute()
{
    UGL_EVENT               event;
	int i;
    while (m_bIsExit != UGL_TRUE){
    	if (winEventGet (m_appID, &event, 200) != UGL_STATUS_OK)
            continue;
        ProcessEvent(event);    	
    }
    return true;
}

void EW_VxWorksAdaptor::ProcessEvent(UGL_EVENT event)
{
        switch (event.header.type)
            {
            /* draw the root window */

            case WIN_EVENT_TYPE_DRAW:
                {
                UGL_WINDOW_ID windowId;
                UGL_RECT windowRect;
                UGL_RECT imageRect;
    
                /* get window rect */

                windowId = (UGL_WINDOW_ID)event.header.objectId;
                winRectGet (windowId, &windowRect);
                UGL_RECT_MOVE_TO (windowRect, 0, 0);
				
				//向消息的目的窗口发送重绘消息			                             
            	EW_Message Msg(EW_MSG_DRAW);
            	m_pAdaptor->SendMsg(&Msg);
                                   
                //Prevent window from drawing too frequently and 
                //starving other windows on slow devices.
                	taskDelay (1);
                }
                break;

            case UGL_EVENT_TYPE_POINTER:
                {
			
                UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event;
   	             UGL_WINDOW_ID windowId = (UGL_WINDOW_ID)event.header.objectId;
				 
				 if (UGL_BUTTON1_DOWN (&event)){				 		
				 	EW_Message Msg(EW_MSG_MOUSE, FMS_LBUTTONDOWN);	
					Msg.Point.x = pInputEvent->x;
	             	Msg.Point.y = pInputEvent->y;	             
	             	m_pAdaptor->SendMsg(& Msg); 
				 }else if(UGL_BUTTON1_UP (&event)){
				 	EW_Message Msg(EW_MSG_MOUSE, FMS_LBUTTONUP);	
			       	Msg.Point.x = pInputEvent->x;
	             	Msg.Point.y = pInputEvent->y;	             
	             	m_pAdaptor->SendMsg(& Msg); 
				 }else if(UGL_BUTTON2_DOWN (&event)){
				 	EW_Message Msg(EW_MSG_MOUSE, FMS_RBUTTONDOWN);	
		            Msg.Point.x = pInputEvent->x;
	             	Msg.Point.y = pInputEvent->y;	             
	             	m_pAdaptor->SendMsg(& Msg); 
				 }else if(UGL_BUTTON2_UP (&event)){
				 	EW_Message Msg(EW_MSG_MOUSE, FMS_RBUTTONUP);	
		            Msg.Point.x = pInputEvent->x;
	             	Msg.Point.y = pInputEvent->y;	             
	             	m_pAdaptor->SendMsg(& Msg); 
				 }else{
				 //鼠标移动
				 	EW_Message Msg(EW_MSG_MOUSE, FMS_BUTTONMOVE);	
		            Msg.Point.x = pInputEvent->x;
	             	Msg.Point.y = pInputEvent->y;	             
	             	m_pAdaptor->SendMsg(& Msg); 				 
				 }//end if
				 				 									                    
                }
                break;
                
			case UGL_EVENT_TYPE_KEYBOARD:
				{
					UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event;
					UGL_WCHAR key = pInputEvent->type.keyboard.key;
					
					if(pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN){
						//VxWorks中没有对键盘的 "按下" 状态和 "弹起" 状态作区别
						//没有做过测试
						EW_Message Msg(EW_MSG_KEY, FKS_DOWN);					
	            		if ((key >= '0' && key <= '9')|| (key >= 'A' && key <= 'Z')
	                			|| (key >= 'a' && key <= 'z'))
	                		Msg.lData = key;
	            		else if (key == 13)
	                		Msg.lData = FVK_ENTER;
	            		else if (key == UGL_UNI_LEFT_ARROW)
	                		Msg.lData = FVK_LEFT;
	            		else if (key == UGL_UNI_RIGHT_ARROW)
	                		Msg.lData = FVK_RIGHT;
	                	else if (key == UGL_UNI_UP_ARROW)
	                		Msg.lData = FVK_UP;
	            		else if (key == UGL_UNI_DOWN_ARROW)
	                		Msg.lData = FVK_DOWN;	                		
	                	else if (key == UGL_UNI_PAGE_UP)
	                		Msg.lData = FVK_PAGE_UP;
	            		else if (key == UGL_UNI_PAGE_DOWN)
	                		Msg.lData = FVK_PAGE_DOWN;	                		
	                	else if (key == UGL_UNI_END)
	                		Msg.lData = FVK_END;	  
			            else if (key == UGL_UNI_DELETE)
	        		        Msg.lData = FVK_DELETE;
	            		else if (key == UGL_UNI_HORIZONTAL_TABULATION)            		
	                		Msg.lData = FVK_TAB;
	                	else if (key == UGL_UNI_ESCAPE)            		
	                		Msg.lData = FVK_ESCAPE;	
						else if (key == UGL_UNI_BACKSPACE)                		
							Msg.lData = FVK_BACKSPACE;	
	                	else 
	                		Msg.lData = key;	               	           

	            		m_pAdaptor->SendMsg(& Msg);            		
            		}else{
						EW_Message Msg(EW_MSG_KEY, FKS_UP);					
	            		if ((key >= '0' && key <= '9')|| (key >= 'A' && key <= 'Z')
	                			|| (key >= 'a' && key <= 'z'))
	                		Msg.lData = key;
	            		else if (key == 13)
	                		Msg.lData = FVK_ENTER;
	            		else if (key == UGL_UNI_LEFT_ARROW)
	                		Msg.lData = FVK_LEFT;
	            		else if (key == UGL_UNI_RIGHT_ARROW)
	                		Msg.lData = FVK_RIGHT;
	                	else if (key == UGL_UNI_UP_ARROW)
	                		Msg.lData = FVK_UP;
	            		else if (key == UGL_UNI_DOWN_ARROW)
	                		Msg.lData = FVK_DOWN;	                		
	                	else if (key == UGL_UNI_PAGE_UP)
	                		Msg.lData = FVK_PAGE_UP;
	            		else if (key == UGL_UNI_PAGE_DOWN)
	                		Msg.lData = FVK_PAGE_DOWN;	                		
	                	else if (key == UGL_UNI_END)
	                		Msg.lData = FVK_END;	  
			            else if (key == UGL_UNI_DELETE)
	        		        Msg.lData = FVK_DELETE;
	            		else if (key == UGL_UNI_HORIZONTAL_TABULATION)            		
	                		Msg.lData = FVK_TAB;
	                	else if (key == UGL_UNI_ESCAPE)            		
	                		Msg.lData = FVK_ESCAPE;	                		
						else if (key == UGL_UNI_BACKSPACE)                		
							Msg.lData = FVK_BACKSPACE;	
	                	else 
	                		Msg.lData = key;	               		
	                
	            		m_pAdaptor->SendMsg(& Msg);            		            		            	            		
            		}                      
				}
				break;
            }//end switch
}

int EW_VxWorksAdaptor::OnTimer()
{
	EW_Message Msg(EW_MSG_TIMER);
 	EW_GetAdaptor()->SendMsg(& Msg);
	wdStart (m_WatchDogId, 10000, (FUNCPTR)EW_VxWorksAdaptor::OnTimer(), 0);
	return 1;
}

void EW_VxWorksAdaptor::GetScreenSize(int *width , int *height)
{
	if(width)
		*width = m_modeInfo.width;
	if(height)
		*height = m_modeInfo.height	;
}

CDC *EW_VxWorksAdaptor::GetDC() 
{ 
	EW_VxworksDrawInterface *draw = (EW_VxworksDrawInterface *)m_pDraw;
	return draw->GetDC(); 	
}

CDC *EW_VxWorksAdaptor::GetMemDC() 
{ 
	EW_VxworksDrawInterface *draw = (EW_VxworksDrawInterface *)m_pDraw;
	return draw->GetMemDC(); 	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -