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

📄 ptctrl_text.cpp

📁 wince下的画图程序
💻 CPP
字号:
#include "StdAfx.h"
#include "PtCtrl_Text.h"

#include "CEPaint.h"
#include <afx.h>

PtCtrl_Text g_ptctl_text;

INT text_wid_ary[512];

INT InitPbCtrl_Text(PtCtrl_Text *pPtCtrl_Text)
{
    InitPbCtrlBase((PtCtrlBase*)pPtCtrl_Text);
	
	pPtCtrl_Text->m_ptctrl_base.PtCtrl_Init = PtCtrl_Text_Init;
	pPtCtrl_Text->m_ptctrl_base.PtCtrl_Destroy = PtCtrl_Text_Destroy;
	
	pPtCtrl_Text->m_ptctrl_base.PtCtrl_OnPaintStart = PtCtrl_Text_OnPaintStart;
	pPtCtrl_Text->m_ptctrl_base.PtCtrl_OnPaintEnd = PtCtrl_Text_OnPaintEnd;
	
	pPtCtrl_Text->m_ptctrl_base.PtCtrl_OnStyleChange = PtCtrl_Text_OnStyleChange;
	pPtCtrl_Text->m_ptctrl_base.PtCtrl_OnColorChange = PtCtrl_Text_OnColorChange;
	
	pPtCtrl_Text->m_ptctrl_base.PtCtrl_OnMouseDown = PtCtrl_Text_OnMouseDown;
	pPtCtrl_Text->m_ptctrl_base.PtCtrl_OnMouseMove = PtCtrl_Text_OnMouseMove;
	pPtCtrl_Text->m_ptctrl_base.PtCtrl_OnMouseRelease = PtCtrl_Text_OnMouseRelease;

	pPtCtrl_Text->m_ptctrl_base.PtCtrl_OnDrawBoard = PtCtrl_Text_OnDrawBoard;
	pPtCtrl_Text->m_ptctrl_base.PtCtrl_OnDrawStyle = PtCtrl_Text_OnDrawStyle;
	
	return 0;
}

INT PtCtrl_Text_Init(PtCtrlBase* pPtCtrl,INT tx /* = -1 */, INT ty /* = -1 */)
{
	PtCtrlBase_Init(pPtCtrl);

	PtCtrl_Text *pPtCtrl_Text = (PtCtrl_Text*)pPtCtrl;
	
	pPtCtrl_Text->m_ptctrl_base.m_ctrl_id = PtCtrlType_Text;
	pPtCtrl_Text->m_opt_flag = PtCtrl_Text_Nothing;
	
	pPtCtrl_Text->cx = -1;
	pPtCtrl_Text->cy = -1;

	pPtCtrl_Text->m_pen = NULL;
	pPtCtrl_Text->m_text_hwnd = NULL;

	memset(pPtCtrl_Text->m_test_str,0,sizeof(pPtCtrl_Text->m_test_str));
    memset(&pPtCtrl_Text->m_text_rect,0,sizeof(pPtCtrl_Text->m_text_rect));

	memset(&text_wid_ary,0,512);
	return 0;
}

INT PtCtrl_Text_Destroy(PtCtrlBase* pPtCtrl, INT tx /* = -1 */, INT ty /* = -1 */)
{
	PtCtrlBase_Destroy(pPtCtrl);
   
    PtCtrl_Text *pPtCtrl_Text = (PtCtrl_Text*)pPtCtrl;

	if(pPtCtrl_Text->m_pen != NULL)
		DeleteObject(pPtCtrl_Text->m_pen);

	return 0;
}

INT PtCtrl_Text_OnPaintStart(PtCtrlBase* pPtCtrl,  INT tx /* = -1 */, INT ty /* = -1 */)
{
	PtCtrlBase_OnPaintStart(pPtCtrl);

	PtCtrl_Text *pPtCtrl_Text = (PtCtrl_Text*)pPtCtrl;
	
	pPtCtrl->PtCtrl_OnColorChange(pPtCtrl,m_pt_app_info.m_color_cur,m_pt_app_info.m_color_bk_cur);

    return 0;
}

INT PtCtrl_Text_OnPaintEnd(PtCtrlBase* pPtCtrl,  INT tx /* = -1 */, INT ty /* = -1 */)
{
	PtCtrlBase_OnPaintEnd(pPtCtrl);

	PtCtrl_Text *pPtCtrl_Text = (PtCtrl_Text*)pPtCtrl;
    
    pPtCtrl_Text->cx = -1;
	pPtCtrl_Text->cy = -1;

	
	switch(pPtCtrl_Text->m_opt_flag)
	{
		
	case PtCtrl_Text_SetText:
		TRACE(L"end settext\n");
		
		//pPtCtrl_Text->m_opt_flag = PtCtrl_Text_DrawText;
		
        //GetWindowPlacement(pPtCtrl_Text->m_text_hwnd,&wpl);
		
		//pPtCtrl_Text->m_text_rect = wpl.rcNormalPosition;
		
		//GetWindowText(pPtCtrl_Text->m_text_hwnd,pPtCtrl_Text->m_test_str,510);
		DestroyWindow(pPtCtrl_Text->m_text_hwnd);
		
		m_pt_app_info.m_pt_board_flag |= PT_BOARD_FLAG_RELOAD;
		InvalidateRect(m_pt_app_info.m_pt_board_hwnd, &m_pt_app_info.m_pt_board_rect,FALSE);
		
		//pPtCtrl_Text->cx = tx;
        //pPtCtrl_Text->cy = ty;
	}

	pPtCtrl_Text->m_opt_flag = PtCtrl_Text_Nothing;
	

	return 0;
}

INT PtCtrl_Text_OnStyleChange(PtCtrlBase* pPtCtrl,  INT tx /* = -1 */, INT ty /* = -1 */)
{
	PtCtrlBase_OnStyleChange(pPtCtrl,tx);
	
	PtCtrl_Text *pPtCtrl_Text = (PtCtrl_Text*)pPtCtrl;
	
	
	return 0;
}

INT PtCtrl_Text_OnColorChange(PtCtrlBase* pPtCtrl,  INT tx /* = -1 */, INT ty /* = -1 */)
{
	PtCtrlBase_OnColorChange(pPtCtrl,tx,ty);
	
	PtCtrl_Text *pPtCtrl_Text = (PtCtrl_Text*)pPtCtrl;
	
	if(pPtCtrl_Text->m_pen != NULL)
		DeleteObject(pPtCtrl_Text->m_pen);

	pPtCtrl_Text->m_pen = CreatePen(PS_SOLID,0,m_pt_app_info.m_color_cur);
	
	
	return 0;
}


INT PtCtrl_Text_OnMouseDown(PtCtrlBase* pPtCtrl,  INT tx /* = -1 */, INT ty /* = -1 */)
{
	PtCtrlBase_OnMouseDown(pPtCtrl);
    
	PtCtrl_Text *pPtCtrl_Text = (PtCtrl_Text*)pPtCtrl;
    //WINDOWPLACEMENT wpl;
	LONG win_style;
	RECT rt;

	switch(pPtCtrl_Text->m_opt_flag)
	{
	case PtCtrl_Text_Nothing:
	    pPtCtrl_Text->m_opt_flag = PtCtrl_Text_SetText;

		memset(pPtCtrl_Text->m_test_str,0,sizeof(pPtCtrl_Text->m_test_str));
        memset(&pPtCtrl_Text->m_text_rect,0,sizeof(pPtCtrl_Text->m_text_rect));

		win_style = WS_BORDER | WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL ;
        
		pPtCtrl_Text->m_text_hwnd = CreateWindow(TEXT ("edit"), NULL,
			win_style,
			tx, ty, 80, 20, m_pt_app_info.m_pt_board_hwnd, (HMENU) NULL,
			m_pt_app_info.m_hInst, NULL);
        
		pPtCtrl_Text->m_ptctrl_base.m_cx = tx;
		pPtCtrl_Text->m_ptctrl_base.m_cy = ty;

		ShowWindow(pPtCtrl_Text->m_text_hwnd,SW_SHOW);
		UpdateWindow(pPtCtrl_Text->m_text_hwnd);
	
		break;
	
	case PtCtrl_Text_SetText:
		TRACE(L"on down\n");
		
		pPtCtrl_Text->m_opt_flag = PtCtrl_Text_DrawText;
		
        //GetWindowPlacement(pPtCtrl_Text->m_text_hwnd,&wpl);
        //pPtCtrl_Text->m_text_rect = wpl.rcNormalPosition;

		GetWindowRect(pPtCtrl_Text->m_text_hwnd,&pPtCtrl_Text->m_text_rect);

		GetWindowRect(m_pt_app_info.m_pt_board_hwnd,&rt);
		OffsetRect(&pPtCtrl_Text->m_text_rect,-rt.left,-rt.top);
		
		GetWindowText(pPtCtrl_Text->m_text_hwnd,pPtCtrl_Text->m_test_str,510);
		DestroyWindow(pPtCtrl_Text->m_text_hwnd);
		
		m_pt_app_info.m_pt_board_flag |= PT_BOARD_FLAG_PTCTRL;
		InvalidateRect(m_pt_app_info.m_pt_board_hwnd, &m_pt_app_info.m_pt_board_rect,FALSE);

		pPtCtrl_Text->cx = tx;
        pPtCtrl_Text->cy = ty;
	}
	
	TRACE(L"On Mouse Down\n");
	
	return 0;
}

INT PtCtrl_Text_OnMouseMove(PtCtrlBase* pPtCtrl,  INT tx /* = -1 */, INT ty /* = -1 */)
{
	PtCtrlBase_OnMouseMove(pPtCtrl);

// 	if(pPtCtrl->m_mouse_state & PT_MOUSE_DOWN)
// 	{
// 		TRACE("OnMouseMove\n");
// 
// 		PtCtrl_Text *pPtCtrl_Text = (PtCtrl_Text*)pPtCtrl;
// 		pPtCtrl_Text->m_opt_flag = PtCtrl_Text_LinkLine;
// 		
// 		pPtCtrl_Text->cx = tx;
// 		pPtCtrl_Text->cy = ty;
// 		
// 				
// 		InvalidateRect(m_pt_app_info.m_pt_board_hwnd, &m_pt_app_info.m_pt_board_rect,FALSE);
// 		
// 	}
	

	return 0;
}

INT PtCtrl_Text_OnMouseRelease(PtCtrlBase* pPtCtrl,  INT tx /* = -1 */, INT ty /* = -1 */)
{
	PtCtrlBase_OnMouseRelease(pPtCtrl);


	return 0;
}


INT PtCtrl_Text_OnDrawBoard(PtCtrlBase* pPtCtrl,  INT tx /* = -1 */, INT ty /* = -1 */)
{
	PtCtrl_Text *pPtCtrl_Text = (PtCtrl_Text*)pPtCtrl;

	RECT rt;

#define DT_FIX 0

	switch(pPtCtrl_Text->m_opt_flag)
	{
	case PtCtrl_Text_DrawText:
		
// 		BitBlt(pPtCtrl->m_pdc,
// 		 	   pPtCtrl_Text->m_text_rect.left,
// 			   pPtCtrl_Text->m_text_rect.top,
// 			   pPtCtrl_Text->m_text_rect.right - pPtCtrl_Text->m_text_rect.left,
// 			   pPtCtrl_Text->m_text_rect.bottom - pPtCtrl_Text->m_text_rect.top,
// 			   m_pt_app_info.m_pt_backup_hdc,
// 			   pPtCtrl_Text->m_text_rect.left,
// 			   pPtCtrl_Text->m_text_rect.top,
// 			   SRCCOPY);

        if(pPtCtrl_Text->m_ptctrl_base.m_ctrl_style)
		{
			//SetBkMode(pPtCtrl->m_pdc,TRANSPARENT);
			SetBkMode(m_pt_app_info.m_pt_backup_hdc,TRANSPARENT);
		}
		
// 		TextOut(m_pt_app_info.m_pt_backup_hdc,
// 			pPtCtrl_Text->m_ptctrl_base.m_cx + DT_FIX,
// 			pPtCtrl_Text->m_ptctrl_base.m_cy + DT_FIX,
// 			pPtCtrl_Text->m_test_str,strlen(pPtCtrl_Text->m_test_str));


		DrawText(m_pt_app_info.m_pt_backup_hdc,pPtCtrl_Text->m_test_str,wcslen(pPtCtrl_Text->m_test_str),&pPtCtrl_Text->m_text_rect,DT_VCENTER);

// 		ExtTextOut(m_pt_app_info.m_pt_backup_hdc,
// 		             pPtCtrl_Text->m_ptctrl_base.m_cx + DT_FIX,
// 					 pPtCtrl_Text->m_ptctrl_base.m_cy + DT_FIX,
// 		             ETO_OPAQUE,&rt,
// 					 pPtCtrl_Text->m_test_str,wcslen(pPtCtrl_Text->m_test_str),
// 		             text_wid_ary
// 					);

		StretchBlt(pPtCtrl->m_pdc,
			0,0,
			m_pt_app_info.m_pt_draw_rect.right,m_pt_app_info.m_pt_draw_rect.bottom,
			m_pt_app_info.m_pt_backup_hdc,
			m_pt_app_info.m_pt_bakup_pos.x,m_pt_app_info.m_pt_bakup_pos.y,
			m_pt_app_info.m_pt_draw_rect.right>>m_pt_app_info.m_pt_zoom_size,m_pt_app_info.m_pt_draw_rect.bottom>>m_pt_app_info.m_pt_zoom_size,
			SRCCOPY);

// 		TextOut(pPtCtrl->m_pdc,
// 			pPtCtrl_Text->m_ptctrl_base.m_cx + DT_FIX,
// 			pPtCtrl_Text->m_ptctrl_base.m_cy + DT_FIX,
// 			pPtCtrl_Text->m_test_str,strlen(pPtCtrl_Text->m_test_str));
		
		if(pPtCtrl_Text->m_ptctrl_base.m_ctrl_style)
		{
			//SetBkMode(pPtCtrl->m_pdc,TRANSPARENT);
			SetBkMode(m_pt_app_info.m_pt_backup_hdc,TRANSPARENT);
		}
		

		pPtCtrl_Text->m_opt_flag = PtCtrl_Text_Nothing;

		break;

	default :
		return 1;
	}


	return 0;
}

INT PtCtrl_Text_OnDrawStyle(PtCtrlBase* pPtCtrl,  INT tx /* = -1 */, INT ty /* = -1 */)
{
	PtCtrlBase_OnDrawStyle(pPtCtrl,tx);
	PtCtrl_Text *pPtCtrl_Text = (PtCtrl_Text*)pPtCtrl;

	RECT rt;
	GetWindowRect(m_pt_app_info.m_pt_style_bn_hwnd[tx],&rt);
	OffsetRect(&rt,-rt.left,-rt.top);
	
	if(tx == pPtCtrl->m_ctrl_style)
		FillRect(pPtCtrl->m_pdc,&rt,(HBRUSH)GetStockObject(WHITE_BRUSH));


#define RT_FIX 2 

	rt.left += RT_FIX ;
	rt.right -= RT_FIX;
	rt.top += RT_FIX;
 	rt.bottom -= RT_FIX;

	switch(tx)
	{
	case 0:
		SelectObject(pPtCtrl->m_pdc,GetStockObject(GRAY_BRUSH));
		SelectObject(pPtCtrl->m_pdc,GetStockObject(BLACK_PEN));

 		
		Rectangle(pPtCtrl->m_pdc, rt.left,rt.top,rt.right,rt.bottom);
	    
		SetBkMode(pPtCtrl->m_pdc,OPAQUE);

		DrawText(pPtCtrl->m_pdc,TEXT("ABC"),3,&rt,DT_CENTER);
		break;
	
	case 1:
		SelectObject(pPtCtrl->m_pdc,GetStockObject(GRAY_BRUSH));
		SelectObject(pPtCtrl->m_pdc,GetStockObject(BLACK_PEN));

		
		Rectangle(pPtCtrl->m_pdc, rt.left,rt.top,rt.right,rt.bottom);
		
		SetBkMode(pPtCtrl->m_pdc,TRANSPARENT);

		DrawText(pPtCtrl->m_pdc,TEXT("ABC"),3,&rt,DT_CENTER);

		break;
	
	case 2:
		break;
	}



	return 0;
}

⌨️ 快捷键说明

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