?? studentui.h
字號:
// 文件studentui.h中的內容
class CStudentUI: public CConUI
{
public:
CStudentUI();
bool InputStuRec(CStudentRec &stu); // 通過鍵盤輸入記錄
void DispStuRecs(CStudentRec *stu, int nNum); // 顯示nNum個記錄
private:
void DispListHead(int nRow = 0); // 顯示表頭
};
CStudentUI::CStudentUI()
{
_SetMainFrameTitle("Management For The Student Scores");
_InitMainFrame(7);
DispListHead();
}
bool CStudentUI::InputStuRec(CStudentRec &stu)
{
bool bRes = false;
char *str[5] = {"Name:", "Student ID:", "Score 1:", "Score 2:", "Score 3:"};
_SetMultiInputTitle( "Input student record data" );
bRes = _InputMultiBox(str, 0, 0, 20, str, 5);
if (bRes){
strncpy(stu.strName, str[0], 20);
strncpy(stu.strID, str[1], 10);
stu.fAve = (float)0.0;
for (int i=0; i<3; i++) {
stu.fScore[i] = (float)atof(str[i+2]);
stu.fAve += stu.fScore[i];
}
stu.fAve = float(stu.fAve/3.0);
stu.chFlag = 'A';
}
return bRes;
}
void CStudentUI::DispListHead(int nRow)
{
int nSizeX, nSizeY;
_GetWindowSize(&nSizeX, &nSizeY); // 獲得窗口的大小
_SaveSettings();
_SetBackColor(15); // 背景色為白色
_SetForeColor(0); // 文本色為黑色
_FillBox(0, nRow, nSizeX-1, 1, false); // 畫背景水平條
_SetCursorPos(0, nRow);
cout.setf(ios::left);
cout<<setw(10)<<" Rec NO"<<setw(20)<<"Student Name"<<setw(10)<<" ID";
cout<<setw(10)<<"Score 1"<<setw(10)<<"Score 2"<<setw(10)<<"Score 3";
cout<<"Average"<<endl;
_LoadSettings();
_GetConwinSize(&nSizeX, &nSizeY); // 獲得控制臺窗口的大小
_DefineWindow(1, 3, nSizeX-2, nSizeY-3); // 重新定義窗口
}
void CStudentUI::DispStuRecs(CStudentRec *stu, int nNum)
{
// 每屏顯示nMaxLine個,若nNum>nMaxLine,
// 則可按PageUp和PageDown向上和向下翻頁
// 若nNum>nMaxLine,則按ESC鍵退出
const int nMaxLine = 20;
int nStart, nEnd, nPage = 0, nMaxPages, nRow=0;
nMaxPages = (nNum-1)/nMaxLine; // 最大可顯示的頁數
unsigned int ch;
int nSizeX, nSizeY, nBkColor, nForeColor;
for (;;) {
nStart = nPage * nMaxLine;
nEnd = nStart + nMaxLine;
if (nEnd>=nNum) nEnd = nNum;
nRow = 0;
_ClearWindow();
for (int i=nStart; i<nEnd; i++) {
if (stu[i].chFlag == 'A') {
_SetCursorPos( 1, nRow ); nRow++;
cout.setf(ios::left);
cout<<setw(10)<<i+1<<setw(20)<<stu[i].strName
<<setw(10)<<stu[i].strID;
cout<<setw(10)<<stu[i].fScore[0]
<<setw(10)<<stu[i].fScore[1]
<<setw(10)<<stu[i].fScore[2];
cout<<stu[i].fAve;
cout.flush(); // 必須有這行代碼,否則顯示不出來
}
}
if (nMaxPages == 0) break;
else {
// 顯示提示信息,背景為黃色,前景色為黑色
nBkColor = _GetBackColor();
nForeColor = _GetForeColor();
_SetBackColor( 14 ); // 黃色
_SetForeColor( 0 ); // 黑色
_GetWindowSize( &nSizeX, &nSizeY );
_FillBox( 0, nSizeY-1, nSizeX, 1, false );
_SetCursorPos( 1, nSizeY-1 );
cout<<"PAGE: "<<nPage<<" RECS: "<<nNum;
cout.flush();
_SetForeColor( nBkColor );
cout<<" <PL. press PAGEUP or"
<<" PAGEDOWN to change pages, and ESC to exit...>";
cout.flush();
// 恢復原來的顏色設置
_SetBackColor( nBkColor );
_SetForeColor( nForeColor );
for(;;) {
ch = _GetKeyChar();
// 當按下ESC退出
if (ch == VK_ESCAPE) return;
if (ch == VK_PRIOR ) { // PAGEUP鍵
nPage--;
if (nPage<0) nPage = 0;
break;
}
if (ch == VK_NEXT ) { // PAGEDOWN鍵
nPage++;
if (nPage>nMaxPages) nPage = nMaxPages;
break;
}
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -