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

📄 resizingdialog.cpp

📁 以SQL语句从数据库里查询出记录
💻 CPP
字号:
////////////////////////////////////////////////////////////////////////
// ResizingDialog.cpp : implementation file
//
// The base class for the dialog box you want to allow resizing
// Use SetConrolInfo() to determine how each control behaves when
// the user resize the dialog box.
// (The "Windows default" is ANCHORE_TOP | ANCHORE_LEFT)
//
// e.g. For a right aligned OK button you'll probably call:
// SetControlInfo(IDOK, ANCHORE_RIGHT)
// For a text control that needs to resize with the dialog you may do:
// SetControlInfo(IDD_MYEDITOR, RESIZE_BOTH)
//
// Note: The dialog box "remebers" its size on destroy and the next time
// you launch it, it'll set the dialog size back to the previous size.
// If you don't like this behavior, call SetRememberSize(FALSE)
//
// LIMITATIONS:
// 1) This class does not handle overlapping controls, 
//    e.g., you cannot place two controls one (RESIZE_VER) and the other
//    with (RESIZE_VER | ANCHORE_BOTTOM) one below the other, they may ovelapp.
//
// 2) This class does not remember the mode of the dialog (Maximized/Minimized)
//	  it would be easy to add this feature, though.

#include "stdafx.h"
#include "ResizingDialog.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// CResizingDialog dialog
CResizingDialog::CResizingDialog(UINT nIDTemplate, CWnd* pParentWnd) : 
				CDialog(nIDTemplate,pParentWnd)
{
	m_minWidth = m_minHeight = 0;	// flag that GetMinMax wasn't called yet
	m_old_cx = m_old_cy = 0;
	m_bSizeChanged = FALSE;
	m_nIDTemplate = nIDTemplate;
	m_bRememberSize = TRUE;
	m_bInited = FALSE;
}

void CResizingDialog::SetControlInfo(WORD CtrlId,WORD Anchore)			
{
	if(Anchore == ANCHORE_LEFT)
		return; // Do nothing

	// Add resizing behaviour for the control
	DWORD c_info = CtrlId | (Anchore << 16);
	m_control_info.Add(c_info);
}

BEGIN_MESSAGE_MAP(CResizingDialog, CDialog)
	//{{AFX_MSG_MAP(CResizingDialog)
	ON_WM_SIZE()
	ON_WM_GETMINMAXINFO()
	ON_WM_DESTROY()
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


//////////////////////////////////////////////////////////////////////////
// CResizingDialog message handlers



//////////////////////////////////////////////////////////////////////////
// OnInitDialog()
//
BOOL CResizingDialog::OnInitDialog()
{
	CDialog::OnInitDialog();

	if(m_bRememberSize)
	{
		// Load the previous size of the dialog box from the INI/Registry
		char dialog_name[7];
		
		itoa(m_nIDTemplate, dialog_name, 16);
		//int cx = AfxGetApp()->GetProfileInt(dialog_name,"CX",0);
		//int cy = AfxGetApp()->GetProfileInt(dialog_name,"CY",0);
		
		//if(cx && cy)
		//{
		//	SetWindowPos( NULL, 0, 0, cx, cy, SWP_NOMOVE );
		//}
	}
	
	m_pDbAccess = GetAdoDb();

	return FALSE;  // return TRUE  unless you set the focus to a control
}


void CResizingDialog::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	int dx = cx - m_old_cx;
	int dy = cy - m_old_cy;

	if(m_old_cx)
	{
		// Move and Size the controls using the information
		// we got in SetControlInfo()
		//
		m_bSizeChanged = TRUE;
		CRect WndRect;
		CWnd *pWnd;
		DWORD c_info;
		short Anchore;
		for(int i = 0; i < m_control_info.GetSize(); i++)
		{
			c_info = m_control_info[i];
			pWnd = GetDlgItem(LOWORD(c_info));
			if(!pWnd)
			{
				TRACE("Control ID - %d NOT FOUND!!\n",LOWORD(c_info));
				continue;
			}

			if(!HIWORD(c_info))
				continue; // do nothing if anchored to top and or left

			Anchore = HIWORD(c_info);
			pWnd->GetWindowRect(&WndRect);  ScreenToClient(&WndRect);
			
			if(Anchore & RESIZE_HOR)
				WndRect.right += dx;
			else if(Anchore & ANCHORE_RIGHT)
				WndRect.OffsetRect(dx,0);

			if(Anchore & RESIZE_VER)
				WndRect.bottom += dy;
			else if(Anchore & ANCHORE_BOTTOM)
				WndRect.OffsetRect(0,dy);

			pWnd->MoveWindow(&WndRect);
		}

	}
	m_old_cx = cx;
	m_old_cy = cy;
}

void CResizingDialog::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
    if (!m_minWidth) // first time
		{
		CDialog::OnGetMinMaxInfo(lpMMI);
		return;
		}
    lpMMI->ptMinTrackSize.x = m_minWidth;
    lpMMI->ptMinTrackSize.y = m_minHeight;
}

