²Ä 23 ³¹¡@³q¥Î±±¨î¶µ(3)¡G¤u¨ã´£¥Ü ( Tool Tip )


¤u¨ã´£¥Ü ( Tool Tip )

·í¨Ï¥ÎªÌ§â·Æ¹«´å¼Ð²¾¨ì¨Æ¥ý«ü©w¦nªº°Ï°ì®É¡A¨t²Î·|Åã¥Ü¤@µøµ¡¡A¦¹µøµ¡¥]§t¤@¬q¤å¦r»¡©ú¬Y¥ó¨Æ¡A³o¤@µøµ¡ºÙ¬°¤u¨ã´£¥Ü ( Tool Tip )¡C¦p¤U¹Ï©Ò¥Üªº¡uµn¿ý½s¿èµ{¦¡¡v¡A¦pªG¨Ï¥ÎªÌ¦b¥k¤W¨¤ªº¡u³Ì¤p¤Æ«ö¶s¡v«ö¶s°±¯d¤@¬q®É¶¡¡A´N·|¥X²{¤@­Ó¶À©³¶Â¦rªº¤pµøµ¡¡A¤W­±¼g¡u³Ì¤p¤Æ¡v¡A³o­Ó¤pµøµ¡´N¬O¡u¤u¨ã´£¥Ü¡v¡C·L³n§â¨Æ¥ý«ü©w¦nªº°Ï°ìºÙ¬°¡utool¡v¡A¤p¤ì°¸Â½¦¨ºÊµø°Ï°ì¡A·í¨Ï¥ÎªÌ§â·Æ¹«´å¼Ð¥ÑºÊµø°Ï°ì²¾¨«®É¡A¤u¨ã´£¥Ü±Û§Y®ø¥¢¡C¡u¤u¨ã´£¥Ü¡v¤]¬O¤@ºØ³q¥Î±±¥ó¡C

¤­ºØ³q¥Î±±¨î¶µ

¤u¨ã´£¥Ü±±¨î¶µÁÙ¦³¥t¥~´XºØ¸û¯S®í¼Ë¤l¡GTracking ToolTips ( ¥i¥H¥Ñµ{¦¡¦Ó«D¨t²Î³]©w¦bÅã¥Ü¦ì¸mªº¤u¨ã´£¥Ü )¡BMultiline ToolTips ( ¦h¦æªº¤u¨ã´£¥Ü )¡BBalloon ToolTips ( ®ð²y§Îª¬ªº¤u¨ã´£¥Ü )¡BIn-Place ToolTips ( ¥H·Æ¹«ÂI¿ï«á¥X²{ªº¤u¨ã´£¥Ü )¡C¤£¹L¤£ºÞ¬O­þ¤@ºØ¤u¨ã´£¥Ü¡A¨ä¹ê¤]³£¬O¤lµøµ¡¡A©Ò¥H­n«Ø¥ß¤u¨ã´£¥Ü¡A¥i¥H¥Î©I¥s CreateWindowEx¡C¦¹¨BÆJ¬°¡G

  1. ¦bµ{¦¡¥ô·N¤@³B¡A©I¥s InitCommonControls ©Î InitCommonControlsEx¡A¥Hªì©l¤Æ³q¥Î±±¥ó¡C³o¤]¬O¨Ï¥Î³q¥Î±±¥óªº¥²­n¨BÆJ¡C
  2. ©w¸qµøµ¡Ãþ§O¬°¡yTOOLTIPS_CLASS32¡z¡A¨Ã¥H NULL µ²§À¡C
  3. ¤@¯ë¦b³B²z WM_CREATE ®É¡A©I¥s CreateWindowEx¡A«Ø¥ß¤u¨ã´£¥Ü¡A¨Ã¨ú±o¨äµøµ¡¥N½X¡C
  4. ©I¥s SendMessage¡Aµo°e°T®§µ¹¤u¨ã´£¥Ü¡A¥H³]©w¤u¨ã´£¥Üªº¦æ¬°¡C

©I¥s CreateWindowEx «Ø¥ß¤u¨ã´£¥Ü®É¡A²Ä¤@­Ó°Ñ¼Æ¡AdwExStyle¡A¥i³]¬° NULL¡F²Ä¤G­Ó°Ñ¼Æ¡AlpClassName¡A¶·«ü¦V¡yTOOLTIPS_CLASS32¡z¦r¦ê¦ì§}¡F²Ä¤T­Ó°Ñ¼Æ¡AlpWindowName¡A¦]¤£»Ýµøµ¡¼ÐÃD¡A¥i³]¬° NULL¡F²Ä¥|­Ó°Ñ¼Æ¡AdwStyle¡A¦³¤CºØ­·®æ¥i¨Ñ¿ï¾Ü¡G

