Hge source Explor 0x9 Power & Random & Ini

Source: Internet
Author: User
Tags float max

Power

  In the Power Management section, the parameters to be used are:

    // Power    int                             npowerstatus;    Hmodule                        hKrnl32;    Getsystempowerstatusfunc       lpfngetsystempowerstatus;

_initpowerstatus ()

  To initialize the power supply information:

    • LoadLibrary ("kernel32.dll")
    • Get the function GetSystemPowerStatus address
    • Call _updatepowerstatus
void Hge_impl::_initpowerstatus () {    = LoadLibrary ("Kernel32.dll");     if (HKrnl32! = NULL        ) " GetSystemPowerStatus " );    _updatepowerstatus ();}
_initpowerstatus

_updatepowerstatus ()

  Get power information.

voidHge_impl::_updatepowerstatus () {system_power_status ps; if(Lpfngetsystempowerstatus! = NULL && lpfngetsystempowerstatus (&PS)) {        if(Ps. ACLineStatus = =1) {Npowerstatus=Hgepwr_ac; }        Else if(Ps. Batteryflag < -) {Npowerstatus=PS.        BatteryLifePercent; }        Else{npowerstatus=hgepwr_unsupported; }    }    Else{npowerstatus=hgepwr_unsupported; }}
_updatepowerstatus

_donepowerstatus ()

  End, release the dynamic link library.

void Hge_impl::_donepowerstatus () {    if(hKrnl32! = NULL) freelibrary (HKRNL32);}
_donepowerstatus

Random

The random number is provided in this module, and the only parameter is the seed of the random number.

int g_seed=0;

random_seed (int Seed)

  Sets the seed of the random number.

void Call Hge_impl::random_seed (int  Seed) {    if(!seed) g_seed=timegettime ();     Else g_seed=seed;}
Random_seed  

random_int (int min, int max)

  Linear and congruential produce an integer random number with a range of (Min,max).

int Call Hge_impl::random_int (intint  max) {    g_seed=214013*g_seed+2531011 ;     return min+ (g_seed ^ g_seed>>)% (max-min+1);}
Random_int  

random_float (float min, float max)

  Generates a floating-point random number with a range of (Min,max).

 float  min, float   Max) {g_seed  =214013  *g_seed+2531011      // return min+g_seed* (1.0f/    4294967295.0f) * (max-min);  return  min+ (g_seed>>16 ) * (1.0f /65535.0f ) * (Max-min);}  
random_float

Ini

In This section, the data is read and written from the specified INI file, so an INI file is required.

    Char                Szinifile[_max_path];

Set (const char* section,const char* name,type value);

  Write different types of parameters.

voidCall Hge_impl::ini_setint (Const Char*section,Const Char*name,intvalue) {    Charbuf[ the]; if(szinifile[0]) {sprintf (buf,"%d", value);    WritePrivateProfileString (section, name, buf, Szinifile); }}voidCall Hge_impl::ini_setfloat (Const Char*section,Const Char*name,floatvalue) {    Charbuf[ the]; if(szinifile[0]) {sprintf (buf,"%f", value);    WritePrivateProfileString (section, name, buf, Szinifile); }}voidCall Hge_impl::ini_setstring (Const Char*section,Const Char*name,Const Char*value) {    if(szinifile[0]) writeprivateprofilestring (section, name, value, Szinifile);}
Setter

Get (const char* section,const char* name, type value);

  Read the data.

intCall Hge_impl::ini_getint (Const Char*section,Const Char*name,intdef_val) {    Charbuf[ the]; if(szinifile[0]) {        if(GetPrivateProfileString (section, name,"", BUF,sizeof(BUF), szinifile)) { returnatoi (BUF);} Else{returnDef_val;} }    returnDef_val;}floatCall Hge_impl::ini_getfloat (Const Char*section,Const Char*name,floatdef_val) {    Charbuf[ the]; if(szinifile[0]) {        if(GetPrivateProfileString (section, name,"", BUF,sizeof(BUF), szinifile)) { return(float) atof (BUF); }        Else{returnDef_val;} }    returnDef_val;}Char* Call Hge_impl::ini_getstring (Const Char*section,Const Char*name,Const Char*def_val) {    if(szinifile[0]) getprivateprofilestring (section, name, Def_val, Szinistring,sizeof(szinistring), szinifile); Elsestrcpy (szinistring, def_val); returnszinistring;}
Getter

  The next thing is graphics!

Hge source Explor 0x9 Power & Random & Ini

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.