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

📄 windlg.c

📁 microwindows最新源码
💻 C
📖 第 1 页 / 共 2 页
字号:
 */static LRESULT CALLBACKmwDialogProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam){	PMWDLGDATA pData;	LRESULT retV = 0;	DLGPROC lpFnDlg = DLG_DLGPROC(hWnd);	if (lpFnDlg)		retV = lpFnDlg(hWnd, Msg, wParam, lParam);	if (!retV)		retV = DefDlgProc(hWnd, Msg, wParam, lParam);	//  Some messages return the value of DLGPROC	if (!dlgReturnLValue(Msg))		return retV;	if (!retV) {		switch (Msg) {		case WM_NCDESTROY:			pData = DLG_PMWDLGDATA(hWnd);			if (pData) {				HWND hPar = GetParent(hWnd);				dlgDestroyInitFont(hWnd, pData);				free(pData);				SetWindowLong(hWnd, DWL_DLGDATA, 0);				SetWindowLong(hWnd, DWL_DLGPROC, 0);				if (hPar)					SetActiveWindow(hPar);			} else				EPRINTF("WARN: mwDialogProc: WM_NCDESTROY without dlgParams\n");			break;		case WM_SETFONT:			pData = DLG_PMWDLGDATA(hWnd);			if (pData == NULL)				return 0;			dlgDestroyInitFont(hWnd, pData);			pData->hFnt = (HFONT) wParam;			if (LOWORD(lParam) != 0)				InvalidateRect(hWnd, NULL, TRUE);			return TRUE;		case WM_GETFONT:			pData = DLG_PMWDLGDATA(hWnd);			if (pData == NULL)				return 0;			return (LPARAM) pData->hFnt;		case WM_SETFOCUS:			dlgSaveCtrlFocus(hWnd, (HWND) wParam);			dlgRestoreCtrlFocus(hWnd);			return 0;		case WM_SHOWWINDOW:			if (!wParam)				dlgSaveCtrlFocus(hWnd, GetFocus());			break;		case WM_ACTIVATE:			if (LOWORD(wParam) == WA_INACTIVE)				dlgSaveCtrlFocus(hWnd, GetFocus());			else				dlgRestoreCtrlFocus(hWnd);			return 0;		case WM_NCHITTEST:			{				POINT curpt;				POINTSTOPOINT(curpt, lParam);				if (PtInRect(&hWnd->clirect, curpt))					return HTNOWHERE;				return DefWindowProc(hWnd, Msg, wParam, lParam);			}		}		return DefWindowProc(hWnd, Msg, wParam, lParam);	}	return DLG_MSGRESULT(hWnd);}/* *  Process messages sent to a dialog and childs */BOOL WINAPIIsDialogMessage(HWND hDlg, LPMSG lpMsg){	static BOOL kShiftStatus = FALSE;	HWND hChild;	int dlgCode;	if (lpMsg->hwnd == hDlg || ISDLGCONTROL(hDlg, lpMsg->hwnd)) {		/*  first check if message is a key message...  */		switch (lpMsg->message) {		case WM_KEYUP:			switch (lpMsg->wParam) {			case VK_LSHIFT:			case VK_RSHIFT:			case VK_SHIFT:				kShiftStatus = FALSE;				break;			}			dlgCode = SendMessage(lpMsg->hwnd, WM_GETDLGCODE,					    lpMsg->wParam, (LPARAM) lpMsg);			if ((dlgCode & DLGC_WANTMESSAGE))				goto skipKeyProcess;			/* msg is sent to top-child */			if (ISDLGCONTROL(hDlg, lpMsg->hwnd))				lpMsg->hwnd = dlgGetCtrlTop(hDlg, lpMsg->hwnd);			break;		case WM_KEYDOWN:			switch (lpMsg->wParam) {			case VK_LSHIFT:			case VK_RSHIFT:			case VK_SHIFT:				kShiftStatus = TRUE;				break;			}			dlgCode = SendMessage(lpMsg->hwnd, WM_GETDLGCODE,					    lpMsg->wParam, (LPARAM) lpMsg);			if ((dlgCode & DLGC_WANTMESSAGE))				goto skipKeyProcess;			/* msg is sent to top-child */			if (ISDLGCONTROL(hDlg, lpMsg->hwnd))				lpMsg->hwnd = dlgGetCtrlTop(hDlg, lpMsg->hwnd);			break;		case WM_CHAR:			dlgCode = SendMessage(lpMsg->hwnd, WM_GETDLGCODE,					    lpMsg->wParam, (LPARAM) lpMsg);			if ((dlgCode & DLGC_WANTMESSAGE))				goto skipKeyProcess;			/* msg is sent to top-child */			if (ISDLGCONTROL(hDlg, lpMsg->hwnd))				lpMsg->hwnd =					dlgGetCtrlTop(hDlg, lpMsg->hwnd);			break;		case WM_SYSCHAR:			dlgCode = SendMessage(lpMsg->hwnd, WM_GETDLGCODE,					    lpMsg->wParam, (LPARAM) lpMsg);			/* msg is sent to top-child */			if (ISDLGCONTROL(hDlg, lpMsg->hwnd)			    && !(dlgCode & DLGC_WANTMESSAGE))				lpMsg->hwnd = dlgGetCtrlTop(hDlg, lpMsg->hwnd);			break;		}		/*  then parse special key messages...  */		switch (lpMsg->message) {		case WM_KEYDOWN:			switch (lpMsg->wParam) {			case VK_TAB:				if ((dlgCode & DLGC_WANTTAB))					break;				DPRINTF("Handle VK_TAB key\n");				hChild = nextTabStop(hDlg, dlgGetCtrlFocus(hDlg),						     kShiftStatus);				if (hChild)					SendMessage(hDlg, WM_NEXTDLGCTL,						    (WPARAM) hChild, 1);				return TRUE;			case VK_DOWN:			case VK_LEFT:			case VK_UP:			case VK_RIGHT:				if ((dlgCode & DLGC_WANTARROWS))					break;				DPRINTF("Handle ARROWS key\n");				hChild = GetNextDlgGroupItem(hDlg, dlgGetCtrlFocus(hDlg),						((lpMsg->wParam == VK_LEFT)						  || (lpMsg-> wParam == VK_UP)));				if (hChild != NULL) {					SendMessage(hDlg, WM_NEXTDLGCTL, (WPARAM) hChild, 1);					if ((dlgCode & DLGC_RADIOBUTTON))						PostMessage(hChild, WM_CHAR, ' ', 0);				}				return TRUE;			case VK_RETURN:				hChild = firstDefButton(hDlg);				if (hChild) {					PostMessage(hDlg, WM_COMMAND,						    MAKELONG(GetDlgCtrlID(hChild), BN_CLICKED),						    (LPARAM) hChild);				} else					SendMessage(hDlg, WM_COMMAND, IDOK, 0);				return TRUE;			case VK_CANCEL:			case VK_ESCAPE:				PostMessage(hDlg, WM_COMMAND, IDCANCEL,					    (LPARAM) GetDlgItem(hDlg, IDCANCEL));				return TRUE;			}			break;		case WM_CHAR:			if ((dlgCode & (DLGC_WANTCHARS)))				break;			if ((lpMsg->wParam == '\t')			    && (dlgCode & DLGC_WANTTAB))				break;			if (parseAccelerator(hDlg, lpMsg->wParam))				return TRUE;			break;		case WM_SYSCHAR:			if (parseAccelerator(hDlg, lpMsg->wParam))				return TRUE;			DPRINTF("SYSCHAR %08X %08X\n", lpMsg->wParam,			       lpMsg->lParam);			break;		}skipKeyProcess:		TranslateMessage(lpMsg);		DispatchMessage(lpMsg);		return TRUE;	}	return FALSE;}/* *  Do a modal DIALOG with arguments */int WINAPIDialogBoxParam(HINSTANCE hInstance, LPCTSTR lpTemplate, HWND hWndParent,	       DLGPROC lpDialogFunc, LPARAM lParam){	int retV = 0;	MSG msg;	DWORD ltm = 0;	PMWDLGDATA params;	HWND hDlg = CreateDialogParam(hInstance, lpTemplate, hWndParent,				  lpDialogFunc, lParam);	if (hDlg) {		BOOL bSendIdle = TRUE;		params = DLG_PMWDLGDATA(hDlg);		params->running = TRUE;		if (hWndParent)			EnableWindow(hWndParent, FALSE);		ShowWindow(hDlg, SW_SHOW);		SetActiveWindow(hDlg);		if ((params->hWndFocus != NULL)		    && IsWindowEnabled(params->hWndFocus))			SetFocus(params->hWndFocus);		else			PostMessage(hDlg, WM_NEXTDLGCTL, 0, 0);		UpdateWindow(hDlg);		while (IsWindow(hDlg) && params->running) {			if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {				if (!IsDialogMessage(hDlg, &msg)) {					TranslateMessage(&msg);					DispatchMessage(&msg);				}				bSendIdle = TRUE;				if (msg.message == WM_QUIT)					break;				if (msg.time != ltm)					MwHandleTimers();				ltm = msg.time;			} else {				if (bSendIdle) {					SendMessage(hDlg, WM_ENTERIDLE, 0, 0);					bSendIdle = FALSE;				}				MwHandleTimers();#ifdef MW_CALL_IDLE_HANDLER				idle_handler();#endif			}		}		if (!params->running) {			retV = params->nResult;			DestroyWindow(hDlg);		}		if (hWndParent)			EnableWindow(hWndParent, TRUE);	}	return retV;}/* *  Do a modal DIALOG */int WINAPIDialogBox(HINSTANCE hInstance, LPCTSTR lpTemplate, HWND hWndParent,	  DLGPROC lpDialogFunc){	return DialogBoxParam(hInstance, lpTemplate, hWndParent, lpDialogFunc, 0);}/* *  Terminate a DIALOG */BOOL WINAPIEndDialog(HWND hDlg, int nResult){	PMWDLGDATA params = DLG_PMWDLGDATA(hDlg);	if (params) {		params->running = FALSE;		params->nResult = nResult;		return TRUE;	}	return FALSE;}/* *  Get base units of dialogs */LONG WINAPIGetDlgBaseUnits(void){	/* return averWidth and Height of system font.*/	return MAKELONG(5, 13);}/* *  Convert dialog base units in screen units */BOOL WINAPIMapDialogRect(HWND hWnd, LPRECT lpRc){	static const char defAlpha[] =		" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";	SIZE sz;	HDC hdc;	HFONT oldFnt;	BOOL retV = FALSE;	//TEXTMETRIC tm;	hdc = GetDC(hWnd);	oldFnt = SelectObject(hdc,			      (HFONT) SendMessage(hWnd, WM_GETFONT, 0, 0));	if (GetTextExtentPoint(hdc, defAlpha, sizeof(defAlpha) - 1, &sz))	//if( GetTextMetrics(hdc, &tm) )	{		//sz.cx = tm.tmAveCharWidth + tm.tmOverhang;		//sz.cy = tm.tmHeight + tm.tmExternalLeading;		sz.cx = (sz.cx +			 (sizeof(defAlpha) - 1) / 2) / (sizeof(defAlpha) - 1);		lpRc->left = MulDiv(lpRc->left, sz.cx, 4);		lpRc->right = MulDiv(lpRc->right, sz.cx, 4);		lpRc->top = MulDiv(lpRc->top, sz.cy, 8);		lpRc->bottom = MulDiv(lpRc->bottom, sz.cy, 8);		retV = TRUE;	}	SelectObject(hdc, oldFnt);	ReleaseDC(hWnd, hdc);	return retV;}HWND WINAPICreateDialog(HINSTANCE hInstance, LPCSTR lpTemplate, HWND hWndParent,	     DLGPROC lpDialogFunc){	return CreateDialogParam(hInstance, lpTemplate, hWndParent,				 lpDialogFunc, 0);}HWND WINAPICreateDialogParam(HINSTANCE hInstance, LPCTSTR lpTemplate,		  HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam){	PMWDLGTEMPLATE pDlg;	MWDLGTEMPLEXTRA dlgExtra;	HWND hDlg, retV;	HWND hFocus, hCtrl;	HFONT hFnt;	RECT rc;	HDC hdc;	PMWDLGDATA pData;	HGLOBAL hResDlg;	int i;	HRSRC hRes = FindResource(hInstance, lpTemplate, RT_DIALOG);	if (hRes == NULL)		return NULL;	hResDlg = LoadResource(hInstance, hRes);	pDlg = (PMWDLGTEMPLATE) LockResource(hResDlg);	if (pDlg == NULL)		return NULL;	resGetDlgTemplExtra(pDlg, &dlgExtra);	hDlg = NULL;	retV = NULL;	hFocus = NULL;	do {		BOOL bVisible = ((pDlg->style & WS_VISIBLE) != 0);		rc.left = pDlg->x;		rc.top = pDlg->y;		rc.right = rc.left + pDlg->cx;		rc.bottom = rc.top + pDlg->cy;		pDlg->style &= ~WS_VISIBLE;	/* dlg should be showed at end.*/		hDlg = CreateWindowEx(pDlg->dwExtendedStyle, "GDLGCLASS",				      dlgExtra.szDlgName,				      pDlg->style | DLG_DEF_STYLE,				      0, 0, 100, 100,				      hWndParent, NULL, hInstance, NULL);		if (hDlg == NULL)			break;		hdc = GetDC(hDlg);		pData = (PMWDLGDATA) malloc(sizeof(MWDLGDATA));		if (pData == NULL)			break;		SetWindowLong(hDlg, DWL_DLGDATA, (LPARAM) pData);		SetWindowLong(hDlg, DWL_DLGPROC, (LPARAM) lpDialogFunc);		SetWindowLong(hDlg, DWL_USER, dwInitParam);		pData->flags = 0;		pData->running = FALSE;		pData->nResult = 0;		pData->hWndFocus = NULL;		// create a font or use default		if ((dlgExtra.szFontName != NULL) &&		    ((hFnt = CreateFont(-MulDivRD(dlgExtra.fontSize,				 GetDeviceCaps(hdc, LOGPIXELSY), 72), 0, 0,				 0, 0, 0, 0, 0, 0, 0, 0, DEFDLG_FONT_QUALITY,				 FF_DONTCARE | DEFAULT_PITCH,				 dlgExtra.szFontName)) != NULL)) {			pData->flags |= DLGF_DESTROYFONT;		} else			hFnt = GetStockObject(DEFAULT_FONT);		pData->hFnt = hFnt;		// calculate screen coords and resize window.		SelectObject(hdc, pData->hFnt);		MapDialogRect(hDlg, &rc);		MoveWindow(hDlg, rc.left, rc.top,			   rc.right - rc.left, 16 + rc.bottom - rc.top, FALSE);		//  items creation		for (i = 0; i < pDlg->cdit; i++) {			PMWDLGITEMTEMPLATE pItem = dlgExtra.pItems[i];			PMWDLGITEMTEMPLEXTRA pItemExtra =				&dlgExtra.pItemsExtra[i];			DWORD style = dlgItemStyle(pItem, pItemExtra);			rc.left = pItem->x;			rc.top = pItem->y;			rc.right = rc.left + pItem->cx;			rc.bottom = rc.top + pItem->cy;			MapDialogRect(hDlg, &rc);			hCtrl = CreateWindowEx(pItem->dwExtendedStyle,				 dlgGetItemClass(pItemExtra),				 pItemExtra->szCaption, style,				 rc.left, rc.top,				 rc.right - rc.left, rc.bottom - rc.top,				 hDlg, (HMENU) (int) pItem->id,				 hInstance, pItemExtra->lpData);			if (hCtrl != NULL) {				if ((hFocus == NULL)				    && (pItem->style & WS_TABSTOP)) {					hFocus = hCtrl;				}				SendMessage(hCtrl, WM_SETFONT,					    (WPARAM) pData->hFnt, 0);			} else				EPRINTF("Error on creating item %d\n", i);		}		ReleaseDC(hDlg, hdc);		if (bVisible) {			MSG msg;			ShowWindow(hDlg, SW_SHOW);			//SetActiveWindow ( hDlg );			UpdateWindow(hDlg);			// MW needs to be painted			while (PeekMessage(&msg, hDlg, 0, 0, PM_REMOVE)) {				TranslateMessage(&msg);				DispatchMessage(&msg);			}		}		//  Finally, send a WM_INITDIALOG message.		//  If returned value is nonzero, sets the focus to the first available item.		if (SendMessage(hDlg, WM_INITDIALOG, (WPARAM) hFocus, dwInitParam)		    && (hFocus != NULL)) {			pData->hWndFocus = hFocus;		}		retV = hDlg;	} while (0);	if (retV == NULL) {		if (hDlg != NULL)			DestroyWindow(hDlg);	}	resDiscardDlgTemplExtra(&dlgExtra);	UnlockResource(hResDlg);	FreeResource(hResDlg);	return retV;}

⌨️ 快捷键说明

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