#include #include #include int lugeja=0; int i=0; int j=0; int kord=0; int voit=0; int tabel[3][3]; LRESULT CALLBACK MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam) { static HWND hwndButton1 = 0; static HWND hwndButton2 = 0; static HWND hwndButton3 = 0; static HWND hwndButton4 = 0; static HWND hwndButton5 = 0; static HWND hwndButton6 = 0; static HWND hwndButton7 = 0; static HWND hwndButton8 = 0; static HWND hwndButton9 = 0; char tulemusv[10]; LPSTR vaartus[2]; vaartus[0]=" "; vaartus[1]="X"; vaartus[2]="O"; HDC hdc; PAINTSTRUCT ps; RECT rc; switch (nMsg) { case WM_CREATE: { hwndButton1 = CreateWindow ("button", " ", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 100, 100, hwnd,(HMENU) 1,((LPCREATESTRUCT) lParam)->hInstance,NULL); hwndButton2 = CreateWindow ("button", " ", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 100, 100, 100, hwnd,(HMENU) 1,((LPCREATESTRUCT) lParam)->hInstance,NULL); hwndButton3 = CreateWindow ("button", " ", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 200, 100, 100, hwnd,(HMENU) 1,((LPCREATESTRUCT) lParam)->hInstance,NULL); hwndButton4 = CreateWindow ("button", " ", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 100, 0, 100, 100, hwnd,(HMENU) 1,((LPCREATESTRUCT) lParam)->hInstance,NULL); hwndButton5 = CreateWindow ("button", " ", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 100, 100, 100, 100, hwnd,(HMENU) 1,((LPCREATESTRUCT) lParam)->hInstance,NULL); hwndButton6 = CreateWindow ("button", " ", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 100, 200, 100, 100, hwnd,(HMENU) 1,((LPCREATESTRUCT) lParam)->hInstance,NULL); hwndButton7 = CreateWindow ("button", " ", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 200, 0, 100, 100, hwnd,(HMENU) 1,((LPCREATESTRUCT) lParam)->hInstance,NULL); hwndButton8 = CreateWindow ("button", " ", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 200, 100, 100, 100, hwnd,(HMENU) 1,((LPCREATESTRUCT) lParam)->hInstance,NULL); hwndButton9 = CreateWindow ("button", " ", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 200, 200, 100, 100, hwnd,(HMENU) 1,((LPCREATESTRUCT) lParam)->hInstance,NULL); return 0; break; } case WM_DESTROY: PostQuitMessage (0); return 0; break; case WM_COMMAND: kord++; if (LOWORD(wParam) == 1 && HIWORD(wParam) == BN_CLICKED && (HWND) lParam == hwndButton1){ SetWindowText(hwndButton1, vaartus[1]); if (kord%2!=0){ SetWindowText(hwndButton1, vaartus[1]); SetWindowText(hwnd, "O kord"); tabel[0][0]=1; lugeja++; } else { SetWindowText(hwndButton1, vaartus[2]); SetWindowText(hwnd, "X kord"); tabel[0][0]=2; lugeja++; } } if (LOWORD(wParam) == 1 && HIWORD(wParam) == BN_CLICKED && (HWND) lParam == hwndButton2){ if (kord%2!=0){ SetWindowText(hwndButton2, vaartus[1]); SetWindowText(hwnd, "O kord"); tabel[0][1]=1; lugeja++; } else { SetWindowText(hwndButton2, vaartus[2]); SetWindowText(hwnd, "X kord"); tabel[0][1]=2; lugeja++; } } if (LOWORD(wParam) == 1 && HIWORD(wParam) == BN_CLICKED && (HWND) lParam == hwndButton3){ if (kord%2!=0){ SetWindowText(hwndButton3, vaartus[1]); SetWindowText(hwnd, "O kord"); tabel[0][2]=1; lugeja++; } else { SetWindowText(hwndButton3, vaartus[2]); SetWindowText(hwnd, "X kord"); tabel[0][2]=2; lugeja++; } } if (LOWORD(wParam) == 1 && HIWORD(wParam) == BN_CLICKED && (HWND) lParam == hwndButton4){ if (kord%2!=0){ SetWindowText(hwndButton4, vaartus[1]); SetWindowText(hwnd, "O kord"); tabel[1][0]=1; lugeja++; } else { SetWindowText(hwndButton4, vaartus[2]); SetWindowText(hwnd, "X kord"); tabel[1][0]=2; lugeja++; } } if (LOWORD(wParam) == 1 && HIWORD(wParam) == BN_CLICKED && (HWND) lParam == hwndButton5){ if (kord%2!=0){ SetWindowText(hwndButton5, vaartus[1]); SetWindowText(hwnd, "O kord"); tabel[1][1]=1; lugeja++; } else { SetWindowText(hwndButton5, vaartus[2]); SetWindowText(hwnd, "X kord"); tabel[1][1]=2; lugeja++; } } if (LOWORD(wParam) == 1 && HIWORD(wParam) == BN_CLICKED && (HWND) lParam == hwndButton6){ if (kord%2!=0){ SetWindowText(hwndButton6, vaartus[1]); SetWindowText(hwnd, "O kord"); tabel[1][2]=1; lugeja++; } else { SetWindowText(hwndButton6, vaartus[2]); SetWindowText(hwnd, "X kord"); tabel[1][2]=2; lugeja++; } } if (LOWORD(wParam) == 1 && HIWORD(wParam) == BN_CLICKED && (HWND) lParam == hwndButton7){ if (kord%2!=0){ SetWindowText(hwndButton7, vaartus[1]); SetWindowText(hwnd, "O kord"); tabel[2][0]=1; lugeja++; } else { SetWindowText(hwndButton7, vaartus[2]); SetWindowText(hwnd, "X kord"); tabel[2][0]=2; lugeja++; } } if (LOWORD(wParam) == 1 && HIWORD(wParam) == BN_CLICKED && (HWND) lParam == hwndButton8){ if (kord%2!=0){ SetWindowText(hwndButton8, vaartus[1]); SetWindowText(hwnd, "O kord"); tabel[2][1]=1; lugeja++; } else { SetWindowText(hwndButton8, vaartus[2]); SetWindowText(hwnd, "X kord"); tabel[2][1]=2; lugeja++; } } if (LOWORD(wParam) == 1 && HIWORD(wParam) == BN_CLICKED && (HWND) lParam == hwndButton9){ if (kord%2!=0){ SetWindowText(hwndButton9, vaartus[1]); SetWindowText(hwnd, "O kord"); tabel[2][2]=1; lugeja++; } else { SetWindowText(hwndButton9, vaartus[2]); SetWindowText(hwnd, "X kord"); tabel[2][2]=2; lugeja++; } } for(i=0; i<3; i++){ if(tabel[0][i]==1 && tabel[1][i]==1 && tabel[2][i]==1) voit=1; if(tabel[i][0]==1 && tabel[i][1]==1 && tabel[i][2]==1) voit=1; if(tabel[0][i]==2 && tabel[1][i]==2 && tabel[2][i]==2) voit=2; if(tabel[i][0]==2 && tabel[i][1]==2 && tabel[i][2]==2) voit=2; } if(tabel[0][0]==1 && tabel[1][1]==1 && tabel[2][2]==1) voit=1; if(tabel[2][0]==1 && tabel[1][1]==1 && tabel[0][2]==1) voit=1; if(tabel[0][0]==2 && tabel[1][1]==2 && tabel[2][2]==2) voit=2; if(tabel[2][0]==2 && tabel[1][1]==2 && tabel[0][2]==2) voit=2; if(voit==1) MessageBox(hwnd, "Vőitis X ", "Teade", MB_OK); if(voit==2) MessageBox(hwnd, "Vőitis O ", "Teade", MB_OK); if(lugeja>8 && voit==0) MessageBox(hwnd, "Viik", "Teade", MB_OK); return 0; break; } return DefWindowProc (hwnd, nMsg, wParam, lParam); } int STDCALL WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) { HWND hwndMain;/* Handle for the main window. */ MSG msg;/* A Win32 message structure. */ WNDCLASSEX wndclass;/* A window class structure. */ char*szMainWndClass = "WinTestWin"; memset (&wndclass, 0, sizeof(WNDCLASSEX)); wndclass.lpszClassName = szMainWndClass; wndclass.cbSize = sizeof(WNDCLASSEX); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = MainWndProc; wndclass.hInstance = hInst; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION); wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); RegisterClassEx (&wndclass); hwndMain = CreateWindow ( szMainWndClass, "Trips-Traps-Trull Alustab X", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 307, 327, NULL, NULL, hInst, NULL ); ShowWindow (hwndMain, nShow); UpdateWindow (hwndMain); while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } return msg.wParam; }