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

📄 uiwnd.c

📁 嵌入工linux开发的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
		kernelFree(pWnd->screenBuffer);		// 释放屏幕保存时所分配的资料
	
	if(bIsMainWin||(pWnd->style&GUIWIN_DIALOG))	// 主窗口或对话框:释放定时器资源和消息队列
	{
		pCurTimer = gpTimerList;
		while(pCurTimer)
		{
			pPreTimer = pCurTimer;
			pCurTimer = pCurTimer->pNext;
			if(pPreTimer->pMsgQueue==pWnd->messageQueue)
				guiTimer_Free((HNDL)pPreTimer);		// 释放一个定时器
		}
		guiReleaseMessageQueue(pWnd->messageQueue);	// 释放消息队列
	}
	
	pWnd->checkFlag = 0;
	if(pWnd==gpTopWindow)
	{
		gpTopWindow=0;
	}
	
	kernelFree(pWnd);			// 释放窗口本身的数据存储空间
}

/*************************************************************************/
// 删除窗口
// 参数:
//	hWnd		窗口句柄
// 返回值:
//	STATUS_OK:	成功
//	STATUS_ERR: 失败
/*************************************************************************/
DLL_EXP(STATUS) guiWindow_Delete(HNDL hWnd) 
{
	TGuiWindow   *pWnd,*pWindowList,*tWindowList;

	guiEnterWCS();
	pWnd  = (TGuiWindow *)hWnd;
	if( pWnd->checkFlag!=GUI_WIN_CHECK_FLAG )	//1112
	{
		guiExitWCS();
		return STATUS_ERR;						// 窗口无效
	}

	pWnd->checkFlag = GUI_DELETED_CHECK_FLAG;	// 5410,设置窗口已被删除的标志
	if(pWnd==gpTopWindow)
		gpTopWindow = NULL;	// 在删除顶层窗口后,系统将失去顶层窗口

	if(pWnd->parent)		// 删除子窗口或对话框
		_guiWindow_ReleaseResource(pWnd, FALSE);
	else					// 删除主窗口
	{
		pWindowList=gpWindowsList;
		while(pWindowList)	// 删除所有子窗口
		{
			tWindowList=pWindowList->back;
			if(pWindowList->parent==pWnd)			// 删除一个子窗口
				_guiWindow_ReleaseResource(pWindowList, FALSE);
			pWindowList = tWindowList;
		}
		_guiWindow_ReleaseResource(pWnd, TRUE);		// 删除主窗口
	}

	guiExitWCS();
	return STATUS_OK;
}

/*************************************************************************/
// 设置窗口座标(不会重绘窗口)
// 参数:
//	hWnd		窗口句柄
//	left,top:	窗口左上角座标
//	right,bottom窗口右下角座标
// 返回值:
//	STATUS_OK:	成功
//	STATUS_ERR: 失败
/*************************************************************************/
DLL_EXP(STATUS) guiWindow_SetLocation(HNDL hWnd, WORD left, WORD top, WORD right, WORD bottom)
{
	TGuiWindow *pWnd;

	guiEnterWCS();
	pWnd  = (TGuiWindow *)hWnd;
	if( pWnd->checkFlag!=GUI_WIN_CHECK_FLAG )	//1112
	{
		guiExitWCS();
		return STATUS_ERR;						// 窗口无效
	}

	pWnd->left = left;
	pWnd->top = top;
	pWnd->right = right;
	pWnd->bottom = bottom;

	guiExitWCS();
	return STATUS_OK;
}

/*************************************************************************/
// 获取窗口座标
// 参数:
//	hWnd		窗口句柄
//	left,top:	窗口左上角座标
//	right,bottom窗口右下角座标
// 返回值:
//	STATUS_OK:	成功
//	STATUS_ERR: 失败
/*************************************************************************/
DLL_EXP(STATUS) guiWindow_GetLocation(HNDL hWnd, WORD *left, WORD *top, WORD *right, WORD *bottom)
{
	TGuiWindow *pWnd;
	
	guiEnterWCS();
	pWnd  = (TGuiWindow *)hWnd;
	if( pWnd->checkFlag!=GUI_WIN_CHECK_FLAG )	//1112
	{
		guiExitWCS();
		return STATUS_ERR;						// 窗口无效
	}
	
	*left = pWnd->left;
	*top  = pWnd->top;
	*right = pWnd->right;
	*bottom = pWnd->bottom;

	guiExitWCS();
	return STATUS_OK;
}