­·®æ¼Æ­È»¡©ú
TTS_ALWAYSTIP1h ¥u­n·Æ¹«¦bºÊµø°Ï°ì¤W¡A´N·|Åã¥Ü¤u¨ã´£¥Ü¡A¤£½×¤÷µøµ¡¬O§_¬O¬¡°Êªº¡C¦pªG¨S¦³³]©w¦¹­·®æ¡A¥u¦³¦b¤÷µøµ¡¬°¬¡°Êªº®É­Ô¡A¤~·|Åã¥Ü¤u¨ã´£¥Ü¡C
TTS_BALLOON40h ¦¹­·®æ¬° 5.80 ª©¥»ªº COMCTRL32.DLL ¤Î¨ä¥H«á¤~¦³ªº­·®æ¡A5.80 ª©¥»ªº COMCTL32.DLL ¬OÀH Internet Explorer 5 ( IE5 ) ´²§Gªº¡A¦]¦¹¦b¦w¸Ë¦³ IE5 ªº Windows §@·~¨t²Î¤¤¡A´N¥i¨Ï¥Î¦¹­·®æ¡C¦¹­·®æªº¤u¨ã´£¥Ü¦p¦Pº©µe¤¤¡A¤Hª«ªº¹ï¸Ü®Ø®Ø¡A¦p¹Ï¡C
TTS_NOANIMATE10h ¦¹­·®æ¬° 5.80 ª©¥»ªº COMCTRL32.DLL ¤Î¨ä¥H«á¤~¦³ªº­·®æ¡C¤@¯ë¦Ó¨¥¡A¤u¨ã´£¥Ü¥X²{®É¡A·|³vº¥¯B²{¦b¿Ã¹õ¤W¡F®ø¥¢®É¡A¬O³vº¥Áô¨S¡C¦pªG±z·Q¬Ý¨£«e­z®ÄªG¡A¥²¶·¥H·Æ¹«¥kÁä«ö¡u§Úªº¹q¸£¡v¡÷¡u¤º®e¡v¡÷¡u¶i¶¥¡v¡÷¡u³]©w¡v¡÷¡uµøı®ÄªG¡v¡A½T©w¡u¦Û­q¡v¤¤¡u¤u¨ã´£¥Ü³vº¥®ø¥¢©Î·Æ°Ê¨ìÀ˵ø¡v¬°¤Ä¿ï¡C¦¹­·®æ·|§í¨î³vº¥¯B²{¦b¿Ã¹õ¤Wªº®ÄªG¡C
TTS_NOFADE20h ¦¹­·®æ¬° 5.80 ª©¥»ªº COMCTRL32.DLL ¤Î¨ä¥H«á¤~¦³ªº­·®æ¡A¦¹­·®æ·|§í¨î³vº¥Áô¨Sªº®ÄªG¡C
TTS_NOPREFIX2h ¨ã¦³¦¹­·®æ®É¡A¤u¨ã´£¥Ü¯àÅã¥Ü¡y&¡z¦r¤¸¡C
TTS_CLOSE80h ¦pªG¤u¨ã´£¥Ü¨ã¦³¼ÐÃD¡A¥B¨ã¦³ TTS_CLOSE ®É¡A·|¦b¤u¨ã´£¥Ü¥k¤W¤èÅã¥ÜÃö³¬«ö¶s¡C§Ú­Ì¥i¥H¹ï¤u¨ã´£¥Üµo°e TTM_SETTITLE ³]©w¼ÐÃD¡C
TTS_USEVISUALSTYLE100h ¨ã¦³¦¹­·®æ®É¡A¯àÅã¥Ü¥DÃD³sµ²¡A»Ý­n©M TTF_PARSELINKS ·f°t¨Ï¥Î¡C

°£¦¹¤§¥~¡A¤u¨ã´£¥ÜÁÙ¨ã³Æ¦³ WS_POPUP ©MÃB¥~ªº WS_EX_TOOLWINDOW ­·®æ¡A¦ý³o¨âºØ­·®æ·|¥Ñ¡yTOOLTIPS_CLASS32¡zÃþ§O«ü©w¡A©Ò¥H¤£»Ý¯S§O«ü©w¡C±µ¤U¨Óªº¥|­Ó°Ñ¼Æ¬Oµøµ¡¦ì¸m»Pµøµ¡¤j¤p§¡¥Ñ¨t²Î³]©w¡A¬Ò³]¬°¡yCW_USEDEFAULT¡z§Y¥i¡C²Ä¤E­Ó°Ñ¼Æ¡AhWndParent¡A¥i¥H¶ñ¤J¤÷µøµ¡¥N½X¡C²Ä¤Q­Ó°Ñ¼Æ¡AhMenu¡A¤£»Ý­n¡A¦]¬°¤u¨ã´£¥Ü¤£·|¦³¿ï³æ¡A³]¬° NULL¡C²Ä¤Q¤@­Ó°Ñ¼Æ¡AhInstance¡AÀ³¶ñ¤J¤u¨ã´£¥Ü©ÒÄݪº¼Ò²Õ¥N½X¡C³Ì«á¤@­Ó°Ñ¼Æ¡AlpParam¡A«h¬O»Ý­n¦Ó©w¡C


¤u¨ã´£¥Üªº°T®§

»P¨ä¥L±±¨î¶µ¤@¼Ë¡A§^¤H¥H©I¥s SendMessage ¹ï¤u¨ã´£¥Üµo¥X°T®§¡A¥H³]©w¨ä¦æ¬°¡C¦¹®É²Ä¤@­Ó°Ñ¼Æ¡AhWnd¡A¶ñ¤J¤u¨ã´£¥Ü¥N½X¡F²Ä¤G­Ó°Ñ¼Æ¡AuMsg¡A¶·¨Ì¤£¦P»Ý­n¦Ó³]©w¡A¤u¨ã´£¥Üªº°T®§³£¬O¥H¡uTTM_¡v¬°¦rÀY¡F²Ä¤T»P³Ì«á¤@­Ó°Ñ¼Æ¡AwParam »P lParam¡A«h¬O¨Ì uMsg ¤£¦P¦Ó³]¤£¦Pªº¼Æ­È¡C¦p¤U¡J

        INVOKE  SendMessage,hToolTip,uMsg,wParam,lParam

©³¤U¥ý¤¶²Ð¦p¦ó¦b¤u¨ã´£¥Ü¤¤¡A·s¼WºÊµø°Ï°ì¡A¥ç§Yµo°e TTM_ADDTOOL °T®§µ¹¤u¨ã´£¥Ü¡C

TTM_ADDTOOL¡J²K¥[ºÊµø°Ï°ì

¹ï¤u¨ã´£¥Üµo¥X TTM_ADDTOOL °T®§®É¡AwParam ¥²¶·³]¬° 0¡AlParam ¬O TOOLINFO µ²ºcÅé¦ì§}¡CTOOLINFO µ²ºcÅé¥]§t¤F¦³ÃöºÊµø°Ï°ìªº¸ê®Æ¤Î­nÅã¥Üªº¤å¦r¡A¥¦ªºÄæ¦ì¦p¤U¡G

TOOLINFO        STRUC
cbSize          DWORD   ?
uFlags          DWORD   ?
hwnd            DWORD   ?
uId             DWORD   ?
rect            RECT    <?>
hinst           DWORD   ?
lpszText        DWORD   ?
lParam          DWORD   ?
TOOLINFO        ENDS

TOOLINFO ªº²Ä¤@­ÓÄæ¦ì¡AcbSize¡A¬O TOOLINFO µ²ºcÅé¤j¤p¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡A¦b©I¥s SendMessage ¤§«e¥²¶·¶ñ¤J¥¿½Tªº¤j¤p¡A¥H«KÅý§@·~¨t²Î¯à¿ëÃѪ©¥»¡CTOOLINFO ªº²Ä¤­­ÓÄæ¦ì¡Arect¡A´N¬OºÊµø°Ï°ì¡AºÊµø°Ï°ì¨ä¹ê¬O¤@¶ô¯x§Î°Ï°ì¡A§Ú­Ì¦³®É§â¾ã­Ó¤u§@°Ï³£·í¦¨ºÊµø°Ï°ì ( ¨Ò¦p§â«ö¶s±±¨î¶µ·í¦¨ºÊµø°Ï°ì®É¡A´N«Ü¦n¥Î )¡F¦³®É¶È¶È§â³¡¥÷¤u§@°Ï·í¦¨ºÊµø°Ï°ì¡A¦³®É¥ç¥i§â¤u§@°Ï¤Á³Î¦¨¼Æ­Ó¯x§Î°Ï°ì¡A·í¦¨¼Æ­ÓºÊµø°Ï°ì¡A·Æ¹«²¾¹L¤£¦PªººÊµø°Ï°ì¥i¥HÅã¥Ü¤£¦Pªº¤å¦r¡C©³¤U¤p¤ì°¸¤À§O»¡©ú³o¨âºØ±¡§Î¡G

µo°e TTM_ADDTOOL µ¹¤u¨ã´£¥Ü«á¡A¦pªGªð¦^®É¡AEAX ¬° TRUE ªí¥Ü©I¥s¦¨¥\¡A­Y¬° FALSE ªí¥Ü¥¢±Ñ¡C

TOOLINFO ¤]¥i¥H¬°¨ä¥¦°T®§¨Ï¥Î¡A¦p TTM_DELTOOL¡A¦]¦¹ uFlags Äæ¦ì¥\¯à¤£¬O¥u¦³ TTF_IDISHWND ©M TTF_SUBCLASS ¨âºØ¦Ó¤w¡A¤p¤ì°¸¾ã²z¦p¤U¡J

  1. TTF_IDISHWND¡G¦pªG«ü©w³o­ÓºX¼Ð¡A´Nªí¥ÜºÊµø°Ï°ì¬O¾ã­Ó¤u§@°Ï¡A¦¹®É¥²¶·§â¸Óµøµ¡ªº¥N½X¶ñ¤J uID Äæ¦ì¡AlpszText ¶ñ¤W­nÅã¥Üªº¤å¦r¦ì§}¡CIDISHWND ¬O¡uID is hWnd¡v¤§·N¡A¥ç§Y uID ¨Ã«DÃѧO½X¦Ó¬Oµøµ¡¥N½X¡C
  2. TTF_SUBCLASS¡G¦¹ºX¼Ðªí¥Ü¤u¨ã´£¥Ü·|¤lÃþ¤ÆºÊµø°Ï°ì©Ò¦bªºµøµ¡¡A¥ç§Y¤u¨ã´£¥Ü·|ÄdºIºÊµø°Ï°ì©Ò¦bµøµ¡ªº°T®§¡A¨Ò¦p WM_MOUSEMOVE¡C¨Æ¹ê¤W¡A·í·Æ¹«´å¼Ð¦bºÊµø°Ï°ì¤W²¾°Ê©Î°±¯d®É¡A¨t²Î¥u·|§â°T®§¶Çµ¹ºÊµø°Ï°ì©Ò¦bªºµøµ¡¡A¦Ó¤£¬O¤u¨ã´£¥Ü¡C¦]¦¹¦pªG¤£¨Ï¥Î TTF_SUBCLASS §â¦¹°T®§ÄdºI¦Ó¶Ç»¼µ¹¤u¨ã´£¥Ü¡A§Ú­Ì´N±o¨Ï¥Î TTM_RELAYEVENT¡A§â°T®§Âàµo¦Ü¤u¨ã´£¥Ü¡C
  3. TTF_CENTERTIP¡G¤@¯ë¤u¨ã´£¥Ü¬O¦b·Æ¹«´å¼Ðªº¥k¤U¤èÅã¥Ü¡A¦ý³]©w¦¹ºX¼Ð®É¡A·|¦bºÊµø°Ï°ì¤U¤èªº¥¿¤¤¶¡Åã¥Ü¡C
  4. TTF_PARSELINKS¡G6.0 ª©¤Î¨ä¥H«áªº COMCTL32.DLL ¥i¥H¨Ï¥Î¡A¦¹ª© COMCTL32.DLL ¬OÀHµÛ XP ³c°â¡C
  5. TTF_RTLREADING¡G¦pªG¨t²Î¬Oªü©Ô§B©Î§Æ§B¨Ó»y¨t¡A³]©w¦¹ºX¼Ð¥i¥H¨Ï¤å¦r¥Ñ¥k¦Ü¥ªªº¶¶§ÇÅã¥Ü¡A¦b¨ä¥¦»y¨t¬OµL®Ä¡C
  6. TTF_ABSOLUTE¡G¥²¶·°t¦X TTF_TRACK ºX¼Ð¡A¥i¥H¨Ï¤u¨ã´£¥Ü¦b TTM_TRACKPOSITION ©Ò«ü©wªº¿Ã¹õ®y¼ÐÅã¥Ü¡C
  7. TTF_TRACK¡G¤u¨ã´£¥Ü·|Åã¥Ü¦bºÊµø°Ï°ì®ÇÃä¡A¦Ó¥B¥H¤£¾×¦íºÊµø°Ï°ì¬°­ì«h¡C¨ã¦³¦¹ºX¼Ðªº¤u¨ã´£¥Ü¡A¥²¶·¥Ñµ{¦¡¦Û¦æ³B²z°T®§¨ÃÅã¥Ü¤u¨ã´£¥Ü¡A©Ò¥H¤£¥i©M TTF_SUBCLASS ¨Ã¥Î¡A§Y¨Ï¨Ï¥Î¤F¡ATTF_SUBCLASS ¤´¬OµL®Ä¦Ó¦h¾lªº¡C
  8. TTF_TRANSPARENT¡G¨Ï¤u¨ã´£¥Ü¸òµÛ·Æ¹«²¾°Ê¡A¦ý®ÄªG¨Ã¤£¦n¡C

TOOLINFO µ²ºcÅ骺 lpszText Äæ¦ì¥i¥H¬O¦r¦ê¦ì§}¡A¤]¥i¥H¬O¦r¦ê¸ê·½ªºÃѧO½X¡A°²¦p¬O«áªÌ¡A¨º»òÁÙ­n¦A³]©w hinst Äæ¦ì¡Ahinst ¬O¥]§t¦³¤å¦r¦r¦ê¸ê·½ªº¼Ò²Õ¥N½X¡A¥¦¥u¦³¦b lpszText ¬O¥Nªí¦r¦ê¸ê·½ªºÃѧO½X®É¤~»Ý­n³]©w¡A¨ä¥L±¡§Î¬OµL¥Îªº¡C³Ì«á¤@­ÓÄæ¦ì lParam

TTM_SETDELAYTIME¡J³]©w©µ¿ð®É¶¡

µo°e TTM_SETDELAYTIME °T®§µ¹¤u¨ã´£¥Ü¡A¥i¥H³]©w¤u¨ã´£¥Üªº©µ¿ð®É¶¡¡A¤èªk¬O¡J

        INVOKE  SendMessage,hToolTip,TTM_SETDELAYTIME,wParam,lParam

¨ä¤¤³Ì«á¤@­Ó°Ñ¼Æ¡AlParam¡A¬O«ü©µ¿ðªº®É¶¡¡A¥H²@¬í¬°³æ¦ì¡C¦Ó wParam ¬O³]©w©µ¿ð­þ¤@ºØ®É¶¡¡A¥i¥H¬O¤U­±´X¥|ºØ¡J

  1. TTDT_INITIAL¡J³]©w·Æ¹«´å¼Ð°±¯d¦bºÊµø°Ï°ì¦h¤Ö²@¬í¡A¤~Åã¥Ü¤u¨ã´£¥Ü¡C
  2. TTDT_AUTOPOP¡J¤u¨ã´£¥ÜÅã¥Ü¥H«á¡A¦h¤Ö²@¬í¤~®ø¥¢¡C
  3. TTDT_RESHOW¡J·í·Æ¹«´å¼Ð¥Ñ¤@­ÓºÊµø°Ï°ì²¾¨ì¥t¤@­ÓºÊµø°Ï°ì«á¡A­nªá¦h¤Ö²@¬í¡A¤~Åã¥Ü¤u¨ã´£¥Ü¡C
  4. TTDT_AUTOMATIC¡J±N«e­z¤T­Ó©µ¿ð®É¶¡«ì´_¦¨¨t²Î¹w³]ªº¤ñ¨ÒÃö«Y¡A¤W­z¤TºØ©µ¿ð®É¶¡ªº¤ñ¨ÒÃö«Y¨Ì¦¸¬O 5¡G50¡G1¡C°Ñ¼Æ lParam ¬°¥¿­È¡A«h³]©w initial ©µ¿ð®É¶¡¡A¥t¨â¶µ®É¶¡«h¨Ì¤ñ¨Ò³]©w¡F­Y¬°­t­È¡A«h·|¨ú±o¤W­z©µ¿ð®É¶¡¡C

TTM_SETMAXTIPWIDTH

³o­Ó°T®§¬O¥Î¨Ó³]©w¤u¨ã´£¥Üªº³Ì¤j¼e«×¡C§Ú­Ì¥i¥H¥Î³oºØ¤èªk¨Ó³]©w¦h¦æ¦r¦ê¡C¤èªk¦p¤U¡J

        INVOKE  SendMessage,hToolTip,TTM_SETMAXTIPWIDTH,0,iWidth

°Ñ¼Æ¤¤ªº wParam ¥²¶·³]¬° 0¡A¦Ó lParam ¬°­n³]©wªº¼e«×¡A¥HÂI¬°³æ¦ì¡C¦pªG­nÅã¥Üªº¦r¦êªø«×¶W¹L¤u¨ã´£¥Üªº³Ì¤j¼e«×¡A¨º»ò³Ñ¤Uªº¦r¦ê·|Åã¥Ü¦b¤U¤@¦æ¡C³oùةҿתº³Ì¤j¼e«×¡A¨Ã¤£¬O«ü¤u¨ã´£¥Ü¤£¯à¶W¹L¦¹¼e«×¡C¦]¬°­^¤å¦rªøµu¤£¦P¡A¨Ã¥B¦Ò¼{¤£­nÅý¤@­Ó­^¤å¦r¤Á¦¨¨â¦æ¡A©Ò¥H¨t²Î¦b¦r¦ê¶W¹L³Ì¤j¼e«×®É¡A¦p¹JªÅ¥Õ¦r¤¸¡A¤~·|³Q¤Á¦¨¨â¦æ¡C¦¹¥~¡A¦pªG¨S¦³³]©w TTM_SETMAXTIPWIDTH¡A§Y¨Ï¨Ï¥Î´«¦æ¦r¤¸ ( 0dh¡B0ah ) ¤]¤£¯à¤Á¦¨¨â¦æ¡F¦ý¬O³]©w¹L TTM_SETMAXTIPWIDTH «á¡A§Y¨Ï¦b³Ì¤j¼e«×¤º¡A¨Ï¥Î´«¦æ¦r¤¸¤]¥i¥H´«¦æ¡C

TTM_SETTITLE

³o­Ó°T®§¬O¥Î¨Ó¦b¤u¨ã´£¥Ü¤ºªº¤W¤èÅã¥Ü¼ÐÃD¡C¤èªk¦p¤U¡J

        INVOKE  SendMessage,hToolTip,TTM_SETTITLE,icon,pszTitle

°Ñ¼Æ icon ¬O¦b¼ÐÃDÄ楪¤è³]©w¹Ï¥Ü¡A¥i¥H¬O¤U­±´XºØ¡JTTI_NONE¡BTTI_INFO¡BTTI_WARNING¡BTTI_ERROR¡BTTI_INFO_LARGE¡BTTI_WARNING_LARGE¡BTTI_ERROR_LARGE¡A¦pªG¬O Windows XP SP2 ¥H«áªºª©¥»¡A¤]¥i¥H¨Ï¥Î¹Ï¥Ü¥N½X¡CpszTitle ¬°¼ÐÃD¦r¦ê¦ì§}¡A¥H¹sµ²§À¡Cªð¦^®É¡ATRUE ªí¥Ü¦¨¥\¡FFALSE ªí¥Ü¥¢±Ñ¡C


½d¨Ò

©³¤U¤p¤ì°¸±N¹ê§@¤@­Óµ{¦¡¡AMEMFREE1.ASM¡A¦¹µ{¦¡·|§â¹q¸£¤¤ªº³Ñ¾lªº¹êÅé°O¾ÐÅé¡B¤À­¶ÀÉ¡BµêÀÀ°O¾ÐÅéÅã¥Ü¥X¨Ó¡A·í¨Ï¥ÎªÌ§â·Æ¹«²¾¨ì¬ÛÃöªº¸ê®Æ®É¡A´N·|¥X²{¤u¨ã´£¥Ü¡A¸ÑÄÀ¬ÛÃöªº³N»y¡C

­ì©l½X¦p¤U¡G

        .586
        .MODEL  FLAT,STDCALL
        OPTION  CASEMAP:NONE

INCLUDE         WINDOWS.INC
INCLUDE         GDI32.INC
INCLUDE         KERNEL32.INC
INCLUDE         USER32.INC
INCLUDE         COMCTL32.INC
INCLUDELIB      GDI32.LIB
INCLUDELIB      KERNEL32.LIB
INCLUDELIB      USER32.LIB
INCLUDELIB      COMCTL32.LIB

GlobalMemoryStatusEx    PROTO   :DWORD

MEMORYSTATUSEX          STRUC
dwLength                DWORD   ?
dwMemoryLoad            DWORD   ?
ullTotalPhys            QWORD   ?
ullAvailPhys            QWORD   ?
ullTotalPageFile        QWORD   ?
ullAvailPageFile        QWORD   ?
ullTotalVirtual         QWORD   ?
ullAvailVirtual         QWORD   ?
ullAvailExtendedVirtual QWORD   ?
MEMORYSTATUSEX          ENDS

;*********************************************************************
.CONST
WND_WIDTH               EQU     200
WND_HEIGHT              EQU     120
ID_TIMER                EQU     2000
FONT_SIZE               EQU     12
TTF_ABSOLUTE            EQU     80h
TTF_TRACK               EQU     20h
TTM_TRACKPOSITION       EQU     412h
TTM_SETMAXTIPWIDTH      EQU     418h
TTM_TRACKACTIVATE       EQU     WM_USER + 17
rect            RECT    <0,0,WND_WIDTH,WND_HEIGHT>
szAppName       BYTE    '³Ñ¾l°O¾ÐÅé',0
szClassName     BYTE    'MemFree',0
szMemIcon       BYTE    'CHIP',0
szToolTipClass  BYTE    'TOOLTIPS_CLASS32',0
szFont          BYTE    '·s²Ó©úÅé',0
szMemFmt        BYTE    '¥þ³¡¹êÅé°O¾ÐÅé¡G%dKB',0dh,0ah,'³Ñ¾l¹êÅé°O¾ÐÅé¡G%dKB',0dh,0ah
                BYTE    '¥þ³¡¤À­¶Àɤj¤p¡G%dKB',0dh,0ah,'³Ñ¤U¤À­¶Àɤj¤p¡G%dKB',0dh,0ah
                BYTE    '¥þ³¡µêÀÀ°O¾ÐÅé¡G%dKB',0dh,0ah,'³Ñ¤UµêÀÀ°O¾ÐÅé¡G%dKB',0
szPhyMem        BYTE    '¹êÅé°O¾ÐÅé¬O«ü¦w¸Ë¦b¹q¸£¥D¾÷ªO',0dh,0ah
                BYTE    '¤Wªº°ÊºAÀH¾÷¦s¨ú°O¾ÐÅé ( Dynamic ',0dh,0ah
                BYTE    'Random Access Memory¡A²ºÙ DRAM )',0dh,0ah
                BYTE    '¥¦¬O¤@ÁûÁûªº¿nÅé¹q¸ô²Õ¦¨ªº¡C',0
szPageFile      BYTE    '¤À­¶ÀÉ¥»«ü«Ø¥ß¦bµwºÐ¤¤ªºµêÀÀ°O¾Ð',0dh,0ah
                BYTE    'Åé¡A¦¹³B¬O«ü¹êÅé°O¾ÐÅé»P¤À­¶Àɤj',0dh,0ah
                BYTE    '¤p¡A¤]¬O¨t²Î©Ò¯à¨Ï¥Îªº°O¾ÐÅé¤W­­',0dh,0ah
                BYTE    '¤j¤p»P³Ñ¾l¤j¤p¡C',0
szVirtual       BYTE    '¤@­Óµ{¦¡©Ò¯à¨Ï¥ÎªºµêÀÀ°O¾ÐÅé¡A¦¹',0dh,0ah
                BYTE    'µêÀÀ°O¾ÐÅ饲¶·¦©°£¨t²Î¥Î¥hªº³¡¥÷',0dh,0ah
                BYTE    '¡A¹ï Win32 ¨t²Î¦Ó¨¥¤j¬ù¬O 2GB¡C',0
;*********************************************************************
.DATA?
hInstance       HINSTANCE               ?
hwnd            HWND                    ?
hFont           HFONT                   ?
hWndToolTip     HWND                    ?
wc              WNDCLASSEX              <?>
msg             MSG                     <?>
msex            MEMORYSTATUSEX          <?>
iccex           INITCOMMONCONTROLSEX    <?>
ti              TOOLINFO                <?>
buffer          BYTE                    160 DUP (?)
;*********************************************************************
.CODE
;---------------------------------------------------------------------
BytesToKB       PROC
                shl     edx,22
                shr     eax,10
                add     eax,edx
                ret
BytesToKB       ENDP
;---------------------------------------------------------------------
SetToolInfo     PROC    id:DWORD
                sub     edx,edx
                mov     eax,id
                mov     ti.uId,eax
                mov     ecx,FONT_SIZE*2
                mul     ecx
                mov     ti.rect.top,eax
                mov     ti.rect.left,0
                add     eax,ecx
                mov     ti.rect.right,WND_WIDTH
                mov     ti.rect.bottom,eax
        .IF id==0
                mov     ti.lpszText,OFFSET szPhyMem
        .ELSEIF id==1
                mov     ti.lpszText,OFFSET szPageFile
        .ELSEIF id==2
                mov     ti.lpszText,OFFSET szVirtual
        .ENDIF
                INVOKE  SendMessage,hWndToolTip,TTM_ADDTOOL,0,OFFSET ti
                ret
SetToolInfo     ENDP
;---------------------------------------------------------------------
WndProc         PROC    hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
                LOCAL   ps:PAINTSTRUCT
                LOCAL   hDC:HDC

.IF uMsg==WM_PAINT
                INVOKE  BeginPaint,hWnd,ADDR ps
                INVOKE  CreateFont,FONT_SIZE,0,0,0,FW_NORMAL,0,0,0,ANSI_CHARSET,\
                        OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,\
                        NULL,OFFSET szFont
                mov     hFont,eax
                INVOKE  SelectObject,ps.hdc,eax
                INVOKE  DeleteObject,eax
                mov     msex.dwLength,SIZEOF MEMORYSTATUSEX
                INVOKE  GlobalMemoryStatusEx,OFFSET msex
                mov     edx,DWORD PTR msex.ullAvailVirtual[4]
                mov     eax,DWORD PTR msex.ullAvailVirtual
                call    BytesToKB
                push    eax
                mov     edx,DWORD PTR msex.ullTotalVirtual[4]
                mov     eax,DWORD PTR msex.ullTotalVirtual
                call    BytesToKB
                push    eax
                mov     edx,DWORD PTR msex.ullAvailPageFile[4]
                mov     eax,DWORD PTR msex.ullAvailPageFile
                call    BytesToKB
                push    eax
                mov     edx,DWORD PTR msex.ullTotalPageFile[4]
                mov     eax,DWORD PTR msex.ullTotalPageFile
                call    BytesToKB
                push    eax
                mov     edx,DWORD PTR msex.ullAvailPhys[4]
                mov     eax,DWORD PTR msex.ullAvailPhys
                call    BytesToKB
                push    eax
                mov     edx,DWORD PTR msex.ullTotalPhys[4]
                mov     eax,DWORD PTR msex.ullTotalPhys
                call    BytesToKB
                push    eax
                push    OFFSET szMemFmt
                push    OFFSET buffer
                call    wsprintf
                INVOKE  DrawText,ps.hdc,OFFSET buffer,eax,OFFSET rect,DT_LEFT
                INVOKE  EndPaint,ps.hdc,ADDR ps

.ELSEIF uMsg==WM_TIMER
                INVOKE  InvalidateRect,hWnd,NULL,TRUE

.ELSEIF uMsg==WM_CREATE
                INVOKE  SetTimer,hWnd,ID_TIMER,1000,NULL
                mov     iccex.dwSize,SIZEOF INITCOMMONCONTROLSEX
                mov     iccex.dwICC,ICC_BAR_CLASSES
                INVOKE  InitCommonControlsEx,OFFSET iccex
                INVOKE  CreateWindowEx,0,OFFSET szToolTipClass,0,TTS_NOPREFIX OR TTS_ALWAYSTIP,\
                        CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,hWnd,0,hInstance,0
                mov     hWndToolTip,eax
                INVOKE  SendMessage,eax,TTM_SETMAXTIPWIDTH,0,200
                mov     ecx,hWnd
                mov     ti.cbSize,SIZEOF TOOLINFO
                mov     ti.uFlags,TTF_SUBCLASS
                mov     ti.hWnd,ecx
                INVOKE  SetToolInfo,0
                INVOKE  SetToolInfo,1
                INVOKE  SetToolInfo,2

.ELSEIF uMsg==WM_DESTROY
                INVOKE  KillTimer,hWnd,ID_TIMER
                INVOKE  PostQuitMessage,NULL

.ELSE
                INVOKE  DefWindowProc,hWnd,uMsg,wParam,lParam
                ret

.ENDIF
                xor     eax,eax
                ret
WndProc         ENDP
;---------------------------------------------------------------------
start:  INVOKE  GetModuleHandle,NULL
        mov     hInstance,eax
        mov     wc.cbSize,SIZEOF WNDCLASSEX
        mov     wc.style,CS_HREDRAW OR CS_VREDRAW OR CS_DBLCLKS
        mov     wc.lpfnWndProc,OFFSET WndProc
        mov     wc.cbClsExtra,NULL
        mov     wc.cbWndExtra,NULL
        mov     wc.hInstance,eax
        INVOKE  LoadIcon,eax,OFFSET szMemIcon
        mov     wc.hIcon,eax
        mov     wc.hIconSm,eax
        INVOKE  LoadCursor,NULL,IDC_ARROW
        mov     wc.hCursor,eax
        mov     wc.hbrBackground,COLOR_WINDOW+1
        mov     wc.lpszMenuName,NULL
        mov     wc.lpszClassName,OFFSET szClassName
        INVOKE  RegisterClassEx,OFFSET wc
        INVOKE  GetSystemMetrics,SM_CXSCREEN
        sub     eax,WND_WIDTH
        shr     eax,1
        push    eax
        INVOKE  GetSystemMetrics,SM_CYSCREEN
        sub     eax,WND_HEIGHT
        pop     edx
        shr     eax,1
        INVOKE  CreateWindowEx,NULL,OFFSET szClassName,OFFSET szAppName,\ 
                WS_SYSMENU OR WS_MINIMIZEBOX,edx,eax,WND_WIDTH,WND_HEIGHT,0,\
                NULL,hInstance,NULL 
        mov     hwnd,eax
        INVOKE  ShowWindow,eax,SW_SHOWDEFAULT
        INVOKE  UpdateWindow,hwnd
.WHILE TRUE
        INVOKE  GetMessage,OFFSET msg,NULL,0,0
.BREAK .IF !eax
        INVOKE  TranslateMessage,OFFSET msg
        INVOKE  DispatchMessage,OFFSET msg
.ENDW
        mov     eax,msg.wParam
        INVOKE  ExitProcess,eax
;*********************************************************************
        END     start

¸ê·½ÀÉ¡AMEMFREE.RC¡A¶È¤@¦æ¡G

CHIP    ICON    CHIP3.ico

¨Ì¤U­±¤èªk²ÕĶ¡G

E:\HomePage\SOURCE\Win32\TOOLTIP>rc memfree.rc [Enter]

E:\HomePage\SOURCE\Win32\TOOLTIP>ml memfree1.asm /link memfree.res [Enter]
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

 Assembling: memfree1.asm
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/SUBSYSTEM:WINDOWS
"memfree1.obj"
"/OUT:memfree1.exe"
"memfree.res"

E:\HomePage\SOURCE\Win32\TOOLTIP>

±zÀ³·í¥i¥H¨£¨ì¡AMEMFREE.EXE ¦b³B²z WM_CREATE ®É¡A©I¥s CreateWindowEx «Ø¥ß¤F¤u¨ã´£¥Ü±±¨î¶µ¡AµM«á§â³o­Óµøµ¡¥N½X¦s¦b hWndToolTip ÅܼÆùØ¡C±µµÛ¥H TTM_SETMAXTIPWIDTH ¬°°Ñ¼Æ©I¥s SendMessage¡A³o¤@­Ó¨BÆJ¬O­­¨î¤u¨ã´£¥Üªº¼e«×¡C¤@¯ë¦Ó¨¥¡A¤u¨ã´£¥Ü·|©¿²¤´«¦æ¡BÂk¦ì¦r¤¸¡A©Ò¥H§Y¬O¦r¦ê¥]§t³o¨â­Ó¦r¤¸¡A¤u¨ã´£¥Ü¤´¬OÅã¥Ü¤@¦æ¡C¦pªG­­¨î¤F¤u¨ã´£¥Ü¼e«×¡A´N¥i¥H¨Ï¥¦¦b¶W¹L¦¹¼e«×¤§«e¦Û°Ê¨ì¤U¤@¦æÅã¥Ü¡C

GlobalMemoryStatus »P GlobalMemoryStatusEx

·Q­nÀò¨ú°O¾ÐÅé¨Ï¥Î±¡§Î¸ê®Æ¡A¥i¥H©I¥s¦­´Áªº GlobalMemoryStatus ©Î¬O GlobalMemoryStatusEx¡A¨âªÌ®t§O¦b«áªÌ¥u¯à¦b Windows 2K/XP ¤Î¥H«áªºª©¥»¡A¦ý¬O¦pªG¹q¸£¤¤¤w¦w¸Ë¶W¹L 4GB ªº°O¾ÐÅé¡AGlobalMemoryStatusEx ¤]¯à¦b 64 ¦ì¤¸ªº§@·~¨t²Î±o¨ì¶W¹L 4GB ªº°O¾ÐÅé¸ê®Æ¡F¦Ó GlobalMemoryStatus «hµLªk¿ì¨ì¡CGlobalMemoryStatusEx ªº­ì«¬¦b MASM32 v7.0 ¨Ã¨S¦³©w¸q¡A¨ì¤F MASM32 v8.2 ¥H«áªºª©¥»¤~¦b KERNEL32.INC ¤¤©w¸q¡A©Ò¥H°²¦p±z¨Ï¥Î MASM32 v7.0 ²ÕĶªº¸Ü¡A½Ð¦Û¦æ¥[¤J¡G

GlobalMemoryStatusEx    PROTO   :DWORD

GlobalMemoryStatusEx ¥u¦³¤@­Ó°Ñ¼Æ¡A¦¹°Ñ¼Æ«ü¦V MEMORYSTATUSEX µ²ºcÅ骺¦ì§}¡A³o­Óµ²ºcÅé¦b MASM32 v7¡ã10 ³£¨S¦³©w¸q¡A©Ò¥H±o¦Û¦æ¦b­ì©l½X¤¤©w¸q¡A¨äÄæ¦ì¦p¤U¡G

MEMORYSTATUSEX          STRUC
dwLength                DWORD   ?
dwMemoryLoad            DWORD   ?
ullTotalPhys            QWORD   ?       ;¹q¸£¦w¸Ëªº¹êÅé°O¾ÐÅé¤j¤p
ullAvailPhys            QWORD   ?       ;³Ñ¾l¹êÅé°O¾ÐÅé¤j¤p
ullTotalPageFile        QWORD   ?       ;¨t²Î©Ò¯à¨Ï¥Îªº°O¾ÐÅé¤W­­¡A¥]§t¤À­¶ÀÉ»P¹êÅé°O¾ÐÅé¤j¤p
ullAvailPageFile        QWORD   ?       ;³Ñ¾l¤À­¶ÀÉ»P¹êÅé°O¾ÐÅé¤j¤p
ullTotalVirtual         QWORD   ?       ;µêÀÀ°O¾ÐÅé¤j¤p
ullAvailVirtual         QWORD   ?       ;³Ñ¾lµêÀÀ°O¾ÐÅé¤j¤p
ullAvailExtendedVirtual QWORD   ?       ;³Ñ¾l©µ¦ùµêÀÀ°O¾ÐÅé¤j¤p
MEMORYSTATUSEX          ENDS

