[ ginjasvinja @ 20.01.2006. 07:59 ] @
Pozdrav svima! Imam programcic koji kreira prozor koji hvata dogadjaje KEYDOWN i KEYUP i ti dogadjaji se hvataju dok se prozor ne zatvori. Ja hocu da ubacim neki tajmer koji je npr. 5 sekundi tako da cekam na dogadjaj 5 sekundi i bez obzira da li se taj dogadjaj ostvari ili ne ako istekne 5 sekundi prekidam cekanje. Pokusala sam da na pocetku programa ucitam trenutno vreme i na njega dodam tih 5 sekundi i to mi je limit. Onda u while petlji gde cekam na dogadjaje ucitavam opet trenutno vreme i proveravam da li je vece od limita i ako jeste prekidam while. Medjutim to ne funkcionise bas onako kako sam ja mislila i problem je sto ne razumem najbolje kako funkcionise GetMessage funkcija. Da li neko ima iskustva sa slicnim stvarima i eventualno neki savet?Kacim kod. Hvala unapred! Code: #include <windows.h> #include "stdio.h" #include "time.h" const char g_szClassName[] = "myWindowClass"; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { boolean processed; LRESULT result; result = 0; processed = false; switch (msg) { case WM_KEYDOWN: // taster je pritisnut!!! processed = true; printf("Pritisnut taster\n"); //DestroyWindow(hwnd); //PostQuitMessage(0); break; case WM_KEYUP: // taster je pushten!!! processed = true; printf("Pusten taster\n"); //DestroyWindow(hwnd); //PostQuitMessage(0); break; case WM_CLOSE: DestroyWindow(hwnd); PostQuitMessage(0); break; } if (!processed) result = DefWindowProc(hwnd, msg, wParam, lParam); return result; } int main() { WNDCLASSEX wc; HWND hwnd; MSG Msg; HINSTANCE hInstance = NULL; time_t currentTime,limitTime,moreTime; currentTime = time (NULL); limitTime = currentTime + 5; moreTime = limitTime - currentTime; wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = NULL; wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = g_szClassName; wc.hIconSm = NULL; if(!RegisterClassEx(&wc)) { MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } hwnd = CreateWindowEx ( WS_EX_TOOLWINDOW, g_szClassName, // TEXT("beznadezan prozor"), NULL, WS_POPUP, 0, 0 , 0, 0, NULL, NULL, hInstance, NULL ); if(hwnd == NULL) { MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } ShowWindow(hwnd, SW_SHOWNORMAL); UpdateWindow(hwnd); while((moreTime > 0) && (GetMessage(&Msg, NULL, 0, 0) > 0)) { TranslateMessage(&Msg); DispatchMessage(&Msg); currentTime = time(NULL); moreTime = limitTime - currentTime; printf("moreTime %ld\n",moreTime); } return Msg.wParam; } |