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

📄 window.c

📁 lgui_0.3.0.rar
💻 C
📖 第 1 页 / 共 3 页
字号:
/*	Copyright (C) 2004-2005 Li Yudong*//*** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.**** This program is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the** GNU General Public License for more details.**** You should have received a copy of the GNU General Public License** along with this program; if not, write to the Free Software** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#include "../include/common.h"#include "../include/blockheap.h"#include "../include/mouse.h"#include "../include/keyboard.h"#include "../include/framebuffer.h"#include "../include/rect.h"#include "../include/invalidregion.h"#include "../include/clipregion.h"#include "../include/hdc.h"#include "../include/lguiapp.h"#include "../include/ipcsocket.h"#include "../include/message.h"#include "../include/regclass.h"#include "../include/shmem.h"#include "../include/caret.h"#include "../include/winnc.h"#include "../include/winbase.h"#include "../include/window.h"#include "../include/scrollbar.h"#include "../include/ipcsignal.h"#include "../include/timer.h"#include "../include/shmem.h"//focus and active window strategy//all windows (exclude controls) have a pointer which pointer to its focus control//the control will get focus automaticly when the window acitved.PWindowsTree	_lGUI_pFocus			=NULL;//_lGUI_pActiveWin//server: if _lGUI_pActiveWin = _lGUI_pWindowsTree then desktop is active//otherwise the top application is active//_lGUI_pActiveWin=_lGUI_pWindowsTree after createwindow PWindowsTree	_lGUI_pActiveWin		=NULL;extern BOOL			_lGUI_bByServer;extern pthread_t	thread_ipcmsg;//extern pthread_t	thread_mouse;//extern pthread_t	thread_kb;extern PWindowsTree _lGUI_pImeWindow;extern PWindowsTree _lGUI_pSkbWindow;extern PWindowsTree _lGUI_pStartMenuWindow;PWindowsTree	_lGUI_pWindowsTree		=NULL;PlGUIAppStat	_lGUI_pAppStat			=NULL;WndCaptureMouse _lGUI_wndCaptureMouse;HWND GUIAPI CreateWindow(  char* lpClassName,	// pointer to registered class name  char* lpWindowName,	// pointer to window name  DWORD dwStyle,        // window style & window statue  int x,                // horizontal position of window  int y,                // vertical position of window  int nWidth,           // window width  int nHeight,          // window height  HWND hWndParent,      // handle to parent or owner window  HMENU hMenu,          // handle to menu or child-window identifier  HANDLE hInstance,     // handle to application instance  LPVOID lpParam	    // pointer to window-creation data){	PWindowsTree pWin;	int iWinType;	iWinType=dwStyle & WS_TYPEMASK;	if(((iWinType==WS_DESKTOP)||(iWinType==WS_MAIN)) && _lGUI_pWindowsTree){		printerror("Main Window or desktop already exist!");		return ERR_INV_HWND;	}	if(((iWinType==WS_CHILD)||(iWinType==WS_CONTROL)) && !_lGUI_pWindowsTree){		printerror("main window or desktop does not exist!");		return ERR_INV_HWND;	}	pWin =(PWindowsTree)malloc(sizeof(WindowsTree));	if(!pWin){		printerror("alloc memory error!\n");		return ERR_INV_HWND;	}	memset(pWin,0,sizeof(WindowsTree));	if(!lpClassName){		printerror("class name string should not be null!");		free(pWin);	}	strcpy(pWin->lpszClassName,lpClassName);	//lpszCaption allowed to be Null string	if(lpWindowName)		strcpy(pWin->lpszCaption,lpWindowName);	pWin->dwStyle		=dwStyle;	pWin->pParent		=hWndParent;	pWin->hMenu			=hMenu;	SetRect(&(pWin->rect),x,y,x+nWidth-1,y+nHeight-1);	if(hWndParent)		ClientToScreenRect(hWndParent,&(pWin->rect));	//alloc memory for scrollbar struct	if(pWin->dwStyle & WS_VSCROLL){		pWin->pVScroll = (LPSCROLLINFO)malloc(sizeof(SCROLLINFO));		if(!(pWin->pVScroll)){			free(pWin);			return ERR_INV_HWND;		}		else{			memset(pWin->pVScroll,0,sizeof(SCROLLINFO));			//default set disabled			pWin->pVScroll->dwStatus |= SS_DISABLED;		}	}	if(pWin->dwStyle & WS_HSCROLL){		pWin->pHScroll = (LPSCROLLINFO)malloc(sizeof(SCROLLINFO));		if(!(pWin->pHScroll)){			free(pWin->pVScroll);			free(pWin);			return ERR_INV_HWND;		}		else{			memset(pWin->pHScroll,0,sizeof(SCROLLINFO));			//default set disabled			pWin->pHScroll->dwStatus |= SS_DISABLED;		}	}	if((pWin->dwStyle & WS_VSCROLL) || (pWin->dwStyle & WS_HSCROLL)){		pWin->pHCurState = (LPSCROLLCURSTATE)malloc(sizeof(SCROLLCURSTATE));		pWin->pVCurState = (LPSCROLLCURSTATE)malloc(sizeof(SCROLLCURSTATE));		if(!pWin->pHCurState || !pWin->pVCurState){			if(pWin->pVScroll)				free(pWin->pVScroll);			if(pWin->pHScroll)				free(pWin->pHScroll);			free(pWin);			return ERR_INV_HWND;		}		else{			memset(pWin->pHCurState,0,sizeof(SCROLLCURSTATE));			memset(pWin->pVCurState,0,sizeof(SCROLLCURSTATE));		}	}	//caret struct	/*	pWin->pCaretInfo = (PCARETINFO)malloc(sizeof(CARETINFO));	if(!pWin->pCaretInfo){		free(pWin->pVScroll);		free(pWin->pHScroll);		free(pWin);		return ERR_INV_HWND;	}	memset(pWin->pCaretInfo,0,sizeof(CARETINFO));	pWin->pCaretInfo->hOwner = (HWND)pWin;	*/	switch(dwStyle & WS_TYPEMASK){	case WS_DESKTOP:		if(CreateDesktop(pWin)==ERR_INV_HWND){			free(pWin);			return ERR_INV_HWND;		}		else{			SendMessage((HWND)pWin,LMSG_CREATE,(WPARAM)hInstance,(LPARAM)lpParam);		}		break;	case WS_MAIN:		if(CreateMain(pWin)==ERR_INV_HWND){			free(pWin);			return ERR_INV_HWND;		}		else{			SendMessage((HWND)pWin,LMSG_CREATE,(WPARAM)hInstance,(LPARAM)lpParam);		}		break;	case WS_CHILD:		if(CreateChild(pWin)==ERR_INV_HWND){			free(pWin);			return ERR_INV_HWND;		}		else{			SendMessage((HWND)pWin,LMSG_CREATE,(WPARAM)hInstance,(LPARAM)lpParam);		}		break;	case WS_CONTROL:		if(CreateControl(pWin)==ERR_INV_HWND){			free(pWin);			return ERR_INV_HWND;		}		else			SendMessage((HWND)pWin,LMSG_CREATE,(WPARAM)hInstance,(LPARAM)lpParam);		break;	case WS_IMEWIN:		if(CreateImeWin(pWin)==ERR_INV_HWND){			free(pWin);			return ERR_INV_HWND;		}		else			SendMessage((HWND)pWin,LMSG_CREATE,(WPARAM)hInstance,(LPARAM)lpParam);		break;	case WS_SKBWIN:		if(CreateSkbWin(pWin)==ERR_INV_HWND){			free(pWin);			return ERR_INV_HWND;		}		else			SendMessage((HWND)pWin,LMSG_CREATE,(WPARAM)hInstance,(LPARAM)lpParam);		break;	case WS_MENUWIN:		if(CreateMenuWin(pWin)==ERR_INV_HWND){			free(pWin);			return ERR_INV_HWND;		}		else			SendMessage((HWND)pWin,LMSG_CREATE,(WPARAM)hInstance,(LPARAM)lpParam);		break;	}	return pWin;}HWND CreateDesktop(	const HWND hWnd){	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	_lGUI_pWindowsTree=pWin;	pWin->threadid=pthread_self();	if(!InitMsgQueue((HWND)pWin)){		printerror("init message queue error!");		return ERR_INV_HWND;	}	if(!InitWindowRgn(pWin)){		printerror("init window clip region error!");		return ERR_INV_HWND;	}	return pWin;}HWND CreateMain(	const HWND hWnd){	PWindowsTree pWin;	RECT rc;	pWin=(PWindowsTree)hWnd;	_lGUI_pWindowsTree=pWin;	pWin->threadid=pthread_self();	if(!InitMsgQueue((HWND)pWin)){		printerror("init message queue error!");		return ERR_INV_HWND;	}	if(!InitWindowRgn((HWND)pWin)){		printerror("init window clip region error!");		return ERR_INV_HWND;	}	//init the bound rect of the cliparea	AddRectClipRegion (_lGUI_pAppStat->pClipRgn, &pWin->rect);	GetBoundClipRegion(_lGUI_pAppStat->pClipRgn);	//send create application message to server	//application name is PID	sprintf(_lGUI_pAppStat->pAppName,"%d",getpid());	CopyRect(&_lGUI_pAppStat->rc,&pWin->rect);	SendMsgByClient(LMSG_IPC_CREATEAPP,(char*)_lGUI_pAppStat,sizeof(lGUIAppStat));	LockMutexForSynchro();	return pWin;}HWND CreateChild(	const HWND hWnd){	PWindowsTree pCurWin;	PWindowsTree pWin;	int iZOrder=0;	pWin=(PWindowsTree)hWnd;	if(!InitMsgQueue((HWND)pWin)){		printerror("init message queue error!");		return ERR_INV_HWND;	}	if(!InitWindowRgn((HWND)pWin)){		printerror("init window clip region error!");		return ERR_INV_HWND;	}	if(pWin->pParent->pChildHead==NULL){		pWin->pParent->pChildHead	=pWin;		pWin->pParent->pChildTail	=pWin;		pWin->pNext					=NULL;		pWin->pPrev					=NULL;	}	else{		pWin->pParent->pChildHead->pPrev=pWin;		pWin->pNext=pWin->pParent->pChildHead;		pWin->pParent->pChildHead=pWin;	}	pCurWin=pWin->pParent->pChildHead;	while(pCurWin){		pCurWin->iZOrder=iZOrder;		iZOrder++;		pCurWin=pCurWin->pNext;	}	///////////////////////////////////////////////////////////	pthread_create(&(pWin->threadid),NULL,			(void*)MessageLoop,(void*)pWin);	//detach thread	//pthread_detach(pWin->threadid);	return pWin;}void* MessageLoop(	void* para){	MSG msg;	static HWND hWnd;	hWnd=(HWND)para;	while (GetMessage(&msg,hWnd)){		pthread_testcancel();		TranslateMessage(&msg);		DispatchMessage(&msg);	}}HWND CreateControl(	const HWND hWnd){	PWindowsTree pCurWin;	PWindowsTree pWin;	int iZOrder=0;	pWin=(PWindowsTree)hWnd;	if(!InitWindowRgn(pWin)){		printerror("init window clip region error!\n");		return ERR_INV_HWND;	}	pWin->threadid=pthread_self();	if(pWin->pParent->pControlHead==NULL){		pWin->pParent->pControlHead	=pWin;		pWin->pParent->pControlTail	=pWin;		pWin->pNext					=NULL;		pWin->pPrev					=NULL;	}	else{		pWin->pParent->pControlHead->pPrev=pWin;		pWin->pNext=pWin->pParent->pControlHead;		pWin->pParent->pControlHead=pWin;	}	pCurWin=pWin->pParent->pControlHead;	while(pCurWin){		pCurWin->iZOrder=iZOrder;		iZOrder++;		pCurWin=pCurWin->pNext;	}	return pWin;}HWND CreateMenuWin(	const HWND hWnd){	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	_lGUI_pStartMenuWindow=pWin;	if(!InitWindowRgn(pWin)){		printerror("init window clip region error!");		return ERR_INV_HWND;	}	return pWin;}HWNDCreateImeWin(	const HWND hWnd){	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	_lGUI_pImeWindow=pWin;	if(!InitWindowRgn(pWin)){		printerror("init window clip region error!");		return ERR_INV_HWND;	}	return pWin;}HWND CreateSkbWin(	const HWND hWnd){	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	_lGUI_pSkbWindow=pWin;	if(!InitWindowRgn(pWin)){		printerror("init window clip region error!");		return ERR_INV_HWND;	}	return pWin;}//===========================================================================BOOL GUIAPI ShowWindow(	HWND hWnd, 	int nCmdShow){	PWindowsTree pWin;	int iWinType;	pWin=(PWindowsTree)hWnd;	iWinType=GetWinType(pWin);	switch(iWinType){	case WS_DESKTOP:		ShowDesktop(pWin,nCmdShow);		break;	case WS_MAIN:		ShowMain(pWin,nCmdShow);		break;	case WS_CHILD:		ShowChild(pWin,nCmdShow);		break;	case WS_CONTROL:		ShowControl(pWin,nCmdShow);		break;	case WS_IMEWIN:		ShowImeWin(pWin,nCmdShow);		break;	case WS_SKBWIN:		ShowSkbWin(pWin,nCmdShow);		break;	case WS_MENUWIN:		ShowMenuWin(pWin,nCmdShow);		break;	}	SendMessage(hWnd,LMSG_SHOWWINDOW,(WPARAM)nCmdShow,(LPARAM)NULL);	return true;}BOOL GUIAPI UpdateWindow(	HWND hWnd){	PWindowsTree pWin;	int iWinType;	pWin=(PWindowsTree)hWnd;	iWinType=GetWinType(pWin);	switch(iWinType){	case WS_DESKTOP:		UpdateDesktop(pWin);		break;	case WS_MAIN:		UpdateMain(pWin);		break;	case WS_CHILD:		UpdateChild(pWin);		break;	case WS_CONTROL:		UpdateControl(pWin);		break;	case WS_IMEWIN:		UpdateImeWin(pWin);		break;	case WS_SKBWIN:		UpdateSkbWin(pWin);		break;	case WS_MENUWIN:		UpdateMenuWin(pWin);		break;	}	return true;}BOOL ShowDesktop(	const HWND hWnd,	int nCmdShow){	PWindowsTree pControl;	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	//set desktop visible	pWin->dwStyle = pWin->dwStyle | WS_VISIBLE;	ReCalClipRegion(pWin);	pControl=pWin->pControlHead;	while(pControl){		ReCalClipRegion(pControl);		pControl=pControl->pNext;	}	ActiveWindow(pWin);	scrInvalidateRect((HWND)pWin, NULL, true);	pControl=pWin->pControlHead;	while(pControl){		if(IsVisible((HWND)pControl)){			scrInvalidateRect((HWND)pControl, NULL, true);		}		pControl=pControl->pNext;	}	return true;

⌨️ 快捷键说明

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