// // 関数: WndProc(HWND, UINT, WPARAM, LPARAM) // // 目的: メイン ウィンドウのメッセージを処理します。 // // WM_COMMAND - アプリケーション メニューの処理 // WM_PAINT - メイン ウィンドウの描画 // WM_DESTROY - 中止メッセージを表示して戻る // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; static HWND hTargetWnd; RECT rect; int buttonWidth = 80; int buttonHeight = 32; static BOOL isSystemKeySet = FALSE; static Receiver receiver; switch (message) { case WM_CREATE: receiver.Start(hWnd); ExecuteIpodStub(); // リストボックス作成 GetClientRect(hWnd, &rect); g_listBox = CreateWindow(_T("LISTBOX"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL, 0, 0, rect.right - rect.left, rect.bottom - rect.top - buttonHeight - 15, hWnd, (HMENU)1, ((LPCREATESTRUCT)lParam)->hInstance, NULL); if (g_listBox == NULL) { MessageBox(hWnd, _T("[ERROR] CreateWindow : List Box"), szTitle, MB_OK); PostMessage(hWnd, WM_DESTROY, 0, 0); break; } EnumWindows(EnumWindowsProc, NULL); // 選択ボタン CreateWindowEx(0, _T("BUTTON"), _T("Select"), WS_CHILD | WS_VISIBLE, (rect.right - rect.left - buttonWidth)/2, rect.bottom - buttonHeight - 10, buttonWidth, buttonHeight, hWnd, (HMENU)ID_SELECT_BUTTON, ((LPCREATESTRUCT)lParam)->hInstance, NULL); break; case WM_BRIDGEMESSAGE: { VMMouseMessage mouseMessage; VMDragButton dragButton; if (!strcmpi((LPCSTR)lParam, "tumble")) { dragButton = LButtonDrag; } else if (!strcmpi((LPCSTR)lParam, "track")) { dragButton = MButtonDrag; } else if (!strcmpi((LPCSTR)lParam, "dolly")) { dragButton = RButtonDrag; } else { break; } POINT startPos, endPos; int deltaX = LOWORD(wParam); int deltaY = HIWORD(wParam); int posX, posY; EnumChildWindows(hTargetWnd, EnumChildProc, NULL); RECT rect; GetWindowRect(hTargetWnd, &rect); //SetWindowPos(hTargetWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); //SetWindowPos(hTargetWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); SetFocus(hTargetWnd); //SetForegroundWindow(hTargetWnd); posX = rect.left + (rect.right - rect.left)/2; posY = rect.top + (rect.bottom - rect.top)/2; //PostMessage(hTargetWnd, WM_SYSKEYDOWN, VK_MENU, MAKELONG(cRepeatON, fAltDown)); //Sleep(5); //PostMessage(hTargetWnd, WM_SYSKEYDOWN, 'F', MAKELONG(cRepeatON, fAltDown)); // 親ウィンドウに送信 if (!isSystemKeySet) { VMVirtualKeyDown(VK_MENU); VMVirtualKeyDown(VK_SHIFT); Sleep(5); isSystemKeySet = TRUE; } // 子ウィンドウに送信 startPos.x = posX; startPos.y = posY; endPos.x = posX + deltaX; endPos.y = posY + deltaY; mouseMessage.hTargetWnd = g_hChildWnd; mouseMessage.dragButton = dragButton; mouseMessage.dragStartPos = startPos; mouseMessage.dragEndPos = endPos; mouseMessage.uKeyState = MK_SHIFT; VMMouseDrag(&mouseMessage); // 親ウィンドウに送信 //if (isSystemKeySet) { // VMVirtualKeyUp(VK_SHIFT); // VMVirtualKeyUp(VK_MENU); // Sleep(5); // isSystemKeySet = FALSE; //} } break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // 選択されたメニューの解析: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; case ID_SELECT_BUTTON: { TCHAR szAppliTitle[MAX_PATH]; int index = SendMessage(g_listBox, LB_GETCURSEL, 0, 0); if (index != LB_ERR) { SendMessage(g_listBox, LB_GETTEXT, index, (LPARAM)szAppliTitle); hTargetWnd = FindWindow(NULL, szAppliTitle); if (hTargetWnd == NULL) { MessageBox(hWnd, _T("NULL"), szTitle, MB_OK); break; } } } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: 描画コードをここに追加してください... EndPaint(hWnd, &ps); break; case WM_DESTROY: VMVirtualKeyUp(VK_SHIFT); VMVirtualKeyUp(VK_MENU); Sleep(5); isSystemKeySet = FALSE; receiver.Stop(); PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }