博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
简单控件的应用(二)—学生管理系统
阅读量:5892 次
发布时间:2019-06-19

本文共 6880 字,大约阅读时间需要 22 分钟。

 

源程序下载地址:http://down.qiannao.com/space/file/luowei505050/-6211-7684-7a0b-5e8f/-5b66-751f-7ba1-7406-7cfb-7edf.rar/.page

菜单、时钟、下拉框等控件,应用,对数据进简单操作,写的很简单,没用到数据库。

主要程序代码:

#include "stdafx.h"

#include <windows.h>

#include <windowsx.h>

#include "resource.h"

#include "MainDlg.h"

 

BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

{

switch(uMsg)

{

HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog);

HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand);

        HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose);

}

 

return FALSE;

}

 

void CALLBACK MyTimeProc(HWND hwnd,UINT message,UINT idTimer,DWORD dwTimer)

{

    SYSTEMTIME stLocal;

    GetLocalTime(&stLocal);

    TCHAR strTime[256];

    wsprintf(strTime,"%i年%i月%i日 %i:%i:%i",stLocal.wYear,stLocal.wMonth,

        stLocal.wDay,stLocal.wHour,stLocal.wMinute,stLocal.wSecond);

    SetDlgItemText(hwnd,IDC_EDITTIME,strTime);

 

}

 

BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)

{

    SetTimer(hwnd,0,1000,MyTimeProc);

return TRUE;

}

 

//============================================================

TCHAR* GetText(HWND hwnd,int id,TCHAR* str)

{

    GetDlgItemText(hwnd,id,str,sizeof(str)+29);

    return(str);

}

//ComboBox-------------------------------

BOOL ExistSame(HWND hwndcombo,TCHAR* str)

{

    int i;

    TCHAR str1[32];

    BOOL BFOUND=FALSE;

    int icount=ComboBox_GetCount(hwndcombo);

    if(0!=icount) //ComboBox_GetCurSel(hwndcombo)!=CB_ERR

    {

        for(i=0;i<icount;i++)

        {

            ComboBox_GetLBText(hwndcombo,i,str1);

            if(lstrcmp(str,str1)==0)

            {

                BFOUND=TRUE;

                break;

            }

            else BFOUND=FALSE;

        }

        return BFOUND;

    }

    else return BFOUND;

}

 

BOOL IsTextNull(HWND hwnd,int id)

{

    TCHAR str[32];

    //TCHAR str1[32]="";

    GetText(hwnd,id,str);

    if(!*str)

        return TRUE;

    else

        return FALSE;

}

 

int SearchItem(HWND hwndcombo,TCHAR* str)

{

    TCHAR str1[32];

    int icount=ComboBox_GetCount(hwndcombo);

    int i;

    int FLAG=-1;

    if(0!=icount)

    {

        for(i=0;i<icount;i++)

        {

            ComboBox_GetLBText(hwndcombo,i,str1);

            if(0==lstrcmp(str,str1))

            {

                FLAG=i;

                break;

            }

            else FLAG=-1;

        }

        return FLAG;

    }

    else return FLAG;

}

//ListBox-------------------------------

BOOL LExistSame(HWND hwndlist,TCHAR* str)

{

    int i;

    TCHAR str1[32];

    BOOL BFOUND=FALSE;

    int icount=ListBox_GetCount(hwndlist);

    if(0!=icount) //ListBox_GetCurSel(hwndlist)!=CB_ERR

    {

        for(i=0;i<icount;i++)

        {

            ListBox_GetText(hwndlist,i,str1);

            if(lstrcmp(str,str1)==0)

            {

                BFOUND=TRUE;

                break;

            }

            else BFOUND=FALSE;

        }

        return BFOUND;

    }

    else return BFOUND;

}

 

BOOL LIsTextNull(HWND hwnd,int id)

{

    TCHAR str[32];

    //TCHAR str1[32]="";

    GetText(hwnd,id,str);

    if(!*str)

        return TRUE;

    else

        return FALSE;

}

 

int LSearchItem(HWND hwndlist,TCHAR* str)

