Guest User

Untitled

a guest
Apr 25th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.27 KB | None | 0 0
  1. #include <windows.h>
  2. #include <commctrl.h>
  3. #include <time.h>
  4. #include "resource.h"
  5.  
  6. unsigned int i=0;
  7. unsigned int timer=30;
  8. HANDLE hThread;
  9. HWND hMainDlg, hDlgButton;
  10.  
  11. void thread()
  12. {
  13.     for(UINT timer = 30; timer >= 0; timer--)
  14.     {
  15.         SetDlgItemInt(hMainDlg, ID_TTIMER, timer, FALSE);
  16.         Sleep(1000);
  17.     }
  18.     EnableWindow(hDlgButton, FALSE);
  19. }
  20.  
  21. BOOL CALLBACK DlgProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam)
  22. {
  23.      switch(Message)
  24.      {
  25.         case WM_INITDIALOG:
  26.             hMainDlg = hwnd;
  27.             hDlgButton = GetDlgItem(hMainDlg, ID_BTCLICK);
  28.             hThread = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)thread, NULL, NULL, NULL);
  29.             break;
  30.                     case WM_CLOSE:
  31.                          if( hThread )
  32.                               CloseHandle(hThread);
  33.                          EndDialog(hwnd,0);
  34.                          break;
  35.                          case WM_COMMAND:
  36.                               switch(LOWORD(wParam))
  37.                               {
  38.                                                     case ID_BTABOUT:
  39.                                                          DialogBox(NULL,MAKEINTRESOURCE(IDD_ABOUT),NULL,DlgProc);
  40.                                                          break;
  41.                                                          case ID_ABOUTEXIT:
  42.                                                               EndDialog(hwnd,0);
  43.                                                               break;
  44.                                                          case ID_BTRESET:
  45.                                                               {
  46.                                                                          timer=30;
  47.                                                                          i=0;
  48.                                                                          SetDlgItemInt(hwnd,ID_TTIMER,timer,FALSE);
  49.                                                                          SetDlgItemInt(hwnd,ID_TCOUNT,i,FALSE);
  50.                                                                          if( hThread )
  51.                                                                             CloseHandle(hThread);
  52.                                                                          hThread = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)thread, NULL, NULL, NULL);
  53.                                                                          }
  54.                                                                          break;
  55.                                                 case ID_BTCLICK:
  56.                                                                    i++;
  57.                                                                     SetDlgItemInt(hwnd,ID_TCOUNT,i,FALSE);
  58.                                                                     break;
  59.                                                          }
  60.                                                          break;
  61.                          case WM_DESTROY:
  62.                               EndDialog(hwnd,0);
  63.                               break;
  64.                               default:
  65.                                       return FALSE;
  66.                                       }
  67.                                       return TRUE;
  68.                                       }
  69. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
  70. {
  71.     InitCommonControls();
  72.     return DialogBox(hInstance,MAKEINTRESOURCE(IDD_MAIN),NULL,DlgProc);
  73. }
Add Comment
Please, Sign In to add comment