/*************************************************************************/
// 从窗口中移走所有控件(菜单和关闭按钮除外)
// 参数:
//	hWnd		窗口句柄
// 返回值:
//	STATUS_OK:	成功
//	STATUS_ERR: 失败
/*************************************************************************/
DLL_EXP(STATUS) guiWindow_RemoveAllControl(HNDL hWnd)
{
	TGuiWindow *pWnd;
	struct dLinkList *pLinkList;
	TGuiControl *pControl;
	
	guiEnterWCS();
	pWnd = (TGuiWindow *)hWnd;
	
	if(pWnd->checkFlag!=GUI_WIN_CHECK_FLAG)		//1112
	{
		guiExitWCS();
		return STATUS_ERR;						// 窗口无效
	}
	
	pLinkList = pWnd->controlList.back;
	while (pLinkList)
	{
		pControl = (TGuiControl *)pLinkList->elementPointer;
		pLinkList = pLinkList->back;
		if(pControl==NULL)		// 控件指针无效
			continue;
		if((HNDL)pControl->handle==pWnd->tWinSysCtr.hClose)	// 关闭按钮
			continue;
		if((HNDL)pControl->handle==pWnd->tWinSysCtr.hMenu)	// 系统菜单
			continue;
		guiControl_Remove(hWnd, (HNDL)pControl);	// 移走控件
	}
	
	guiExitWCS();
	return STATUS_OK;	
}

/*************************************************************************/
// 建立对话框
// 参数:	
//	hParentWnd		父窗口句柄
//	left,top		左上角座标
//	right,bottom	右下角座标
//	caption			窗口标题
// 返回值:
//	成功:			对话框句柄
//	失败:			NULL
/*************************************************************************/
DLL_EXP(HNDL) guiDialog_Create (HNDL hParentWnd, int left, int top, int right, int bottom, 
								const char *caption, WORD style)
{
	TGuiWindow *pWnd;
	HNDL hWnd;
	
	// 对话框风格:边框、独立的消息队列、无关闭Button、标题居中
	style |= GUIWIN_DIALOG;
	style &= DIALOG_MASK;
	hWnd = guiWindow_Create(hParentWnd, caption, NULL, NULL, style);
	
	if( !hWnd )
		return NULL;				// 创建对话框失败

	pWnd = (TGuiWindow *)hWnd;		// 设置座标
	pWnd->left  = left;
	pWnd->top   = top;
	pWnd->right = right;
	pWnd->bottom = bottom;

	return hWnd;
}

/*************************************************************************/
// 显示对话框
// 参数:	
//	hDialog		对话框句柄
// 返回值:
//	成功:		STATUS_OK
//	失败:		STATUS_ERR
/*************************************************************************/
DLL_EXP(STATUS) guiDialog_Show(HNDL hDialog)
{
	STATUS result;
	TGuiWindow *pBackWindow,*pDialog;

	guiEnterWCS();
	pDialog = (TGuiWindow *)hDialog;
	if( pDialog->checkFlag!=GUI_WIN_CHECK_FLAG )
	{
		guiExitWCS();
		return STATUS_ERR;			// 对话框无效
	}

	// by zhangxp  2003/06/11
	//gBackWindowStyle=gpTopWindow->style;
	pDialog->BackWindowStyle = gpTopWindow->style;

	gpTopWindow->style|=GUIWIN_IMAGE_SAVE;

	
	pBackWindow=gpTopWindow;		// 暂存背景窗口

	result=guiWindow_Show(hDialog);
	guiExitWCS();
	if(result==STATUS_OK)
		// by zhangxp  2003/06/11
		//gpBackWindow=pBackWindow;	// 背景窗口
		pDialog->pBackWindow=pBackWindow;

	return result;
}

