registerhotkeyregisterhotkey
RegisterHotKey
TheRegisterHotKeyfunctiondefinesasystem-widehotkey.
BOOLRegisterHotKey(
HWNDhWnd,//windowtoreceivehot-keynotification
intid,//identifierofhotkey
UINTfsModifiers,//key-modifierflags
UINTvk//virtual-keycode
);
Parameters
hWnd
HandletothewindowthatwillreceiveWM_HOTKEYmessagesgeneratedbythehotkey.IfthisparameterisNULL,WM_HOTKEYmessagesarepostedtothemessagequeueofthecallingthreadandmustbeprocessedinthemessageloop.
id
Specifiestheidentifierofthehotkey.Nootherhotkeyinthecallingthreadshouldhavethesameidentifier.Anapplicationmustspecifyavalueintherange0x0000through0xBFFF.Ashareddynamic-linklibrary(DLL)mustspecifyavalueintherange0xC000through0xFFFF(therangereturnedbytheGlobalAddAtomfunction).Toavoidconflictswithhot-keyidentifiersdefinedbyothersharedDLLs,aDLLshouldusetheGlobalAddAtomfunctiontoobtainthehot-keyidentifier.
fsModifiers
SpecifieskeysthatmustbepressedincombinationwiththekeyspecifiedbythenVirtKeyparameterinordertogeneratetheWM_HOTKEYmessage.ThefsModifiersparametercanbeacombinationofthefollowingvalues.ValueMeaning
MOD_ALTEitheraltkeymustbehelddown.
MOD_CONTROLEitherctrlkeymustbehelddown.
MOD_SHIFTEithershiftkeymustbehelddown.
MOD_WINEitherWINDOWSkeywashelddown.ThesekeysarelabeledwiththeMicrosoftWindowslogo.
vk
Specifiesthevirtual-keycodeofthehotkey.
ReturnValues
Ifthefunctionsucceeds,thereturnvalueisnonzero.
Ifthefunctionfails,thereturnvalueiszero.Togetextendederrorinformation,callGetLastError.
Remarks
Whenakeyispressed,thesystemlooksforamatchagainstallhotkeys.Uponfindingamatch,thesystempoststheWM_HOTKEYmessagetothemessagequeueofthethreadthatregisteredthehotkey.Thismessageispostedtothebeginningofthequeuesoitisremovedbythenextiterationofthemessageloop.

Thisfunctioncannotassociateahotkeywithawindowcreatedbyanotherthread.
RegisterHotKeyfailsifthekeystrokesspecifiedforthehotkeyhavealreadybeenregisteredbyanotherhotkey.
IfthewindowidentifiedbythehWndparameteralreadyregisteredahotkeywiththesameidentifierasthatspecifiedbytheidparameter,thenewvaluesforthefsModifiersandvkparametersreplacethepreviouslyspecifiedvaluesfortheseparameters.
WindowsCE:WindowsCEversions2.0andlatersupportanadditionalflag,calledMOD_KEYUP,forthefsModifiersparameter.IfyousettheMOD_KEYUPflag,thewindowwillbesentaWM_HOTKEYmessageonakeyupeventaswellasonakeydownevent.
RegisterHotKeycanbeusedtoregisterhotkeysacrossthreads.
QuickInfo
WindowsNT:Requiresversion3.1orlater.
Windows:RequiresWindows95orlater.
WindowsCE:Unsupported.
Header:Declaredinwinuser.h.
ImportLibrary:Useuser32.lib.
SeeAlso
KeyboardInputOverview,KeyboardInputFunctions,GlobalAddAtom,UnregisterHotKey,WM_HOTKEY
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-30550-1.html
对自己定位清晰的boy