Yuav Tsim Lub Qhov Rais Ua Haujlwm Li Cas

Cov txheej txheem:

Yuav Tsim Lub Qhov Rais Ua Haujlwm Li Cas
Yuav Tsim Lub Qhov Rais Ua Haujlwm Li Cas

Video: Yuav Tsim Lub Qhov Rais Ua Haujlwm Li Cas

Video: Yuav Tsim Lub Qhov Rais Ua Haujlwm Li Cas
Video: yuav tau tsim kho tus kheej lub neej thiaj yuav vam meej tau 2024, Hlis ntuj nqeg
Anonim

Cov ntsiab cai ntawm kev ua haujlwm ntawm tus neeg siv interface ntawm kev ua haujlwm ntawm lub Windows tsev neeg yog ua raws li lub tswvyim ntawm lub qhov rais. Lub desktop, taskbar, npe, cov lus qhib, cov nyees khawm, cov ntawv qhia yog txhua qhov rai. Yog li ntawd, qhov tseeb, thiaj li yuav ua rau pom txhua lub caij interface, koj yuav tsum tsim kom muaj lub qhov rai ua haujlwm.

Yuav tsim lub qhov rais ua haujlwm li cas
Yuav tsim lub qhov rais ua haujlwm li cas

Tsim nyog

  • - compiler;
  • - Windows Platform SDK.

Cov Lus Qhia

Kauj ruam 1

Sau npe cov chav kawm ntawm lub qhov rais yuav tsum tsim, yog xav tau. Hu rau API txoj haujlwm rau RegisterClass, RegisterClassEx lossis siv cov haujlwm uas tsim nyog ntawm lub moj khaum siv.

Lub RegisterClass thiab RegisterClassEx ua haujlwm lees txais cov taw tes rau cov qauv ntawm hom WNDCLASS thiab WNDCLASSEX, ntsig txog, raws li lawv qhov ntsuas xwb. Tus nqi xa rov qab ntawm hom ATOM tuaj yeem siv ua chaw ntawm cov chav kawm lub npe thaum tsim lub qhov rai. Yog tias muaj nuj nqi hu tsis, tus nqi xa rov qab yog 0.

Instantiate tus qauv ntawm hom WNDCLASS lossis WNDCLASSEX. Sau txhua qhov uas tsim nyog. Hauv qhov tshwj xeeb, cov nqi tsim nyog yuav tsum tau muab tso rau hauv:

- cbSize - tus qauv loj hauv bytes;

- style - txheej txheej ntawm chav rau lub qhov rai;

- lpfnWndProc - pointer rau lub txheej txheem qhov rai;

- hInstance yog qhov kov ntawm lub module uas cov chav kawm ntawm lub qhov rais tau sau npe;

- lpszClassName yog cov cim qhia rau lub npe.

Qhov seem ntawm daim teb tuaj yeem sau nrog NULL qhov tseem ceeb. Ua kom muaj nuj nqi hu rau kev sau npe ntawm qhov rai chav kawm. Tshawb xyuas qhov tshwm sim xa rov qab.

Kauj ruam 2

Xaiv cov chav kawm qhov rai uas twb muaj lawm yog tias tsim nyog. Koj yuav tsum paub lub cim chav kawm lub npe (tus tau dhau los ntawm lpszClassName pointer thaum sau npe rau nws) lossis tus nqi ATOM sib xws. Cov chav kawm tuaj yeem nyob hauv cheeb tsam qib daim ntawv thov, thoob ntiaj teb ntawm qib kev thov (sau npe nrog CS_GLOBALCLASS chij), lossis chav qhia ntawv kab ke. Hom kawg suav nrog cov chav kawm ntawm lub qhov rais nrog cov npe: khawm, ComboBox, Kho kom raug, ListBox, MDIClient, ScrollBar, Static. Cov chav kawm xws li RichEdit20W lossis SysListView32 raug tso npe thaum cov tsev qiv ntawv coj tau raug thauj.

Kauj ruam 3

Tsim lub qhov rai rai. Siv API ua haujlwm CreateWindow, CreateWindowEx, lossis cov txheej txheem tsim nyog rau cov khoom hauv chav kawm ntawm lub moj khaum lossis cov tsev qiv ntawv uas koj siv. Daim qauv rau cov CreateWindowEx muaj nuj nqi zoo li qhov no:

HWND TsimWindowEx (DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, rau cov menyuam x, rau cov menyuam y, rau cov menyuam, rau cov menyuamHeight, HWND hWndPauv, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);

Tus cwj pwm ntawm CreateWindow txawv ntawm CreateWindowEx tsuas yog thaum tsis muaj dwExStyle parameter.

Hu xov tooj rau CreateWindow lossis CreateWindowEx. Dhau rau ntawm lpClassName parameter lub npe lossis ATOM tus nqi ntawm lub qhov rai chav kawm uas koj tau txhais hauv thawj lossis theem thib ob. Cov xiam x, y, nWidth, nHeight tuaj yeem yog qhov ua kom sib haum thiab ntau thiab tsawg ntawm lub qhov rais tau tsim. Niam txiv qhov rai kov (yog tias muaj) dhau hWndParent.

Txuag thiab parse tus nqi rov qab los ntawm CreateWindow lossis CreateWindowEx. Ntawm kev vam meej, lawv yuav rov qab ua tus kov rau lub qhov rais tshiab; ntawm kev ua tsis tiav, TSIS TAU.

Pom zoo: