?? ssms.cpp
字號:
OPENFILENAME OpenFileName;
char szDirName[MAX_PATH]="";
char szFile[MAX_PATH]="\0";
char szFileTitle[MAX_PATH]="\0";
char szFilter[]={"所有文件\0*.*\0文本文件(*.txt)\0*.txt\0C源程序(*.c)\0*.c"};
OpenFileName.lStructSize=sizeof(OPENFILENAME);
OpenFileName.hwndOwner =hWnd;
OpenFileName.hInstance =hInst;
OpenFileName.lpstrFilter =szFilter;
OpenFileName.lpstrCustomFilter= (LPTSTR)NULL;
OpenFileName.nMaxCustFilter =0L;
OpenFileName.nFilterIndex =1L;
OpenFileName.lpstrFile =szFile;
OpenFileName.nMaxFile=sizeof(szFile);
OpenFileName.lpstrFileTitle =szFileTitle;
OpenFileName.nMaxFileTitle =sizeof(szFileTitle);
OpenFileName.lpstrInitialDir =NULL;
OpenFileName.lpstrTitle ="請選擇取一個文本文件";
OpenFileName.nFileExtension =0;
OpenFileName.nFileOffset =0;
OpenFileName.lpstrDefExt ="*.*";//txt";
OpenFileName.lCustData =0;
OpenFileName.Flags =OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
if(GetOpenFileName(&OpenFileName))
{
bOpen=1;
strcpy(strFileName,OpenFileName.lpstrFile);
head=load(strFileName);
/*
HANDLE hFile;
DWORD dwFileSize,dwBytesRead,dwFileSize1;
hFile=CreateFile(
OpenFileName.lpstrFile,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
(HANDLE)NULL);
if(hFile!=INVALID_HANDLE_VALUE)
{
dwFileSize=GetFileSize(hFile,NULL);
if(dwFileSize!=0xFFFFFFFF)
{
struct student temp;
dwFileSize1=sizeof(struct student);
while(dwFileSize>=0)
{
// dwFileSize=sizeof(struct student);
ReadFile(hFile,(LPVOID)&temp,dwFileSize1,&dwBytesRead,NULL);
// WriteFile(hFile,(LPVOID)&temp,dwFileSize,&dwBytesWrite,NULL);
if(dwBytesRead!=0)
{
p=(STU *)malloc(sizeof(STU));
p->num=temp.num;
p->score[0]=temp.score[0];
p->score[1]=temp.score[1];
p->score[2]=temp.score[2];
p->aver=temp.aver;
strcpy(p->name,temp.name);
p->next=NULL;
if(head==NULL)head=q=p;
else {q->next=p;q=p;}
}
else
{
MessageBox(NULL,"讀字節為0","出錯",MB_OK);
break;
}
dwFileSize-=dwFileSize;
}
}
else MessageBox(NULL,"檢取文件大小失敗","出錯",MB_OK);
*/
}
else MessageBox(NULL,"打開文件失敗","出錯",MB_OK);
return head;
}
// Mesage handler for about box.
LRESULT CALLBACK ScoreApp(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
long lNum;
char strName[20];
int iScore[3];
char strNum[10],strMath[10],strEng[10],strComp[10];
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
GetDlgItemText(hDlg,IDC_NUM,strNum,9);
GetDlgItemText(hDlg,IDC_NAME,strName,19);
GetDlgItemText(hDlg,IDC_MATH,strMath,9);
GetDlgItemText(hDlg,IDC_ENG,strEng,9);
GetDlgItemText(hDlg,IDC_COMP,strComp,9);
lNum=atol(strNum);
iScore[0]=atoi(strMath);
iScore[1]=atoi(strEng);
iScore[2]=atoi(strComp);
head=insert(head,lNum,strName,iScore);
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
// case IDC_ENG:
// case IDC_MATH:
break;
}
break;
}
return FALSE;
}
STU *insert(STU *head,long num,char name[],int score[3])
{ STU *new1,*p,*q;
int j;
/*輸入數據生成一個新結點*/
new1=(STU *)malloc(sizeof(STU));
strcpy(new1->name,name);
new1->num=num;
new1->aver=0;
for(j=0;j<3;j++){
new1->score[j]=score[j];
new1->aver+=new1->score[j];
}
new1->aver/=3;
/*新結點按照學號從小到大插入鏈表*/
p=head;
if(head==NULL){ /*鏈表是空鏈表*/
head=new1;
new1->next=NULL;
}
else { /*尋找插入位置*/
while((p->next!=NULL)&&(p->num!=new1->num)){ q=p;p=p->next; }
if(p->num>new1->num){
if(head==p){ new1->next=head;head=new1; }
else { q->next=new1;new1->next=p; }
}
else {
p->next=new1;
new1->next=NULL;
}
}
return(head);
}
//* 函數:saveTextFile (HWND, HWND)
//* 用途:調用公共對話框函數,顯示"另存為"對話框,由用戶選擇
//* 文本名,然后把編輯控件中的內容保存到該文件中.
void SaveTextFile(HWND hWnd)//, HWND hWndEdit )
{
if(!bOpen)
{
OPENFILENAME OpenFileName;
char szDirName[MAX_PATH]="";
char szFile[MAX_PATH]="\0";
char szFileTitle[MAX_PATH]="\0";
char szFilter[]={"All Files\0*.*\0"};
OpenFileName.lStructSize=sizeof(OPENFILENAME);
OpenFileName.hwndOwner=hWnd;
OpenFileName.hInstance=hInst;
OpenFileName.lpstrFilter=szFilter;
OpenFileName.lpstrCustomFilter=(LPTSTR)NULL;
OpenFileName.nMaxCustFilter=0L;
OpenFileName.nFilterIndex=1L;
OpenFileName.lpstrFile=szFile;
OpenFileName.nMaxFile=sizeof(szFile);
OpenFileName.lpstrFileTitle=szFileTitle;
OpenFileName.nMaxFileTitle=sizeof(szFileTitle);
OpenFileName.lpstrInitialDir=NULL;
OpenFileName.lpstrTitle="另存為";
OpenFileName.nFileOffset=0;
OpenFileName.nFileExtension=0;
OpenFileName.lpstrDefExt=NULL;
OpenFileName.lCustData=0;
OpenFileName.Flags=OFN_OVERWRITEPROMPT;
if (GetSaveFileName (&OpenFileName))
{ strcpy(strFileName,OpenFileName.lpstrFile);
}
else return ;
}
HANDLE hFile;
DWORD dwFileSize,dwBytesWrite;
//創建文件。(如果已經有了同名文件,則覆蓋該文件)。
hFile=CreateFile
(
strFileName,
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
(HANDLE)NULL);
if(hFile!=INVALID_HANDLE_VALUE)
{
STU *p=head;
struct student temp;
while(p)
{ //檢取編輯控件內容的字節大小。
dwFileSize=sizeof(struct student);
// 分配文件緩沖區。
temp.num=p->num;
temp.score[0]=p->score[0];
temp.score[1]=p->score[1];
temp.score[2]=p->score[2];
temp.aver=p->aver ;
strcpy(temp.name,p->name );
// 把編輯控件中的內容裝到文件緩沖區。
//把文件緩沖區中的數據存寫到文件中。
WriteFile(hFile,(LPVOID)&temp,dwFileSize,&dwBytesWrite,NULL);
if(!dwBytesWrite)
{
MessageBox(NULL,"寫入文件出錯","出錯",MB_OK);
break;
}
p=p->next;
}
SetWindowText(hWnd,strFileName);
CloseHandle(hFile);
bSave=1;
}
else
MessageBox(hWnd,"創建文件失敗!",NULL,MB_OK|MB_ICONEXCLAMATION);
return ;
}
LRESULT CALLBACK ScoreFindNum(HWND hDlg, UINT message, WPARAM wParam,LPARAM lParam)
{
// char strName[20];
// int iScore[3];//
// char strNum[10];//,strMath[10],strEng[10],strComp[10];
switch (message)
{
case WM_INITDIALOG:
SetWindowText(hDlg,strFindModi);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
GetDlgItemText(hDlg,IDC_FIND_NUM,strFind,10);
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
// case IDC_ENG:
// case IDC_MATH:
break;
}
break;
}
return FALSE;
}
LRESULT CALLBACK ScoreFindName(HWND hDlg, UINT message, WPARAM wParam,LPARAM lParam)
{
// char strName[20];
// int iScore[3];
switch (message)
{
case WM_INITDIALOG:
SetWindowText(hDlg,strFindModi);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
GetDlgItemText(hDlg,IDC_FIND_NAME,strFind,10);
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
// case IDC_ENG:
// case IDC_MATH:
break;
}
break;
}
return FALSE;
}
LRESULT CALLBACK ScoreModi(HWND hDlg, UINT message, WPARAM wParam,LPARAM lParam)
{
//long lNum;
// int iSo
char strNum[10],strMath[10],strEng[10],strComp[10];
switch (message)
{
case WM_INITDIALOG:
_itoa(stP->num, strNum, 10);
_itoa(stP->score[0],strMath, 10);
_itoa(stP->score[1], strEng, 10);
_itoa(stP->score[2], strComp, 10);
SetDlgItemText(hDlg,IDC_NUM,strNum);
SetDlgItemText(hDlg,IDC_NAME,stP->name);
SetDlgItemText(hDlg,IDC_MATH,strMath);
SetDlgItemText(hDlg,IDC_ENG,strEng);
SetDlgItemText(hDlg,IDC_COMP,strComp);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
GetDlgItemText(hDlg,IDC_NUM,strNum,9);
GetDlgItemText(hDlg,IDC_NAME,stP->name,19);
GetDlgItemText(hDlg,IDC_MATH,strMath,9);
GetDlgItemText(hDlg,IDC_ENG,strEng,9);
GetDlgItemText(hDlg,IDC_COMP,strComp,9);
stP->num=atol(strNum);
stP->score[0]=atoi(strMath);
stP->score[1]=atoi(strEng);
stP->score[2]=atoi(strComp);
//strcpy(stP->name,strName);
stP->aver =(float)(stP->score[0]+stP->score[1]+stP->score[2])/3.0;
EndDialog(hDlg, LOWORD(wParam));
// case IDC_ENG:
// case IDC_MATH:
break;
}
break;
}
return FALSE;
}
void ShowRecord(HDC hdc,HWND hWnd,STU *head,int ShowMode,char strFind[20])
{
// static char szFormat[]=;
cxChar=0;
cyChar=5;
static char szTop[]="學號 姓名 數學 英語 計算機 平均";
char strNotFind[]="沒有該學生的記錄!";
// char strPz[10];
char szBuffer[180];//,strNum[8],strMath[5],strEng[5],strComp[5];
STU *p=head;
if(ShowMode==0)
{
if(head==NULL)
{
cxChar=0;
cyChar+=20;
TextOut(hdc,cxChar,cyChar," ",strlen(" "));
return ;
}
TextOut(hdc,cxChar,cyChar/2,szTop,(sizeof szTop)-1);
while(p!=NULL)
{
cxChar=0;
cyChar+=20;
TextOut(hdc,cxChar,cyChar,szBuffer,
sprintf(szBuffer,"%-6d %-7s %-6d %-6d %-6d %-8.1f",p->num,p->name,p->score[0],p->score[1],p->score[2],p->aver));
// MessageBox(NULL,szBuffer,"輸出出錯",MB_OK);
p=p->next;
}
}
if(iShowMode==1)
{
int bFind=0;
long lNum;
lNum=atol(strFind);
TextOut(hdc,cxChar,cyChar/2,szTop,(sizeof szTop)-1);
while(p!=NULL)
{
if(p->num==lNum)
{ bFind=1;
cxChar=0;
cyChar+=20;
TextOut(hdc,cxChar,cyChar,szBuffer,
sprintf(szBuffer,"%-6d %-7s %-6d %-6d %-6d %-8.1f",p->num,p->name,p->score[0],p->score[1],p->score[2],p->aver));
}
p=p->next;
}
if(!bFind)
{
cxChar=0;
cyChar+=20;
TextOut(hdc,cxChar,cyChar,strNotFind,strlen(strNotFind));
}
}
if(iShowMode==2)
{
int bFind=0;
TextOut(hdc,cxChar,cyChar/2,szTop,(sizeof szTop)-1);
while(p!=NULL)
{
if(!strcmp(p->name,strFind))
{ bFind=1;
cxChar=0;
cyChar+=20;
TextOut(hdc,cxChar,cyChar,szBuffer,
sprintf(szBuffer,"%-6d %-7s %-6d %-6d %-6d %-8.1f",p->num,p->name,p->score[0],p->score[1],p->score[2],p->aver));
}
p=p->next;
}
if(!bFind)
{
cxChar=0;
cyChar+=20;
TextOut(hdc,cxChar,cyChar,strNotFind,strlen(strNotFind));
}
}
return ;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -