锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
絎竴姝?瀹氫箟娑堟伅銆?/font>
銆鎺ㄨ崘鐢ㄦ埛鑷畾涔夋秷鎭嚦灝戞槸WM_USER+100錛屽洜涓哄緢澶氭柊鎺т歡涔熻浣跨敤WM_USER娑堟伅銆?br>#define WM_MY_MESSAGE (WM_USER+100)
絎簩姝?瀹炵幇娑堟伅澶勭悊鍑芥暟銆?/strong>
璇ュ嚱鏁頒嬌鐢╓PRAM鍜孡PARAM鍙傛暟騫惰繑鍥濴PESULT銆?
LPESULT CMainFrame::OnMyMessage(WPARAM wParam, LPARAM lParam)
{
// TODO: 澶勭悊鐢ㄦ埛鑷畾涔夋秷鎭?
...
return 0;
}
絎笁姝?鍦ㄧ被澶存枃浠剁殑AFX_MSG鍧椾腑璇存槑娑堟伅澶勭悊鍑芥暟:
class CMainFrame:public CMDIFrameWnd
{
...
// 涓鑸秷鎭槧灝勫嚱鏁?
protected:
// {{AFX_MSG(CMainFrame)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
}
絎洓姝?鍦ㄧ敤鎴風被鐨勬秷鎭潡涓紝浣跨敤ON_MESSAGE瀹忔寚浠ゅ皢娑堟伅鏄犲皠鍒版秷鎭鐞嗗嚱鏁頒腑銆?/strong>
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_TIMER()
ON_MESSAGE(WM_MY_MESSAGE, OnMyMessage)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
銆銆濡傛灉鐢ㄦ埛闇瑕佷竴涓畾涔夋暣涓郴緇熷敮涓鐨勬秷鎭?鍙互璋冪敤SDK鍑芥暟RegisterWindowMessage瀹氫箟娑堟伅:
static UINT WM_MY_MESSAGE=RegisterWindowMessage("User");
銆銆騫朵嬌鐢∣N_REGISTERED_MESSAGE瀹忔寚浠ゅ彇浠N_MESSAGE瀹忔寚浠?鍏朵綑姝ラ鍚屼笂銆?br>銆銆褰撻渶瑕佷嬌鐢ㄨ嚜瀹氫箟娑堟伅鏃?鍙互鍦ㄧ浉搴旂被涓殑鍑芥暟涓皟鐢ㄥ嚱鏁癙ostMessage鎴朣endMessage鍙戦佹秷鎭?font color="#990000">PoseMessage(WM_MY_MESSAGE,O,O);
濡傛灉鍚戝叾浠栬繘紼嬪彂閫佹秷鎭彲閫氳繃濡備笅鏂規硶鍙戦佹秷鎭?
DWORD result;
SendMessageTimeout(wnd->m_hWnd, // 鐩爣紿楀彛
WM_MY_MESSAGE, // 娑堟伅
0, // WPARAM
0, // LPARAM
SMTO_ABORTIFHUNG |
SMTO_NORMAL,
TIMEOUT_INTERVAL,
&result);
浠ラ伩鍏嶅叾瀹冭繘紼嬪鏋滆闃誨鑰岄犳垚緋葷粺姝葷瓑鐘舵併?br> 鍙槸濡傛灉闇瑕佸悜鍏跺畠綾?(濡備富妗嗘灦銆佸瓙紿楀彛銆佽綾匯佸璇濇銆佺姸鎬佹潯銆佸伐鍏鋒潯鎴栧叾浠栨帶浠剁瓑
鍙戦佹秷鎭椂涓婅堪鏂規硶鏄懼緱鏃犺兘涓哄姏錛岃屽湪緙栫▼榪囩▼涓線寰闇瑕佽幏鍙栧叾瀹冪被涓殑鏌愪釜璇嗗埆淇″彿
妗嗘灦緇欐垜浠犳垚浜嗙縐嶉檺鍒?浣嗘槸鍙互閫氳繃鑾峰彇鏌愪釜綾葷殑鎸囬拡鑰屽悜榪欎釜綾誨彂閫佹秷鎭紝
鑰岃嚜瀹氫箟娑堟伅鐨勫悇縐嶅姩浣滃垯鍦ㄨ繖涓被涓畾涔夛紝榪欐牱灝卞彲浠ヨ嚜鐢辮嚜鍦ㄧ殑鍚戝叾瀹冪被鍙戦佹秷鎭簡銆?nbsp;
銆銆涓嬮潰涓劇殑渚嬪瓙鍙欒堪浜嗗悜瑙嗙被鍜屾鏋剁被鍙戦佹秷鎭殑鏂規硶錛?br>鈽呭湪涓繪鏋剁被涓悜瑙嗙被鍙戦佹秷鎭細
1.瑙嗙被涓畾涔夋秷鎭細
ON_REGISTERED_MESSAGE(WM_MY_MESSAGE,OnMyMessage) //瀹氫箟娑堟伅鏄犲皠
2.瑙嗙被瀹氫箟娑堟伅澶勭悊鍑芥暟錛?br>LRESULT CMessageView::OnMyMessage(WPARAM wParam, LPARAM lParam)
{
// TODO: 澶勭悊鐢ㄦ埛鑷畾涔夋秷鎭?
...
return 0;
}
3.鍙戦佹秷鎭殑嫻嬭瘯鍑芥暟
void CMainFrame::OnTest()
{
CView * active = GetActiveView();//鑾峰彇褰撳墠瑙嗙被鎸囬拡
if(active != NULL)
active->PostMessage(WM_MY_MESSAGE,0,0);
}
鈽呭湪鍏跺畠綾諱腑鍚戣綾誨彂閫佹秷鎭細
//鍙戦佹秷鎭殑嫻嬭瘯鍑芥暟
void CMyDialog::OnTest()
{
CMDIFrameWnd *pFrame;
CMDIChildWnd *pChild;
CView *pView;
//鑾峰彇涓葷獥鍙f寚閽?br> pFrame =(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
// 鑾峰彇瀛愮獥鍙f寚閽?br> pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
//鑾峰彇瑙嗙被鎸囬拡
pView = pChild->GetActiveView();
if(pView != NULL)
pView->PostMessage(WM_MY_MESSAGE,0,0);//鍙戦佹秷鎭?br>}
鍏朵綑姝ラ鍚屼笂銆?br>鈽呭湪瑙嗙被涓悜涓繪鏋跺彂閫佹秷鎭?
棣栧厛鍦ㄤ富妗嗘灦涓畾涔夌浉鍏崇殑娑堟伅,鏂規硶鍚屼笂,鐒跺悗鍦ㄥ彂閫佹秷鎭殑鍑芥暟涓坊鍔犱唬鐮佸涓?br>//鍙戦佹秷鎭殑嫻嬭瘯鍑芥暟
void CMessageView::OnTest()
{
CFrameWnd * active = GetActiveFrame();//鑾峰彇褰撳墠涓葷獥鍙f鏋舵寚閽?br> if(active != this)
active->PostMessage(WM_MY_MESSAGE,0,0);
return 0;
}
銆銆鍦ㄥ叾瀹冪被涓悜涓嶅悓鐨勭被鍙戦佹秷鎭彲渚濇鏂規硶綾繪帹錛岃繖鏍鋒垜浠殑紼嬪簭灝卞彲浠ョ殑涓嶅彈闄愬埗鍚戝叾瀹冪被鍜岃繘紼嬪彂閫佹秷鎭紝鑰岄伩鍏嶄簡縐嶇鎰忔兂涓嶅埌鐨勯闄┿?br>
銆愬疄渚嬨?
銆銆涓嬮潰涓涓緥瀛愮▼搴忎負澶氭枃妗g▼搴忛噷鍦ㄤ竴瀵硅瘽妗嗕腑鍚戣綾誨彂閫佹秷鎭?璇﹁堪浜嗗彂閫佽嚜瀹氫箟娑堟伅鐨勫叿浣撹繃紼嬨?br>銆銆瀹炵幇姝ラ錛?/p>
絎竴姝ワ細鍦╒C++涓柊寤哄伐紼婱essage錛屾墍鏈塁lassWizard姝ラ閫夐」鍧囦負緙虹渷,瀹屾垚銆?br>絎簩姝ワ細鍦ㄤ富鑿滃崟涓坊鍔犳祴璇曡彍鍗曚負璋冨嚭瀵硅瘽妗嗭紝鍦ㄦ鏋剁被涓緩绔嬬浉搴斿嚱鏁癘nTest().
絎笁姝ワ細鍦ㄨ祫婧愪腑寤虹珛瀵硅瘽妗嗭紝閫氳繃ClassWizard娣誨姞鏂扮被TestDialog,娣誨姞嫻嬭瘯鎸夐挳, 鍦ㄥ璇濇綾諱腑寤虹珛鐩稿簲鍑芥暟OnDialogTest()
//閫氳繃瀵硅瘽妗嗘寜閽彂閫佹秷鎭殑鍑芥暟
void TestDialog::OnDialogTest()
{
CMDIFrameWnd *pFrame;
CMDIChildWnd *pChild;
CView *pView;
//鑾峰彇涓葷獥鍙f寚閽?br> pFrame =(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
// 鑾峰彇瀛愮獥鍙f寚閽?br> pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
//鑾峰彇瑙嗙被鎸囬拡
pView = pChild->GetActiveView();
if(pView != NULL)
pView ->PostMessage(WM_MY_MESSAGE,0,0);//鍙戦佹秷鎭?br>}
銆銆鍦∕essage.h澶存枃浠朵腑娣誨姞濡備笅璇彞錛?br>static UINT WM_MY_MESSAGE=RegisterWindowMessage("Message");
絎洓姝?鍦ㄨ綾諱腑娣誨姞鑷畾涔夋秷鎭?
鍦ㄥご鏂囦歡MessageView.h涓坊鍔犳秷鎭槧灝?br>protected:
//{{AFX_MSG(CMessageView)
//}}AFX_MSG
afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam); //姝よ涓烘坊鍔犱唬鐮?br>DECLARE_MESSAGE_MAP()
鍦ㄨ綾繪枃浠禡essageView.cpp涓殑娑堟伅鏄犲皠涓坊鍔犺嚜瀹氫箟娑堟伅鏄犲皠
BEGIN_MESSAGE_MAP(CMessageView, CView)
//{{AFX_MSG_MAP(CMessageView)
//}}AFX_MSG_MAP
// Standard printing commands
ON_REGISTERED_MESSAGE(WM_MY_MESSAGE,OnMyMessage) //姝よ娣誨姞浠g爜瀹氫箟鍞竴娑堟伅
END_MESSAGE_MAP()
娣誨姞鐩稿簲鐨?娑堟伅澶勭悊鍑芥暟
LRESULT CMessageView::OnMyMessage(WPARAM wParam, LPARAM lParam)
{
CRect rect;
GetClientRect(&rect);
InvalidateRect(&rect);
test=!test;
return 0;
}
鍦∕essageView.h涓坊鍔犲竷灝斿彉閲?public:BOOL test;
鍦ㄨ綾繪瀯閫犲嚱鏁頒腑鍒濆鍖?test鍙橀噺:test=FALSE;
淇敼CMessageView::OnDraw()鍑芥暟
void CMessageView::OnDraw(CDC* pDC)
{
CMessageDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// 浠ヤ笅紼嬪簭鏄劇ず娑堟伅鍝嶅簲鏁堟灉
if(test)
pDC->TextOut(0,0,"娑堟伅鍝嶅簲!");
}
絎簲姝ワ細鏄劇ず嫻嬭瘯瀵硅瘽妗?br>鍦∕ainFrame綾諱腑鍖呭惈瀵硅瘽妗嗗ご鏂囦歡錛?br>#include "TestDialog.h";
OnTest()鍑芥暟涓坊鍔犱唬鐮?br>void CMainFrame::OnTest()
{
TestDialog dialog;
dialog.DoModal();
}
榪愯紼嬪簭,鍦ㄦ祴璇曡彍鍗曟墦寮瀵硅瘽妗?鐐瑰嚮嫻嬭瘯鎸夐挳鍗沖彲鐪嬪埌緇撴灉
|
void CDlgTest::PrintOneNum()
{
CDC dc;
CPrintDialog printDlg(FALSE);
CPrintInfo Info;
printDlg.GetDefaults();
dc.Attach(printDlg.GetPrinterDC());
dc.m_bPrinting=TRUE;
CString strTitle;
strTitle.LoadString(AFX_IDS_APP_TITLE);
DOCINFO di;
::ZeroMemory(&di,sizeof(DOCINFO));
di.cbSize=sizeof(DOCINFO);
di.lpszDocName=strTitle;
if(dc.m_hDC)
{
BOOL bPrintingOk=dc.StartDoc(&di);
CPrintInfo Info;
m_nCurrentNum_WhenPrint=1; //褰撳墠琛ㄦ暟涓?,榪欎釜鐢ㄦ潵鎺у埗鎵撳嵃鐨勮〃鏁?/font>
int nPageTotalScale=0; //鍒濆鍖栦粠0寮濮?/font>
Info.m_nCurPage=1; //浠庣涓欏靛紑濮?/font>
dc.StartPage(); //寮濮嬫墦鍗伴〉
for(;;)
{
//鎵撳嵃瀹岄渶瑕佺殑琛ㄦ暟m_nTotalNum鍒欓鍑哄驚鐜?/font>
if(m_nCurrentNum_WhenPrint >m_nTotalNum) break;
else //鎵撳嵃涓寮犺〃
{
nPageTotalScale=OnPrintReport (&dc,&Info,nPageTotalScale, m_nCurrentNum_WhenPrint);
m_nCurrentNum_WhenPrint ++;
nPageTotalScale+=30; //鎵撳嵃涓嬩竴寮犺〃鐨勮璺濅粠錛?0寮濮?/font>
}
}
bPrintingOk=(dc.EndPage()>0); //緇撴潫涓欏?/font>
m_nCurrentNum_WhenPrint =0;
if(bPrintingOk)
dc.EndDoc();
else
dc.AbortDoc();
}
else
{
MessageBox("璇鋒鏌ユ墦鍗版満鏄惁榪炴帴瀹屽ソ錛?,"鎴戠殑紼?搴?,MB_ICONEXCLAMATION);
}
dc.Detach();
}
int CdlgTest::OnPrintReport(CDC *pDC, CPrintInfo *pInfo,
int nXBasePointWhenPrint, int m_nCurrentNum_WhenPrint)
{
int nXCurrentPoint=nXBasePointWhenPrint; //榪涜琛屾帶鍒剁殑鍙橀噺
//--------鎹㈤〉---------
if(nXCurrentPoint+210> 2000) //210涓哄皢瑕佸崰鐢ㄧ殑闀垮害
{
pDC->EndPage();
pDC->StartPage();
nXCurrentPoint=0;
pInfo->m_nCurPage++;
}
nXCurrentPoint+=210;
pDC->TextOut(0,nXCurrentPoint,"鎴戠殑鎶ヨ〃鍐呭錛屼粠0錛?10鐨勮〃闀垮害 ");
//姣忓綋鎵撳嵃鐨勮緭鍑鴻鎹㈣鐨勬椂鍊欏氨瑕佸垽鏂璱f(nXCurrentPoint+灝嗚浣跨敤鐨勯珮搴?gt; 2000)2000涓鴻瀹氱殑涓寮犵焊鐨勯珮搴︺?濡傛灉澶т簬綰稿紶楂樺害灝辮鎹㈤〉銆傝繖鏍峰氨淇濊瘉鎵撳嵃鍐呭榪炵畫銆?/font>
return nXCurrentPoint; //鏈鍚庤繑鍥炴墦鍗板畬褰撳墠琛ㄦ椂褰撳墠鐨勯〉闈㈤珮搴︼紝
浠ヤ究涓嬩竴寮犺〃鎺ョ潃榪欎釜楂樺害鎵撳嵃
}
聽鍦ㄥ崟鏂囨。涓殑浣跨敤鏂規硶
姝ラ涓銆鍒濆鍖?/font>
鍦–View綾葷殑.h澶存枃浠朵腑鍖呭惈鏂囦歡:
聽聽聽 #include "Gridctrl.h"
騫朵笖鎵嬪啓鍔犲叆濡備笅鐨勬垚鍛樺嚱鏁?
聽聽聽聽CGridCtrl * m_pGridCtrl;
姝ラ浜屻鏋勯犱笌鏋愭瀯
鏋勯犲嚱鏁頒腑:
聽聽聽m_pGridCtrl = NULL;
鏋愭瀯鍑芥暟涓?
聽聽聽if(m_pGridCtrl)
聽聽聽聽聽聽聽delete m_pGridCtrl;
姝ラ涓?濡傛灉闇瑕佹墦鍗板姛鑳界殑璇濇坊鍔犲悓鍚嶆墦鍗板嚱鏁頒唬鐮?/font>
鍦–View綾葷殑OnBeginPrinting()鍑芥暟涓坊鍔犲涓嬩唬鐮?
if(m_pGridCtrl)
聽聽聽聽m_pGridCtrl->OnBeginPrinting(pDC,pInfo); //綆鍗曞惂,榪欏氨鏄被鐨勫ソ澶?br />
鍏跺畠涓や釜鎵撳嵃鍑芥暟涔熶竴鏍風殑鍋氭硶.
姝ラ鍥?鍦∣nInitaUpdate()鍑芥暟涓垨鑰呬綘鑷繁娣誨姞鐨勮鏄劇ずGrid鐨勬秷鎭嚱鏁頒腑濡備笅鍒濆鍖?
//鍒涘緩闈炴ā寮忓璇濇涓婁緥鍙栬嚜瀹為檯宸ョ▼,紼嶆湁淇敼!
CDlg *dlg;
dlg=new CDlg();
dlg->Create(IDD_Dlg,this);
//鍒濆鍖朑ridCtrl鎺т歡
if(m_pGridCtrl!=NULL)
{
delete m_pGridCtrl;
m_pGridCtrl=NULL;
}
if (m_pGridCtrl == NULL)
{
// Create the Gridctrl object
m_pGridCtrl = new CGridCtrl;
if (!m_pGridCtrl) return 0;
// Create the Gridctrl window
CRect rect;
GetClientRect(rect);
m_pGridCtrl->Create(rect, this, 100);
// fill it up with stuff
m_pGridCtrl->SetEditable(false);
m_pGridCtrl->SetTextBkColor(RGB(0xFF, 0xFF, 0xE0)); //榛勮壊鑳屾櫙
m_pGridCtrl->EnableDragAndDrop(false);
try {
m_pGridCtrl->SetRowCount(k); //璁劇疆琛屾暟涓簁琛?br /> m_pGridCtrl->SetColumnCount(4); //k鍒?br /> m_pGridCtrl->SetFixedRowCount(1); //鏍囬琛屼負涓琛?br /> m_pGridCtrl->SetFixedColumnCount(1); //鍚屼笂
}
catch (CMemoryException* e)
{
e->ReportError();
e->Delete();
return 0;
}
//濉厖鍒楁爣棰?br /> int row=0;
for(int col=0;col<4;col++)
{
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = row;
Item.col = col;
if(col==0){
Item.nFormat = DT_CENTER|DT_WORDBREAK;
Item.strText.Format(_T("銆愮被鍒?),col);
}
else if(col==1){
Item.nFormat = DT_LEFT|DT_WORDBREAK;
Item.strText.Format(_T("絎竴鍒?),col);
}
else if(col==2){
Item.nFormat = DT_LEFT|DT_WORDBREAK;
Item.strText.Format(_T("絎簩鍒?),col);
}
m_pGridCtrl->SetItem(&Item);
}
// fill rows/cols with text
for (row = 1; row < k; row++)
for (col = 0; col < h; col++)
{
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = row;
Item.col = col;
if (col < 1) { //琛屾爣棰樺ご
Item.nFormat = DT_CENTER|DT_VCENTER
|DT_SINGLELINE|DT_END_ELLIPSIS
|DT_NOPREFIX;
Item.strText.Format(_T("%d"),row);
}
else if(col==1){ //絎竴鍒楃殑鍊?br /> Item.nFormat = DT_CENTER|DT_VCENTER
|DT_SINGLELINE|DT_END_ELLIPSIS
|DT_NOPREFIX;
str="aa";
Item.strText.Format(_T("%s"),str);
}else if(col==2){ //絎簩鍒楃鍊?br /> Item.nFormat = DT_CENTER|DT_VCENTER
|DT_SINGLELINE|DT_END_ELLIPSIS
|DT_NOPREFIX;
CString str;
str="bb";
Item.strText.Format(_T("%s"),str);
}
m_pGridCtrl->SetItem(&Item);
}
m_pGridCtrl->AutoSize();
//--------------璁劇疆琛屽垪璺?-----------------
for(int a=1;a<m;a++)
m_pGridCtrl->SetRowHeight(a,21); //璁劇疆鍚勮楂?br /> m_pGridCtrl->SetRowHeight(0,24); //璁劇疆0琛岄珮
m_pGridCtrl->SetColumnWidth(1,110); //璁劇疆2鍒楀
m_pGridCtrl->SetColumnWidth(2,160); //璁劇疆3鍒楀
m_pGridCtrl->SetColumnWidth(3,100); //璁劇疆4鍒楀
}
姝ラ浜? 娣誨姞WM_SIZE娑堟伅,璋冩暣鎺т歡鐨勭晫闈㈠崰灞忓箷澶у皬
聽聽if(m_pGridCtrl->GetSafeHWnd())
聽聽聽{
聽聽聽聽聽聽CRect rect;
聽聽聽聽聽GetClientRect(rect);
聽聽聽聽聽m_pGridCtrl->MoveWindow(rect);
聽聽聽}
鍦ㄨ祫婧愮鐞嗗櫒涓柊鍒涘緩涓涓璇濇錛屽亣璁句負CDlgTestReportBox銆?浠庡伐鍏風涓姞鍏ustom Control錛屽氨鏄漢澶村儚鐨勯偅涓紝灝嗗叾鍖哄煙鎷変幾鑷寵鏄劇ず鏁版嵁琛ㄦ牸鐨勫ぇ灝忥紝鍏呮弧鏁翠釜瀵硅瘽妗嗐?/p>
鍦–DlgTestReportBox綾葷殑澶存枃浠朵腑錛?/p>
#include "GridCtrl.h"
鍐嶅畾涔夋垚鍛樺彉閲忥細
CGridCtrl* m_pGrid;
娣誨姞OnShowWindow()娑堟伅澶勭悊鍑芥暟濡備笅錛?/p>
void CDlgTestReportBox::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
// TODO: Add your message handler code here
if(m_pGrid!=NULL)
{
delete m_pGrid;
m_pGrid=NULL;
}
if(m_pGrid==NULL)
{
m_pGrid=new CGridCtrl;
CRect rect;
GetDlgItem(IDC_ReportAera)->GetWindowRect(rect); //寰楀埌鏄劇ず鍖哄煙
ScreenToClient(&rect);
m_pGrid->Create(rect,this,100);
m_pGrid->SetEditable(false);
m_pGrid->SetTextBkColor(RGB(0xFF, 0xFF, 0xE0)); //榛勮壊鑳屾櫙
try
{
m_pGrid->SetRowCount(10); //鍒濆涓?0琛?br /> m_pGrid->SetColumnCount(11); //鍒濆鍖栦負11鍒?br /> m_pGrid->SetFixedRowCount(1); //琛ㄥご涓轟竴琛?br /> m_pGrid->SetFixedColumnCount(1); //琛ㄥご涓轟竴鍒?
}
catch (CMemoryException* e)
{
e->ReportError();
e->Delete();
// return FALSE;
}
for (int row = 0; row < m_pGrid->GetRowCount(); row++)
for (int col = 0; col < m_pGrid->GetColumnCount(); col++)
{
//璁劇疆琛ㄦ牸鏄劇ず灞炴?br /> GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = row;
Item.col = col;
if(row==0&&col==0) //絎?0錛?)鏍?br /> {
Item.nFormat = DT_CENTER|DT_WORDBREAK;
Item.szText.Format(_T("鎶ヨ〃鏄劇ず"),col);
}
else if (row < 1) //璁劇疆0琛岃〃澶存樉紺?br /> {
Item.nFormat = DT_CENTER|DT_WORDBREAK;
Item.szText.Format(_T(" 欏圭洰%d"),col);
}
else if (col < 1) //璁劇疆0鍒楄〃澶存樉紺?br /> {
if(row< m_pGrid->GetRowCount()-4)
{
Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
Item.szText.Format(_T("絎?d嬈?),row);
}
}
else
{
Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
Item.szText.Format(_T(""),2);
}
m_pGrid->SetItem(&Item);
}
m_pGrid->Invalidate();
}
//--------------璁劇疆琛屽垪璺?-----------------
for(int a=0;aGetRowCount();a++)
m_pGrid->SetRowHeight(a,16); //璁劇疆鍚勮楂?
m_pGrid->SetColumnWidth(0,58); //璁劇疆0鍒楀
for(int b=1;bGetColumnCount();b++)
m_pGrid->SetColumnWidth(b,59); //璁劇疆鍚勫垪瀹?br />}
聽
姝ラ浜屻宓屽叆涓婇潰鐨勫璇濇 鏄劇ず鏁版嵁
鍦ㄤ綘闇瑕佹樉紺烘暟鎹殑瀵硅瘽妗嗕笂鐨勫ご鏂囦歡涓紝鍋囪涓篊DlgTest錛屽姞鍏?/p>
#include "GridCtrl.h"
CDlgTestReportBox* m_pTestReportBox;
灝嗘暟鎹樉紺哄璇濇鏀懼叆浣犵殑瀵硅瘽妗嗙浉搴斾綅緗笂錛屽湪CDlgTest::OnInitDialog() 涓細
if(!m_pTestReportBox)
{
聽聽聽聽聽m_pTestReportBox=new CDlgTestReportBox(this);
}
m_pTestReportBox->Create(IDD_DlgTestReportBox,this);
//瀹氫箟鍖哄煙鍙橀噺
CRect rectDraw;
GetDlgItem(IDC_AeraReport)->GetWindowRect(rectDraw);
ScreenToClient(&rectDraw); //鍔ㄦ佹祴璇曟暟鎹樉紺哄尯鍩焤ectDraw
//灝嗗搴旂殑瀵硅瘽妗嗘斁鍒版寚瀹氬尯鍩?/font>
m_pTestReportBox->MoveWindow(rectDraw);
m_pTestReportBox->ShowWindow(SW_SHOW);
鑷畾涔夊~鍏呮暟鎹殑鍑芥暟錛欳DlgTest::FillGrid() 濡備笅錛?/p>
CGridCtrl* pGrid=m_pTestReportBox->m_pGrid;濂界瘡鍟?蹇欎簡涓澶╂椂闂寸粓浜庡啓瀹屼簡!
for (int row = pGrid->GetRowCount()-1; row >= pGrid->GetRowCount()-3; row--)
{
for (int col = 1; col <= pGrid->GetColumnCount(); col++)
{
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = row;
Item.col = col;
if(row==pGrid->GetRowCount()-3&&col>0) //騫沖潎鍊?br /> {
if(col==10){
Item.nFormat = DT_CENTER|DT_WORDBREAK;
Item.szText.Format(_T(" %6.2f "),avjch);
}
else{
Item.nFormat = DT_CENTER|DT_WORDBREAK;
Item.szText.Format(_T(" %6.2f "),av[col-1]);
}
}
pGrid->SetItem(&Item); //鎻愪氦鏁版嵁
if(row==0||col==0)
{
COLORREF clr = RGB(0, 0, 0);
pGrid->SetItemBkColour(row, col, clr);
pGrid->SetItemFgColour(row, col, RGB(255,0,0));
}
}//寰幆緇撴潫
pGrid->Invalidate();
}
浣犲繀欏誨湪stdafx.h鏂囦歡涓?鍖呭惈聽 #include <afxtempl.h>聽聽聽 // MFC templates
鍦ㄥご鏂囦歡涓寘鍚?#include <io.h>
鍏朵腑 CBank.h鏂囦歡濡備笅錛?br />
class CBank : public CObject聽
{
DECLARE_SERIAL(CBank)聽聽 //澹版槑搴忓垪鍖栧瓨鍌?br />public:
聽聽聽 聽聽 CBank();
聽聽聽聽聽聽 CBank(CString str){ m_bankname = str; }
聽聽聽聽聽聽 CBank(const CBank &b){ m_bankname= b.m_bankname;} //鎷瘋礉鏋勯犲嚱鏁?br />聽聽聽聽聽 聽 virtual ~CBank();
private:
聽聽聽聽聽聽 CString聽 m_bankname;
public:
聽聽聽 virtual void Serialize(CArchive& ar);
};typedef CTypedPtrMap<CMapStringToOb,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 CString,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 CBank*>CBanktmp;聽 //榪欎釜鎵嶆槸鎴戜滑鏍規嵁姝ょ被鐢熸垚鐨勭被鍨?/p>
瀹冪殑瀹炵幇鏂囦歡.cpp濡備笅錛?br />
IMPLEMENT_SERIAL(CBank, CObject, 1)聽聽 //瀹炵幇搴忓垪鍖栧瓨鍌?br />CBank::CBank()
{
聽 聽 m_bankname="";
}
CBank::~CBank()
{}
void CBank::Serialize(CArchive& ar)
{
聽聽聽 if (ar.IsLoading())
聽聽聽 {
聽聽聽聽聽聽聽 ar >> m_bankname;
聽聽聽 }
聽聽聽 else
聽聽聽 {
聽聽聽聽聽聽聽 ar << m_bankname;
聽聽聽 }
}
/*----------------------------------------------------
浠庢枃浠朵腑璇誨彇鍙傛暟錛?br />娉ㄦ剰錛?鍏朵腑鐨刴_map鏄繖鏍峰畾涔夌殑錛?font color="#0000ff">CBanktmp聽 m_map;
-------------------------------------------------*/
void CDlgBankIn::LoadBankName()
{
聽聽聽聽聽聽 UINT聽 nFlags = CFile::typeBinary |CFile::modeReadWrite;
聽聽聽聽聽聽 if(_access(_T("BankName.dat"),0))
聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽 nFlags |= CFile::modeCreate;
聽聽聽聽聽聽 }
聽聽聽聽聽聽 CFile file;
聽聽聽聽聽聽 CFileException fe;
聽聽聽聽聽聽 if (file.Open(_T("BankName.dat"),nFlags, &fe))
聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽 if(file.GetLength()==0)聽聽 //濡傛灉鏂囦歡涓虹┖鍒欎笉榪涜璇誨彇鎿嶄綔
聽聽聽聽 聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽 else
聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 CArchive ar(&file, CArchive::load);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 m_map.Serialize(ar);聽聽 //璇誨彇鏂囦歡
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //鏍規嵁鏂囦歡鍐呭濉厖鍒楄〃妗?br />聽聽聽聽 聽聽聽聽聽聽聽聽聽聽 POSITION聽聽 pos;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 CString聽聽聽 strKey;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 CBank聽聽 *pB=NULL;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 for( pos = m_map.GetStartPosition(); pos != NULL; )
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 m_map.GetNextAssoc(pos,strKey,(CBank*)pB);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 m_CmbBank.AddString(strKey);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 delete聽 pB;
聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽 }
聽聽聽聽聽聽 file.Close();
}
/*-------------------------------------------------
鍔熻兘: 鍏堟墦寮鏂囦歡,鐒跺悗鏌ユ壘鏂囦歡涓槸鍚︽湁涓庣紪杈戞鍏抽敭瀛楃浉鍚岀殑鍐呭,
聽聽聽 聽聽 濡傛灉鏈夌浉鍚屽唴瀹瑰垯涓嶆坊鍔?濡傛灉娌℃湁鐩稿悓鍐呭鍒欏啓鏂囦歡.
------------------------------------- ------------*/
void CDlgBankList::OnBtnAdd()
{
聽聽聽聽聽聽 // TODO: Add your control notification handler code here
聽聽聽聽聽聽 CString聽 strKey;
聽聽聽聽聽聽 GetDlgItemText(IDC_EDITBank,strKey);
聽聽聽聽聽聽 if (0 != strKey.GetLength())
聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽 CBank聽 *pB;
聽聽聽聽聽聽聽聽聽 //鎵撳紑鏂囦歡
聽聽聽聽聽 聽聽 UINT聽 nFlags = CFile::typeBinary |CFile::modeRead;
聽聽聽聽聽聽聽聽聽 CFile file;
聽聽聽聽聽聽聽聽聽 CFileException fe;
聽聽聽聽聽聽聽聽聽 if (file.Open(_T("BankName.dat"),nFlags, &fe))
聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 if(file.GetLength()==0)聽 //濡傛灉鏂囦歡涓虹┖鍒欎笉榪涜搴忓垪鍖栨搷浣?br />聽聽聽聽 聽聽聽聽聽聽聽聽聽聽聽 {聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 else
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 CArchive ar(&file, CArchive::load);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 m_map.Serialize(ar);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //鍒嗘瀽鏂囦歡騫剁粰鏂囦歡娣誨姞緙栬緫妗嗙殑鍐呭
聽聽聽聽 聽聽聽聽聽聽聽聽聽聽 if(!m_map.Lookup(strKey,(CBank*)pB))聽 //褰撲笉瀛樺湪鏃舵墠闇瑕佹坊鍔?br />聽聽聽聽聽 聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 if (CB_ERR != m_ListBox.AddString(strKey))
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 m_map.SetAt(strKey, new CBank(strKey));聽 //緇欏叧閿瓧strKey璧嬪?br />聽聽聽聽 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽 file.Close();聽聽聽聽聽聽 //瀛樺偍鏂囦歡
聽聽聽聽 nFlags = CFile::typeBinary |CFile::modeWrite;
聽聽聽聽聽聽 if (file.Open(_T("BankName.dat"),nFlags, &fe))
聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 CArchive ar(&file, CArchive::store);
聽聽聽聽聽聽聽聽聽聽聽 m_map.Serialize(ar);聽聽 //搴忓垪鍖栧瓨鍌?br />聽聽聽聽 }
聽聽聽 }
}
/*-------------------------------------------------
鍔熻兘: 鍏堟墦寮鏂囦歡,鐒跺悗鏌ユ壘鏂囦歡涓殑鍏抽敭瀛?
聽聽聽聽鎵懼埌鍚庡垯鍒犻櫎姝ゅ叧閿瓧, 浣嗘槸娉ㄦ剰鍏抽敭瀛楀搴旂殑鍐呭浠嶇劧娌℃湁鍒犻櫎錛岃繖鐐規湡寰呮敼榪?
-------------------------------------------------*/
void CDlgBankList::OnBtnDel()
{
聽聽聽聽聽聽 // TODO: Add your control notification handler code here
聽聽聽聽聽聽 int iIndex;聽聽聽聽聽聽
聽聽聽聽聽聽 CString聽 strKey;
聽聽聽聽聽聽 if(LB_ERR!=m_ListBox.GetCurSel())
聽聽聽聽聽聽 {
聽聽聽聽聽聽聽 //鎵撳紑鏂囦歡
聽聽聽聽聽& nbsp;聽聽聽聽 UINT聽 nFlags = CFile::typeBinary |CFile::modeRead;
聽聽聽聽聽聽聽聽聽聽 CFile file;
聽聽聽聽聽聽聽聽聽聽 CFileException fe;
聽聽聽聽聽聽聽聽聽聽 if (file.Open(_T("BankName.dat"),nFlags, &fe))
聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽 CArchive ar(&file, CArchive::load);
聽聽聽聽聽聽聽聽聽聽聽聽聽 m_map.Serialize(ar);聽
聽聽聽聽聽聽聽聽聽聽聽聽聽 iIndex=m_ListBox.GetCurSel();
聽聽聽聽聽聽聽聽聽聽聽聽聽 m_ListBox.GetText(iIndex,strKey);
聽聽聽聽聽聽聽聽聽聽聽聽聽 m_ListBox.DeleteString(iIndex);
聽聽聽聽聽聽聽聽聽聽聽聽聽 //鍒嗘瀽鏂囦歡騫剁粰鏂囦歡娣誨姞緙栬緫妗嗙殑鍐呭
聽聽聽聽 聽聽聽聽聽聽聽聽聽 CBank聽 *pB=NULL;
聽聽聽聽聽聽聽聽聽聽聽聽聽 if(m_map.Lookup(strKey,(CBank*)pB))
聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 m_map.RemoveKey(strKey);聽聽 //鍒犻櫎鍏抽敭瀛?浣嗘病鏈夊垹闄ゅ叧閿瓧瀵瑰簲鐨勫唴瀹?br />聽聽聽聽 聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽 file.Close();
聽聽聽聽聽聽聽聽聽聽聽 //瀛樺偍鏂囦歡
聽聽聽聽聽 聽聽聽聽 nFlags = CFile::typeBinary |CFile::modeWrite;
聽聽聽聽聽聽聽聽聽聽 if (file.Open(_T("BankName.dat"),nFlags, &fe))
聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 CArchive ar(&file, CArchive::store);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 m_map.Serialize(ar);聽聽 //搴忓垪鍖栧瓨鍌?br />聽聽聽聽聽 聽聽聽聽 }
聽聽聽聽聽聽 }
}