#include <windows.h>
#include <mmsystem.h>
#ifdef __BORLANDC__
  #pragma argsused
#endif
extern HINSTANCE _hInstance;
 static const char tytul[] = "Dzwięki";



LONG APIENTRY GlownaFunkcja(
HWND hwnd,                /* window handle                   */
UINT message,             /* type of message                 */
UINT wParam,              /* additional information          */
LONG lParam)              /* additional information          */
{
  switch (message) {

      case WM_PAINT:
      {

              //hdc=GetDC(hwnd);
              PAINTSTRUCT ps;
              BeginPaint(hwnd,&ps);

              EndPaint(hwnd,&ps);

                    }
              break;
              case WM_COMMAND:
              int zb_wyjscie;
              int zb_wejscie;

                  switch (LOWORD(wParam)) {
                    case 10:
                    PlaySound("beep.wav",NULL, SND_FILENAME | SND_ASYNC );
                     break;

                   case 20:
                     HANDLE zbior;
                     char * wsk;
                     unsigned long rozmiar, ac;
                     zbior=CreateFile("beep.wav",GENERIC_READ,FILE_SHARE_READ,0,
                     OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,0);
                     if (zbior==INVALID_HANDLE_VALUE) {
                     MessageBox(NULL,"Blad otwarcia pliku","Blad",MB_OK | MB_ICONSTOP | MB_TASKMODAL);
                     return 0;
                     }
                     rozmiar=GetFileSize(zbior,0);
                     wsk=(char*)VirtualAlloc(0,rozmiar,MEM_COMMIT,PAGE_READWRITE);
                     ReadFile(zbior,wsk,rozmiar,&ac,0);
                     PlaySound((LPCSTR)wsk,NULL, SND_MEMORY | SND_ASYNC );
                     VirtualFree(wsk,rozmiar,MEM_FREE);
                     break;

              case 30:
                   PlaySound("SystemExit",NULL, SND_ALIAS | SND_ASYNC );
               break;

               case 40:
               PlaySound(NULL,NULL,NULL);
               break;

               case 50:
                   SendMessage(hwnd,WM_DESTROY,0,0);
               break;
 }
 break;
     case WM_CLOSE : { DestroyWindow(hwnd); break; }

    // send message to main loop ordering the program to end
    case WM_DESTROY : { PostQuitMessage(0); return 0; }

              default:
           return DefWindowProc(hwnd, message, wParam, lParam);


}
return NULL;

};
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
  MSG msg;
 HWND main_hwnd;
 WNDCLASS glowne_okno; // holds data used to set up the window's class

  glowne_okno.style = CS_HREDRAW | CS_VREDRAW;
  glowne_okno.lpfnWndProc = GlownaFunkcja;
  glowne_okno.cbClsExtra = glowne_okno.cbWndExtra = 0;
  glowne_okno.hInstance = _hInstance;
  glowne_okno.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  glowne_okno.hCursor = LoadCursor(NULL, IDC_ARROW);
  glowne_okno.hbrBackground = (HBRUSH)COLOR_WINDOW;
  glowne_okno.lpszMenuName = NULL;
  glowne_okno.lpszClassName = tytul;

  if (RegisterClass(&glowne_okno))
    {
    main_hwnd = CreateWindow(tytul, tytul,
                 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
                 CW_USEDEFAULT, CW_USEDEFAULT,
                 CW_USEDEFAULT, CW_USEDEFAULT,
                 HWND_DESKTOP, NULL, _hInstance, NULL);
    }
  else
    main_hwnd = NULL;

 if (main_hwnd) // if window creation was successful
   {
   ShowWindow(main_hwnd, nCmdShow); // show the window
   UpdateWindow(main_hwnd);         // cause its contents to be painted
   CreateWindow("button", "Plik", WS_CHILD | WS_VISIBLE,
   5,10,50,30, main_hwnd, (HMENU)10, hInstance, NULL);
   CreateWindow("button", "Pamiec", WS_CHILD | WS_VISIBLE,
   55,10,60,30, main_hwnd, (HMENU)20, hInstance, NULL);
   CreateWindow("button", "Zdarzenie", WS_CHILD | WS_VISIBLE,
   115,10,70,30, main_hwnd, (HMENU)30, hInstance, NULL);
   CreateWindow("button", "Stop", WS_CHILD | WS_VISIBLE,
   185,10,50,30, main_hwnd, (HMENU)40, hInstance, NULL);
   CreateWindow("button", "Koniec", WS_CHILD | WS_VISIBLE,
   405,10,50,30, main_hwnd, (HMENU)50, hInstance, NULL);

   while (GetMessage(&msg, NULL, 0, 0) > 0)
     {
     TranslateMessage(&msg); // handle messages sent to
     DispatchMessage(&msg);  // program & its  windows
     }
   }

 return msg.message;

}
