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

📄 wincaret.c

📁 MinGUI 可视化程序代码
💻 C
字号:
/******************************************************************************** Copyright  2006 National ASIC Center, All right Reserved** FILE NAME:      Caret.c* PROGRAMMER:     ming.c* Date of Creation:   2006/08/8** DESCRIPTION:*     Single Line Editor* NOTE:** FUNCTIONS LIST:* -----------------------------------------------------------------------------** -----------------------------------------------------------------------------* * MODIFICATION HISTORY*     LastModify  2006/10/30******************************************************************************/#include "mingui.h"//-----------------------------------------------------------------------------#define DEF_BLINK_TIME		500	/* default blink time in ms*/typedef struct {	HWND	hwnd;		/* != NULL if caret is created*/	int	x;	int	y;	int	nWidth;	int	nHeight;	int nShowCount;	BOOL fShown;		/* caret is currently visible*/	UINT	BlinkTimeInterval;	HANDLE  BlinkTimerHandle;} CARETINFO;/* local data*/static CARETINFO sysCaret={0,0,0,0,0,0,0,0,0};	/* the system caret*//* local procs*/static void CM_XorDrawCaret(void);static void CM_BlinkCarret(HWND hWnd);void CreateCaret(HWND hWnd, int width, int height){ if(sysCaret.hwnd && sysCaret.fShown)  {  HideCaret(sysCaret.hwnd);  }  sysCaret.hwnd=hWnd;  sysCaret.nShowCount=0;  sysCaret.nWidth = (width <= 0)?1:width;  sysCaret.nHeight = (height <= 0)?1:height;  sysCaret.BlinkTimeInterval = DEF_BLINK_TIME;  if(sysCaret.BlinkTimerHandle)  { ResetTimer(sysCaret.BlinkTimerHandle,hWnd,DEF_BLINK_TIME,DEF_BLINK_TIME,CM_BlinkCarret,true);  }  else  { sysCaret.BlinkTimerHandle=CreateTimer(hWnd,DEF_BLINK_TIME,DEF_BLINK_TIME,CM_BlinkCarret,true);  }}BOOL DestroyCaret(HWND hWnd){  if(sysCaret.hwnd==hWnd)   { if(sysCaret.fShown)      { HideCaret(hWnd);     }     EnableTimer(sysCaret.BlinkTimerHandle,false);     sysCaret.hwnd = NULL;   }   return true;}
/*
HideCaret() function will hide caret at right now,but it will be shown again at next second automatically.
if you want to stop the caret,you should use DestroyCaret() function.
*/
BOOL HideCaret(HWND hWnd){  if(sysCaret.hwnd==hWnd && sysCaret.fShown)   { sysCaret.fShown = false;	 CM_XorDrawCaret();
	 return true;   }   return false;}void CM_BlinkCarret(HWND hWnd){  if(sysCaret.hwnd==hWnd)   { sysCaret.fShown = !sysCaret.fShown;	 CM_XorDrawCaret();   }}BOOL ShowCaret(HWND hWnd){  if(sysCaret.hwnd==hWnd && !sysCaret.fShown)   {  sysCaret.fShown = true;	 /* show caret, this call made it visible*/	  CM_XorDrawCaret();   } 	return true;} BOOL SetCaretPos(HWND hWnd,int nX, int nY){ if(sysCaret.hwnd==hWnd && (sysCaret.x != nX || sysCaret.y != nY))  {	if (sysCaret.fShown)     { CM_XorDrawCaret();	/* toggle off*/	  sysCaret.x = nX;      sysCaret.y = nY;	  CM_XorDrawCaret();	/* toggle on in new location*/	}	sysCaret.x = nX;	sysCaret.y = nY;	return true;  }  return false; }BOOL GetCaretPos(HWND hWnd,TPOINT *lpPoint){ if(sysCaret.hwnd==hWnd)  { lpPoint->x = sysCaret.x;	lpPoint->y = sysCaret.y;	return true;  }  return false;}UINT GetCaretBlinkTime(void){	return sysCaret.BlinkTimeInterval;}BOOL SetCaretBlinkTime(UINT uMSeconds){  sysCaret.BlinkTimeInterval = uMSeconds;	/* SetSysTimer */	return true;}/* Draw the caret using XOR.  Same routine is used to show and hide caret.*/static void CM_XorDrawCaret(void){   HDC dc = GetClientDC(sysCaret.hwnd);
 	SetPenLogic(dc,PL_XOR);
    ((TWndCanvas *)dc)->Foreground = UNIT_PIXEL_MASK;
		     if (sysCaret.nWidth == 1)    {  DrawVerLine(dc,sysCaret.x, sysCaret.y,sysCaret.nHeight);    }     else    {  FillRect(dc,sysCaret.x, sysCaret.y,sysCaret.nWidth,sysCaret.nHeight);    }

    ReleaseDC(dc);
}

⌨️ 快捷键说明

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