Source code of the identity card number lottery program [VC ++ 6]

Source: Internet
Author: User

// Giftdlg. h: header file
//

# If! Defined (afx_giftdlg_h1_21d8d4ef_07f4_4f29_9351_78f99bff77231_encoded ded _)
# Define afx_giftdlg_h1_21d8d4ef_07f4_4f29_9351_78f99bff77231_encoded _

# If _ msc_ver> 1000
# Pragma once
# Endif // _ msc_ver> 1000

//////////////////////////////////////// /////////////////////////////////////
// Cgiftdlg Dialog

Class cgiftdlg: Public cdialog
{
// Construction
Public:
Int freemem ();
Int resetdata ();
Int initdata (); // initializes the Array
Cgiftdlg (cwnd * pparent = NULL); // standard Constructor
Char * Code [1000]; // pointer to the ID card number Array
Char * name [1000]; // pointer to the name Array
Char data [1000]; // random array
Int PTR; // the pointer of the progress bar pointing to a random array.
Int totalid; // The total number of IDs used for the lottery. If one is selected, the value is reduced by 1.
Bool bstart; // indicates whether the progress bar is rolling.

// Dialog data
// {Afx_data (cgiftdlg)
Enum {IDD = idd_gift_dialog };
Cbutton m_btgo;
Cstring m_code;
Cstring m_msg;
//} Afx_data

// Classwizard generated virtual function overrides
// {Afx_virtual (cgiftdlg)
Protected:
Virtual void dodataexchange (cdataexchange * PDX); // DDX/DDV support
//} Afx_virtual

// Implementation
Protected:
Hicon m_hicon;

// Generated message map Functions
// {Afx_msg (cgiftdlg)
Virtual bool oninitdialog ();
Afx_msg void onpaint ();
Afx_msg hcursor onquerydragicon ();
Virtual void onok ();
Afx_msg void ontimer (uint nidevent );
Afx_msg void oncancelmode ();
Virtual void oncancel ();
//} Afx_msg
Declare_message_map ()
};

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

# Endif //! Defined (afx_giftdlg_h1_21d8d4ef_07f4_4f29_9351_78f99bff77231_encoded ded _)
// Giftdlg. cpp: implementation file
//

# Include "stdafx. H"
# Include "gift. H"
# Include "giftdlg. H"

# Ifdef _ debug
# Define new debug_new
# UNDEF this_file
Static char this_file [] = _ file __;
# Endif

//////////////////////////////////////// /////////////////////////////////////
// Cgiftdlg Dialog

Cgiftdlg: cgiftdlg (cwnd * pparent/* = NULL */)
: Cdialog (cgiftdlg: IDD, pparent)
{
// {Afx_data_init (cgiftdlg)
M_code = _ T ("");
M_msg = _ T ("");
//} Afx_data_init
// Note that loadicon does not require a subsequent destroyicon in Win32
M_hicon = afxgetapp ()-> loadicon (idr_mainframe );
}

Void cgiftdlg: dodataexchange (cdataexchange * PDX)
{
Cdialog: dodataexchange (PDX );
// {Afx_data_map (cgiftdlg)
Ddx_control (PDX, idok, m_btgo );
Ddx_text (PDX, idc_static_code2, m_code );
Ddx_text (PDX, idc_static_msg, m_msg );
//} Afx_data_map
}

Begin_message_map (cgiftdlg, cdialog)
// {Afx_msg_map (cgiftdlg)
On_wm_paint ()
On_wm_querydragicon ()
On_wm_timer ()
On_wm_cancelmode ()
//} Afx_msg_map
End_message_map ()

//////////////////////////////////////// /////////////////////////////////////
// Cgiftdlg message handlers

Bool cgiftdlg: oninitdialog ()
{
Cdialog: oninitdialog ();
Initdata ();
Bstart = false;
// 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
M_msg.format ("press the START key to start rolling. Number of winners: % d", totalid );
Updatedata (false );
Return true; // return true unless you set the focus to a control
}

// 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 cgiftdlg: 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;
Getclientrect (& rect );
Int x = (rect. Width ()-cxicon + 1)/2;
Int y = (rect. Height ()-cyicon + 1)/2;

// Draw the icon
DC. drawicon (X, Y, m_hicon );
}
Else
{
Cdialog: onpaint ();
}
}

// The system callthis to obtain the cursor to display while the user drags
// The minimized window.
Hcursor cgiftdlg: onquerydragicon ()
{
Return (hcursor) m_hicon;
}

Void cgiftdlg: onok ()
{
// Todo: add extra validation here
If (bstart)
{
Killtimer (1 );
Bstart = false;
M_msg.format ("press start to start rolling, lottery box in number: % d", totalid-1 );
M_code.format ("extracted number: % s/n name: % s", code [DATA [PTR], name [DATA [PTR]);
// Afxmessagebox (m_code );
Resetdata (); // remove the number and disrupt it again
If (totalid <1)
{
M_btgo.enablewindow (false );
}
M_btgo.setwindowtext ("START ");
}
Else
{
Settimer (1,100, null );
Bstart = true;
M_msg.format ("select a prize by pressing the stop key ");
M_btgo.setwindowtext ("stop ");
}
Updatedata (false );
// Cdialog: onok ();
}

Void cgiftdlg: ontimer (uint nidevent)
{
// Todo: add your message handler code here and/or call default
M_code.format ("current number: % s", code [DATA [PTR]);
Updatedata (false );
PTR ++;
PTR % = totalid;
Cdialog: ontimer (nidevent );
}

Void cgiftdlg: oncancelmode ()
{
Cdialog: oncancelmode ();
 
// Todo: add your message handler code here
 
}

Int cgiftdlg: initdata ()
{
 
File * fp = fopen ("id.txt", "R ");
PTR = 0;
Totalid = 1;
If (FP = NULL)
{
Return 0;
}
Char Buf [80];
Int line = 0;
While (! Feof (FP ))
{
Char * P = fgets (BUF, 80, FP );
If (P! = NULL)
{
Name [Line] = (char *) malloc (80 );
Code [Line] = (char *) malloc (80 );
Memset (code [Line], 0, 80 );
Memset (name [Line], 0, 80 );

Int flag = 0;
For (INT I = 0; I <80 & Buf [I]! = '/0'; I ++)
{
If (BUF [I]! = ',') & (Flag = 0 ))
{
Code [Line] [I] = Buf [I];
}
Else if (flag = 0)
{
Flag = I;
}
Else if (BUF [I]! = ',') & (Flag! = 0 ))
{
Name [Line] [i-flag-1] = Buf [I];
}
}
Trace ("% s-% s", code [Line], name [Line]);
Memset (BUF, 0, 80 );
Line ++;
}
}
Fclose (FP );
For (Int J = 0; j <line; j ++)
{
Data [J] = J;
}
For (INT I = 0; I <line; I ++)
{
Int Pos = rand () % (line-I) + I;
Int temp = data [I];
Data [I] = data [POS];
Data [POS] = temp;
Trace ("% d", data [I]);
}
Totalid = line;
Return 1;
}

Int cgiftdlg: resetdata ()
{
// PTR removal, swap with the last one, and then release the memory
Int line = totalid;
Int temp = data [PTR];
Data [PTR] = data [Line-1];
Data [Line-1] = temp;
// Afxmessagebox (name [DATA [Line-1]);
Free (code [DATA [Line-1]);
Free (name [DATA [Line-1]);
Totalid --;
Line --;
PTR = 0;
For (INT I = 0; I <line; I ++) // re-disrupt
{
Int Pos = rand () % (line-I) + I;
Int temp = data [I];
Data [I] = data [POS];
Data [POS] = temp;
Trace ("% d", data [I]);
}
 
 
Return 1;
}

Int cgiftdlg: freemem ()
{
Int line = totalid;
For (INT I = 0; I <line; I ++)
{
Free (code [I]);
Free (name [I]);
}
Return 1;
}

Void cgiftdlg: oncancel ()
{
// Todo: add extra cleanup here
Freemem ();
Cdialog: oncancel ();
}
Id.txt
332601771212061, octopus
110103198511110453, Li Guang
21010119541201045x, Zhou Yu
320304780102066, Han Xin
442601771212061, Shen Bing
510103198511110453, Hongzhi
220101841201045x, Fan Jin
520304197801020661 Zeng Guo
352601771212088, Trojan
540122198511110453 Jia Hai

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.