From 3622cff07fb6bf5552953ade20ddca7a6ee9b365 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 4 Feb 2007 23:33:35 +0000 Subject: [PATCH] MTD interface change --- winmain.cc | 818 ++++++++++++++++++++++++++--------------------------- 1 file changed, 409 insertions(+), 409 deletions(-) diff --git a/winmain.cc b/winmain.cc index b1fae7d..504f48b 100644 --- a/winmain.cc +++ b/winmain.cc @@ -86,21 +86,21 @@ void MILLISLEEP(ULONG a) DWORD WINAPI commandthreadStart(void *arg) { - command->run(); - return 0; + command->run(); + return 0; } void LoadRemoteFunctions() { - user32dll=LoadLibrary("user32.dll"); - if (user32dll!=NULL) { - dynGetRawInputData=(GETRAWINPUTDATAFNC)GetProcAddress(user32dll,"GetRawInputData"); - if (dynGetRawInputData!=NULL) { - dynRegisterRawInputDevices=(REGISTERRAWINPUTDEVICEFNC)GetProcAddress(user32dll,"RegisterRawInputDevices"); - if (dynRegisterRawInputDevices!=NULL) { - remotefnc=true; - } - } - } + user32dll=LoadLibrary("user32.dll"); + if (user32dll!=NULL) { + dynGetRawInputData=(GETRAWINPUTDATAFNC)GetProcAddress(user32dll,"GetRawInputData"); + if (dynGetRawInputData!=NULL) { + dynRegisterRawInputDevices=(REGISTERRAWINPUTDEVICEFNC)GetProcAddress(user32dll,"RegisterRawInputDevices"); + if (dynRegisterRawInputDevices!=NULL) { + remotefnc=true; + } + } + } } bool InitApp(HINSTANCE hinst,int cmdshow); @@ -112,22 +112,22 @@ HACCEL acc; #define ERROR_MSG(str) MessageBox(win_main,str,"Error!",MB_OK|MB_ICONWARNING) INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmdshow) { - hinstance=hinst; + hinstance=hinst; //On Windows we have to init a window, we use DXUT - LoadRemoteFunctions(); - if (!InitApp(hinst,cmdshow)) return false; + LoadRemoteFunctions(); + if (!InitApp(hinst,cmdshow)) return false; //Starting Network support - WSADATA wsadat; + WSADATA wsadat; int result = WSAStartup(MAKEWORD(2,2),&wsadat); if (result!=NO_ERROR) { ERROR_MSG("Initialising WinSocked: Error at WSAStartup()\n"); - return 0; + return 0; } - + result= CoInitializeEx(NULL,COINIT_MULTITHREADED );//Initialize COM for DirectShow if (result!=S_OK) { - ERROR_MSG("Initialising COM: Error at Coinitialize()\n"); - return 0; + ERROR_MSG("Initialising COM: Error at Coinitialize()\n"); + return 0; } @@ -151,8 +151,8 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd { ERROR_MSG("Could not create objects. Memory problems?\n"); shutdown(1); - WSACleanup(); - return 0; + WSACleanup(); + return 0; } // Get logging module started -------------------------------------------------------------------------------------- @@ -161,12 +161,12 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd { ERROR_MSG("Could not initialise log object. Aborting.\n"); shutdown(1); - WSACleanup(); - return 0; + WSACleanup(); + return 0; } logger->log("Core", Log::INFO, "Starting up..."); - + // Init modules ---------------------------------------------------------------------------------------------------- @@ -181,8 +181,8 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd { logger->log("Core", Log::EMERG, "Remote module failed to initialise"); shutdown(1); - WSACleanup(); - return 0; + WSACleanup(); + return 0; } success = led->init(0); @@ -194,11 +194,11 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd { logger->log("Core", Log::EMERG, "LED module failed to initialise"); shutdown(1); - WSACleanup(); - return 0; + WSACleanup(); + return 0; } - success = mtd->init("/dev/mtd1"); + success = mtd->init(); if (success) { logger->log("Core", Log::INFO, "Mtd module initialised"); @@ -207,8 +207,8 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd { logger->log("Core", Log::EMERG, "Mtd module failed to initialise"); shutdown(1); - WSACleanup(); - return 0; + WSACleanup(); + return 0; } success = timers->init(); @@ -220,8 +220,8 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd { logger->log("Core", Log::EMERG, "Timers module failed to initialise"); shutdown(1); - WSACleanup(); - return 0; + WSACleanup(); + return 0; } UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC(); @@ -238,8 +238,8 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd { logger->log("Core", Log::EMERG, "Video module failed to initialise"); shutdown(1); - WSACleanup(); - return 0; + WSACleanup(); + return 0; } success = osd->init((void*)&win); @@ -251,8 +251,8 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd { logger->log("Core", Log::EMERG, "OSD module failed to initialise"); shutdown(1); - WSACleanup(); - return 0; + WSACleanup(); + return 0; } success = audio->init(Audio::MPEG2_PES); @@ -264,8 +264,8 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd { logger->log("Core", Log::EMERG, "Audio module failed to initialise"); shutdown(1); - WSACleanup(); - return 0; + WSACleanup(); + return 0; } success = vdr->init(3024); @@ -277,8 +277,8 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd { logger->log("Core", Log::EMERG, "VDR module failed to initialise"); shutdown(1); - WSACleanup(); - return 0; + WSACleanup(); + return 0; } success = viewman->init(); @@ -290,8 +290,8 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd { logger->log("Core", Log::EMERG, "ViewMan module failed to initialise"); shutdown(1); - WSACleanup(); - return 0; + WSACleanup(); + return 0; } success = command->init(); @@ -303,8 +303,8 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd { logger->log("Core", Log::EMERG, "Command module failed to initialise"); shutdown(1); - WSACleanup(); - return 0; + WSACleanup(); + return 0; } // Other init ------------------------------------------------------------------------------------------------------ @@ -315,27 +315,27 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd // Ok, all major device components and other bits are loaded and ready lastmousemove=timeGetTime(); - + HANDLE commandthread; - commandthread= CreateThread(NULL, 0, commandthreadStart, NULL,0, - NULL); + commandthread= CreateThread(NULL, 0, commandthreadStart, NULL,0, + NULL); MSG message; message.message=WM_NULL; bool run=true; while(run && WaitForSingleObject(commandthread,0)==WAIT_TIMEOUT) { - if (PeekMessage(&message, NULL, 0,0,PM_REMOVE)!=0) { - if (TranslateAccelerator(win_main,acc,&message)==NULL) { - TranslateMessage(&message); - DispatchMessage(&message); - switch (message.message) { - case WM_QUIT: - run=false; //TODO post exit to command Messages - }; - } - } else { - //Render - ((OsdWin*)osd)->Render(); - } + if (PeekMessage(&message, NULL, 0,0,PM_REMOVE)!=0) { + if (TranslateAccelerator(win_main,acc,&message)==NULL) { + TranslateMessage(&message); + DispatchMessage(&message); + switch (message.message) { + case WM_QUIT: + run=false; //TODO post exit to command Messages + }; + } + } else { + //Render + ((OsdWin*)osd)->Render(); + } } // When that returns quit ------------------------------------------------------------------------------------------ WaitForSingleObject(commandthread,INFINITE); @@ -347,219 +347,219 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd } bool TranslateMousePosition(POINT *pos) { - - RECT clientrect; - ScreenToClient(win,pos); - GetClientRect(win,&clientrect); - if (!PtInRect(&clientrect,*pos)) return false;//Don't pass it further - pos->x=((double)pos->x)/((double) (clientrect.right-clientrect.left)) - *((double)Video::getInstance()->getScreenWidth()); - pos->y=((double)pos->y)/((double) (clientrect.bottom-clientrect.top)) - *((double)Video::getInstance()->getScreenHeight()); - return true; + + RECT clientrect; + ScreenToClient(win,pos); + GetClientRect(win,&clientrect); + if (!PtInRect(&clientrect,*pos)) return false;//Don't pass it further + pos->x=((double)pos->x)/((double) (clientrect.right-clientrect.left)) + *((double)Video::getInstance()->getScreenWidth()); + pos->y=((double)pos->y)/((double) (clientrect.bottom-clientrect.top)) + *((double)Video::getInstance()->getScreenHeight()); + return true; } void CalculateWindowSize(RECT * size,ULONG size_mode) { - - DWORD width, height; - DWORD adjheight,adjwidth; - if (!wnd_fullscreen) { - DWORD flags =WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU - |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX; - RECT wnted={50,50,150,150}; - AdjustWindowRect(&wnted,flags ,false); - adjwidth=-wnted.left+wnted.right-100; - adjheight=-wnted.top+wnted.bottom-100; - } else { - adjwidth=adjheight=0; - } - width=size->right-size->left-adjwidth; - height=size->bottom-size->top-adjheight; - UCHAR mode=video->getMode(); - UCHAR aspect=((VideoWin*)video)->getAspectRatio(); - UCHAR tvsize=((VideoWin*)video)->getPseudoTVsize(); - double aspectrt=4./3.; - if (tvsize==Video::ASPECT16X9) { - if (aspect==Video::ASPECT16X9) { - aspectrt=4./3.; //looks strange, but it is a 16:9 tv - } else if (aspect==Video::ASPECT4X3) { - aspectrt=4./3./(16./9.)*(4./3.); //I hope this is correct - } - } else if (tvsize==Video::ASPECT4X3) { - if (aspect==Video::ASPECT16X9) { - if (mode!=Video::NORMAL) { - aspectrt=16./9.; - } else { - aspectrt=4./3.; - } - } else if (aspect==Video::ASPECT4X3) { - aspectrt=4./3.; - } - } - if (!wnd_fullscreen) { - switch (size_mode) { - case WMSZ_BOTTOM: - case WMSZ_BOTTOMRIGHT: - case WMSZ_TOP: - case WMSZ_TOPRIGHT: - width=(ULONG)(((double)height)*aspectrt); - size->right=size->left+width+adjwidth; - break; - case WMSZ_BOTTOMLEFT: - case WMSZ_TOPLEFT: - width=(ULONG)(((double)height)*aspectrt); - size->left=size->right-width-adjwidth; - break; - case WMSZ_LEFT: - case WMSZ_RIGHT: - height=(ULONG)(((double)width)/aspectrt); - size->bottom=size->top+height+adjheight; - break; - } - MoveWindow(win,0,0,width,height,TRUE); - } else { - RECT newrect={0,0,width,height}; - DWORD newlength; - if ((ULONG)(((double)height)*aspectrt)>width) { - newlength=(ULONG)(((double)width)/aspectrt); - newrect.top+=(height-newlength)/2; - newrect.bottom-=(height-newlength); - } else { - newlength=(ULONG)(((double)height)*aspectrt); - newrect.left+=(width-newlength)/2; - newrect.right-=(width-newlength); - } - MoveWindow(win,newrect.left,newrect.top,newrect.right,newrect.bottom,TRUE); - } - + + DWORD width, height; + DWORD adjheight,adjwidth; + if (!wnd_fullscreen) { + DWORD flags =WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU + |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX; + RECT wnted={50,50,150,150}; + AdjustWindowRect(&wnted,flags ,false); + adjwidth=-wnted.left+wnted.right-100; + adjheight=-wnted.top+wnted.bottom-100; + } else { + adjwidth=adjheight=0; + } + width=size->right-size->left-adjwidth; + height=size->bottom-size->top-adjheight; + UCHAR mode=video->getMode(); + UCHAR aspect=((VideoWin*)video)->getAspectRatio(); + UCHAR tvsize=((VideoWin*)video)->getPseudoTVsize(); + double aspectrt=4./3.; + if (tvsize==Video::ASPECT16X9) { + if (aspect==Video::ASPECT16X9) { + aspectrt=4./3.; //looks strange, but it is a 16:9 tv + } else if (aspect==Video::ASPECT4X3) { + aspectrt=4./3./(16./9.)*(4./3.); //I hope this is correct + } + } else if (tvsize==Video::ASPECT4X3) { + if (aspect==Video::ASPECT16X9) { + if (mode!=Video::NORMAL) { + aspectrt=16./9.; + } else { + aspectrt=4./3.; + } + } else if (aspect==Video::ASPECT4X3) { + aspectrt=4./3.; + } + } + if (!wnd_fullscreen) { + switch (size_mode) { + case WMSZ_BOTTOM: + case WMSZ_BOTTOMRIGHT: + case WMSZ_TOP: + case WMSZ_TOPRIGHT: + width=(ULONG)(((double)height)*aspectrt); + size->right=size->left+width+adjwidth; + break; + case WMSZ_BOTTOMLEFT: + case WMSZ_TOPLEFT: + width=(ULONG)(((double)height)*aspectrt); + size->left=size->right-width-adjwidth; + break; + case WMSZ_LEFT: + case WMSZ_RIGHT: + height=(ULONG)(((double)width)/aspectrt); + size->bottom=size->top+height+adjheight; + break; + } + MoveWindow(win,0,0,width,height,TRUE); + } else { + RECT newrect={0,0,width,height}; + DWORD newlength; + if ((ULONG)(((double)height)*aspectrt)>width) { + newlength=(ULONG)(((double)width)/aspectrt); + newrect.top+=(height-newlength)/2; + newrect.bottom-=(height-newlength); + } else { + newlength=(ULONG)(((double)height)*aspectrt); + newrect.left+=(width-newlength)/2; + newrect.right-=(width-newlength); + } + MoveWindow(win,newrect.left,newrect.top,newrect.right,newrect.bottom,TRUE); + } + } void AdjustWindow() { - if (!wnd_fullscreen) { - RECT winrect; - GetWindowRect(win_main,&winrect); - CalculateWindowSize(&winrect,WMSZ_BOTTOM); - MoveWindow(win_main,winrect.left, - winrect.top,winrect.right-winrect.left,winrect.bottom-winrect.top,true); - } else { - RECT winrect; - GetWindowRect(win_main,&winrect); - CalculateWindowSize(&winrect,WMSZ_BOTTOM); - - } + if (!wnd_fullscreen) { + RECT winrect; + GetWindowRect(win_main,&winrect); + CalculateWindowSize(&winrect,WMSZ_BOTTOM); + MoveWindow(win_main,winrect.left, + winrect.top,winrect.right-winrect.left,winrect.bottom-winrect.top,true); + } else { + RECT winrect; + GetWindowRect(win_main,&winrect); + CalculateWindowSize(&winrect,WMSZ_BOTTOM); + + } } void ToggleFullscreen() { - if (wnd_fullscreen) { - wnd_fullscreen=false; - SetWindowLong(win_main,GWL_STYLE,WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU + if (wnd_fullscreen) { + wnd_fullscreen=false; + SetWindowLong(win_main,GWL_STYLE,WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX); - SetWindowPos(win_main,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); - - SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_TOP,wnd_fs_rect.left,wnd_fs_rect.top, - wnd_fs_rect.right-wnd_fs_rect.left, - wnd_fs_rect.bottom-wnd_fs_rect.top, - SWP_DRAWFRAME | SWP_FRAMECHANGED); - MoveWindow(win,wnd_fs_rect_client.left,wnd_fs_rect_client.top, - wnd_fs_rect_client.right-wnd_fs_rect_client.left, - wnd_fs_rect_client.bottom-wnd_fs_rect_client.top,TRUE); - AdjustWindow(); - } else { - GetWindowRect(win_main,&wnd_fs_rect); - GetWindowRect(win,&wnd_fs_rect_client); - SetWindowLong(win_main,GWL_STYLE,WS_VISIBLE | WS_POPUP ); - SetWindowPos(win_main,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); - HMONITOR monitor=MonitorFromWindow(win_main,MONITOR_DEFAULTTONEAREST); - MONITORINFO moninfo; - moninfo.cbSize=sizeof(moninfo); - wnd_fullscreen=true; - if (!GetMonitorInfo(monitor,&moninfo)) return ; - SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_TOP,moninfo.rcMonitor.left,moninfo.rcMonitor.top, - moninfo.rcMonitor.right,moninfo.rcMonitor.bottom,SWP_FRAMECHANGED); - - AdjustWindow(); - - } + SetWindowPos(win_main,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); + + SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_TOP,wnd_fs_rect.left,wnd_fs_rect.top, + wnd_fs_rect.right-wnd_fs_rect.left, + wnd_fs_rect.bottom-wnd_fs_rect.top, + SWP_DRAWFRAME | SWP_FRAMECHANGED); + MoveWindow(win,wnd_fs_rect_client.left,wnd_fs_rect_client.top, + wnd_fs_rect_client.right-wnd_fs_rect_client.left, + wnd_fs_rect_client.bottom-wnd_fs_rect_client.top,TRUE); + AdjustWindow(); + } else { + GetWindowRect(win_main,&wnd_fs_rect); + GetWindowRect(win,&wnd_fs_rect_client); + SetWindowLong(win_main,GWL_STYLE,WS_VISIBLE | WS_POPUP ); + SetWindowPos(win_main,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); + HMONITOR monitor=MonitorFromWindow(win_main,MONITOR_DEFAULTTONEAREST); + MONITORINFO moninfo; + moninfo.cbSize=sizeof(moninfo); + wnd_fullscreen=true; + if (!GetMonitorInfo(monitor,&moninfo)) return ; + SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_TOP,moninfo.rcMonitor.left,moninfo.rcMonitor.top, + moninfo.rcMonitor.right,moninfo.rcMonitor.bottom,SWP_FRAMECHANGED); + + AdjustWindow(); + + } } void ToggleTopmost() { - wnd_topmost=!wnd_topmost; - SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_NOTOPMOST,0,0, - 0,0,SWP_NOMOVE | SWP_NOSIZE); + wnd_topmost=!wnd_topmost; + SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_NOTOPMOST,0,0, + 0,0,SWP_NOMOVE | SWP_NOSIZE); } void CursorUpdate() { - POINT cursorpos; - GetCursorPos(&cursorpos); - HWND asswind; - asswind=WindowFromPoint(cursorpos); - if (asswind!=win_main && asswind!=win) { - return ; //not our responsibility - } - if ((timeGetTime()-lastmousemove)<4000 || cmenu) { - SetCursor(LoadCursor(NULL,IDC_ARROW)); - } else { - SetCursor(NULL); - } + POINT cursorpos; + GetCursorPos(&cursorpos); + HWND asswind; + asswind=WindowFromPoint(cursorpos); + if (asswind!=win_main && asswind!=win) { + return ; //not our responsibility + } + if ((timeGetTime()-lastmousemove)<4000 || cmenu) { + SetCursor(LoadCursor(NULL,IDC_ARROW)); + } else { + SetCursor(NULL); + } } bool ContextMenu(HWND wind,int x,int y) { - POINT p={x,y}; - RECT clientrect; - ScreenToClient(wind,&p); - GetClientRect(wind,&clientrect); - if (!PtInRect(&clientrect,p)) return false; - ClientToScreen(wind,&p); - HMENU menu; - HMENU popup; - menu=LoadMenu(hinstance,MAKEINTRESOURCE(VOMPMENU)); - popup=GetSubMenu(menu,0); - if (wnd_fullscreen) { - CheckMenuItem(popup,VOMP_FULL_SCREEN,MF_BYCOMMAND|MF_CHECKED); - } else { - CheckMenuItem(popup,VOMP_FULL_SCREEN,MF_BYCOMMAND|MF_UNCHECKED); - } - if (wnd_topmost) { - CheckMenuItem(popup,VOMP_TOPMOST,MF_BYCOMMAND|MF_CHECKED); - } else { - CheckMenuItem(popup,VOMP_TOPMOST,MF_BYCOMMAND|MF_UNCHECKED); - } - cmenu=true; - TrackPopupMenu(popup,TPM_RIGHTBUTTON|TPM_LEFTALIGN,x,y,0,wind, NULL); - cmenu=false; - - - DestroyMenu(menu); - return true; + POINT p={x,y}; + RECT clientrect; + ScreenToClient(wind,&p); + GetClientRect(wind,&clientrect); + if (!PtInRect(&clientrect,p)) return false; + ClientToScreen(wind,&p); + HMENU menu; + HMENU popup; + menu=LoadMenu(hinstance,MAKEINTRESOURCE(VOMPMENU)); + popup=GetSubMenu(menu,0); + if (wnd_fullscreen) { + CheckMenuItem(popup,VOMP_FULL_SCREEN,MF_BYCOMMAND|MF_CHECKED); + } else { + CheckMenuItem(popup,VOMP_FULL_SCREEN,MF_BYCOMMAND|MF_UNCHECKED); + } + if (wnd_topmost) { + CheckMenuItem(popup,VOMP_TOPMOST,MF_BYCOMMAND|MF_CHECKED); + } else { + CheckMenuItem(popup,VOMP_TOPMOST,MF_BYCOMMAND|MF_UNCHECKED); + } + cmenu=true; + TrackPopupMenu(popup,TPM_RIGHTBUTTON|TPM_LEFTALIGN,x,y,0,wind, NULL); + cmenu=false; + + + DestroyMenu(menu); + return true; } LONG FAR PASCAL WindowProc(HWND wind, UINT msg, WPARAM wparam, LPARAM lparam) { - + switch (msg) { case WM_DESTROY: { - //TODO: call command - logger->log("Core", Log::NOTICE, "Window closed, shutting down..."); - - ((RemoteWin*)Remote::getInstance())->SendPower(); - PostQuitMessage(0); - }break; + //TODO: call command + logger->log("Core", Log::NOTICE, "Window closed, shutting down..."); + + ((RemoteWin*)Remote::getInstance())->SendPower(); + PostQuitMessage(0); + }break; case WM_SIZING: { - CalculateWindowSize((RECT*) lparam,wparam); - return TRUE; - }break; - case WM_SIZE: { + CalculateWindowSize((RECT*) lparam,wparam); + return TRUE; + }break; + case WM_SIZE: { int width = LOWORD(lparam); int height = HIWORD(lparam); //Call device } break; - case WM_PAINT: + case WM_PAINT: RECT r; PAINTSTRUCT ps; if (GetUpdateRect(wind, &r, FALSE)) { @@ -568,128 +568,128 @@ LONG FAR PASCAL WindowProc(HWND wind, UINT msg, WPARAM wparam, LPARAM lparam) EndPaint(wind, &ps); } break; - case WM_KEYDOWN: - if (((RemoteWin*)remote)->ReceiveButtonVK(wparam)) { - return 0L; //We process that Key - } else { - return DefWindowProc(wind, msg, wparam, lparam); - } - - break; - case WM_APPCOMMAND: - if (((RemoteWin*)remote)->ReceiveButtonAP(GET_APPCOMMAND_LPARAM(lparam))){ - return TRUE; //yes we process that message - } else { - return DefWindowProc(wind, msg, wparam, lparam); - } - - break; - case WM_INPUT: - if (remotefnc ) { - //only on XP! - LPRAWINPUT lpit; - UINT risize; - dynGetRawInputData((HRAWINPUT)lparam,RID_INPUT,NULL,&risize,sizeof(RAWINPUTHEADER)); - lpit=(LPRAWINPUT)malloc(risize); - dynGetRawInputData((HRAWINPUT)lparam,RID_INPUT,lpit,&risize,sizeof(RAWINPUTHEADER)); - - if (lpit->header.dwType==RIM_TYPEHID && lpit->data.hid.dwSizeHid>=2) { - DWORD button=lpit->data.hid.bRawData[1] | (lpit->data.hid.bRawData[0]<< 8); - if (((RemoteWin*)remote)->ReceiveButtonRI(button)){ - free(lpit); - return 0; //yes we process that message - } - } - free(lpit); - } - return DefWindowProc(wind, msg, wparam, lparam); - - - break; - case WM_COMMAND: - if (LOWORD(wparam)==VOMP_FULL_SCREEN) { - ToggleFullscreen(); - return 0; - } - if (LOWORD(wparam)==VOMP_TOPMOST) { - ToggleTopmost(); - return 0; - } - if (((RemoteWin*)remote)->ReceiveButtonAP(LOWORD(wparam))){ - return 0; //yes we process that message - } else { - return DefWindowProc(wind, msg, wparam, lparam); - } - - break; - case WM_SETCURSOR: - if (((HANDLE)wparam)==win) { - CursorUpdate(); - return 1; - } else { - return DefWindowProc(wind, msg, wparam, lparam); - } - break; - case WM_SYSCOMMAND: - if (wparam==SC_MAXIMIZE) { - ToggleFullscreen(); - return 0; - } else if (wparam==SC_SCREENSAVE || wparam==SC_MONITORPOWER) { - return 0; - } else { - return DefWindowProc(wind,msg,wparam, lparam); - } - break; - case WM_MOUSEMOVE: { - - lastmousemove=timeGetTime(); - SetCursor(LoadCursor(NULL,IDC_ARROW)); - SetTimer(wind,VOMP_CURSORUPDATE,4500,NULL); - POINT mpos={GET_X_LPARAM(lparam),GET_Y_LPARAM(lparam)}; - ClientToScreen(wind,&mpos); - if (TranslateMousePosition(&mpos)) { - Message *mousemes=new Message(); - mousemes->message=Message::MOUSE_MOVE; - mousemes->from=NULL; - mousemes->to=ViewMan::getInstance(); - mousemes->parameter=(mpos.x & 0xFFFF)<< 16| (mpos.y & 0xFFFF); - mousemes->tag=0; - //command->postMessageFromOuterSpace(mousemes); - command->postMessageIfNotBusy(mousemes); - } - - return 0; - //return DefWindowProc(wind,msg,wparam, lparam); - } - break; - case WM_TIMER: - if (wparam==VOMP_CURSORUPDATE) { - CursorUpdate(); - return 0; - } - return DefWindowProc(wind, msg, wparam, lparam); - - break; - case WM_CONTEXTMENU: - if (!ContextMenu(wind,GET_X_LPARAM(lparam),GET_Y_LPARAM(lparam))) { - return DefWindowProc(wind, msg, wparam, lparam); - } else { - return 0; - } - break; - case WM_LBUTTONDOWN:{ - POINT mpos={GET_X_LPARAM(lparam),GET_Y_LPARAM(lparam)}; - ClientToScreen(wind,&mpos); - if (TranslateMousePosition(&mpos)) { - Message *mousemes=new Message(); - mousemes->message=Message::MOUSE_LBDOWN; - mousemes->from=NULL; - mousemes->to=ViewMan::getInstance(); - mousemes->parameter=(mpos.x & 0xFFFF)<< 16| (mpos.y & 0xFFFF); - mousemes->tag=0; - command->postMessageFromOuterSpace(mousemes); - } - }break; + case WM_KEYDOWN: + if (((RemoteWin*)remote)->ReceiveButtonVK(wparam)) { + return 0L; //We process that Key + } else { + return DefWindowProc(wind, msg, wparam, lparam); + } + + break; + case WM_APPCOMMAND: + if (((RemoteWin*)remote)->ReceiveButtonAP(GET_APPCOMMAND_LPARAM(lparam))){ + return TRUE; //yes we process that message + } else { + return DefWindowProc(wind, msg, wparam, lparam); + } + + break; + case WM_INPUT: + if (remotefnc ) { + //only on XP! + LPRAWINPUT lpit; + UINT risize; + dynGetRawInputData((HRAWINPUT)lparam,RID_INPUT,NULL,&risize,sizeof(RAWINPUTHEADER)); + lpit=(LPRAWINPUT)malloc(risize); + dynGetRawInputData((HRAWINPUT)lparam,RID_INPUT,lpit,&risize,sizeof(RAWINPUTHEADER)); + + if (lpit->header.dwType==RIM_TYPEHID && lpit->data.hid.dwSizeHid>=2) { + DWORD button=lpit->data.hid.bRawData[1] | (lpit->data.hid.bRawData[0]<< 8); + if (((RemoteWin*)remote)->ReceiveButtonRI(button)){ + free(lpit); + return 0; //yes we process that message + } + } + free(lpit); + } + return DefWindowProc(wind, msg, wparam, lparam); + + + break; + case WM_COMMAND: + if (LOWORD(wparam)==VOMP_FULL_SCREEN) { + ToggleFullscreen(); + return 0; + } + if (LOWORD(wparam)==VOMP_TOPMOST) { + ToggleTopmost(); + return 0; + } + if (((RemoteWin*)remote)->ReceiveButtonAP(LOWORD(wparam))){ + return 0; //yes we process that message + } else { + return DefWindowProc(wind, msg, wparam, lparam); + } + + break; + case WM_SETCURSOR: + if (((HANDLE)wparam)==win) { + CursorUpdate(); + return 1; + } else { + return DefWindowProc(wind, msg, wparam, lparam); + } + break; + case WM_SYSCOMMAND: + if (wparam==SC_MAXIMIZE) { + ToggleFullscreen(); + return 0; + } else if (wparam==SC_SCREENSAVE || wparam==SC_MONITORPOWER) { + return 0; + } else { + return DefWindowProc(wind,msg,wparam, lparam); + } + break; + case WM_MOUSEMOVE: { + + lastmousemove=timeGetTime(); + SetCursor(LoadCursor(NULL,IDC_ARROW)); + SetTimer(wind,VOMP_CURSORUPDATE,4500,NULL); + POINT mpos={GET_X_LPARAM(lparam),GET_Y_LPARAM(lparam)}; + ClientToScreen(wind,&mpos); + if (TranslateMousePosition(&mpos)) { + Message *mousemes=new Message(); + mousemes->message=Message::MOUSE_MOVE; + mousemes->from=NULL; + mousemes->to=ViewMan::getInstance(); + mousemes->parameter=(mpos.x & 0xFFFF)<< 16| (mpos.y & 0xFFFF); + mousemes->tag=0; + //command->postMessageFromOuterSpace(mousemes); + command->postMessageIfNotBusy(mousemes); + } + + return 0; + //return DefWindowProc(wind,msg,wparam, lparam); + } + break; + case WM_TIMER: + if (wparam==VOMP_CURSORUPDATE) { + CursorUpdate(); + return 0; + } + return DefWindowProc(wind, msg, wparam, lparam); + + break; + case WM_CONTEXTMENU: + if (!ContextMenu(wind,GET_X_LPARAM(lparam),GET_Y_LPARAM(lparam))) { + return DefWindowProc(wind, msg, wparam, lparam); + } else { + return 0; + } + break; + case WM_LBUTTONDOWN:{ + POINT mpos={GET_X_LPARAM(lparam),GET_Y_LPARAM(lparam)}; + ClientToScreen(wind,&mpos); + if (TranslateMousePosition(&mpos)) { + Message *mousemes=new Message(); + mousemes->message=Message::MOUSE_LBDOWN; + mousemes->from=NULL; + mousemes->to=ViewMan::getInstance(); + mousemes->parameter=(mpos.x & 0xFFFF)<< 16| (mpos.y & 0xFFFF); + mousemes->tag=0; + command->postMessageFromOuterSpace(mousemes); + } + }break; default: return DefWindowProc(wind, msg, wparam, lparam); } @@ -698,10 +698,10 @@ LONG FAR PASCAL WindowProc(HWND wind, UINT msg, WPARAM wparam, LPARAM lparam) bool InitApp(HINSTANCE hinst,int cmdshow) { - /* main window */ - WNDCLASS wcs; - DWORD flags; - wcs.style = CS_HREDRAW | CS_VREDRAW; + /* main window */ + WNDCLASS wcs; + DWORD flags; + wcs.style = CS_HREDRAW | CS_VREDRAW; wcs.lpfnWndProc = WindowProc; wcs.cbClsExtra = 0; wcs.cbWndExtra = sizeof(DWORD); @@ -711,22 +711,22 @@ bool InitApp(HINSTANCE hinst,int cmdshow) { wcs.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wcs.lpszMenuName = NULL; wcs.lpszClassName = "vomp"; - acc=LoadAccelerators(hinst,MAKEINTRESOURCE(VOMPACCELERATOR)); - if (!RegisterClass(&wcs)) + acc=LoadAccelerators(hinst,MAKEINTRESOURCE(VOMPACCELERATOR)); + if (!RegisterClass(&wcs)) return false; - flags =WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU + flags =WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX; - RECT wnted={50,50,768+50,576+50}; - AdjustWindowRect(&wnted,flags ,false); - win_main=CreateWindow("vomp","VOMP on Windows",flags, CW_USEDEFAULT,CW_USEDEFAULT, - wnted.right-wnted.left,wnted.bottom-wnted.top,NULL,NULL,hinst,NULL); - if (!win_main) + RECT wnted={50,50,768+50,576+50}; + AdjustWindowRect(&wnted,flags ,false); + win_main=CreateWindow("vomp","VOMP on Windows",flags, CW_USEDEFAULT,CW_USEDEFAULT, + wnted.right-wnted.left,wnted.bottom-wnted.top,NULL,NULL,hinst,NULL); + if (!win_main) return FALSE; - ShowWindow(win_main,SW_SHOWNORMAL); + ShowWindow(win_main,SW_SHOWNORMAL); UpdateWindow(win_main); - /* in order to handle letterboxing we use a child window */ - WNDCLASS child_wcs; - child_wcs.style = CS_HREDRAW | CS_VREDRAW; + /* in order to handle letterboxing we use a child window */ + WNDCLASS child_wcs; + child_wcs.style = CS_HREDRAW | CS_VREDRAW; child_wcs.lpfnWndProc = WindowProc; child_wcs.cbClsExtra = 0; child_wcs.cbWndExtra = sizeof(DWORD); @@ -736,38 +736,38 @@ bool InitApp(HINSTANCE hinst,int cmdshow) { child_wcs.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); child_wcs.lpszMenuName = NULL; child_wcs.lpszClassName = "vomp_playback"; - if (!RegisterClass(&child_wcs)) + if (!RegisterClass(&child_wcs)) return false; - win=CreateWindow("vomp_playback","Vomp Playback Window",WS_VISIBLE | WS_CHILD |WS_CLIPCHILDREN, - 0,0,768,576,win_main,NULL,hinst,NULL); - if (!win) - return FALSE; - ShowWindow(win,SW_SHOWNORMAL); - UpdateWindow(win); - if (remotefnc) {//at least windows XP - /* We want to support MCE Remote controls*/ - RAWINPUTDEVICE remote_control_data[4]; - ZeroMemory(remote_control_data,sizeof(remote_control_data)); - remote_control_data[0].usUsagePage=0xFFBC; - remote_control_data[0].usUsage=0x88; - remote_control_data[0].dwFlags=0; - remote_control_data[1].usUsagePage=0x0C; - remote_control_data[1].usUsage=0x80; - remote_control_data[1].dwFlags=0; - remote_control_data[2].usUsagePage=0x0C; - remote_control_data[2].usUsage=0x01; - remote_control_data[2].dwFlags=0; - remote_control_data[3].usUsagePage=0x01; - remote_control_data[3].usUsage=0x80; - remote_control_data[3].dwFlags=0; - if (dynRegisterRawInputDevices(remote_control_data,4,sizeof(remote_control_data[0]))!=TRUE) { - MessageBox(0,"Registering remote control failed!","Aborting!",0); - return FALSE; - } - - } - return TRUE; + win=CreateWindow("vomp_playback","Vomp Playback Window",WS_VISIBLE | WS_CHILD |WS_CLIPCHILDREN, + 0,0,768,576,win_main,NULL,hinst,NULL); + if (!win) + return FALSE; + ShowWindow(win,SW_SHOWNORMAL); + UpdateWindow(win); + if (remotefnc) {//at least windows XP + /* We want to support MCE Remote controls*/ + RAWINPUTDEVICE remote_control_data[4]; + ZeroMemory(remote_control_data,sizeof(remote_control_data)); + remote_control_data[0].usUsagePage=0xFFBC; + remote_control_data[0].usUsage=0x88; + remote_control_data[0].dwFlags=0; + remote_control_data[1].usUsagePage=0x0C; + remote_control_data[1].usUsage=0x80; + remote_control_data[1].dwFlags=0; + remote_control_data[2].usUsagePage=0x0C; + remote_control_data[2].usUsage=0x01; + remote_control_data[2].dwFlags=0; + remote_control_data[3].usUsagePage=0x01; + remote_control_data[3].usUsage=0x80; + remote_control_data[3].dwFlags=0; + if (dynRegisterRawInputDevices(remote_control_data,4,sizeof(remote_control_data[0]))!=TRUE) { + MessageBox(0,"Registering remote control failed!","Aborting!",0); + return FALSE; + } + + } + return TRUE; } @@ -867,7 +867,7 @@ ULLONG ntohll(ULLONG a) ULLONG htonll(ULLONG a) { - return (((ULLONG)htonl((ULONG)((a<<32)>> 32))<<32) - |(ULONG)htonl(((ULONG) (a >> 32)))); + return (((ULLONG)htonl((ULONG)((a<<32)>> 32))<<32) + |(ULONG)htonl(((ULONG) (a >> 32)))); } #endif -- 2.39.5