/*************************************************************************/
// 关闭对话框(不会删除对话框及其所用的资源)
// 参数:
//	hDialog		对话框句柄
// 返回值:
//	成功:		STATUS_OK
//	失败:		STATUS_ERR
/*************************************************************************/
DLL_EXP(STATUS) guiDialog_Close(HNDL hDialog)
{
	TGuiMessage message;
	TWindow  *pDialog;
	HNDL  hTopWnd;
	//int left, top, right, bottom;

	guiEnterWCS();
	if( hDialog!=(HNDL)gpTopWindow )
	{
		guiExitWCS();
		return STATUS_ERR;			// 对话框不是顶层窗口
	}

	pDialog = (TGuiWindow *)hDialog;
	if( pDialog->checkFlag!=GUI_WIN_CHECK_FLAG )
	{
		guiExitWCS();
		return STATUS_ERR;			// 对话框无效
	}
	
	pDialog->status = GUIWIN_NOT_ACTIVE;	// 对话框置为不活动状态

	guiCaret_Disable();		// 关闭光标
	guiListbox_Shrink();	// 收起PopList
	guiMenu_Shrink();		// 收起Menu
	guiHWR_End();			// 停止手写识别线程

	gpTopWindow=NULL;
	
// by zhangxp  2003/06/11
//	guiWindow_Show((HNDL)gpBackWindow);	// 恢复原顶层窗口
//	gpTopWindow->style=gBackWindowStyle;
	guiWindow_Show((HNDL)pDialog->pBackWindow);	// 恢复原顶层窗口
	gpTopWindow->style = pDialog->BackWindowStyle;

	guiExitWCS();
	return STATUS_OK;
}

/*************************************************************************/
// 删除对话框(如果对话框为顶层窗口,则先关闭它再删除)
// 参数:
//	hDialog		对话框句柄
// 返回值:
//	成功:		STATUS_OK
//	失败:		STATUS_ERR
/*************************************************************************/
DLL_EXP(STATUS) guiDialog_Delete(HNDL hDialog)
{
	TGuiWindow  *pDialog;

	pDialog = (TGuiWindow *)hDialog;
	if(pDialog->checkFlag!=GUI_WIN_CHECK_FLAG)
		return STATUS_ERR;				// 对话框无效

	guiDialog_Close(hDialog);			// 关闭对话框
	return(guiWindow_Delete(hDialog));	// 删除对话框窗口
} 
                     
//extern int gwmtest;
//int gDialogTest = 0;
//int gDialogCount = 0;

