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

📄 qikunyudlg.cpp

📁 通过VC++实现的各种文字通用的排序算法
💻 CPP
字号:
// QikunyuDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Qikunyu.h"
#include "QikunyuDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CQikunyuDlg dialog

CQikunyuDlg::CQikunyuDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CQikunyuDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CQikunyuDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CQikunyuDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CQikunyuDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CQikunyuDlg, CDialog)
	//{{AFX_MSG_MAP(CQikunyuDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CQikunyuDlg message handlers

BOOL CQikunyuDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CQikunyuDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CQikunyuDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CQikunyuDlg::OnOK() 
{
    FILE * pf = fopen ("f:\\程序\\藏文排序和码表转换\\lwx1.txt", "r");
	char  szLine[128] = {'\0'};
	WORD   code = 0x0000;
	BYTE   b1=0, b2=0;
	TibetCode tc;

	while(!feof( pf))
	{
		
		memset((void*) szLine, '\0', 128);
		fscanf(pf, "%s %x", szLine,  &code);
		
		b1 = (BYTE) szLine[0];
		b2 = (BYTE) szLine[1];
		WORD  tCode = MAKEWORD(b2, b1);
		WORD  wHua=code;// = UniCodeToGBK( code );
		
		tc.tCode = tCode;
		tc.hCode = wHua;
		m_arr.Add ( tc);
		//fprintf(pw, "%s %x%x   %x  %x \r\n",  szLine, b1,b2, code, wHua);
	}
	if( pf ) fclose( pf );

	// sorting 
	Sorting( &m_arr );
   

	FILE * pw = fopen ("f:\\程序\\藏文排序和码表转换\\table.txt", "w");
	int size =  m_arr.GetSize(); 
	int i=0;
	for( i=0;i<size;i++)
	{
		tc = m_arr.GetAt(i); 
		fprintf(pw, "{0x%x, 0x%x},\n",   tc.tCode,  tc.hCode );
	}

	if( pw ) fclose( pw );
	AfxMessageBox("OK");
}



WORD  CQikunyuDlg::UniCodeToGBK( WORD  w )
{
	if( w == 0 ) return 0;
	char buf[3] = {'\0'};
	WideCharToMultiByte(CP_ACP,WC_COMPOSITECHECK, &w, 2, buf, 2, NULL, NULL);
	BYTE b1 = buf[0];
	BYTE b2 = buf[1];
	WORD  wRet = MAKEWORD(b2, b1);
	return wRet;
}

	
void CQikunyuDlg::Sorting(	CArray <TibetCode, TibetCode& > *  parr)
{
	int size =  parr->GetSize(); 
	int i=0, k=0;
	TibetCode tc1, tc2;
	WORD  wt, wh;
    for(i=0; i<size;i++)
	{
		for(k=0;k<size-i-1;k++) 
		{
			tc1 = parr->GetAt( k);
			tc2 = parr->GetAt( k+1);
			if( tc1.tCode > tc2.tCode  )
			{
				wt = tc1.tCode;
				wh = tc1.hCode; 
				tc1.tCode  = tc2.tCode;
				tc1.hCode  = tc2.hCode;
				tc2.tCode = wt;
				tc2.hCode = wh;
				parr->SetAt(k,    tc1);
				parr->SetAt(k+1,  tc2);				
			}
		}
	}
}

⌨️ 快捷键说明

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