void CResizingDialog::OnDestroy() 
{
	// Save the size of the dialog box, so next time
	// we'll start with this size
	if(m_bRememberSize && m_bSizeChanged && m_old_cx && m_old_cy)
		{
		CRect rc;
		GetWindowRect(&rc);
		char dialog_name[7];	
		itoa(m_nIDTemplate, dialog_name, 16);				

		//AfxGetApp()->WriteProfileInt(dialog_name,"CX",rc.Width());
		//AfxGetApp()->WriteProfileInt(dialog_name,"CY",rc.Height());
		}
	m_minWidth = m_minHeight = m_old_cx = m_old_cy = 0;
	m_bSizeChanged = FALSE;
	CDialog::OnDestroy();
}


int CResizingDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// Remember the original size so later we can calculate
	// how to place the controls on dialog Resize
	m_minWidth  = lpCreateStruct->cx;
	m_minHeight = lpCreateStruct->cy;
	return 0;
}

void CResizingDialog::OnOK()
{
}
void CResizingDialog::OnCancel()
{
}

void CResizingDialog::InitDataBuffer()
{
	m_arrControlID.RemoveAll();
	m_arrValue.RemoveAll();
}

BOOL CResizingDialog::PushData(CString strSQL)
{
	m_arrValue.RemoveAll();
	CString str;
	for (long i = 0; i <  m_arrControlID.GetSize(); i++) {
		CWnd *pWnd = GetDlgItem(m_arrControlID.GetAt(i));
		char lpClassName[255];
		::GetClassName(pWnd->GetSafeHwnd(), lpClassName, 255);
		CString str = lpClassName;
		if (str == "Button") {
			CButton *button = (CButton*)pWnd;
			if (0 == button->GetCheck()) m_arrValue.Add("0");
			else m_arrValue.Add("1");}
		else {
			GetDlgItemText( m_arrControlID.GetAt(i), str); 
			m_arrValue.Add(str); 
		}
	}

	return m_pDbAccess->AddRecordValues(strSQL,m_arrValue);
}

BOOL CResizingDialog::UpdateDbRec(CString strSQL)
{
	m_arrValue.RemoveAll();
	CString str;
	for (long i = 0; i <  m_arrControlID.GetSize(); i++) {
		CWnd *pWnd = GetDlgItem(m_arrControlID.GetAt(i));
		char lpClassName[255];
		::GetClassName(pWnd->GetSafeHwnd(), lpClassName, 255);
		CString str = lpClassName;
		if (str == "Button") {
			CButton *button = (CButton*)pWnd;
			if (0 == button->GetCheck()) m_arrValue.Add("0");
			else m_arrValue.Add("1");}
		else {
			GetDlgItemText( m_arrControlID.GetAt(i), str); 
			m_arrValue.Add(str); 
		}
	}

	return m_pDbAccess->AmendRecordValues(strSQL,m_arrValue);
}

BOOL CResizingDialog::StringToDate(CString str, COleDateTime &t)
{
	int nYear,nMonth,nDay;
	CTime tt = CTime::GetCurrentTime();
	nYear = tt.GetYear();
	nMonth = tt.GetMonth();
	nDay = tt.GetDay();

	if(!str.IsEmpty())
		sscanf(str, "%d-%d-%d", &nYear, &nMonth, &nDay);
	
	t.SetDate(nYear,nMonth,nDay);
	return TRUE;
}

BOOL CResizingDialog::PopData(CString strSQL)
{
	m_pDbAccess->GetRecordValues(strSQL,m_arrValue);
	
	long lCount = m_arrValue.GetSize();
	for (long i = 0; i < lCount; i++) {
		CWnd *pWnd = GetDlgItem(m_arrControlID.GetAt(i));
		char lpClassName[255];
		::GetClassName(pWnd->GetSafeHwnd(), lpClassName, 255);
		CString str = lpClassName;
		if (str == "SysDateTimePick32") {
			CDateTimeCtrl *date = (CDateTimeCtrl*)pWnd;
			COleDateTime t;
			if (StringToDate(m_arrValue.GetAt(i), t))
			date->SetTime(t);
		}
		else if (str == "Button") {
			CButton *button = (CButton*)pWnd;
			button->SetCheck(atol(m_arrValue.GetAt(i)));
		}
		else if (str == "ComboBox") {
			CString strCmb;
			CComboBox *cmbox = (CComboBox*)pWnd;
			long lCmbCount = cmbox->GetCount();
			for (long j = 0; j < lCmbCount; j++) {
				cmbox->GetLBText(j, strCmb);
				if (strCmb == m_arrValue.GetAt(i)) {
					cmbox->SetCurSel(j);
					break;
				}
			}
		}
		else{
			CString strText = m_arrValue.GetAt(i);
			if(strText.IsEmpty())SetDlgItemText(m_arrControlID.GetAt(i),"");
			else SetDlgItemText(m_arrControlID.GetAt(i), m_arrValue.GetAt(i));
		}
	}
	
	return TRUE;
}

HRESULT CResizingDialog::ShowPic(HWND hWnd,char *lpstrFile)
{
	return S_OK;
}

⌨️ 快捷键说明

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