LRESULT CALLBACK winProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int i; switch (message) { case WM_CREATE: { HWND combo = CreateWindow("combobox", "combobox", CBS_SORT | CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | WS_TABSTOP, 690, 25, 75, 1000, hWnd, 0, inst, 0); for (i = 9; i > 0; --i) { port[3] = '0' + i; SendMessage(combo, CB_ADDSTRING, (WPARAM)0, (LPARAM)port); } SendMessage(combo, CB_SETCURSEL, (WPARAM)0, (LPARAM)0); for (i = 0; i < 2; ++i) createButtonBank(hWnd, i); break; } case WM_DESTROY: break; case WM_COMMAND: if (HIWORD(wParam) == CBN_SELCHANGE) { i =(int)SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0); curlink = links + i; port[3] = '1' + i; InvalidateRect(hWnd, 0, FALSE); break; } else if (LOWORD(wParam) >= 4096) { action(hWnd, LOWORD(wParam) - 4096); break; } else if (LOWORD(wParam) != IDCANCEL) { break; } case WM_CLOSE: PostQuitMessage(0); break; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); COLORREF col = 0; if (curlink->status != LINK_UNKNOWN) { col = RGB((curlink->status == LINK_OK) ? 0 : 0xff, (curlink->status == LINK_ERROR) ? 0 : 0xff, 0); } myFillRect(hdc, 785, 25, 860, 49, col); for (i = 0; i < 2; ++i) { int y = 250 + i * 348; showDigits(hdc, 760, y, curlink->outputs[i]); } EndPaint(hWnd, &ps); break; } case WM_ACTIVATE: hDlgCurrent = wParam ? hWnd : 0; break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
void playVideo(const string &file) { //myFillRect(screen, NULL, 0); //SDL_GL_SwapBuffers(); SMPEG *mpeg; SMPEG_Info info; mpeg = SMPEG_new(file.c_str(), &info, false); bool hasAudio = (info.has_audio > 0); if ( SMPEG_error(mpeg) ) { dout << "MPEG error: " << SMPEG_error(mpeg) << endl; exit(1); } int done = 0; SDL_Surface *videoSurface = SDL_AllocSurface( SDL_SWSURFACE, nearestPow2(info.width), nearestPow2(info.height), 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 ); if ( !videoSurface ) { dout << "Failed to allocate memory for video playback" << endl; exit(1); } SMPEG_enablevideo(mpeg, 1); SDL_mutex *mutex = SDL_CreateMutex(); SMPEG_setdisplay(mpeg, videoSurface, mutex, videoUpdate ); SMPEG_scaleXY(mpeg, info.width, info.height); //SMPEG_setdisplayregion(mpeg, 0, 0, info.width, info.height); //SMPEG_setdisplay(mpeg, screen, NULL, update); if(hasAudio) { SDL_AudioSpec audiofmt; Uint16 format; int freq, channels; /* Tell SMPEG what the audio format is */ Mix_QuerySpec(&freq, &format, &channels); audiofmt.format = format; audiofmt.freq = freq; audiofmt.channels = channels; SMPEG_actualSpec(mpeg, &audiofmt); /* Hook in the MPEG music mixer */ Mix_HookMusic(SMPEG_playAudioSDL, mpeg); SMPEG_enableaudio(mpeg, 1); SMPEG_setvolume(mpeg, 100); } else { Mix_PauseMusic(); SMPEG_enableaudio(mpeg, 0); } glBlendFunc(GL_ONE, GL_ZERO); glEnable(GL_TEXTURE_2D); SMPEG_play(mpeg); while( !done && SMPEG_status( mpeg ) == SMPEG_PLAYING ) { SDL_Event event; while ( SDL_PollEvent(&event) ) { switch (event.type) { case SDL_KEYDOWN: { if ( event.key.keysym.sym == SDLK_SPACE ) { done = 1; } break; } case SDL_QUIT: { exit(1); } default: break; } } if(drawVideoFrame) { SDL_mutexP(mutex); drawVideoFrame = false; drawVideo(videoSurface, info.width, info.height); //printf("draw in %i\n", time(NULL)); SDL_mutexV(mutex); SDL_GL_SwapBuffers(); } } SMPEG_stop(mpeg); if(hasAudio) { Mix_HookMusic(NULL, NULL); } else { Mix_ResumeMusic(); } SDL_FreeSurface(videoSurface); myFillRect(screen, NULL, 0); SDL_GL_SwapBuffers(); SMPEG_delete(mpeg); }