²Ä¤@­ÓÄæ¦ì¡AdwLength¡A¬O MEMORYSTATUSEX µ²ºcÅ骺¤j¤p¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡A¥²¶·¦b©I¥s GlobalMemoryStatusEx «e¶ñ¦n³o­ÓÄæ¦ì¡C¥Ñ²Ä¤G­ÓÄæ¦ì¨ì³Ì«áªºÄæ¦ì¬O©I¥s GlobalMemoryStatusEx ¤§«á¡A¥Ñ§@·~¨t²Î¶ñ¤Wªº¡C²Ä¤G­ÓÄæ¦ì¡AdwMemoryLoad¡Aªí¥Ü¹êÅé°O¾ÐÅé¤w¨Ï¥Îªº¦Ê¤À¤ñ¡A¬O 0 ¨ì 100 ªº¾ã¼Æ¡C¨ä¾lªºÄæ¦ì³£¬O¦U¦¡°O¾ÐÅ骺¤j¤pªº¸ê®Æ¡A¥þ¬O¥H¦ì¤¸²Õ¬°³æ¦ì¡C¦pªG GlobalMemoryStatusEx ¦¨¥\ªº¶Ç¦^ MEMORYSTATUSEX µ²ºcÅé¡A«h EAX ¬°«D¹s­È¡A§_«h EAX ¬°¹s¡C¦pªG±z¥Î MASM32 v7.0 ²ÕĶ¡A¦]¨ä KERNEL32.LIB ¨Ã¥¼¥]§t GlobalMemoryStatusEx ªº¸ê®Æ¡A·|§Î¦¨µLªk³sµ²ªº±¡§Î¡A½Ð§ï¥Î MASM32 v9.0 ¥H¤W²ÕĶ¡A©Î¬O¦b·L³nºô¯¸¤U¸ü 6.0.6001.18000.367-KRMSDK_EN.iso¡A³o¬O Windows SDK for Windows Server 2008 ªº¥úºÐ¼v¹³ÀÉ¡A¦b¨ä¡y\Setup\WinSDKBuild-WinSDKBuild_VistaLibs_X86-common.0.cab¡zÀ£ÁYÀɤ¤µÑ¨ú¡yKernel32_Lib.34A9A805_A741_4A0D_A5EA_FE0276BE952C¡zÀɮסA±N¨ä§ï¦W¬°¡yKERNEL32.LIB¡z¡A¦A½Æ¼g¨ì¡yC:\MASM32\LIB¡z¤l¥Ø¿ýùؤ]¥i¥H²ÕĶ¦¨¥\¡C

¦Ü©ó GlobalMemoryStatus API »P GlobalMemoryStatusEx ¬Û¦P¡A¤]³£¥u¦³¤@­Ó°Ñ¼Æ¡A¦¹°Ñ¼Æ¬O«ü¦V MEMORYSTATUS µ²ºcÅ骺¦ì§}¡AMEMORYSTATUS µ²ºcÅé»P MEMORYSTATUSEX ¤]«Ü¬Û¦ü¡A¨ä®t§O¬O MEMORYSTATUS µ²ºcÅé¤Ö¤F³Ì«á¤@­ÓÄæ¦ì¡A¦Ó¥B©Ò¦³Äæ¦ìªºªø«×³£¬OÂù¦r²Õ¡AGlobalMemoryStatus »P MEMORYSTATUS ¦b MASM32 v7.0 ³£¤w©w¸q¡A¤£¶·§Ú­Ì¶O¤ß¡C


¨ì²Ä¤G¤Q¤G³¹¡A ¦^¨ì­º­¶¡A¨ì²Ä¤G¤Q¥|³¹