A website for better software and better life in Internet!

   Chinese URLs

   Greeting Creator

   Input Tips Everyday

   Source Code
Java Applet Games
Visit webpage in VC
M3U Music List Editor
Input Tips everyday
Combox in HTML
Self-made Screen Saver
Model of Neural Network
Display Chinese Characters
Mouse in Maze, a classic game in math
Serial Port Communication

Source Code -> Source Code of "Input Tips Everyday"

Source Code of Input Tips Every Day

Some users of "Input Tips every day" wrote email to me and ask how to make such a software. So I public my source code, for study only.

Create a Dialog Based application using MFC AppWizard, and there are CAboutDlg, CTipDlg, CTipApp created.
I add method OnHelp() in CAboutDlg class, so when you click About, you can read help.htm directly.
In CTipApp::InitInstance(), I add some sentence to control File Name of the Dialog:

    CTipDlg dlg;

    m_pMainWnd = &dlg;

    if (m_lpCmdLine[0] == _T('\0'))

        dlg.pFileName = "Tips.TXT";


        dlg.pFileName = m_lpCmdLine;

    int nResponse = dlg.DoModal();

So, every one using the same computer can use diferent input parameters to save his data seperately.
Create such a dialog,
and IDs of the buttons are:ID_PREVIOUS, ID_NEXT, ID_DELETE, ID_RECORD, IDC_Tips(Edit Box), IDC_TIME, IDC_INDEX. In CLASSWIZARD we can add OnClick function for every button.
Here is TipDlg.h which defined all of the member functions.
ATTN: gray part is added by CLASSWIZARD

// TipDlg.h : header file


#if !defined(AFX_TIPDLG_H__AB6D347B_A4AB_11D3_B8FB_82898A0F2927__INCLUDED_)

#define AFX_TIPDLG_H__AB6D347B_A4AB_11D3_B8FB_82898A0F2927__INCLUDED_

#if _MSC_VER > 1000

#pragma once

#endif // _MSC_VER > 1000

#define IDM_TIMER15        WM_USER+1

#define IDM_TIMER20        WM_USER+2

#define IDM_TIMER30        WM_USER+3

#define IDM_ONTOP        WM_USER+4

#define IDM_NOTOP        WM_USER+5


// CTipDlg dialog

class CTipDlg : public CDialog



    int index;

    BOOL    bOnTop;

    CString pRecord;

protected://Import tant functions. handle every file operation.
                    // called by OnRecord,OnDelete,OnPrevious,OnNext

                    //When I use Access database .MDB in version 3.0,
                    //I only change this function.

    int FileOp (CString& tempString, BOOL bRead, BOOL bSetLength);


    CString pFileName;

// Construction


    CTipDlg(CWnd* pParent = NULL);    // standard constructor

//    ~CTipDlg();

// Dialog Data


    enum { IDD = IDD_TIP_DIALOG };

    CString    m_Tips;


    // ClassWizard generated virtual function overrides



    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support


// Implementation


    HICON m_hIcon;

    // Generated message map functions


    virtual BOOL OnInitDialog();

    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);

    afx_msg void OnPaint();

    afx_msg HCURSOR OnQueryDragIcon();

    afx_msg void OnTimer(UINT nIDEvent);

    afx_msg void OnRecord();

    afx_msg void OnPrevious();

    afx_msg void OnNext();

    afx_msg void OnDelete();

    afx_msg BOOL OnHelpInfo(HELPINFO* pHelpInfo);

    virtual void OnCancel();





//Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_TIPDLG_H__AB6D347B_A4AB_11D3_B8FB_82898A0F2927__INCLUDED_)

Here is TipDlg.cpp. Handle 4 buttons.
// TipDlg.cpp : implementation file #include "stdafx.h" #include "Tip.h" #include "TipDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) afx_msg void OnHelp(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) ON_BN_CLICKED(IDC_HELP1, OnHelp) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTipDlg dialog CTipDlg::CTipDlg(CWnd* pParent /*=NULL*/) : CDialog(CTipDlg::IDD, pParent) { //{{AFX_DATA_INIT(CTipDlg) m_Tips = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CTipDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTipDlg) DDX_Text(pDX, IDC_Tips, m_Tips); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CTipDlg, CDialog) //{{AFX_MSG_MAP(CTipDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_TIMER() ON_BN_CLICKED(ID_RECORD, OnRecord) ON_BN_CLICKED(ID_PREVIOUS, OnPrevious) ON_BN_CLICKED(ID_NEXT, OnNext) ON_BN_CLICKED(ID_DELETE, OnDelete) ON_WM_HELPINFO() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTipDlg message handlers BOOL CTipDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX <0xf000);
    #ifndef _DEBUG SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE); 
    bOnTop="TRUE;" CMenu* pSysMenu="GetSystemMenu(FALSE);" 
 if (pSysMenu != "NULL)" {pSysMenu->DeleteMenu(4, MF_BYPOSITION);    //Maximum;

        pSysMenu->DeleteMenu(2, MF_BYPOSITION);    //Size;


        pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, "&About Tip...");


        pSysMenu->AppendMenu(MF_STRING, IDM_TIMER15, "&15 Minutes(Default)");

        pSysMenu->AppendMenu(MF_STRING, IDM_TIMER20, "&20 Minutes");

        pSysMenu->AppendMenu(MF_STRING, IDM_TIMER30, "&30 Minutes");


        pSysMenu->AppendMenu(MF_STRING, IDM_ONTOP, "Always &OnTop");

        pSysMenu->AppendMenu(MF_STRING, IDM_NOTOP, "&Cancel OnTop");


    // Set the icon for this dialog.  The framework does this automatically

    //  when the application's main window is not a dialog

    SetIcon(m_hIcon, TRUE);            // Set big icon

    SetIcon(m_hIcon, FALSE);        // Set small icon


    // TODO: Add extra initialization here

    pRecord = "Tips in " + pFileName;

    index = GetProfileInt(pRecord, "number", 1);

    index = FileOp( m_Tips, TRUE, FALSE);

    int time = GetProfileInt(pRecord, "timer", 15);

    SetTimer(1, time*1000 * 60, NULL);    //15 Minutes.

    return TRUE;  // return TRUE  unless you set the focus to a control


void CTipDlg::OnSysCommand(UINT nID, LPARAM lParam)


    CAboutDlg dlgAbout;



    case    IDM_ABOUTBOX:



    case IDM_TIMER15:

            WriteProfileString(pRecord, "timer", "15");

            SetTimer(1, 15*1000*60, NULL);    //15 Minutes.

            MessageBox("Timer has been changed as 15 Minutes.", "Right!", MB_ICONEXCLAMATION|MB_OK);


    case IDM_TIMER20:

            WriteProfileString(pRecord, "timer", "20");

            SetTimer(1, 20*1000*60, NULL);    //20 Minutes.

            MessageBox("Timer has been changed as 20 Minutes.", "Right!", MB_ICONEXCLAMATION|MB_OK);


    case IDM_TIMER30:

            WriteProfileString(pRecord, "timer", "30");

            SetTimer(1, 30*1000*60, NULL);    //30 Minutes.

            MessageBox("Timer has been changed as 30 Minutes.", "Right!", MB_ICONEXCLAMATION|MB_OK);


    case IDM_ONTOP:

            SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);

            bOnTop = TRUE;


    case IDM_NOTOP:

            SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);

            bOnTop = FALSE;



        CDialog::OnSysCommand(nID, lParam);



// If you add a minimize button to your dialog, you will need the code below

//  to draw the icon.  For MFC applications using the document/view model,

//  this is automatically done for you by the framework.

void CTipDlg::OnPaint() 


    if (IsIconic())


        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

        // Center icon in client rectangle

        int cxIcon = GetSystemMetrics(SM_CXICON);

        int cyIcon = GetSystemMetrics(SM_CYICON);

        CRect rect;


        int x = (rect.Width() - cxIcon + 1) / 2;

        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon

        dc.DrawIcon(x, y, m_hIcon);




        CString tempString;

        tempString.Format("%d", index);

        SetDlgItemText(IDC_INDEX, tempString);

        SYSTEMTIME m_Time;


        tempString.Format("%d:%d", m_Time.wHour, m_Time.wMinute);

        SetDlgItemText(IDC_TIME,  tempString);

        SetDlgItemText(IDC_Tips, m_Tips);




// The system calls this to obtain the cursor to display while the user drags

//  the minimized window.

HCURSOR CTipDlg::OnQueryDragIcon()


    return (HCURSOR) m_hIcon;


void CTipDlg::OnTimer(UINT nIDEvent) 


    // TODO: Add your message handler code here and/or call default





void CTipDlg::OnRecord() 


    // TODO: Add your control notification handler code here

    GetDlgItemText(IDC_Tips, m_Tips);

    index = GetProfileInt(pRecord, "number", 1) ;

    FileOp(m_Tips, FALSE, TRUE);



void CTipDlg::OnPrevious() 


    // TODO: Add your control notification handler code here

    if (index == 1)


    index --;

    index = FileOp(m_Tips, TRUE, FALSE);



void CTipDlg::OnNext() 


    // TODO: Add your control notification handler code here

    index ++;

    index = FileOp(m_Tips, TRUE, FALSE);



void CTipDlg::OnDelete() 


    // TODO: Add your control notification handler code here

    int total = GetProfileInt(pRecord, "number", 1);

    if (index >= total)


        index --;

        index = FileOp(m_Tips, TRUE, TRUE);




int CTipDlg::FileOp(CString& String, BOOL bRead, BOOL bSet)



    PHKEY hKey;

    DWORD dwDisposition;

    index = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\Tips", 
      0, "Index", KEY_QUERY_VALUE , KEY_ALL_ACCESS, NULL, hKey, &dwDisposition);

    long lSize;

    index = RegQueryValue(*hKey, "Index", &index, &lSize);


    CStdioFile m_hfile;

    if( !m_hfile.Open( pFileName, CFile::modeCreate | CFile::modeNoTruncate
           | CFile::modeReadWrite | CFile::typeText ) ) 

#ifdef     _DEBUG afxDump

    << "Unable to open file" <<

        exit( 1 ); 
    int    temp;    
    CString tempString1,tempString2;  
    BOOL bEOF; 
    for (temp=0;(temp<index)&&(bEOF=m_hfile.ReadString(tempString1)); temp++)
        {tempString2= tempString1;} 
    if(bSet== TRUE) 
        DWORD dwPosition=m_hfile.GetPosition();
        if(bRead== FALSE) {
            index="temp" + 1; 
        CString number;     
        number.Format("%d", index); 
        WriteProfileString(pRecord, "number", number);
    String=  tempString2;  
    return temp;
    BOOL CTipDlg::OnHelpInfo(HELPINFO* pHelpInfo) 
    { // TODO: Add your message handler code here and/or call default

    ShellExecute(*this, "open", "help.htm", NULL, NULL, SW_SHOW);

    return TRUE;


void CTipDlg::OnCancel() 


    // TODO: Add extra cleanup here


    if (bOnTop == FALSE)




    int iTemp = MessageBox("Are you sure you want to close the Tips?\n
    It's a pity!", "Exit?", MB_YESNO|MB_ICONSTOP|MB_DEFBUTTON2);

    if (iTemp == IDYES)




void CAboutDlg::OnHelp() 


    // TODO: Add your control notification handler code here

    ShellExecute(*this, "open", "help.htm", NULL, NULL, SW_SHOW);    


^ Top

   Contact Info
  User Support Sales Question Webmaster

Copyright 1998-2002 Fadshop.net, Inc. All rights reserved.