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

📄 button.c

📁 详细的MiniGUI源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
			break;		case LMSG_SETTEXT:			pString=(char*)lParam;			strcpy(pWin->lpszCaption,pString);			if(IsVisible(hWnd))				winInvalidateRect(hWnd,NULL,true);			break;		case BM_SETCHECK:			if(wParam)				((PWindowsTree)hWnd)->dwStyle |= BS_BUTTON_CHECKED;			else				((PWindowsTree)hWnd)->dwStyle &= ~BS_BUTTON_CHECKED;			winInvalidateRect(hWnd,NULL,true);			break;		case BM_GETCHECK:			if(IsChecked(hWnd))				return CHECKED;			else				return UNCHECKED;			break;		case LMSG_PENMOVE:			break;		case LMSG_NCPAINT:			GetWindowRect(hWnd,&rc);			SetRect(&rc,0,0,rc.right-rc.left,rc.bottom-rc.top);			if(IsBorder(hWnd)){				hPen=CreatePen(PS_SOLID,1,RGB(88,87,81));				SelectObject(hDC,hPen);				winRectangle(hDC,rc.left,rc.top,rc.right,rc.bottom);				DeleteObject(hPen);			}						break;		case LMSG_PAINT:			GetWindowRect(hWnd,&rc);			SetRect(&rc,0,0,rc.right-rc.left,rc.bottom-rc.top);			iWidth	=rc.right - rc.left + 1;			iHeight	=rc.bottom - rc.top + 1;			if(iHeight<13) break;			ps.bPaintDirect=false;			hDC=BeginPaint(hWnd, &ps);			if(!hDC){				return true;			}			hPenBlack	=CreatePen(PS_SOLID,1,RGB_SYSTEMBLACK);			hPenGray	=CreatePen(PS_SOLID,1,RGB_SYSTEMLTGRAY);			hPenBright	=CreatePen(PS_SOLID,1,RGB_SYSTEMBRIGHT);			hPenDark	=CreatePen(PS_SOLID,1,RGB_SYSTEMDARK);			SetTextColor(hDC,RGB(0,0,0));			DrawText(hDC,pWin->lpszCaption,strlen(pWin->lpszCaption),&rc,DT_RIGHT | DT_VCENTER);			//CENTER BLANK winRectangle			yCenter=rc.top + (rc.bottom - rc.top)/2;			xCenter=7;			SetRect(&rcBox,xCenter - 6,yCenter - 6,xCenter + 6, yCenter + 6);			//Draw bound			//left top			SelectObject(hDC,hPenDark);			winMoveToEx(hDC,rcBox.right-1,rcBox.top,&point);			winLineTo(hDC,rcBox.left,rcBox.top);			winLineTo(hDC,rcBox.left,rcBox.bottom-1);			//left top black bound			SelectObject(hDC,hPenBlack);			winMoveToEx(hDC,rcBox.right-2,rcBox.top+1,&point);			winLineTo(hDC,rcBox.left+1,rcBox.top+1);			winLineTo(hDC,rcBox.left+1,rcBox.bottom-2);			//right bottom white bound			SelectObject(hDC,hPenGray);			winMoveToEx(hDC,rcBox.right,rcBox.top,&point);			winLineTo(hDC,rcBox.right,rcBox.bottom);			winLineTo(hDC,rcBox.right,rcBox.bottom);			//right bottom bright bound			SelectObject(hDC,hPenBright);			winMoveToEx(hDC,rcBox.right-1,rcBox.top+1,&point);			winLineTo(hDC,rcBox.right-1,rcBox.bottom-1);			winLineTo(hDC,rcBox.left+1,rcBox.bottom-1);			if(pWin->dwStyle & BS_BUTTON_CHECKED){				//Draw Check				SelectObject(hDC,hPenBlack);				winMoveToEx(hDC,rcBox.left+3,rcBox.top+5,&point);				winLineTo(hDC,rcBox.left+3,rcBox.top+7);				winMoveToEx(hDC,rcBox.left+4,rcBox.top+6,&point);				winLineTo(hDC,rcBox.left+4,rcBox.top+8);				winMoveToEx(hDC,rcBox.left+5,rcBox.top+7,&point);				winLineTo(hDC,rcBox.left+5,rcBox.top+9);				winMoveToEx(hDC,rcBox.left+6,rcBox.top+6,&point);				winLineTo(hDC,rcBox.left+6,rcBox.top+8);				winMoveToEx(hDC,rcBox.left+7,rcBox.top+5,&point);				winLineTo(hDC,rcBox.left+7,rcBox.top+7);				winMoveToEx(hDC,rcBox.left+8,rcBox.top+4,&point);				winLineTo(hDC,rcBox.left+8,rcBox.top+6);				winMoveToEx(hDC,rcBox.left+9,rcBox.top+3,&point);				winLineTo(hDC,rcBox.left+9,rcBox.top+5);			}			//destroy the hdc object			DeleteObject(hPenBlack);			DeleteObject(hPenGray);			DeleteObject(hPenBright);			DeleteObject(hPenDark);			EndPaint(hWnd, &ps);			break;		case LMSG_DESTROY:			break;		default:			return DefWindowProc(hWnd, iMsg, wParam, lParam);	}	return true;}static LRESULT RadioButtonCtrlProc(	HWND hWnd, 	int iMsg, 	WPARAM wParam, 	LPARAM lParam){	PWindowsTree pWin;	RECT rc;	RECT rcBox;	HDC hDC;	unsigned long iRetMsg;	PAINTSTRUCT ps;	int iWidth,iHeight;	int xCenter,yCenter;	HPEN hPen;	HBRUSH hBrush;	COLORREF crColor;	PWNDCLASSEX pWndClass;	LRESULT res;	char* pString;	int iLen;	HPEN hPenBlack;	HPEN hPenGray;	HPEN hPenBright;	HPEN hPenDark;	POINT point;	pWin=(PWindowsTree)hWnd;	switch(iMsg)	{		case LMSG_CREATE:			break;		case LMSG_COMMAND:			break;		case LMSG_ERASEBKGND:			pWndClass=GetRegClass(pWin->lpszClassName);			if(!pWndClass)				return (LRESULT)NULL;			hBrush=pWndClass->hbrBackground;			crColor=((BRUSH*)hBrush)->crBrushColor;			if(IsFocus(hWnd))				((BRUSH*)hBrush)->crBrushColor=RGB(93,158,255);			else				((BRUSH*)hBrush)->crBrushColor=RGB(144,144,144);			res=DefWindowProc(hWnd, iMsg, wParam, lParam);			((BRUSH*)hBrush)->crBrushColor=crColor;			return res;		case LMSG_PENDOWN:			break;		case LMSG_PENUP:			if(!IsChecked(hWnd))				((PWindowsTree)hWnd)->dwStyle |= BS_BUTTON_CHECKED;			winInvalidateRect(hWnd,NULL,true);			UpdateWindow(hWnd);			NotifyParent(hWnd, BN_CLICKED);			break;		case LMSG_GETTEXT:			pString=(char*)lParam;			if(!pString)				return 0;			else{				iLen=(int)wParam;				if(!iLen){					strcpy(pString,pWin->lpszCaption);					return strlen(pString);				}				else{					strncpy(pString,pWin->lpszCaption,(size_t)iLen);					return strlen(pString);				}			}			break;		case LMSG_SETTEXT:			pString=(char*)lParam;			strcpy(pWin->lpszCaption,pString);			if(IsVisible(hWnd))				winInvalidateRect(hWnd,NULL,true);			break;		case BM_SETCHECK:			if(wParam)				((PWindowsTree)hWnd)->dwStyle |= BS_BUTTON_CHECKED;			else				((PWindowsTree)hWnd)->dwStyle &= ~BS_BUTTON_CHECKED;			winInvalidateRect(hWnd,NULL,true);			break;		case BM_GETCHECK:			if(IsChecked(hWnd))				return CHECKED;			else				return UNCHECKED;			break;		case LMSG_PENMOVE:			break;		case LMSG_NCPAINT:			GetWindowRect(hWnd,&rc);			SetRect(&rc,0,0,rc.right-rc.left,rc.bottom-rc.top);			if(IsBorder(hWnd)){				hPen=CreatePen(PS_SOLID,1,RGB(88,87,81));				SelectObject(hDC,hPen);				DeleteObject(hPen);				winRectangle(hDC,rc.left,rc.top,rc.right,rc.bottom);			}						break;		case LMSG_PAINT:			GetWindowRect(hWnd,&rc);			SetRect(&rc,0,0,rc.right-rc.left,rc.bottom-rc.top);			iWidth	=rc.right - rc.left + 1;			iHeight	=rc.bottom - rc.top + 1;			if(iHeight<13) break;			ps.bPaintDirect=false;			hDC=BeginPaint(hWnd, &ps);			if(!hDC){				return true;			}			SetTextColor(hDC,RGB(0,0,0));			DrawText(hDC,pWin->lpszCaption,strlen(pWin->lpszCaption),&rc,DT_RIGHT | DT_VCENTER);			//CENTER BLANK winRectangle			yCenter=rc.top + (rc.bottom - rc.top)/2;			xCenter=7;			SetRect(&rcBox,xCenter-6,yCenter-6,xCenter+5,yCenter+5);			hPenBlack	=CreatePen(PS_SOLID,1,RGB_SYSTEMBLACK);			hPenGray	=CreatePen(PS_SOLID,1,RGB_SYSTEMLTGRAY);			hPenBright	=CreatePen(PS_SOLID,1,RGB_SYSTEMBRIGHT);			hPenDark	=CreatePen(PS_SOLID,1,RGB_SYSTEMDARK);			SelectObject(hDC,hPenDark);			winMoveToEx(hDC,rcBox.left+4,rcBox.top,&point);			winLineTo(hDC,rcBox.left+7,rcBox.top);			winMoveToEx(hDC,rcBox.left+2,rcBox.top+1,&point);			winLineTo(hDC,rcBox.left+9,rcBox.top+1);			winMoveToEx(hDC,rcBox.left+1,rcBox.top+3,&point);			winLineTo(hDC,rcBox.left+1,rcBox.top+4);			winMoveToEx(hDC,rcBox.left,rcBox.top+4,&point);			winLineTo(hDC,rcBox.left,rcBox.top+7);			winMoveToEx(hDC,rcBox.left+1,rcBox.top+8,&point);			winLineTo(hDC,rcBox.left+1,rcBox.top+9);			SelectObject(hDC,hPenBlack);			winMoveToEx(hDC,rcBox.left+4,rcBox.top+1,&point);			winLineTo(hDC,rcBox.left+7,rcBox.top+1);			winMoveToEx(hDC,rcBox.left+2,rcBox.top+2,&point);			winLineTo(hDC,rcBox.left+3,rcBox.top+2);			winMoveToEx(hDC,rcBox.left+8,rcBox.top+2,&point);			winLineTo(hDC,rcBox.left+9,rcBox.top+2);			winSetPixel(hDC,rcBox.left+2,rcBox.top+3,RGB_SYSTEMBLACK);			winMoveToEx(hDC,rcBox.left+1,rcBox.top+4,&point);			winLineTo(hDC,rcBox.left+1,rcBox.top+7);			winSetPixel(hDC,rcBox.left+2,rcBox.top+8,RGB_SYSTEMBLACK);			SelectObject(hDC,hPenBright);			winMoveToEx(hDC,rcBox.left+2,rcBox.top+9,&point);			winLineTo(hDC,rcBox.left+3,rcBox.top+9);			winMoveToEx(hDC,rcBox.left+4,rcBox.top+10,&point);			winLineTo(hDC,rcBox.left+7,rcBox.top+10);			winMoveToEx(hDC,rcBox.left+8,rcBox.top+9,&point);			winLineTo(hDC,rcBox.left+9,rcBox.top+9);			winSetPixel(hDC,rcBox.left+9,rcBox.top+8,RGB_SYSTEMBRIGHT);			winMoveToEx(hDC,rcBox.left+10,rcBox.top+7,&point);			winLineTo(hDC,rcBox.left+10,rcBox.top+4);			winSetPixel(hDC,rcBox.left+9,rcBox.top+3,RGB_SYSTEMBRIGHT);			SelectObject(hDC,hPenGray);			winMoveToEx(hDC,rcBox.left+2,rcBox.top+10,&point);			winLineTo(hDC,rcBox.left+3,rcBox.top+10);			winMoveToEx(hDC,rcBox.left+4,rcBox.top+11,&point);			winLineTo(hDC,rcBox.left+7,rcBox.top+11);			winMoveToEx(hDC,rcBox.left+8,rcBox.top+10,&point);			winLineTo(hDC,rcBox.left+9,rcBox.top+10);			winMoveToEx(hDC,rcBox.left+10,rcBox.top+9,&point);			winLineTo(hDC,rcBox.left+10,rcBox.top+8);			winMoveToEx(hDC,rcBox.left+11,rcBox.top+7,&point);			winLineTo(hDC,rcBox.left+11,rcBox.top+4);			winMoveToEx(hDC,rcBox.left+10,rcBox.top+3,&point);			winLineTo(hDC,rcBox.left+10,rcBox.top+2);			//Draw check			if(pWin->dwStyle & BS_BUTTON_CHECKED){				SelectObject(hDC,hPenBlack);				winMoveToEx(hDC,rcBox.left+4,rcBox.top+5,&point);				winLineTo(hDC,rcBox.left+7,rcBox.top+5);				winMoveToEx(hDC,rcBox.left+4,rcBox.top+6,&point);				winLineTo(hDC,rcBox.left+7,rcBox.top+6);				winMoveToEx(hDC,rcBox.left+5,rcBox.top+4,&point);				winLineTo(hDC,rcBox.left+5,rcBox.top+7);				winMoveToEx(hDC,rcBox.left+6,rcBox.top+4,&point);				winLineTo(hDC,rcBox.left+6,rcBox.top+7);			}			//destroy the hdc object			DeleteObject(hPenBlack);			DeleteObject(hPenGray);			DeleteObject(hPenBright);			DeleteObject(hPenDark);			EndPaint(hWnd, &ps);			break;		case LMSG_DESTROY:			break;		default:			return DefWindowProc(hWnd, iMsg, wParam, lParam);	}	return true;}//group radio button control procedurestatic LRESULT AutoRadioButtonCtrlProc(	HWND hWnd, 	int iMsg, 	WPARAM wParam, 	LPARAM lParam){	PWindowsTree pWin;	RECT rc;	RECT rcBox;	HDC hDC;	unsigned long iRetMsg;	PAINTSTRUCT ps;	int iWidth,iHeight;	int xCenter,yCenter;	HPEN hPen;	HBRUSH hBrush;	COLORREF crColor;	PWNDCLASSEX pWndClass;	LRESULT res;	DWORD dwData;	PWindowsTree pControl;	char* pString;	int iLen;	HPEN hPenBlack;	HPEN hPenGray;	HPEN hPenBright;	HPEN hPenDark;	POINT point;	pWin=(PWindowsTree)hWnd;	switch(iMsg)	{		case LMSG_CREATE:			if(IsGroup(hWnd))				pWin->pParent->dwData+=1;			pWin->dwData=pWin->pParent->dwData;			break;		case LMSG_COMMAND:			break;		case LMSG_ERASEBKGND:			pWndClass=GetRegClass(pWin->lpszClassName);			if(!pWndClass)				return (LRESULT)NULL;			hBrush=pWndClass->hbrBackground;			crColor=((BRUSH*)hBrush)->crBrushColor;			if(IsFocus(hWnd))				((BRUSH*)hBrush)->crBrushColor=RGB(93,158,255);			else				((BRUSH*)hBrush)->crBrushColor=RGB(144,144,144);			res=DefWindowProc(hWnd, iMsg, wParam, lParam);			((BRUSH*)hBrush)->crBrushColor=crColor;			return res;		case LMSG_PENDOWN:			break;		case LMSG_PENUP:			if(!IsChecked(hWnd)){				((PWindowsTree)hWnd)->dwStyle |= BS_BUTTON_CHECKED;				winInvalidateRect(hWnd,NULL,true);				UpdateWindow(hWnd);				dwData=pWin->dwData;				pControl=pWin->pParent->pControlHead;				while(pControl){					if(pControl!=pWin){						if((GetButtonType((HWND)pControl)==BS_AUTORADIOBUTTON) && (pControl->dwData==dwData)){							SendMessage((HWND)pControl,BM_SETCHECK,(WPARAM)false,(LPARAM)NULL);						}					}					pControl=pControl->pNext;				}			}			NotifyParent(hWnd, BN_CLICKED);			break;		case LMSG_GETTEXT:			pString=(char*)lParam;			if(!pString)				return 0;			else{				iLen=(int)wParam;				if(!iLen){					strcpy(pString,pWin->lpszCaption);					return strlen(pString);				}				else{					strncpy(pString,pWin->lpszCaption,(size_t)iLen);					return strlen(pString);				}			}			break;		case LMSG_SETTEXT:			pString=(char*)lParam;			strcpy(pWin->lpszCaption,pString);			if(IsVisible(hWnd))				winInvalidateRect(hWnd,NULL,true);			break;		case BM_SETCHECK:			if(wParam)				((PWindowsTree)hWnd)->dwStyle |= BS_BUTTON_CHECKED;			else				((PWindowsTree)hWnd)->dwStyle &= ~BS_BUTTON_CHECKED;			winInvalidateRect(hWnd,NULL,true);			break;		case BM_GETCHECK:			if(IsChecked(hWnd))				return CHECKED;			else				return UNCHECKED;			break;		case LMSG_PENMOVE:			break;		case LMSG_NCPAINT:			GetWindowRect(hWnd,&rc);			SetRect(&rc,0,0,rc.right-rc.left,rc.bottom-rc.top);					if(IsBorder(hWnd)){				hPen=CreatePen(PS_SOLID,1,RGB(88,87,81));				SelectObject(hDC,hPen);				DeleteObject(hPen);				winRectangle(hDC,rc.left,rc.top,rc.right,rc.bottom);			}			break;		case LMSG_PAINT:			GetWindowRect(hWnd,&rc);			SetRect(&rc,0,0,rc.right-rc.left,rc.bottom-rc.top);			iWidth	=rc.right - rc.left + 1;			iHeight	=rc.bottom - rc.top + 1;			if(iHeight<13) break;			ps.bPaintDirect=false;			hDC=BeginPaint(hWnd, &ps);			if(!hDC){				return true;			}			SetTextColor(hDC,RGB(0,0,0));			DrawText(hDC,pWin->lpszCaption,strlen(pWin->lpszCaption),&rc,DT_RIGHT | DT_VCENTER);			//CENTER BLANK winRectangle			yCenter=rc.top + (rc.bottom - rc.top)/2;			xCenter=7;			SetRect(&rcBox,xCenter-6,yCenter-6,xCenter+5,yCenter+5);			hPenBlack	=CreatePen(PS_SOLID,1,RGB_SYSTEMBLACK);			hPenGray	=CreatePen(PS_SOLID,1,RGB_SYSTEMLTGRAY);			hPenBright	=CreatePen(PS_SOLID,1,RGB_SYSTEMBRIGHT);			hPenDark	=CreatePen(PS_SOLID,1,RGB_SYSTEMDARK);			SelectObject(hDC,hPenDark);			winMoveToEx(hDC,rcBox.left+4,rcBox.top,&point);			winLineTo(hDC,rcBox.left+7,rcBox.top);			winMoveToEx(hDC,rcBox.left+2,rcBox.top+1,&point);			winLineTo(hDC,rcBox.left+9,rcBox.top+1);			winMoveToEx(hDC,rcBox.left+1,rcBox.top+3,&point);			winLineTo(hDC,rcBox.left+1,rcBox.top+4);			winMoveToEx(hDC,rcBox.left,rcBox.top+4,&point);			winLineTo(hDC,rcBox.left,rcBox.top+7);			winMoveToEx(hDC,rcBox.left+1,rcBox.top+8,&point);			winLineTo(hDC,rcBox.left+1,rcBox.top+9);			SelectObject(hDC,hPenBlack);			winMoveToEx(hDC,rcBox.left+4,rcBox.top+1,&point);			winLineTo(hDC,rcBox.left+7,rcBox.top+1);			winMoveToEx(hDC,rcBox.left+2,rcBox.top+2,&point);			winLineTo(hDC,rcBox.left+3,rcBox.top+2);			winMoveToEx(hDC,rcBox.left+8,rcBox.top+2,&point);			winLineTo(hDC,rcBox.left+9,rcBox.top+2);			winSetPixel(hDC,rcBox.left+2,rcBox.top+3,RGB_SYSTEMBLACK);			winMoveToEx(hDC,rcBox.left+1,rcBox.top+4,&point);			winLineTo(hDC,rcBox.left+1,rcBox.top+7);			winSetPixel(hDC,rcBox.left+2,rcBox.top+8,RGB_SYSTEMBLACK);			SelectObject(hDC,hPenBright);			winMoveToEx(hDC,rcBox.left+2,rcBox.top+9,&point);			winLineTo(hDC,rcBox.left+3,rcBox.top+9);			winMoveToEx(hDC,rcBox.left+4,rcBox.top+10,&point);			winLineTo(hDC,rcBox.left+7,rcBox.top+10);			winMoveToEx(hDC,rcBox.left+8,rcBox.top+9,&point);			winLineTo(hDC,rcBox.left+9,rcBox.top+9);			winSetPixel(hDC,rcBox.left+9,rcBox.top+8,RGB_SYSTEMBRIGHT);			winMoveToEx(hDC,rcBox.left+10,rcBox.top+7,&point);			winLineTo(hDC,rcBox.left+10,rcBox.top+4);			winSetPixel(hDC,rcBox.left+9,rcBox.top+3,RGB_SYSTEMBRIGHT);			SelectObject(hDC,hPenGray);			winMoveToEx(hDC,rcBox.left+2,rcBox.top+10,&point);			winLineTo(hDC,rcBox.left+3,rcBox.top+10);			winMoveToEx(hDC,rcBox.left+4,rcBox.top+11,&point);			winLineTo(hDC,rcBox.left+7,rcBox.top+11);			winMoveToEx(hDC,rcBox.left+8,rcBox.top+10,&point);			winLineTo(hDC,rcBox.left+9,rcBox.top+10);			winMoveToEx(hDC,rcBox.left+10,rcBox.top+9,&point);			winLineTo(hDC,rcBox.left+10,rcBox.top+8);			winMoveToEx(hDC,rcBox.left+11,rcBox.top+7,&point);			winLineTo(hDC,rcBox.left+11,rcBox.top+4);			winMoveToEx(hDC,rcBox.left+10,rcBox.top+3,&point);			winLineTo(hDC,rcBox.left+10,rcBox.top+2);			//Draw check			if(pWin->dwStyle & BS_BUTTON_CHECKED){				SelectObject(hDC,hPenBlack);				winMoveToEx(hDC,rcBox.left+4,rcBox.top+5,&point);				winLineTo(hDC,rcBox.left+7,rcBox.top+5);				winMoveToEx(hDC,rcBox.left+4,rcBox.top+6,&point);				winLineTo(hDC,rcBox.left+7,rcBox.top+6);				winMoveToEx(hDC,rcBox.left+5,rcBox.top+4,&point);				winLineTo(hDC,rcBox.left+5,rcBox.top+7);				winMoveToEx(hDC,rcBox.left+6,rcBox.top+4,&point);				winLineTo(hDC,rcBox.left+6,rcBox.top+7);			}			//destroy the hdc object			DeleteObject(hPenBlack);			DeleteObject(hPenGray);			DeleteObject(hPenBright);			DeleteObject(hPenDark);			EndPaint(hWnd, &ps);			break;		case LMSG_DESTROY:			break;		default:			return DefWindowProc(hWnd, iMsg, wParam, lParam);	}	return true;}static unsigned int GetButtonType(	HWND hWnd){	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	return pWin->dwStyle & BS_TYPEMASK;}static BOOL IsChecked(	HWND hWnd){	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	if((pWin->dwStyle & BS_BUTTON_CHECKED)==BS_BUTTON_CHECKED)		return true;	else		return false;}static BOOL IsGroup(	HWND hWnd){	PWindowsTree pWin;	pWin=(PWindowsTree)hWnd;	if((pWin->dwStyle & BS_GROUP)==BS_GROUP)		return true;	else		return false;}

⌨️ 快捷键说明

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