Lm th? no ? c ?c m?t x? l? c?a s? giao di?n i?u khi?n (HWND)

D?ch tiu ? D?ch tiu ?
ID c?a bi: 124103
Bung t?t c? | Thu g?n t?t c?

? Trang ny

Tm t?t

N c th? h?u ch ? thao tc m?t c?a s? k?t h?p v?i m?t consoleapplication. Win32 API cung c?p khng c phng php tr?c ti?p cho vi?c thu th?p thewindow x? l? lin quan ?n m?t ?ng d?ng giao di?n i?u khi?n. Tuy nhin, b?n canobtain c?a s? x? l? b?ng cch g?i FindWindow(). Ch?c nng ny l?y awindow x? l? d?a trn m?t tn l?p ho?c tn c?a s?.

G?i GetConsoleTitle() ? xc ?nh tiu ? giao di?n i?u khi?n hi?n t?i. Sau supplythe hi?n t?i giao di?n i?u khi?n tn ? FindWindow().

Thng tin thm

B?i v? nhi?u c?a s? c th? c cng tn, b?n nn thay ?i tiu ? c?a s? giao di?n i?u khi?n thecurrent ? m?t tiu ? duy nh?t. i?u ny s? gip ngn ch?n thewrong c?a s? x? l? ?c tr? l?i. S? d?ng SetConsoleTitle() ? changethe tiu ? c?a s? giao di?n i?u khi?n hi?n t?i. ? y l qu tr?nh:
  1. G?i GetConsoleTitle() ? ti?t ki?m tiu ? c?a s? giao di?n i?u khi?n hi?n t?i.
  2. G?i SetConsoleTitle() ? thay ?i tiu ? giao di?n i?u khi?n ? m?t tiu ? duy nh?t.
  3. G?i Sleep(40) ? ?m b?o tiu ? c?a s? ? ?c C?p Nh?t.
  4. G?i FindWindow (NULL, uniquetitle), ? c ?c HWND ny g?i tr? v? HWND--ho?c NULL n?u thao tc th?t b?i.
  5. G?i SetConsoleTitle() v?i gi tr? L?y t? b?c 1, ? khi ph?c l?i tiu ? c?a s? ban ?u.
B?n nn ki?m tra k?t qu? HWND. V d?, b?n c th? ki?m tra ? xem n?u thereturned HWND tng ?ng v?i qu tr?nh hi?n t?i b?i callingGetWindowText() trn HWND v so snh k?t qu? withGetConsoleTitle().

HWND k?t qu? khng ?c ?m b?o ? ph h?p v?i t?t c? c?a s? handleoperations.

M?u m?

Cc ch?c nng sau truy l?c hi?n t?i giao di?n i?u khi?n ?ng d?ng windowhandle (HWND). N?u ch?c nng thnh cng, gi tr? tr? l?i l x? l? c?a c?a s? giao di?n i?u khi?n. N?u ch?c nng khng thnh cng, gi tr? tr? l?i l NULL. B? Someerror ki?m tra qua, cho ng?n g?n.
   HWND GetConsoleHwnd(void)
   {
       #define MY_BUFSIZE 1024 // Buffer size for console window titles.
       HWND hwndFound;         // This is what is returned to the caller.
       char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated
                                           // WindowTitle.
       char pszOldWindowTitle[MY_BUFSIZE]; // Contains original
                                           // WindowTitle.

       // Fetch current window title.

       GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);

       // Format a "unique" NewWindowTitle.

       wsprintf(pszNewWindowTitle,"%d/%d",
                   GetTickCount(),
                   GetCurrentProcessId());

       // Change current window title.

       SetConsoleTitle(pszNewWindowTitle);

       // Ensure window title has been updated.

       Sleep(40);

       // Look for NewWindowTitle.

       hwndFound=FindWindow(NULL, pszNewWindowTitle);

       // Restore original window title.

       SetConsoleTitle(pszOldWindowTitle);

       return(hwndFound);
   }
				

Thu?c tnh

ID c?a bi: 124103 - L?n xem xt sau cng: 09 Thang Hai 2014 - Xem xt l?i: 3.0
T? kha:
kbhowto kbwndw kbmt KB124103 KbMtvi
My d?ch
QUAN TRONG: Bai vit nay c d?ch b?ng phn mm dich thu?t cua Microsoft va co th c Cng ng Microsoft chinh sa l?i thng qua cng ngh CTF thay vi mt bin dich vin chuyn nghip. Microsoft cung c?p cc bi vi?t ?c c? bin d?ch vin v ph?n m?m d?ch thu?t th?c hi?n v c?ng ?ng ch?nh s?a l?i ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng nhi?u ngn ng? Tuy nhin, bi vi?t do my d?ch hoc thm chi cng ng chinh sa sau khng ph?i lc no c?ng hon h?o. Cc bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny: 124103

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com