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

📄 winbase.c

📁 详细的MiniGUI源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
}BOOL IsCloseBoxPressed(	HWND hWnd){	PWindowsTree pWin;	pWin = (PWindowsTree)hWnd;	if((pWin->dwStyle & WS_CLOSEBOXPRESSED) == WS_CLOSEBOXPRESSED)		return true;	else		return false;	}void MoveWindowTopMost(	const HWND hWnd){	PWindowsTree pWin;	PWindowsTree pCurWin;	PWindowsTree pParent;	int iZOrder=0;	int iWinType;	//if window type is desktop or main window then exit	iWinType=GetWinType(hWnd);	if((iWinType==WS_DESKTOP)||(iWinType==WS_MAIN))		return;	pWin=(PWindowsTree)hWnd;	pParent=pWin->pParent;	if(!pParent)		return;	if(iWinType==WS_CHILD){		if(pParent->pChildHead==pWin)			return;		pWin->pPrev->pNext=pWin->pNext;		pWin->pNext->pPrev=pWin->pPrev;		pParent->pChildHead->pPrev=pWin;		pWin->pNext=pParent->pChildHead;		pParent->pChildHead=pWin;	}	else{//Is Control		if(pParent->pControlHead==pWin)			return;		pWin->pPrev->pNext=pWin->pNext;		pWin->pNext->pPrev=pWin->pPrev;		pParent->pControlHead->pPrev=pWin;		pWin->pNext=pParent->pControlHead;		pParent->pControlHead=pWin;	}		pCurWin=pWin;	while(pCurWin){		pCurWin->iZOrder=iZOrder;		iZOrder++;		pCurWin=pCurWin->pNext;	}}void SetFocusNoPaint(	const HWND hWnd){	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	if(!pWin)		return;	if(!IsControl(hWnd))		return;	if(!IsVisible(hWnd))		return;	if(!IsActive((HWND)(pWin->pParent)))		return;	if(IsFocus(hWnd))		return;	if(_lGUI_pFocus)		UnSetFocus((HWND)_lGUI_pFocus);	_lGUI_pFocus=pWin;	pWin->pParent->pFocus=pWin;	pWin->dwStyle = pWin->dwStyle | WS_FOCUS;}void GUIAPI SetFocus(	const HWND hWnd){	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	if(!pWin)		return;	if(!IsControl(hWnd))		return;	if(!IsVisible(hWnd))		return;	if(!IsActive((HWND)(pWin->pParent)))		return;	if(IsFocus(hWnd))		return;	if(_lGUI_pFocus)		UnSetFocus((HWND)_lGUI_pFocus);	_lGUI_pFocus=pWin;	pWin->pParent->pFocus=pWin;	pWin->dwStyle = pWin->dwStyle | WS_FOCUS;	winInvalidateRect(hWnd,NULL,true);	SendNotifyMessage(hWnd,LMSG_SETFOCUS,(WPARAM)NULL,(LPARAM)NULL);}void UnSetFocus(	const HWND hWnd){	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	if(!pWin)		return;	if(!IsControl(hWnd))		return;	if(!IsFocus(hWnd))		return;	pWin->dwStyle = pWin->dwStyle & ~WS_FOCUS;	//if((pWin->dwStyle & WS_VISIBLE)==WS_VISIBLE)	winInvalidateRect(hWnd,NULL,true);	SendNotifyMessage(hWnd,LMSG_KILLFOCUS,(WPARAM)NULL,(LPARAM)NULL);}void UnSetFocusNoPaint(	const HWND hWnd){	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	if(!pWin)		return;	if(!IsControl(hWnd))		return;	if(!IsFocus(hWnd))		return;	pWin->dwStyle = pWin->dwStyle & ~WS_FOCUS;}void ActiveApplication(){	PWindowsTree pWin;	pWin=_lGUI_pWindowsTree->pChildHead;	_lGUI_pActiveWin = NULL;	if(pWin){		ActiveWindow(pWin);	}	else{		ActiveWindow(_lGUI_pWindowsTree);	}}void DisactiveApplication(){	if(!_lGUI_pActiveWin)		return;	DisactiveWindow((HWND)_lGUI_pActiveWin);	_lGUI_wndCaptureMouse.pWin=NULL;}void DisactiveWindow(	const HWND hWnd){	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	if(!pWin)		return;	if(!IsActive(hWnd))		return;	if((pWin->dwStyle & WS_ACTIVE)==WS_ACTIVE){		pWin->dwStyle = pWin->dwStyle & ~WS_ACTIVE;		_lGUI_pActiveWin=NULL;				SendNotifyMessage(hWnd,LMSG_DISACTIVEWINDOW,(WPARAM)NULL,(LPARAM)NULL);	}}void ActiveWindow(	const HWND hWnd){	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	if(IsActive(hWnd))		return;	if(_lGUI_pActiveWin)		DisactiveWindow((HWND)_lGUI_pActiveWin);	if(_lGUI_pActiveWin!=pWin){		_lGUI_pActiveWin=pWin;		pWin->dwStyle = pWin->dwStyle | WS_ACTIVE;		SendNotifyMessage(hWnd,LMSG_ACTIVEWINDOW,(WPARAM)NULL,(LPARAM)NULL);	}}inline int wndGetBorder(	HWND hWnd){	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	if(!pWin)		return 0;	if(pWin->dwStyle & WS_BORDER)		return WIN_BORDER_WIDTH;	else if(pWin->dwStyle & WS_THINBORDER)		return WIN_THINBORDER_WIDTH;	else if(pWin->dwStyle & WS_THICKBORDER)		return WIN_THICKBORDER_WIDTH;	else		return 0;	return 0;}BOOL GUIAPI GetWindowRect(	HWND hWnd,	LPRECT lpRect){	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	if(!pWin)		return false;	CopyRect(lpRect,&(pWin->rect));	return true;}BOOL scrGetClientRect(	const HWND hWnd, 	LPRECT lpRect){	PWindowsTree pWin;	BOOL bVScroll;	BOOL bHScroll;	int iBorder;	int iWidth,iHeight;	pWin=(PWindowsTree)hWnd;	if(!pWin)		return false;	if(pWin->dwStyle & WS_VSCROLL)		bVScroll = true;	else		bVScroll = false;	if(pWin->dwStyle & WS_HSCROLL)		bHScroll = true;	else		bHScroll = false;	iBorder = wndGetBorder(hWnd);	memcpy(lpRect,&(pWin->rect),sizeof(RECT));	//border & scrollbar	iWidth=GetSystemMetrics(SM_CXVSCROLL);	iHeight=GetSystemMetrics(SM_CYHSCROLL);	if(iBorder)		InflateRect(lpRect,(-1) * iBorder,(-1) * iBorder);	if(bVScroll)		SetRect(lpRect,lpRect->left,lpRect->top,lpRect->right-iWidth,lpRect->bottom);	if(bHScroll)		SetRect(lpRect,lpRect->left,lpRect->top,lpRect->right,lpRect->bottom-iHeight);	//caption?	if(IsCaption(hWnd))		SetRect(lpRect,lpRect->left,lpRect->top + WIN_CAPTION_HEIGHT,			lpRect->right,lpRect->bottom);	return true;}BOOL GUIAPI GetClientRect(	const HWND hWnd, 	LPRECT lpRect){	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	if(!pWin)		return false;	scrGetClientRect(hWnd,lpRect);	//convert to client coord	if(pWin->pParent)		ScreenToClientRect((HWND)(pWin->pParent),lpRect);	return true;}DWORD GetWindowStyle (	HWND hWnd){	PWindowsTree pWin = (PWindowsTree)hWnd;    return pWin->dwStyle;}LRESULT DefWindowProc(	HWND hWnd, 	UINT iMsg, 	WPARAM wParam,	LPARAM lParam){	PWindowsTree pWin;	PWindowsTree pControl;	PInvalidRect pInvRect;	PClipRect	 pClipRect;	HDC hDC;	RECT rc,rcHScrollBar,rcVScrollBar;	HBRUSH hBrush;	COLORREF crColor;	PWNDCLASSEX pWndClass;	pWin=(PWindowsTree)hWnd;	hDC=(HDC)wParam;	switch(iMsg){	case LMSG_ACTIVEWINDOW:		if(pWin->pFocus){			SetFocus(pWin->pFocus);		}		else{			pControl=pWin->pControlTail;			if(pControl)    			SetFocus(pControl);		}		//set the caption rect invalidate		wndGetCaptionRect(hWnd,&rc);		//printf("active:%d,%d,%d,%d\n",		//	rc.left,rc.top,rc.right,rc.bottom);		scrInvalidateRect(hWnd,&rc,true);		break;	case LMSG_DISACTIVEWINDOW:		UnSetFocus((HWND)(pWin->pFocus));		//set the caption rect invalidate		wndGetCaptionRect(hWnd,&rc);		//printf("disactive:%d,%d,%d,%d\n",		//	rc.left,rc.top,rc.right,rc.bottom);				scrInvalidateRect(hWnd,&rc,true);		break;	case LMSG_ERASEBKGND:		pWndClass=GetRegClass(pWin->lpszClassName);		if(!pWndClass)			return (LRESULT)NULL;		hBrush=pWndClass->hbrBackground;		crColor=((BRUSH*)hBrush)->crBrushColor;		//erase invalid region background according to invalidatrect		pInvRect=pWin->pInvRgn->pHead;		if(hDC->iType==DC_TYPE_MEM){//Is Memory DC			while(pInvRect){				pClipRect=pWin->pClipRgn->pHead;				if(pInvRect->bErase){					while(pClipRect){						if(IntersectRect(&rc,&(pInvRect->rect),&(pClipRect->rect)))							EraseRect2Memory(hDC,&(pWin->rect),&rc,crColor);						pClipRect=pClipRect->pNext;					}				}				pInvRect=pInvRect->pNext;			}		}		else{			//fill the intersect of invalidate region and clip region			while(pInvRect){				pClipRect=pWin->pClipRgn->pHead;				if(pInvRect->bErase){					while(pClipRect){						if(IntersectRect(&rc,&(pInvRect->rect),&(pClipRect->rect)))							EraseRect2Screen(&rc,crColor);						pClipRect=pClipRect->pNext;					}				}				pInvRect=pInvRect->pNext;			}		}		break;	case LMSG_SETFOCUS:		break;	case LMSG_KILLFOCUS:		//pWin->dwStyle=pWin->dwStyle & ~ WS_FOCUS;		break;	case LMSG_NCPAINT:		wndDrawNCFrame (hWnd,(HDC)wParam);				break;	//=========================================================================	case LMSG_NCPENDOWN:		wndGetOkButtonRect(hWnd,&rc);		if(PtInRect(&rc,(int)wParam,(int)lParam)){			CaptureMouse(hWnd,BYOKBUTTON);			OkButtonPenDownProc(hWnd);			break;		}		wndGetCloseBoxRect(hWnd,&rc);		if(PtInRect(&rc,(int)wParam,(int)lParam)){			CaptureMouse(hWnd,BYCLOSEBOX);			CloseBoxPenDownProc(hWnd);			break;		}					wndGetVScrollBarRect(hWnd,&rcVScrollBar);		wndGetHScrollBarRect(hWnd,&rcHScrollBar);		if(PtInRect(&rcVScrollBar,(int)wParam,(int)lParam)){			CaptureMouse(hWnd,BYVSCROLL);			VScrollBarPenDownProc(hWnd,(int)wParam,(int)lParam);		}		else if(PtInRect(&rcHScrollBar,(int)wParam,(int)lParam)){			CaptureMouse(hWnd,BYHSCROLL);			HScrollBarPenDownProc(hWnd,(int)wParam,(int)lParam);		}		break;	case LMSG_NCPENMOVE:		if(_lGUI_wndCaptureMouse.iByWho == BYVSCROLL){			VScrollBarPenMoveProc(hWnd,(int)wParam,(int)lParam);		}		else if(_lGUI_wndCaptureMouse.iByWho == BYHSCROLL){			HScrollBarPenMoveProc(hWnd,(int)wParam,(int)lParam);		}		break;	case LMSG_NCPENUP:		if(_lGUI_wndCaptureMouse.pWin){			if(_lGUI_wndCaptureMouse.iByWho == BYOKBUTTON){				OkButtonPenUpProc(hWnd);				break;			}			else if(_lGUI_wndCaptureMouse.iByWho == BYCLOSEBOX){				CloseBoxPenUpProc(hWnd);				break;			}		}					wndGetVScrollBarRect(hWnd,&rcVScrollBar);		wndGetHScrollBarRect(hWnd,&rcHScrollBar);		if(_lGUI_wndCaptureMouse.pWin){			if(_lGUI_wndCaptureMouse.iByWho == BYVSCROLL)				VScrollBarPenUpProc(hWnd);			else if(_lGUI_wndCaptureMouse.iByWho == BYHSCROLL)				HScrollBarPenUpProc(hWnd);		}		else{			if((pWin->dwStyle & WS_VSCROLL) && PtInRect(&rcVScrollBar,(int)wParam,(int)lParam))				VScrollBarPenUpProc(hWnd);			else if((pWin->dwStyle & WS_HSCROLL) && PtInRect(&rcHScrollBar,(int)wParam,(int)lParam))				HScrollBarPenUpProc(hWnd);		}		DisCaptureMouse();		break;	}	return 0;}//===========================================================================void CaptureMouse(	HWND hWnd,	int iByWho){	_lGUI_wndCaptureMouse.pWin = (PWindowsTree)hWnd;	_lGUI_wndCaptureMouse.iByWho = iByWho;}void DisCaptureMouse(){	_lGUI_wndCaptureMouse.pWin = NULL;}HWND GetCaptureWindow(){	return (HWND)_lGUI_wndCaptureMouse.pWin;}//=================================BOOL inline IsServerProcess(){	char lpszClassName[256];	int i=0;	strcpy(lpszClassName,_lGUI_pWindowsTree->lpszClassName);	while(lpszClassName[i]){		lpszClassName[i]=toupper(lpszClassName[i]);		i++;	}	if(strcmp(lpszClassName,"DESKTOP")==0)		return true;	else		return false;}//client/server mutex  void LockMutexForSynchro(){	pthread_mutex_lock(&mutex_cs);}void UnLockMutexForSynchro(){	pthread_mutex_unlock(&mutex_cs);}

⌨️ 快捷键说明

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