Yuav Ua Li Cas Kom Tau Coj Mus Rau Lub Qhov Rais

Cov txheej txheem:

Yuav Ua Li Cas Kom Tau Coj Mus Rau Lub Qhov Rais
Yuav Ua Li Cas Kom Tau Coj Mus Rau Lub Qhov Rais

Video: Yuav Ua Li Cas Kom Tau Coj Mus Rau Lub Qhov Rais

Video: Yuav Ua Li Cas Kom Tau Coj Mus Rau Lub Qhov Rais
Video: Tsis Muaj Peev Xwm Yuav Ua Li Cas 2024, Hlis ntuj nqeg
Anonim

Lub tswvyim ntawm tus neeg siv khoom siv hauv Windows yog raws li lub tswvyim ntawm lub qhov rais. Kev sib tham, khawm, tswj vaj huam sib luag, npe yog txhua qhov rai. Yog li no, txhawm rau kom ua ib qho haujlwm nrog rau txhua lub ntsiab lus ntawm qhov interface ntawm koj tus kheej lossis lwm tus neeg thov, koj yuav tsum tau txais lub qhov rai tuav.

Yuav ua li cas kom tau coj mus rau lub qhov rais
Yuav ua li cas kom tau coj mus rau lub qhov rais

Tsim nyog

  • - Platform SDK pob;
  • - compiler.

Cov Lus Qhia

Kauj ruam 1

Tau txais tus kov rau lub qhov rais los ntawm tsim nws. Hu xov tooj mus rau CreateWindow lossis CreateWindowEx API ua haujlwm, lossis hu rau cov txheej txheem kev tsim nyog (ntawm cov khoom tsim nyog) ntawm cov chav kawm ntawm cov haujlwm siv los yog cov tsev qiv ntawv uas muab cov haujlwm ua haujlwm nrog lub qhov rais lossis kev tswj hwm. Cov CreateWindow thiab CreateWindowEx ua haujlwm ncaj qha rov qab qhov rai kov ntawm kev tsim tau zoo. Yog tias hu ua tsis tiav, lawv rov qab NULL. Kev ua yuam kev vim li cas thiaj tuaj yeem thov siv qhov GetLastError API ua haujlwm. Prototypes thiab cov ncauj lus kom ntxaws txog cov kev txiav txim ntawm tus qauv ntawm CreateWindow thiab CreateWindowEx tuaj yeem tau los ntawm cov kab ntawv sib txuas https://msdn.microsoft.com/en-us/library/windows/desktop/ms632679%28v=vs.85%29.aspx thiab https:// msdn.microsoft.com / en-us / tsev qiv ntawv / windows / desktop / ms632680% 28v = vs.85% 29.aspx Thaum siv chav kawm ntawm cov qauv sib txawv, kev tsim cov txheej txheem operating system window tuaj yeem tshwm sim ncaj qha (los ntawm kev hu xov tooj rau txoj kev) lossis implicitly (kev siv ntawm RAII lub tswv yim). Yog li ntawd, nws yog qhov zoo dua kom tau txais lub qhov rai coj ntawm ntawm cov khoom npaj tau npaj ua ntej. Koj tuaj yeem kawm txog cov qauv ntawm cov chav kawm uas rov qab lub qhov rais tuav encapsulated los ntawm qhov khoom nyob rau hauv cov ntaub ntawv ntawm cov coj ua. Piv txwv, hauv MFC, cov txheej txheem sib xws yog GetSafeHwnd ntawm CWnd chav kawm.

Kauj ruam 2

Tau txais tus kov rau lub qhov rais los ntawm nrhiav nws. Siv cov FindWindow thiab FindWindowEx API ua haujlwm los yog cov khoom siv chav kawm kom tsim nyog rau lub moj khaum koj siv. Qhov kev tshawb no yog ua los ntawm cov chav kawm lub npe thiab lub npe qhov rai. Cov lus piav qhia ntawm cov tsis thiab cov yam ntxwv ntawm lub luag haujlwm tuaj yeem pom ntawm qhov txuas https://msdn.microsoft.com/en-us/library/windows/desktop/ms633499%28v=vs.85%29.aspx Lub semantics ntawm muaj nuj nqi FindWindowEx zoo ib yam li FindWindow nrog qhov sib txawv yog tias nws tshawb rau menyuam qhov rai. Cov ntaub ntawv rau FindWindowEx muaj nyob rau ntawm

Kauj ruam 3

Pom tus kov rau lub qhov rais thaum teev lawv cov teeb tsa. Siv API ua haujlwm EnumWindows, EnumChildWindows, EnumThreadWindows, lossis cov hau kev ntawm cov khoom hauv chav kawm ntawm lub moj khaum uas koj siv. Qhov EnumWindows thiab EnumChildWindows ua haujlwm enumerate theem saum toj qhov rais thiab me nyuam qhov rai, feem. Txoj hauj lwm EnumThreadWindows enumerates txhua qhov tsis yog menyuam qhov rais ntawm cov xov hais tawm. Txhua qhov ntawm cov haujlwm no yuav tsum dhau los ntawm tus taw qhia mus rau txheej txheem callback, uas yuav dhau los ua haujlwm ntawm lub qhov rais pom raws li tsis dhau lub sijhawm ua haujlwm. lub qhov rai uas yuav tsum tau. Cov ntaub ntawv rau cov haujlwm tau piav qhia yog muab rau ntawm cov kev sib txuas: - EnumWindows: https://msdn.microsoft.com/en-us/library/windows/desktop/ms633497%28v=vs.85%29.aspx; - EnumChildWindows: https:// msdn.microsoft.com/en-us/library/windows/desktop/ms633494%28v=vs.85%29.aspx; - EnumThreadWindows: https://msdn.microsoft.com/en-us/library / windows / desktop /ms633495%28v=vs.85%29.aspx.

Kauj ruam 4

Tau txais tus kov rau lub qhov rais ntawm paub ua kom sib haum. WindowFromPoint, ChildWindowFromPoint, ChildWindowFromPointEx cov hauj lwm xa rov qab mus rau lub qhov rais uas tau teev tseg rau. Cov hauj lwm WindowFromPoint yog qhov yooj yim siv, tab sis tsis rov ua cov haujlwm rau lub qhov rais zais lossis xiam oob khab. Koj tuaj yeem nrhiav cov ntaub ntawv rau ntawm nws siv ntawm https://msdn.microsoft.com/en-us/library/windows/desktop/ms633558%28v=vs.85%29.aspx. Qhov ChildWindowFromPoint thiab ChildWindowFromPointEx ua haujlwm nrhiav cov tes tuav rau tus menyuam cov qhov rai ntawm niam txiv ib lub qhov rais uas yog rau ib qho muab. Hauv qhov xwm txheej no, kev coj tus cwj pwm ntawm ChildWindowFromPointEx tuaj yeem hloov pauv tau siv ib qho ntsuas ntxiv. Cov ntaub ntawv rau cov haujlwm no yog muab los ntawm cov kev sib txuas: - ChildWindowFromPoint: https://msdn.microsoft.com/en-us/library/windows/desktop/ms632676%28v=vs.85%29.aspx; - ChildWindowFromPointEx: https:// msdn.microsoft.com/en-us/library/windows/desktop/ms632677%28v=vs.85%29.aspx.

Pom zoo: