ºìÁªLinuxÃÅ»§
Linux°ïÖú

C++ÖпØÖÆWindows¹Ø»úµÄʵÓü¼ÇÉ

·¢²¼Ê±¼ä:2006-05-03 12:11:52À´Ô´:ºìÁª×÷Õß:°®µÄ±ßÔµ
ÎÒÃÇÔÚÓ¦ÓóÌÐò±àÖÆÍê³Éºó£¬ÐèÒªÉè¼ÆÓ¦ÓóÌÐòµÄ°ü×°ºÍ·Ö·¢¹¦ÄÜ¡£ÔÚ±àд°²×°³ÌÐòʱ£¬¾­³£»áÓöµ½ÕâÑùµÄÎÊÌ⣺³ÌÐò°²×°Íê³ÉºóÐèÒªÖØÐÂÆô¶¯¼ÆËã»ú¡£ÄÇôÔÚ´úÂëÖÐÈçºÎ¿ØÖÆWindowsµÄ¹Ø»ú»òÖØÐÂÆô¶¯ÄØ£¿

¡¡ÒªÊµÏÖÕâ¸ö¹¦ÄÜ£¬ÐèÒªÓõ½Windows APIÌṩµÄÒ»¸öExitWindowsExº¯Êý¡£ÎÒÃÇ¿ÉÒÔͨ¹ý²é¿´C++ BuilderÌṩµÄ°ïÖúÎļþµÃµ½Õâ¸öº¯ÊýµÄʹÓøñʽ:

¡¡

BOOL ExitWindowsEx(

UINT uFlags,

// ÉèÖùػú²ÎÊý

DWORD dwReserved

// ϵͳ±£Áô×Ö

);

ÉèÖÃuFlagsµÄ²ÎÊý˵Ã÷£º

EWX_FORCE¡¡Ç¿ÖÆÖÕÖ¹³ÌÐòÔËÐжøÍ˳öϵͳ ¡¡

EWX_LOGOFF Í˳ö¶øÒÔÆäËüÉí·ÝµÇ¼

EWX_REBOOT ÖØÐÂÆô¶¯

EWX_SHUTDOWN¹Ø»ú¡¡

dwReservedÊÇϵͳ±£Áô×Ö£¬Ëæ±ãÌîÈë¸ö0¼´¿É¡£

Á˽âExitWindowsExº¯ÊýµÄʹÓøñʽºó£¬ÏÂÃæÒÔʵÀý˵Ã÷ÔÚC++ BuilderÖпØÖÆWindows¹Ø»ú»òÖØÐÂÆô¶¯µÄ·½·¨¡£

Éè¼Æ²½ÖèÈçÏ£º ¡¡

1.ÔËÐÐC++ Builderϵͳºó£¬Ïȼ¤»îÑ¡µ¥¡°File/New Application¡±£¬´´½¨Ò»¸öй¤³Ì¡£ ¡¡ ¡¡

2.¼¤»îÑ¡µ¥¡°File/Save As¡±°Ñ´°Ìåµ¥ÔªÒÔÎļþÃûexitu.cpp´æÅÌ£¬È»ºó¼¤»îÑ¡µ¥¡°File/Save Project As¡±°Ñ¹¤³ÌÎļþÒÔÎļþÃûexitp.bpr´æÅÌ¡££¨×¢Ò⣺¹¤³ÌÎļþÃûÓë´°Ìåµ¥ÔªÎļþÃû²»ÒªÍ¬Ãû¡££© ¡¡

3.ÔÚ´°ÌåÉÏÔö¼ÓËĸöTButton×é¼þButton1¡¢Button2¡¢Button3ºÍButton4£¬·Ö±ðÉèÖÃËüÃǵÄCaptionÊôÐÔΪ¡°ÆäËüÉí·ÝµÇ¼¡±¡¢¡°¹Ø»ú¡±¡¢¡°ÖØÐÂÆô¶¯¡±ºÍ¡°Ç¿Öƹػú¡±¡£

4.·Ö±ðÉèÖÃButton1¡¢Button2¡¢Button3ºÍButton4×é¼þµÄOnClickʼþÏìÓ¦´úÂëÈçÏ£º

void __fastcall TForm1::Button1Click(TObject Sender)

{

//ÆäËüÉí·ÝµÇ¼

DWORD temp;

ExitWindowsEx(EWX_LOGOFF,temp);

}

//------------------------------

void __fastcall TForm1::Button2Click(TObject Sender)

{

//¹Ø»ú

DWORD temp;

ExitWindowsEx(EWX_SHUTDOWN,temp);

}

//------------------------------

void __fastcall TForm1::Button3Click(TObject Sender)

{

//ÖØÐÂÆô¶¯

DWORD temp;

ExitWindowsEx(EWX_REBOOT,temp);

}

//------------------------------

void __fastcall TForm1::Button4Click(TObject Sender)

{

//Ç¿Öƹػú

DWORD temp;

ExitWindowsEx(EWX_FORCE,temp);

}

5.ÔËÐгÌÐòºó£¬·Ö±ðµ¥»÷Ëĸö°´Å¥²âÊÔËüÃǵŦÄÜ¡£Èç¹ûÄÜÍê³É¸÷ÖÖÉèÖõŦÄÜ£¬ËµÃ÷ÄãÒѳɹ¦ÁË£¬ÄÇô¾Í¿ÉÒÔ½«±¾ÎĽéÉܵķ½·¨ÔËÓõ½×Ô¼º¿ª·¢µÄC++ BuilderÓ¦ÓóÌÐòÖÐÈ¥¿ØÖÆWindowsµÄ¹Ø±ÕÁË¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