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

📄 ipcsocket.c

📁 详细的MiniGUI源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
			memcpy((void*)pCurPointer,&(pHead->rect),sizeof(RECT));			pCurPointer+=sizeof(RECT);			pHead=pHead->pNext;		}		SendMsgByServer(pStat,LMSG_IPC_CLIPRGNCHANGE,pAttachData,iAttachSize);		free(pAttachData);	}}//recalculate clip regioin of all application main window under current window void RecalClipRgnUnderThis(	const PlGUIAppStat pStat){	PlGUIAppStat pCurStat,pPrevStat;	pCurStat=pStat;	while(pCurStat){		SetInitRectClipRegion(pCurStat->pClipRgn,&pCurStat->rc);		pPrevStat=_lGUI_pAppStat;		while(pPrevStat!=pCurStat){			if(pPrevStat->bVisible)				SubtractClipRegion(pCurStat->pClipRgn,&(pPrevStat->rc));			pPrevStat=pPrevStat->pNext;		}		pCurStat=pCurStat->pNext;	}	if(IsVisible(_lGUI_pImeWindow)){		pCurStat=pStat;		while(pCurStat){			SubtractClipRegion(pCurStat->pClipRgn,&(_lGUI_pImeWindow->rect));			pCurStat=pCurStat->pNext;		}	}	if(IsVisible(_lGUI_pSkbWindow)){		pCurStat=pStat;		while(pCurStat){			SubtractClipRegion(pCurStat->pClipRgn,&(_lGUI_pSkbWindow->rect));			pCurStat=pCurStat->pNext;		}	}}//===============================================================================//****************************client*********************************************//===============================================================================//Initial ipc socket for clientBOOL InitIpcSocketClient(){	_lGUI_fdSocket=cli_conn(CS_PATH);	if(_lGUI_fdSocket<0)		return false;	pthread_create(&thread_ipcmsg,NULL,ReadMainLoopClient,(void*)&_lGUI_fdSocket);	return true;}//thread main loop for client socketvoid* ReadMainLoopClient(	void* srvfd){	void* pData;	int iSize;	int iRet;	int old_cancel_type;	int fd;	int iMsg;	fd=*((int*)srvfd);	pData=malloc(SIZE_IPC_MSG);	if(!pData)		pthread_exit(0);	//register thread cleanup function	pthread_cleanup_push(cleanup_after_malloc,pData);	pthread_cleanup_push(cleanup_after_opensock,srvfd);	while(1){		iRet = sock_read(fd,(void*)&iMsg,sizeof(int));		if(iRet==SOCKERR_CLOSED || iRet==SOCKERR_IO){			//printerror("socket error while reading type of message!");			pthread_exit(0);		}		//read the size of added data 		iRet=sock_read(fd,(void*)&iSize,sizeof(int));		if(iRet==SOCKERR_CLOSED || iRet==SOCKERR_IO){			//printerror("socket error while reading size of message!");			pthread_exit(0);		}		//read added data		iRet=sock_read(fd,pData,iSize);		if(iRet==SOCKERR_CLOSED || iRet==SOCKERR_IO){			//printerror("socket error while reading message!");			pthread_exit(0);		}		ProcessIpcMessageClient(iMsg,pData,iSize);	}	//thread cleanup function	pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,&old_cancel_type);	pthread_cleanup_pop(1);	pthread_cleanup_pop(1);	pthread_setcanceltype(old_cancel_type,NULL);}//process ipc message for clientBOOL ProcessIpcMessageClient(	int iMsg,  	void* pAttachData, 	int iAttachSize){	POINT point;	PWindowsTree pControl,pChild;	int iCounter,i;	RECT rect;	void* pCurPointer;	int iMenuId;	int iRetMsg;	WPARAM wParam;		PClipRect pCRect;	switch (iMsg & MTYPE_MASK){	case MTYPE_IPC:		switch(iMsg){		case LMSG_IPC_EXITSERVER:			//server send the message to client when exit 			DestroyWindow((HWND)_lGUI_pWindowsTree);			break;		case LMSG_IPC_SHOWMAINWIN_ANS:			//confirm message for show main window 			//together with initial clip region 			pCurPointer=(void*)pAttachData;			EmptyClipRegion(_lGUI_pAppStat->pClipRgn);			iCounter=iAttachSize/sizeof(RECT);			for(i=0;i<iCounter;i++){				memcpy(&rect,pCurPointer,sizeof(RECT));				AddRectClipRegion(_lGUI_pAppStat->pClipRgn, &rect);				pCurPointer+=sizeof(RECT);			}			GetBoundClipRegion(_lGUI_pAppStat->pClipRgn);			UnLockMutexForSynchro();			break;		case LMSG_IPC_CLIPRGNCHANGE:			//clip region changed 			pCurPointer=(void*)pAttachData;			EmptyClipRegion(_lGUI_pAppStat->pClipRgn);			iCounter=iAttachSize/sizeof(RECT);			for(i=0;i<iCounter;i++){				memcpy(&rect,pCurPointer,sizeof(RECT));				AddRectClipRegion(_lGUI_pAppStat->pClipRgn, &rect);				pCurPointer+=sizeof(RECT);			}			GetBoundClipRegion(_lGUI_pAppStat->pClipRgn);			ReCalClipRegionApp();			break;		case LMSG_IPC_REDRAW:			//redraw message			memcpy(&rect,pAttachData,sizeof(RECT));//pAttachData:RECT			scrInvalidateRect((HWND)_lGUI_pWindowsTree,&rect,true);			//scrInvalidateRect((HWND)_lGUI_pWindowsTree,NULL,true);			//redraw sub window			pChild=_lGUI_pWindowsTree->pChildHead;			while(pChild){				scrInvalidateRect((HWND)pChild,&rect,true);				pControl=pChild->pControlHead;				while(pControl){					scrInvalidateRect((HWND)pControl,&rect,true);					//scrInvalidateRect((HWND)pControl,NULL,true);					pControl=pControl->pNext;				}				pChild=pChild->pNext;			}			//redraw control			pControl=_lGUI_pWindowsTree->pControlHead;			while(pControl){				scrInvalidateRect((HWND)pControl,&rect,true);				//scrInvalidateRect((HWND)pControl,NULL,true);				pControl=pControl->pNext;			}			break;		case LMSG_IPC_ACTIVEAPP:			ActiveApplication();			break;		case LMSG_IPC_DISACTIVEAPP:			DisactiveApplication();			break;		case LMSG_IPC_CHAR:			if(!_lGUI_pFocus)				return false;			else{				//printf("%s,%d\n",(char*)pAttachData,iAttachSize);				*((char*)pAttachData+iAttachSize)=0;				SendMessage(_lGUI_pFocus,LMSG_CHAR,*((WPARAM*)pAttachData),(LPARAM)NULL);			}				break;		case LMSG_IPC_KEYDOWN:			if(!_lGUI_pFocus)				return false;			else{				wParam = (WPARAM)*((char*)pAttachData);				SendMessage(_lGUI_pFocus,LMSG_KEYDOWN,wParam,(LPARAM)NULL);			}			break;		}		break;/*	case MTYPE_KEY://key board 		//iSendMsg=(iMsg & ~MTYPE_MASK) | MTYPE_KEY;		//printf("%s\n",(char*)pAttachData);		if(!_lGUI_pFocus)			return false;		else			PostMessage(_lGUI_pFocus,iMsg,(WPARAM)pAttachData,(LPARAM)NULL);		break;*/	case MTYPE_MOUSE://Mouse message 		memcpy(&point,pAttachData,sizeof(POINT));		return ProcessMouseMsgClient(iMsg,point.x,point.y);	}	return true;}//send message by clientBOOL SendMsgByClient(	int iMsg,	void* pAttachData,	int iAttachSize){	void* pData;	if(!_lGUI_fdSocket)		return false;	//send message value 	sock_write(_lGUI_fdSocket,(void*)&iMsg,sizeof(int));	//send size of added data	sock_write(_lGUI_fdSocket,(void*)&iAttachSize,sizeof(int));	//send added data	if(pData && iAttachSize)		sock_write(_lGUI_fdSocket,pAttachData,iAttachSize);	return true;}BOOL ProcessMouseMsgClient(	int iMsg,	int x, 	int y){	PClipRect pCRect;	RECT rcClient;	PWindowsTree pWin,pControl;	switch(iMsg){	case LMSG_PENDOWN:		ProcessMouseDownMsgClient(iMsg,x,y);		break;	case LMSG_PENMOVE:		ProcessMouseMoveMsgClient(iMsg,x,y);		break;	case LMSG_PENUP:		ProcessMouseUpMsgClient(iMsg,x,y);		break;	}	return true;}BOOL ProcessMouseDownMsgClient(	int iMsg, 	int x, 	int y){	PClipRect pCRect;	RECT rcClient;	PWindowsTree pWin,pControl;	//1. within sub window	pWin=_lGUI_pWindowsTree->pChildHead;	while(pWin){		//1.1within clip region of the sub window		if(PtInRect(&(pWin->rect),x,y)){			pCRect=pWin->pClipRgn->pHead;			while(pCRect){				if(PtInRect(&(pCRect->rect),x,y)){					//Move the sub window top. 					if(pWin->pParent->pChildHead!=pWin)						ShowWindow((HWND)pWin,true);					else{						ActiveWindow((HWND)pWin);					}					scrGetClientRect((HWND)pWin,&rcClient);					if(PtInRect(&rcClient,x,y))						PostMessage(pWin,LMSG_PENDOWN,(WPARAM)x,(LPARAM)y);					else						PostMessage(pWin,LMSG_NCPENDOWN,(WPARAM)x,(LPARAM)y);					return true;				}				pCRect=pCRect->pNext;			}			//1.2within the control of the sub window			pControl=pWin->pControlHead;			while(pControl){				if(PtInRect(&(pControl->rect),x,y)){					//move the sub window top 					if(pWin->pParent->pChildHead!=pWin)						ShowWindow((HWND)pControl,true);					scrGetClientRect((HWND)pControl,&rcClient);					if(PtInRect(&rcClient,x,y))						PostMessage(pControl,LMSG_PENDOWN,(WPARAM)x,(LPARAM)y);					else						PostMessage(pControl,LMSG_NCPENDOWN,(WPARAM)x,(LPARAM)y);					SetFocus((HWND)pControl);					return true;				}				pControl=pControl->pNext;			}		}		pWin=pWin->pNext;	}	//2.within the main window	pCRect=_lGUI_pWindowsTree->pClipRgn->pHead;	while(pCRect){		if(PtInRect(&(pCRect->rect),x,y)){			scrGetClientRect((HWND)_lGUI_pWindowsTree,&rcClient);			if(PtInRect(&rcClient,x,y)){				PostMessage(_lGUI_pWindowsTree,LMSG_PENDOWN,(WPARAM)x,(LPARAM)y);			}			else{				PostMessage(_lGUI_pWindowsTree,LMSG_NCPENDOWN,(WPARAM)x,(LPARAM)y);			}			if(!IsActive(_lGUI_pWindowsTree))				ActiveWindow(_lGUI_pWindowsTree);			return true;		}		pCRect=pCRect->pNext;	}	//3.within the control of the main window 	pWin=_lGUI_pWindowsTree->pControlHead;	while(pWin){		pCRect=pWin->pClipRgn->pHead;		while(pCRect){			if(PtInRect(&(pCRect->rect),x,y)){				scrGetClientRect((HWND)pWin,&rcClient);				if(PtInRect(&rcClient,x,y))					PostMessage(pWin,LMSG_PENDOWN,(WPARAM)x,(LPARAM)y);				else					PostMessage(pWin,LMSG_NCPENDOWN,(WPARAM)x,(LPARAM)y);				if(!IsActive((HWND)_lGUI_pWindowsTree)){					RECT rc;					_lGUI_pActiveWin = _lGUI_pWindowsTree;					_lGUI_pWindowsTree->dwStyle |=  WS_ACTIVE;					wndGetCaptionRect((HWND)_lGUI_pWindowsTree,&rc);					scrInvalidateRect((HWND)_lGUI_pWindowsTree,&rc,true);								}				SetFocus(pWin);				return true;			}			pCRect=pCRect->pNext;		}		pWin=pWin->pNext;	}	return true;}BOOL ProcessMouseMoveMsgClient(	int iMsg, 	int x, 	int y){	PClipRect pCRect;	RECT rcClient;	PWindowsTree pWin,pControl;	//who captured the mouse 	if(_lGUI_wndCaptureMouse.pWin){		//if within the clip region of the window/control which captured the mouse 		//then send message to it		if(PtInRect(&(_lGUI_wndCaptureMouse.pWin->pClipRgn->rcBound),x,y)){			pCRect=_lGUI_wndCaptureMouse.pWin->pClipRgn->pHead;			while(pCRect){				if(PtInRect(&(pCRect->rect),x,y)){					scrGetClientRect((HWND)(_lGUI_wndCaptureMouse.pWin),&rcClient);					if((_lGUI_wndCaptureMouse.iByWho == BYCLIENT) && PtInRect(&rcClient,x,y)){						PostMessage(_lGUI_wndCaptureMouse.pWin,LMSG_PENMOVE,(WPARAM)x,(LPARAM)y);						return true;					}					if((_lGUI_wndCaptureMouse.iByWho == BYVSCROLL) ||(_lGUI_wndCaptureMouse.iByWho == BYHSCROLL)){						PostMessage(_lGUI_wndCaptureMouse.pWin,LMSG_NCPENMOVE,(WPARAM)x,(LPARAM)y);						return true;					}				}				pCRect=pCRect->pNext;			}		}	}	else{//if no window/control captured mouse		//then send the message to window/control which mouse is being over it		//1.within a sub window		pWin=_lGUI_pWindowsTree->pChildHead;		while(pWin){			if(PtInRect(&(pWin->rect),x,y)){				//1.1 within the clip region of the sub window				pCRect=pWin->pClipRgn->pHead;				while(pCRect){					if(PtInRect(&(pCRect->rect),x,y)){						scrGetClientRect((HWND)pWin,&rcClient);						if(PtInRect(&rcClient,x,y))							PostMessage(pWin,LMSG_PENMOVE,(WPARAM)x,(LPARAM)y);						else							PostMessage(pWin,LMSG_NCPENMOVE,(WPARAM)x,(LPARAM)y);						return true;					}					pCRect=pCRect->pNext;				}				//1.2 within controls of the sub window				pControl=pWin->pControlHead;				while(pControl){					if(PtInRect(&(pControl->rect),x,y)){						scrGetClientRect((HWND)pControl,&rcClient);						if(PtInRect(&rcClient,x,y))							PostMessage(pControl,LMSG_PENMOVE,(WPARAM)x,(LPARAM)y);						else							PostMessage(pControl,LMSG_NCPENMOVE,(WPARAM)x,(LPARAM)y);						return true;					}					pControl=pControl->pNext;				}			}			pWin=pWin->pNext;		}		//2.within clip region of main window 		pCRect=_lGUI_pWindowsTree->pClipRgn->pHead;		while(pCRect){			if(PtInRect(&(pCRect->rect),x,y)){					scrGetClientRect((HWND)_lGUI_pWindowsTree,&rcClient);					if(PtInRect(&rcClient,x,y))						PostMessage(_lGUI_pWindowsTree,LMSG_PENMOVE,(WPARAM)x,(LPARAM)y);					else						PostMessage(_lGUI_pWindowsTree,LMSG_NCPENMOVE,(WPARAM)x,(LPARAM)y);				return true;			}			pCRect=pCRect->pNext;		}		//3.within clip region of controls of main window		pWin=_lGUI_pWindowsTree->pControlHead;		while(pWin){			pCRect=pWin->pClipRgn->pHead;			while(pCRect){				if(PtInRect(&(pCRect->rect),x,y)){					scrGetClientRect((HWND)pWin,&rcClient);					if(PtInRect(&rcClient,x,y))						PostMessage(pWin,LMSG_PENMOVE,(WPARAM)x,(LPARAM)y);					else						PostMessage(pWin,LMSG_NCPENMOVE,(WPARAM)x,(LPARAM)y);					return true;				}				pCRect=pCRect->pNext;			}			pWin=pWin->pNext;		}	}	return true;}BOOL ProcessMouseUpMsgClient(	int iMsg, 	int x,	int y){	PClipRect pCRect;	RECT rcClient;	PWindowsTree pWin,pControl;	if(_lGUI_wndCaptureMouse.pWin){		//send the message to which captured mouse before.		if(_lGUI_wndCaptureMouse.iByWho == BYCLIENT){			PostMessage((HWND)_lGUI_wndCaptureMouse.pWin,LMSG_PENUP,(WPARAM)x,(LPARAM)y);		}		else{			PostMessage((HWND)_lGUI_wndCaptureMouse.pWin,LMSG_NCPENUP,(WPARAM)x,(LPARAM)y);		}	}	else{		//if no window/control captured mouse before		//then send the message to the control/window where mouse put up.		//1.within a sub window		pWin=_lGUI_pWindowsTree->pChildHead;		while(pWin){			if(PtInRect(&(pWin->rect),x,y)){				//1.1 within clip region of the sub window				pCRect=pWin->pClipRgn->pHead;				while(pCRect){					if(PtInRect(&(pCRect->rect),x,y)){						scrGetClientRect((HWND)pWin,&rcClient);						if(PtInRect(&rcClient,x,y))							PostMessage(pWin,LMSG_PENUP,(WPARAM)x,(LPARAM)y);						else							PostMessage(pWin,LMSG_NCPENUP,(WPARAM)x,(LPARAM)y);						return true;					}					pCRect=pCRect->pNext;				}				//1.2 within controls of the sub window				pControl=pWin->pControlHead;				while(pControl){					if(PtInRect(&(pControl->rect),x,y)){						scrGetClientRect((HWND)pControl,&rcClient);						if(PtInRect(&rcClient,x,y))							PostMessage(pControl,LMSG_PENUP,(WPARAM)x,(LPARAM)y);						else							PostMessage(pControl,LMSG_NCPENUP,(WPARAM)x,(LPARAM)y);						return true;					}					pControl=pControl->pNext;				}			}			pWin=pWin->pNext;		}		//2.within clip region of main window		pCRect=_lGUI_pWindowsTree->pClipRgn->pHead;		while(pCRect){			if(PtInRect(&(pCRect->rect),x,y)){				scrGetClientRect((HWND)_lGUI_pWindowsTree,&rcClient);				if(PtInRect(&rcClient,x,y))					PostMessage(_lGUI_pWindowsTree,LMSG_PENUP,(WPARAM)x,(LPARAM)y);				else					PostMessage(_lGUI_pWindowsTree,LMSG_NCPENUP,(WPARAM)x,(LPARAM)y);				return true;			}			pCRect=pCRect->pNext;		}		//3.within controls of main window		pWin=_lGUI_pWindowsTree->pControlHead;		while(pWin){			pCRect=pWin->pClipRgn->pHead;			while(pCRect){				if(PtInRect(&(pCRect->rect),x,y)){					scrGetClientRect((HWND)pWin,&rcClient);					if(PtInRect(&rcClient,x,y))						PostMessage(pWin,LMSG_PENUP,(WPARAM)x,(LPARAM)y);					else						PostMessage(pWin,LMSG_NCPENUP,(WPARAM)x,(LPARAM)y);					return true;				}				pCRect=pCRect->pNext;			}			pWin=pWin->pNext;		}	}	return true;}void SendString2Client(	char* pString){	if(!_lGUI_pAppStat)		return;	SendMsgByServer(_lGUI_pAppStat,LMSG_IPC_CHAR,(void*)pString,strlen(pString));}void SendKeyDown2Client(	BYTE byteKeyValue){	char pString[3];	pString[0] = byteKeyValue;	pString[1] = '\0';	if(!_lGUI_pAppStat)		return;	SendMsgByServer(_lGUI_pAppStat,LMSG_IPC_KEYDOWN,(void*)pString,strlen(pString));}

⌨️ 快捷键说明

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