{

    TCHAR str1[32];

    int icount=ListBox_GetCount(hwndlist);

    int i;

    int FLAG=-1;

    if(0!=icount)

    {

        for(i=0;i<icount;i++)

        {

            ListBox_GetText(hwndlist,i,str1);

            if(0==lstrcmp(str,str1))

            {

                FLAG=i;

                break;

            }

            else FLAG=-1;

        }

        return FLAG;

    }

    else return FLAG;

}

 

//===================================================

void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)

{

switch(id)

{

case IDC_ADDSTU:

            {

                TCHAR str[32];

                HWND hwndcomboname=GetDlgItem(hwnd,IDC_COMBONAME);

                if(!IsTextNull(hwnd,IDC_EDITADD))

                {

                    GetText(hwnd,IDC_EDITADD,str);

                    if(ExistSame(hwndcomboname,str))

                    {

                        MessageBox(hwnd,TEXT("列表中已有此记录!"),TEXT("提示"),MB_OK);

                    }

                    else

                    {

                        ComboBox_InsertString(hwndcomboname,-1,TEXT(str));

                        SetDlgItemText(hwnd,IDC_EDITADD,TEXT(""));

                    }

                }

                else

                {

                    MessageBox(hwnd,TEXT("请输入要添加的记录!"),TEXT("提示"),MB_OK);

                }

            }break;

        case IDC_DELSTU:

            {

                TCHAR str[32];

                //TCHAR str1[32];

                HWND hwndcomboname=GetDlgItem(hwnd,IDC_COMBONAME);

                if(!IsTextNull(hwnd,IDC_EDITDEL))

                {

                    GetText(hwnd,IDC_EDITDEL,str);

                    int i=SearchItem(hwndcomboname,str);

                    if(-1==i)

                    {

                        MessageBox(hwnd,TEXT("列表中没有此项记录!"),TEXT("回复"),MB_OK);

                    }

                    else

                    {

                        ComboBox_DeleteString(hwndcomboname,i);

                        MessageBox(hwnd,TEXT("已删除了此记录!"),TEXT("删除结果"),MB_OK);

                        SetDlgItemText(hwnd,IDC_EDITDEL,TEXT(""));

                    }

                }

                else

                {

                    MessageBox(hwnd,TEXT("请输入要删除的记录!"),TEXT("提示"),MB_OK);

                }

            }break;

        case IDC_SEARCHSTU:

            {

                HWND hwndcomboname=GetDlgItem(hwnd,IDC_COMBONAME);

                if(!IsTextNull(hwnd,IDC_EDITSEARCH))

                {

                    TCHAR str[32];

                    GetText(hwnd,IDC_EDITSEARCH,str);

                    int i=SearchItem(hwndcomboname,str);

                    if(-1==i)

                    {

                        MessageBox(hwnd,TEXT("没有此项记录!"),TEXT("查询结果"),MB_OK);

                    }

                    else

                    {

                        ComboBox_SetCurSel(hwndcomboname,i);

                        MessageBox(hwnd,TEXT("找到了此记录!"),TEXT("查找结果"),MB_OK);

                        SetDlgItemText(hwnd,IDC_EDITSEARCH,TEXT(""));

                    }

                }

                else

                {

                    MessageBox(hwnd,TEXT("请输入要查找的记录!"),TEXT("提示"),MB_OK);

                }

            }break;

        case IDC_ALTERSTU:

            {

                HWND hwndcomboname=GetDlgItem(hwnd,IDC_COMBONAME);

                int locate=-1;

                if(!IsTextNull(hwnd,IDC_EDITSNAME))

                {

                    TCHAR str1[32];

                    GetText(hwnd,IDC_EDITSNAME,str1);

                    locate=SearchItem(hwndcomboname,str1);

                    if(-1==locate)

                    {

                        MessageBox(hwnd,TEXT("没有此项记录!"),TEXT("回复"),MB_OK);

                    }

                    else

                    {

                        ComboBox_DeleteString(hwndcomboname,locate);

                        SetDlgItemText(hwnd,IDC_EDITDEL,TEXT(""));

                        if(!IsTextNull(hwnd,IDC_EDITDNAME))

                        {

                            TCHAR str2[32];

                            GetText(hwnd,IDC_EDITDNAME,str2);

                            ComboBox_InsertString(hwndcomboname,locate,str2);

                            ComboBox_SetCurSel(hwndcomboname,locate);

                            MessageBox(hwnd,TEXT("已修改此项记录!"),TEXT("修改结果"),MB_OK);

                            SetDlgItemText(hwnd,IDC_EDITDNAME,TEXT(""));

                            SetDlgItemText(hwnd,IDC_EDITSNAME,TEXT(""));

                        }

                        else

                        {

                            MessageBox(hwnd,TEXT("请输入要修改之后的记录!"),TEXT("提示"),MB_OK);

                        }

                    }

                }

                else

                {

                    MessageBox(hwnd,TEXT("请输入要修改的记录!"),TEXT("提示"),MB_OK);

                }

                

            }break;

 

///=================================================================

        case IDC_CHECKLOOK:

            {

                HWND hwndCheck=GetDlgItem(hwnd,IDC_CHECK1);

                int checkState=Button_GetCheck(hwndCheck);

                if(BST_CHECKED==checkState)

                {

                    MessageBox(hwnd,TEXT("复选框被选中"),TEXT("回复"),MB_OK);

                }

                if(BST_UNCHECKED==checkState)

                {

                    MessageBox(hwnd,TEXT("复选框没有被选中"),TEXT("回复"),MB_OK);

                }

            }break;

            case IDC_CHECKSETTING:

            {

                HWND hwndCheck=GetDlgItem(hwnd,IDC_CHECK1);

                int checkState=Button_GetCheck(hwndCheck);

                if(BST_CHECKED==checkState)

                {

                    Button_SetCheck(hwndCheck,BST_UNCHECKED);

                    MessageBox(hwnd,TEXT("复选框设为了未选中状态"),TEXT("回复"),MB_OK);

                }

                if(BST_UNCHECKED==checkState)

                {

                    Button_SetCheck(hwndCheck,BST_CHECKED);

                    MessageBox(hwnd,TEXT("复选框设为了选中状态"),TEXT("回复"),MB_OK);

                }

            }break;

 

///=========================================================

            case IDC_LADDSTU:

            {

                TCHAR str[32];

                HWND hwndlist=GetDlgItem(hwnd,IDC_LIST1);

                if(!LIsTextNull(hwnd,IDC_LEDITADD))

                {

                    GetText(hwnd,IDC_LEDITADD,str);

                    if(LExistSame(hwndlist,str))

                    {

                        MessageBox(hwnd,TEXT("列表中已有此记录!"),TEXT("提示"),MB_OK);

                    }

                    else

                    {

                        ListBox_InsertString(hwndlist,-1,TEXT(str));

                        SetDlgItemText(hwnd,IDC_LEDITADD,TEXT(""));

                    }

                }

                else

                {

                    MessageBox(hwnd,TEXT("请输入要添加的记录!"),TEXT("提示"),MB_OK);

                }

            }break;

 

            case IDC_LDELSTU:

            {

                HWND hwndlist=GetDlgItem(hwnd,IDC_LIST1);

                int i=ListBox_GetCurSel(hwndlist);

                ListBox_DeleteString(hwndlist,i);

                //MessageBox(hwnd,TEXT("已删除了此记录!"),TEXT("删除结果"),MB_OK);

            }break;

            case ID_MENUITEMOPEN:

            {

                MessageBox(hwnd,TEXT("[打开]菜单项被调用!"),TEXT("菜单响应"),MB_OK);

            }break;

            case ID_MENUITEMQUIT:

            {

                MessageBox(hwnd,TEXT("[退出]菜单项被调用!"),TEXT("菜单响应"),MB_OK);

                EndDialog(hwnd,IDD_MAIN);

            }break;

default:

        break;

}

}

 

 

 

void Main_OnClose(HWND hwnd)

{

EndDialog(hwnd, 0);

}

转载于:https://www.cnblogs.com/luowei010101/archive/2011/09/07/2170158.html

你可能感兴趣的文章