?? ssms.cpp
字號:
// SSMS.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
#include <stdio.h>
#include <commdlg.h>
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
RECT rect;
BOOL bSave=1,bOpen;
long cxChar,cyChar;
char strFind[20],strFileName[256],strFindModi[40];
int iShowMode;
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ScoreApp(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ScoreFindNum(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ScoreFindName(HWND hDlg, UINT message, WPARAM wParam,LPARAM lParam);
LRESULT CALLBACK ScoreModi(HWND hDlg, UINT message, WPARAM wParam,LPARAM lParam);
typedef struct node STU;
struct student
{
long num;
int score[3];
float aver;
char name[20];
};
struct node
{
long num;
int score[3];
float aver;
char name[20];
struct node *next;
};
STU *stP;
STU *OpenTextFile(HWND);
STU *insert(STU *head,long num,char name[],int score[3]);
void save(STU *head,char filename[]);
void SaveTextFile(HWND hWnd);//, HWND hWndEdit )
void ShowRecord(HDC hdc,HWND hWnd,STU *head,int ShowMode,char strFind[20]);
HFONT hFont;
STU *head=NULL;
STU *load(char filename[])
{
FILE *fp;
STU *p,*q,*head;
struct student per;
q=head=NULL;
if((fp=fopen(filename,"rb"))==NULL)
return head;
else {
while(!feof(fp))
if(fread(&per,sizeof(struct student),1,fp)==1)
{
p=(STU *)malloc(sizeof(STU));
p->num=per.num;
p->score[0]=per.score[0];
p->score[1]=per.score[1];
p->score[2]=per.score[2];
p->aver=per.aver;
strcpy(p->name,per.name);
// MessageBox(NULL,per.name,"姓名",MB_OK);
p->next=NULL;
if(head==NULL)head=q=p;
else {q->next=p;q=p;}
}
}
fclose(fp);
return (head);
}
// Foward declarations of functions included in this code module:
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_SSMS, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SSMS);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SSMS);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_SSMS;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,//WS_BORDER|WS_CAPTION|WS_VSCROLL,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TEXTMETRIC tm;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
STU *p;p=head;
// long lNum;
switch (message)
{
case WM_CLOSE:
if(!bSave)MessageBox(NULL,"文件沒保存,不能退出","退出出錯",MB_OK);
else DestroyWindow(hWnd);
break;
case WM_QUIT:
MessageBox(NULL,"WM_QUIT","MSG",MB_OK);
break;
case WM_CREATE:
hdc=GetDC(hWnd);
hFont=CreateFont(
20,0,0,0,400,0,0,0,
GB2312_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_DONTCARE,"自定義字體");
SelectObject(hdc,hFont);
GetTextMetrics(hdc,&tm);
cxChar=tm.tmAveCharWidth ;
cyChar=tm.tmHeight ;
ReleaseDC(hWnd,hdc);
rect.top=3*cyChar/2;
return 0;
case WM_SIZE:
rect.right =LOWORD(lParam);
rect.bottom =HIWORD(lParam);
UpdateWindow(hWnd);
return 0;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_DELETE_NUM:
if(head==NULL)
{
MessageBox(NULL,"沒有任何學(xué)生記錄,不能刪除","出錯",MB_OK);
break;
}
long lNum;
strcpy(strFindModi,"按學(xué)號刪除");
DialogBox(hInst, (LPCTSTR)IDD_FIND_NUM, hWnd, (DLGPROC)ScoreFindNum);
iShowMode=1;
p=head;
STU *q;
lNum=atol(strFind);
while((p->next!=NULL)&&(p->num!=lNum))
{ q=p;
p=p->next;
}
if(lNum==p->num){
InvalidateRect(hWnd,NULL,1);
int bDelete=MessageBox(NULL,"是否是你要刪除的記錄","提示",MB_YESNO|MB_ICONQUESTION);
if(bDelete==IDYES)
{
stP=p;
bSave=0;
if(head==p)head=p->next;
else q->next=p->next;
free(p);
}
}
else
{
MessageBox(NULL,"未找到該學(xué)號的學(xué)生記錄!","",MB_OK);
}
break;
case IDM_FIND_NAME:
strcpy(strFindModi,"按姓名查找");
DialogBox(hInst,(LPCTSTR)IDD_FIND_NAME,hWnd,(DLGPROC)ScoreFindName);
iShowMode=2;
InvalidateRect(hWnd,NULL,1);
//ShowRecord(hdc,hWnd,p,iShowMode,strFind);
break;
case IDM_MODI_NAME:
if(head==NULL)
{
MessageBox(NULL,"沒有任何學(xué)生記錄,不修改","出錯",MB_OK);
break;
}
strcpy(strFindModi,"按姓名修改");
DialogBox(hInst,(LPCTSTR)IDD_FIND_NAME,hWnd,(DLGPROC)ScoreFindName);
iShowMode=2;
// lNum=atol(strFind);
p=head;
while((p->next!=NULL)&&(strcmp(p->name,strFind)))p=p->next;
if(!strcmp(p->name,strFind)){
stP=p;
bSave=0;
DialogBox(hInst, (LPCTSTR)IDD_MODI, hWnd, (DLGPROC)ScoreModi);
}
else
{
MessageBox(NULL,"未找到該學(xué)號的學(xué)生記錄!","",MB_OK);
}
InvalidateRect(hWnd,NULL,1);
break;
case IDM_MODI_NUM:
if(head==NULL)
{
MessageBox(NULL,"沒有任何學(xué)生記錄,不修改","出錯",MB_OK);
break;
}
strcpy(strFindModi,"按學(xué)號修改:");
DialogBox(hInst, (LPCTSTR)IDD_FIND_NUM, hWnd, (DLGPROC)ScoreFindNum);
iShowMode=1;
p=head;
lNum=atol(strFind);
while((p->next!=NULL)&&(p->num!=lNum))p=p->next;
if(lNum==p->num){
stP=p;
bSave=0;
DialogBox(hInst, (LPCTSTR)IDD_MODI, hWnd, (DLGPROC)ScoreModi);
}
else
{
MessageBox(NULL,"未找到該學(xué)號的學(xué)生記錄!","",MB_OK);
}
break;
case IDM_FIND_NUM:
strcpy(strFindModi,"按學(xué)號查找:");
DialogBox(hInst, (LPCTSTR)IDD_FIND_NUM, hWnd, (DLGPROC)ScoreFindNum);
iShowMode=1;
InvalidateRect(hWnd,NULL,1);
break;
case IDM_MODI_INPUT:
bSave=0;
DialogBox(hInst, (LPCTSTR)IDD_MODI_APP, hWnd, (DLGPROC)ScoreApp);
break;
case IDM_PRINT:
iShowMode=0;
InvalidateRect(hWnd,NULL,1);
//PrintText(hWnd,head);
break;
case IDM_FILE_OPEN:
OpenTextFile(hWnd);
break;
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
SaveTextFile(hWnd);
DestroyWindow(hWnd);
break;
case IDM_SAVE:
SaveTextFile(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
SelectObject(hdc,hFont);
ShowRecord(hdc,hWnd,head,iShowMode,strFind);
EndPaint(hWnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
STU *OpenTextFile(HWND hWnd)
{
// STU *p,*q,*head;
// struct student per;
// q=head=NULL;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -