Common Algorithm Implementation

Source: Internet
Author: User
Tags 04x

Cstring newguid ()
{
Guid;
: Cocreateguid (& guid); // generates a guid
Cstring STR;
Str. format (_ T ("% 08x % 04x % 04x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x"), guid. data1, guid. data2, guid. data3,
Guid. data4 [0], guid. data4 [1], guid. data4 [2], guid. data4 [3], guid. data4 [4], guid. data4 [5], guid. data4 [6], guid. data4 [7]);
Return STR;
}

Cstring getdatestr2 (ctime T)
{
Cstring re;
Re. format (_ T ("%. 4D-%. 2D-%. 2d "), T. getyear (), T. getmonth (), T. getday ());
Return re;
}
// Obtain the string of the current date
Cstring getdatestr ()
{
Ctime T = ctime: getcurrenttime ();
Return getdatestr2 (t );
}

// Determines whether the number is a number. It indicates a number that does not contain a negative number.
Int isnum (const cstring & Str)
{
If (Str. isempty ())
Return-1;
Int ndot = 0;
// The value can only consist of 0 to 9 decimal places
For (INT I = 0; I <Str. getlength (); I ++)
{
Char CH = Str. getat (I );
If ('.' = CH) // decimal point
{
Ndot ++;
Continue;
}
If (CH> = '0' & Ch <= '9') // number
Continue;
Return-2; // invalid character
}
If (ndot> 1)
Return-3; // more than two decimal places
Else if (0 = ndot)
Return 1; // integer
Else if (1 = ndot)
Return 0; // floating point number
Return-1000; // unknown error
}
// A number containing symbols
Int issignnum (const cstring & Str)
{
If (Str. isempty ())
Return-1;
Int ndot = 0;
// The value can only consist of 0 to 9 decimal places
For (INT I = 0; I <Str. getlength (); I ++)
{
Char CH = Str. getat (I );
If ('.' = CH) // decimal point
{
Ndot ++;
Continue;
}
If (CH> = '0' & Ch <= '9') // number
Continue;
Else if (CH = '-' & I = 0)
Continue;
Return-2; // invalid character
}
If (ndot> 1)
Return-3; // more than two decimal places
Else if (0 = ndot)
Return 1; // integer
Else if (1 = ndot)
Return 0; // floating point number
Return-1000; // unknown error
}

// Determine whether the number is correct.
Bool isnumber (lpctstr psztext)
{

For (INT I = 0; I <lstrlen (psztext); I ++)
If (! _ Istdigit (psztext [I])
Return false;

Return true;
}

// Determine whether the string is in English
Bool isenglish (const cstring Str)
{
Int nindex;
Int nlen = Str. getlength ();
Bool Re = true;
For (nindex = 0; nindex <nlen; nindex ++)
{
If (Str. getat (nindex)> 127)
{
Re = false;
Break;
}
}
Return re;

}

// Method for determining a date in VC
Bool isdate (lpctstr psztext)
{
// Format shocould be 99/99/9999.

If (lstrlen (psztext )! = 10)
Return false;

Return _ istdigit (psztext [0])
& _ Istdigit (psztext [1])
& Psztext [2] ==_t ('/')
& _ Istdigit (psztext [3])
& _ Istdigit (psztext [4])
& Psztext [5] ==_t ('/')
& _ Istdigit (psztext [6])
& _ Istdigit (psztext [7])
& _ Istdigit (psztext [8])
& _ Istdigit (psztext [9]);
}
// Calculate the number of digits of a positive integer
Int calintbit (unsigned input)
{
Int COUNT = 1;
While (input/10! = 0)
{
Count ++;
Input/= 10;
}
Return count;
}

Cstring zuobiaozhuanhuan (const double & input)
{
Cstring STR;
Int du, Fen, Miao;
Du = (INT) input;
Double TMP = (input-du) * 60;
Fen = (INT) TMP;
TMP = (TMP-fen) * 60;
Miao = (INT) TMP;
If (TMP-Miao> 0.5)
{
Miao + = 1; // rounding
}
Cstring dustr (_ T ("°"), fenstr (_ T ("'"), miaostr (_ T ("″"));
Str. Format (_ T ("% d % S % d % s"), du, dustr, Fen, fenstr, Miao, miaostr );
Return STR;
}

// Input range
Bool scope (const cstring & input)
{
Int Fenge = 0;
For (INT I = 0; I <input. getlength (); I ++)
{
If (input. getat (I) = '-')
{
Fenge ++; // The number of '-' signs.
}
}
If (Fenge> 1 | Fenge = 0) // The input string contains more than 1 '-', or false is returned if no such separator exists.
{
Return false;
}
Else if (Fenge = 1)
{
Int Index = input. Find ('-');
Cstring min, Max;
Min = input. mid (0, index );
Max = input. mid (index + 1, input. getlength ()-index-1 );
If (isnum (min )! = 1 & isnum (min )! = 0)
{
Return false; // The string before '-' is not a numerical value.
}
If (isnum (max )! = 0 & isnum (max )! = 1)
{
Return false; // The string after '-' is not a numerical value.
}
If (cstod (min)> cstod (max ))
{
Return false;
}
}

Return true;
}

Double getmax (const cstring & input)
{
Cstring Max;
Int Index = input. Find ('-');
Max = input. mid (index + 1, input. getlength ()-index-1 );
Return cstod (max );
}

Double getmin (const cstring & input)
{
Cstring min;
Int Index = input. Find ('-');
Min = input. mid (0, index );
Return cstod (min );
}

Void setsipbnstatus (INT show );
// Full screen
Void fullscreen (cwnd * pwnd, bool _ bmove)
{
Hwnd hbar =: shfindmenubar (pwnd-> m_hwnd );
: Commandbar_show (hbar, false );

Pwnd-> setforegroundwindow ();
: Shfullscreen (pwnd-> m_hwnd, shfs_hidetaskbar | shfs_hidesipbutton | shfs_hidestarticon );
Rect clirect;
Pwnd-> getclientrect (& clirect );

If (_ bmove)
{
// Clirect. Top-= 26;
Clirect. Bottom + = 26 * heightscale;
Pwnd-> movewindow (& clirect );
}

// Remove the keypad button
Setsipbnstatus (sw_hide );
} // End of fullscreen
// Exit full screen
Void exitfullscreen (cwnd * pwnd, bool _ bmove)
{
Hwnd hbar =: shfindmenubar (pwnd-> m_hwnd );
: Commandbar_show (hbar, true );

Setsipbnstatus (sw_show );

Shfullscreen (pwnd-> m_hwnd, shfs_showtaskbar | shfs_showsipbutton | shfs_showstarticon );
Hwnd htask =: findwindow (text ("hhtaskbar"), null );
: Showwindow (htask, sw_show );

Rect clirect;
Pwnd-> getclientrect (& clirect );

If (_ bmove)
{
// Clirect. Top-= 26;
Clirect. Bottom-= 26 * heightscale;
Pwnd-> movewindow (& clirect );
}
}

// Exit the full screen. The input method button below is not displayed.
Void exitfullscreenhidesip (cwnd * pwnd, bool _ bmove)
{
Hwnd hbar =: shfindmenubar (pwnd-> m_hwnd );
: Commandbar_show (hbar, false );

Shfullscreen (pwnd-> m_hwnd, shfs_showtaskbar | shfs_showstarticon );
Hwnd htask =: findwindow (text ("hhtaskbar"), null );
: Showwindow (htask, sw_show );

Rect clirect;
Pwnd-> getclientrect (& clirect );

If (_ bmove)
{
// Clirect. Top-= 26;
Clirect. Bottom-= 26 * heightscale;
Pwnd-> movewindow (& clirect );
}
 
}

// Search for the final index of a character in the string
Int lastindexof (const cstring & STR, const char C)
{
Int I = Str. getlength ()-1;
While (I> = 0) // find the '_' character in the string
{
If (Str. getat (I) = C)
Break;
I --;
}
Return I;
}
// Determine whether the number after division is the first number.
# Define num_zero 1.0e-10
Bool divisibility (const double dividend, const double divisor)
{
Bool Re = false;
If (dividend <divisor) // The divisor is smaller than the divisor.
Return re;
Double result = dividend/divisor;
Result = Result-(INT) result; // obtain the fractional part.

If (FABS (result) <= num_zero) // zero
{
Re = true;
}
Return re;
}
// Obtain the current system time and return the string yyyy-mm-dd hh: mm: Ss.
Cstring getcurtime ()
{
Ctime time = ctime: getcurrenttime ();
Cstring curtime;
Curtime. format (_ T ("%. 4D-%. 2D-%. 2d %. 2d: %. 2d: %. 2d "), time. getyear (), time. getmonth (), time. getday (), time. gethour (), time. getminute (), time. getsecond ());
Return curtime;
}
// Set the display status of the Soft Keyboard
Void setsipbnstatus (INT show)
{
Hwnd hwndsipbutton =: findwindow (text ("ms_sipbutton"), null );
If (null! = Hwndsipbutton)
{
: Showwindow (hwndsipbutton, show );
}
}

Bool existfile (const cstring & filename)
{
Win32_find_data findfiledata;
Handle hfind;
Hfind = findfirstfile (filename, & findfiledata );
If (hfind! = Invalid_handle_value)
{
Findclose (hfind );
Return true;
}
Else
{
Findclose (hfind );
Return false;
}

}

// Separate the string
// Strcontent: the string to be separated, for example, a; B; C; d
// Arstring: separated Array
// Ncount: array size
// Ctoken: delimiter
Void splite (cstring strcontent, carray <cstring, cstring> & arrstring, Int & ncount, const char & ctoken)
{
If (strcontent. Trim () = _ T (""))
Return;

Int nbegin;
Int nend;
Int conlength = strcontent. getlength ();
Nbegin = 0;
If (strcontent. getat (conLength-1 )! = Ctoken)
Strcontent + = ctoken;
Nend = strcontent. Find (ctoken, 0 );
Ncount = 0;

While (nend> = 0)
{
Arrstring. Add (strcontent. mid (nbegin, nend-nbegin ));
Ncount ++;
Nbegin = nend + 1;
If (nbegin> = conlength)
Break;
Nend = strcontent. Find (ctoken, nbegin );
}
}

Bool strinarray (const cstring & STR, const carray <cstring, cstring> & arrstr)
{
Int arrcount = arrstr. getcount ();

For (INT I = 0; I <= arrCount-1; I ++)
{
If (arrstr. getat (I) = Str)
Return true;
}
Return false;
}
// Determine whether a string is in another string
Bool strinstring (const cstring & becontain, const cstring & strcontent)
{
If (strcontent = _ T ("") | becontain = _ T (""))
Return false;
If (becontain. getlength ()> strcontent. getlength ())
Return false;
Int Index = strcontent. Find (becontain );
If (index> = 0)
Return true;
Else
Return false;
}
// Load Bitmap Based on screen specifications
Void loadbmp (cbitmap * pbitmap, uint nid16, uint nid32)
{
Assert (pbitmap );

If (heightscale> 1.5 | widthscale> 1.5)
{
Pbitmap-> loadbitmapw (nid32 );
}
Else
{
Pbitmap-> loadbitmapw (nid16 );
}
}

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.