/*************************************************************************/
// 显示一个消息盒
// 参数:
//	left,top	消息盒左上角座标
//	right,bottom消息盒右下角座标
//	caption		消息盒标题
//	message		消息盒中显示的信息
//	style		消息盒风格(参见头文件中的定义)
// 返回值:
//	参数不正确或出错时返回0
//	正确时返回选中的Button(参见头文件中的定义)
/*************************************************************************/
DLL_EXP(int) guiMessageBoxEx(int left, int top, int right, int bottom,
						const char *caption, const char *message, WORD style)
{
	HNDL hDialog,hParentWnd;
	TGuiWindow *pDialog;
	TGuiMessage tMessage;
	TGuiMessageQueue * pMessageQueue;
	short width,height;
	short buttonWidth,buttonHeight,buttonTop,buttonBottom,offset1,offset2,titleHeight;
	HNDL hButton1, hButton2;
	int iRet1,iRet2,iRet;
	short iconWidth,iconHeight,messageLeft;
	BYTE *pIcon;

	width = right-left+1;		// 消息盒宽度和高度
	height = bottom-top+1;

	guiEnterWCS();
	guiPushFont(GUI_DEFAULT_FONT);			// 计算Button的高度和宽度
	buttonHeight=guiGetStringHeight()+4;
	buttonWidth=guiGetStringWidth(RES_STR_CANCEL[gLanguage])+22;	// 以"取消"或"Cancel"Button为标准
	titleHeight=buttonHeight;						// 标题条高度
	guiPopFont();

	offset1=(width-buttonWidth-2)>>1;	// 只有一个Button时,Button与窗口左边的距离
	offset2=(width-2-(buttonWidth<<1))/3;	// 有两个Button时,左右两边的边距
	
	//buttonTop=height-buttonHeight-4;	// Button的纵座标
	//buttonBottom=height-5;
	buttonTop=height-buttonHeight-8;	// Button的纵座标  zhangxp
	buttonBottom=height-9;
                     
	pIcon=NULL;  // by zhangxp       

	switch( style&GUIMB_TYPEMASK)		// 创建Button组合
	{
	case GUIMB_OK:				// 只有一个"确定"Button
		hButton1=guiButton_Create( offset1+1, buttonTop,offset1+buttonWidth, buttonBottom,
			RES_STR_OK[gLanguage], BUTTON_WIN3D);
		hButton2=NULL;
		iRet1=GUI_IDOK;
		iRet2=0;                                                 
                                                 
//		pIcon = (BYTE *)icon_Gui_MB_Exclamation;//  icon_MSGBOX_ICONEXCLAMATION; by zhangxp

		break;
	case GUIMB_OKCANCEL:		// "确定"和"取消"两个Button
		hButton1=guiButton_Create( offset2+1, buttonTop,offset2+buttonWidth, buttonBottom,
			RES_STR_OK[gLanguage], BUTTON_WIN3D);
		hButton2=guiButton_Create( width-buttonWidth-offset2-1, buttonTop,width-offset2-2, 
			buttonBottom,RES_STR_CANCEL[gLanguage], BUTTON_WIN3D);
		iRet1=GUI_IDOK;
		iRet2=GUI_IDCANCEL;

		pIcon = (BYTE *)icon_Gui_MB_Question;	// icon_MSGBOX_QUESTION;  by zhangxp

		break;
	case GUIMB_YESNO:			// "是"和"否"两个Button
		hButton1=guiButton_Create( offset2+1, buttonTop,offset2+buttonWidth, buttonBottom,
			RES_STR_YES[gLanguage], BUTTON_WIN3D);
		hButton2=guiButton_Create( width-buttonWidth-offset2-1, buttonTop,width-offset2-2,
			buttonBottom,RES_STR_NO[gLanguage], BUTTON_WIN3D);
		iRet1=GUI_IDYES;
		iRet2=GUI_IDNO;
		pIcon = (BYTE *)icon_Gui_MB_Question;	// icon_MSGBOX_QUESTION;  by zhangxp
		break;
	default:
		guiExitWCS();
		return 0;		// Button组合错误
	}

	hDialog = guiDialog_Create(0,left, top, right, bottom, caption,
		GUIWIN_BORDER|GUIWIN_CAPTION_CENTER|GUIWIN_CLOSE_NONE);	// 创建对话框
	guiControl_Add(hDialog, hButton1);	// 将Button组合加入窗口
	if(hButton2)
		guiControl_Add(hDialog, hButton2);
	guiDialog_Show(hDialog);		// 显示消息盒
#ifndef __WIN32__
	wave_error();
#endif	
	switch( style&GUIMB_ICONMASK )
	{
	case GUIMB_ICONEXCLAMATION:
		pIcon = (BYTE *)icon_Gui_MB_Exclamation;//  icon_MSGBOX_ICONEXCLAMATION;
		break;
	case GUIMB_ICONQUESTION:
		pIcon = (BYTE *)icon_Gui_MB_Question;	// icon_MSGBOX_QUESTION;
		break;
	case GUIMB_ICONWARNING:
		pIcon = (BYTE *)icon_Gui_MB_Warning;	// icon_MSGBOX_WARNING;
		break;
	case GUIMB_ICONSTOP:
		pIcon = (BYTE *)icon_Gui_MB_Stop;		// icon_MSGBOX_STOP;
		break;
	case GUIMB_ICONOK:
		pIcon = (BYTE *)icon_Gui_MB_Ok;			//icon_MSGBOX_OK;
		break;
	default:
		break;              // by zhangxp
		//pIcon=NULL;
	}
	
	messageLeft=5;
	titleHeight += 10;
	if(pIcon)			// icon的高度和宽度
	{
		iconWidth = guiGetImageWidth(pIcon);
		iconHeight= guiGetImageHeight(pIcon);
		//guiPutImage(hDialog,5,titleHeight+4,iconWidth+4,titleHeight+iconHeight+3,pIcon);
		guiPutImage(hDialog,5,titleHeight,iconWidth+4,titleHeight+iconHeight-1,pIcon);
		messageLeft+=iconWidth+7;
	}

	pDialog=(TGuiWindow *)hDialog;
	guiPushFont(pDialog->font);	// 显示信息
	guiShowStringInArea(hDialog, message, messageLeft, titleHeight/*titleHeight+4*/, width-4,buttonTop-5, 

⌨️ 快捷键说明

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