/** Gets a file list from data. Caller must ensure that the data actually contains a file list. */ Vector<Path>* Win32DropTarget::getFileListFromData(IDataObject* data) { FORMATETC fmtetc = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stgmed; Vector<Path>* files = bs_new<Vector<Path>>(); if(data->GetData(&fmtetc, &stgmed) == S_OK) { PVOID data = GlobalLock(stgmed.hGlobal); HDROP hDrop = (HDROP)data; UINT numFiles = DragQueryFileW(hDrop, 0xFFFFFFFF, nullptr, 0); files->resize(numFiles); for(UINT i = 0; i < numFiles; i++) { UINT numChars = DragQueryFileW(hDrop, i, nullptr, 0) + 1; wchar_t* buffer = (wchar_t*)bs_alloc((UINT32)numChars * sizeof(wchar_t)); DragQueryFileW(hDrop, i, buffer, numChars); (*files)[i] = UTF8::fromWide(WString(buffer)); bs_free(buffer); } GlobalUnlock(stgmed.hGlobal); ReleaseStgMedium(&stgmed); } return files; }
void DragData::asFilenames(Vector<String>& result) const { #if USE(CF) if (m_platformDragData) { WCHAR filename[MAX_PATH]; STGMEDIUM medium; if (FAILED(m_platformDragData->GetData(cfHDropFormat(), &medium))) return; HDROP hdrop = reinterpret_cast<HDROP>(GlobalLock(medium.hGlobal)); if (!hdrop) return; const unsigned numFiles = DragQueryFileW(hdrop, 0xFFFFFFFF, 0, 0); for (unsigned i = 0; i < numFiles; i++) { if (!DragQueryFileW(hdrop, i, filename, WTF_ARRAY_LENGTH(filename))) continue; result.append(static_cast<UChar*>(filename)); } // Free up memory from drag DragFinish(hdrop); GlobalUnlock(medium.hGlobal); return; } result = m_dragDataMap.get(cfHDropFormat()->cfFormat); #endif }
void DragData::asFilenames(Vector<String>& result) const { WCHAR filename[MAX_PATH]; STGMEDIUM medium; if (FAILED(m_platformDragData->GetData(cfHDropFormat(), &medium))) return; HDROP hdrop = (HDROP)GlobalLock(medium.hGlobal); if (!hdrop) return; const unsigned numFiles = DragQueryFileW(hdrop, 0xFFFFFFFF, 0, 0); for (unsigned i = 0; i < numFiles; i++) { if (!DragQueryFileW(hdrop, 0, filename, ARRAYSIZE(filename))) continue; result.append((UChar*)filename); } // Free up memory from drag DragFinish(hdrop); GlobalUnlock(medium.hGlobal); }
LRESULT nsPluginInstance::ProcessMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_MOVE: // Update trap mouse if required UpdateTrapMouse(); return 0; case WM_SIZE: // Update trap mouse if required UpdateTrapMouse(); // Inform that the window size has been changed FrontendImpl::OnSize(); return 0; case WM_PAINT: // Let the frontend draw into it's window FrontendImpl::OnDraw(); // Ping Ping(); return 0; // Drag and drop of files case WM_DROPFILES: { // Get dropped filenames. Because there's no way - without extreme overhead :) - to check whether // we really need to use Unicode or ASCII is quite enough, we always use Unicode just to be sure. const uint32 nNumOfFiles = DragQueryFileW(reinterpret_cast<HDROP>(wParam), 0xFFFFFFFF, static_cast<LPWSTR>(nullptr), 0); if (nNumOfFiles) { // Create the file list PLCore::Array<PLCore::String> lstFiles; lstFiles.Resize(nNumOfFiles); for (uint32 i=0; i<nNumOfFiles; i++) { // Get the length of the string (+1 for \0) const UINT nSize = DragQueryFileW(reinterpret_cast<HDROP>(wParam), i, nullptr, 0) + 1; // Create the string and fill it wchar_t *pszFile = new wchar_t[nSize]; DragQueryFileW(reinterpret_cast<HDROP>(wParam), i, pszFile, nSize); // Store the string (the PL string takes over the control) lstFiles[i] = PLCore::String(pszFile, false, nSize - 1); } // Inform the frontend FrontendImpl::OnDrop(lstFiles); return 0; } } default: break; } return DefWindowProc(hWnd, msg, wParam, lParam); }
HRESULT csMenu::Initialize(LPCITEMIDLIST /*pidlFolder*/, IDataObject *pdtobj, HKEY /*hkeyProgID*/) { FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stg = { TYMED_HGLOBAL }; if( FAILED(pdtobj->GetData(&etc, &stg)) ) { return E_INVALIDARG; } HDROP hDrop = (HDROP)GlobalLock(stg.hGlobal); if( hDrop == NULL ) { ReleaseStgMedium(&stg); return E_INVALIDARG; } _files.clear(); UINT sizeFN = 0; WCHAR *filename = 0; const UINT uNumFiles = DragQueryFileW(hDrop, UINT_MAX, NULL, 0); for(UINT i = 0; i < uNumFiles; i++) { const UINT reqFN = DragQueryFileW(hDrop, i, NULL, 0); if( reqFN < 1 ) { continue; } if( reqFN+1 > sizeFN ) { sizeFN = 0; delete[] filename; filename = new wchar_t[reqFN+1]; if( filename == 0 ) { continue; } sizeFN = reqFN+1; } if( DragQueryFileW(hDrop, i, filename, sizeFN) == 0 ) { continue; } _files.push_back(filename); } delete[] filename; GlobalUnlock(stg.hGlobal); ReleaseStgMedium(&stg); _files.sort(); return _files.size() > 0 ? S_OK : E_INVALIDARG; }
LRESULT MetroWindow::OnDropfiles(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled) { const LPCWSTR PackageSubffix[] = { L".exe", L".dll", L".com", L".sys", L"scr", L"fon", L"drv" }; HDROP hDrop = (HDROP)wParam; UINT nfilecounts = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); WCHAR dropfile_name[MAX_PATH]; std::vector<std::wstring> filelist; for (UINT i = 0; i < nfilecounts; i++) { DragQueryFileW(hDrop, i, dropfile_name, MAX_PATH); auto ext=PathFindExtensionW(dropfile_name); if (ext) { for (auto s : PackageSubffix) { if (_wcsicmp(s, ext)) { filelist.push_back(dropfile_name); break; } } } if (!filelist.empty()) { ::SetWindowTextW(::GetDlgItem(m_hWnd, IDC_IMAGE_URI_EDIT), filelist[0].c_str()); if (PortableExecutableFileRander(filelist.at(0)) != S_OK) { ::MessageBoxW(m_hWnd, filelist.at(0).c_str(), L"Cannot analyzer this file", MB_OK | MB_ICONSTOP); return S_FALSE; } } } DragFinish(hDrop); ::InvalidateRect(m_hWnd, NULL, TRUE); return S_OK; }
unsigned DragData::numberOfFiles() const { #if USE(CF) if (!m_platformDragData) return 0; STGMEDIUM medium; if (FAILED(m_platformDragData->GetData(cfHDropFormat(), &medium))) return 0; HDROP hdrop = static_cast<HDROP>(GlobalLock(medium.hGlobal)); if (!hdrop) return 0; unsigned numFiles = DragQueryFileW(hdrop, 0xFFFFFFFF, 0, 0); DragFinish(hdrop); GlobalUnlock(medium.hGlobal); return numFiles; #else return 0; #endif }
HRESULT WINAPI CDrvDefExt::Initialize(LPCITEMIDLIST pidlFolder, IDataObject *pDataObj, HKEY hkeyProgID) { FORMATETC format; STGMEDIUM stgm; HRESULT hr; TRACE("%p %p %p %p\n", this, pidlFolder, pDataObj, hkeyProgID); if (!pDataObj) return E_FAIL; format.cfFormat = CF_HDROP; format.ptd = NULL; format.dwAspect = DVASPECT_CONTENT; format.lindex = -1; format.tymed = TYMED_HGLOBAL; hr = pDataObj->GetData(&format, &stgm); if (FAILED(hr)) return hr; if (!DragQueryFileW((HDROP)stgm.hGlobal, 0, m_wszDrive, _countof(m_wszDrive))) { ERR("DragQueryFileW failed\n"); ReleaseStgMedium(&stgm); return E_FAIL; } ReleaseStgMedium(&stgm); TRACE("Drive properties %ls\n", m_wszDrive); return S_OK; }
STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hRegKey) { FORMATETC format={CF_HDROP,NULL,DVASPECT_CONTENT,-1,TYMED_HGLOBAL}; STGMEDIUM medium; int i,nLen; WCHAR szDirectory[MAX_PATH]; HRESULT hr; TCHAR szAppData[MAX_PATH]; hr = SHGetSpecialFolderPath(NULL, szAppData,CSIDL_COMMON_DESKTOPDIRECTORY ,FALSE); // Initialize can be called more than once if (m_pDataObj) m_pDataObj->Release(); // duplicate the object pointer and registry handle if (pDataObj) { m_pDataObj = pDataObj; pDataObj->AddRef(); } pDataObj->GetData(&format,&medium); m_nSelected=DragQueryFileW((HDROP&)medium.hGlobal,0xFFFFFFFF,NULL,0); if (m_nSelected == -1 || m_nSelected ==0) { wcscpy(m_szCommand,L"DeleteFileInRecycled"); return NOERROR; } m_szCommand[0] = L'\0'; for(i=0;i<m_nSelected;i++) { DragQueryFileW((HDROP&)medium.hGlobal,i,szDirectory,MAX_PATH); if (i != 0) wcscat(m_szCommand,L" "); nLen = wcslen(m_szCommand); m_szCommand[nLen] = L'"'; m_szCommand[nLen+1] = L'\0'; wcscat(m_szCommand,szDirectory); nLen = wcslen(m_szCommand); m_szCommand[nLen] = L'"'; m_szCommand[nLen+1] = L'\0'; } return NOERROR; }
static UINT WINAPI DragQueryFileUW(HDROP hDrop, UINT iFile, LPSTR lpszFile, UINT cch) { if (!lpszFile || cch == 0) { // String not specified. Don't bother converting anything. return DragQueryFileW(hDrop, iFile, (LPWSTR)lpszFile, cch); } // Allocate a buffer for the filename. wchar_t *lpszwFile = (wchar_t*)malloc(cch * sizeof(wchar_t)); UINT uRet = DragQueryFileW(hDrop, iFile, lpszwFile, cch); // Convert the filename from UTF-16 to UTF-8. WideCharToMultiByte(CP_UTF8, 0, lpszwFile, -1, lpszFile, cch, NULL, NULL); free(lpszwFile); return uRet; }
// --------------------------------------------------------------------------- // void __fastcall TForm1::DropFiles(TWMDropFiles Msg) { TStringList *list = new TStringList(); wchar_t *fn = new wchar_t[MAX_PATH]; int n = DragQueryFileW((HDROP) Msg.Drop, -1, NULL, 0); for (int i = 0; i < n; ++i) { DragQueryFileW((HDROP) Msg.Drop, i, fn, MAX_PATH); list->Add(String(fn)); } fn_ParseFiles(list); delete[]fn; delete list; DragFinish((HDROP) Msg.Drop); }
static void LoadClipboardFromDrop(HDROP hDrop) { WCHAR szFileName[MAX_PATH]; DragQueryFileW(hDrop, 0, szFileName, ARRAYSIZE(szFileName)); DragFinish(hDrop); LoadClipboardDataFromFile(szFileName); }
int DragQueryFileUTF8(HDROP hDrop, int idx, char *buf, int bufsz) { if (buf && bufsz && idx!=-1 && GetVersion()< 0x80000000) { int reqsz = DragQueryFileW(hDrop,idx,NULL,0)+32; WIDETOMB_ALLOC(wbuf, reqsz); if (wbuf) { int rv=DragQueryFileW(hDrop,idx,wbuf,wbuf_size/sizeof(WCHAR)); if (rv) { if (!WideCharToMultiByte(CP_UTF8,0,wbuf,-1,buf,bufsz,NULL,NULL) && GetLastError()==ERROR_INSUFFICIENT_BUFFER) buf[bufsz-1]=0; } WIDETOMB_FREE(wbuf); return rv; } } return DragQueryFileA(hDrop,idx,buf,bufsz); }
UINT DragQueryFileUTF8(HDROP hDrop, UINT idx, char *buf, UINT bufsz) { if (buf && bufsz && idx!=-1 AND_IS_NOT_WIN9X) { const UINT reqsz = DragQueryFileW(hDrop,idx,NULL,0); WIDETOMB_ALLOC(wbuf, reqsz+32); if (wbuf) { UINT rv=DragQueryFileW(hDrop,idx,wbuf,(int)(wbuf_size/sizeof(WCHAR))); if (rv) { if (!WideCharToMultiByte(CP_UTF8,0,wbuf,-1,buf,bufsz,NULL,NULL) && GetLastError()==ERROR_INSUFFICIENT_BUFFER) buf[bufsz-1]=0; } WIDETOMB_FREE(wbuf); return rv; } } return DragQueryFileA(hDrop,idx,buf,bufsz); }
//--------------------------------------------------------------------------- // Drag and drop event on main form MESSAGE void __fastcall TForm1::FWmDropFiles(TWMDropFiles &msg) { wchar_t DropFileName[MAX_PATH]; POINT droppoint; // get 0th dropfilepath DragQueryFileW( (HDROP)msg.Drop, 0, DropFileName, MAX_PATH); Label1->Caption = (String)DropFileName; }
/************************************************************************* * DragQueryFileA [SHELL32.@] * DragQueryFile [SHELL32.@] */ UINT WINAPI DragQueryFileA( HDROP hDrop, UINT lFile, LPSTR lpszFile, UINT lLength) { LPSTR lpDrop; UINT i = 0; DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop); TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength); if(!lpDropFileStruct) goto end; lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles; if(lpDropFileStruct->fWide) { LPWSTR lpszFileW = NULL; if(lpszFile) { lpszFileW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR)); if(lpszFileW == NULL) { goto end; } } i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength); if(lpszFileW) { WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL); HeapFree(GetProcessHeap(), 0, lpszFileW); } goto end; } while (i++ < lFile) { while (*lpDrop++); /* skip filename */ if (!*lpDrop) { i = (lFile == 0xFFFFFFFF) ? i : 0; goto end; } } i = strlen(lpDrop); if (!lpszFile ) goto end; /* needed buffer size */ lstrcpynA (lpszFile, lpDrop, lLength); end: GlobalUnlock(hDrop); return i; }
bool ClipboardUtil::GetFilenames(IDataObject* data_object, std::vector<std::wstring>* filenames) { DCHECK(data_object && filenames); if(!HasFilenames(data_object)) { return false; } STGMEDIUM medium; if(FAILED(data_object->GetData(GetCFHDropFormat(), &medium))) { return false; } HDROP hdrop = static_cast<HDROP>(GlobalLock(medium.hGlobal)); if(!hdrop) { return false; } const int kMaxFilenameLen = 4096; const unsigned num_files = DragQueryFileW(hdrop, 0xffffffff, 0, 0); for(unsigned int i=0; i<num_files; ++i) { wchar_t filename[kMaxFilenameLen]; if(!DragQueryFileW(hdrop, i, filename, kMaxFilenameLen)) { continue; } filenames->push_back(filename); } DragFinish(hdrop); GlobalUnlock(medium.hGlobal); // 据我所知不需要调用ReleaseStgMedium, DragFinish已经帮助我们释放了hGlobal. return true; }
VOID DropFiles(HWND hWnd, HDROP hDrop) { WCHAR CpzPathW[MAX_NTPATH]; CmvsImageManager *ImageManager = g_CmvsObject->ImageManager; AllocConsole(); for (ULONG_PTR Index = 0; DragQueryFileW(hDrop, Index, CpzPathW, countof(CpzPathW)); ++Index) { CmvsUnpackerX cpz(ImageManager); cpz.Auto(CpzPathW); } FreeConsole(); DragFinish(hDrop); }
void CDJMasterDlg::OnDropFiles(HDROP hDropInfo) { UINT unFileCount; WCHAR szFilePath[200]; unFileCount = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0); //系统的API函数 for( UINT i=0;i < unFileCount;i++) { int pathLen = DragQueryFileW(hDropInfo, i, szFilePath, _countof(szFilePath)); //API函数 AddMusicFile(szFilePath); } DragFinish(hDropInfo); //API函数 CDialog::OnDropFiles(hDropInfo); }
static bool getWebLocData(IDataObject* dataObject, String& url, String* title) { bool succeeded = false; #if PLATFORM(CF) WCHAR filename[MAX_PATH]; WCHAR urlBuffer[INTERNET_MAX_URL_LENGTH]; STGMEDIUM medium; if (FAILED(dataObject->GetData(cfHDropFormat(), &medium))) return false; HDROP hdrop = static_cast<HDROP>(GlobalLock(medium.hGlobal)); if (!hdrop) return false; if (!DragQueryFileW(hdrop, 0, filename, ARRAYSIZE(filename))) goto exit; if (_wcsicmp(PathFindExtensionW(filename), L".url")) goto exit; if (!GetPrivateProfileStringW(L"InternetShortcut", L"url", 0, urlBuffer, ARRAYSIZE(urlBuffer), filename)) goto exit; if (title) { PathRemoveExtension(filename); *title = String((UChar*)filename); } url = String((UChar*)urlBuffer); succeeded = true; exit: // Free up memory. DragFinish(hdrop); GlobalUnlock(medium.hGlobal); #endif return succeeded; }
LRESULT CWebWindow::_windowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_CREATE: { DragAcceptFiles(hwnd, TRUE); //SetTimer(hwnd, 100, 20, NULL); } return 0; case WM_CLOSE: if (m_windowClosingCallback) { if (!m_windowClosingCallback(this, m_windowClosingCallbackParam)) return 0; } ShowWindow(hwnd, SW_HIDE); DestroyWindow(hwnd); return 0; case WM_DESTROY: { //KillTimer(hwnd, 100); RemovePropW(hwnd, L"wkeWebWindow"); m_hwnd = NULL; if (m_windowDestroyCallback) m_windowDestroyCallback(this, m_windowDestroyCallbackParam); wkeDestroyWebView(this); } return 0; //case WM_TIMER: // { // wkeRepaintIfNeeded(this); // } // return 0; case WM_PAINT: { PAINTSTRUCT ps = { 0 }; HDC hdc = BeginPaint(hwnd, &ps); _paintDC(hdc, (HDC)wkeGetViewDC(this)); EndPaint(hwnd, &ps); } return 0; case WM_ERASEBKGND: return TRUE; case WM_SIZE: { RECT rc = { 0 }; GetClientRect(hwnd, &rc); int width = rc.right - rc.left; int height = rc.bottom - rc.top; CWebView::resize(width, height); wkeRepaintIfNeeded(this); } return 0; case WM_DROPFILES: { wchar_t szFile[MAX_PATH + 8] = {0}; wcscpy(szFile, L"file:///"); HDROP hDrop = reinterpret_cast<HDROP>(wParam); UINT uFilesCount = DragQueryFileW(hDrop, 0xFFFFFFFF, szFile, MAX_PATH); if (uFilesCount != 0) { UINT uRet = DragQueryFileW(hDrop, 0, (wchar_t*)szFile + 8, MAX_PATH); if ( uRet != 0) { wkeLoadURLW(this, szFile); SetWindowTextW(hwnd, szFile); } } DragFinish(hDrop); } return 0; //case WM_NCHITTEST: // if (IsWindow(m_hwnd) && flagsOff(GetWindowLong(m_hwnd, GWL_STYLE), WS_CAPTION)) // { // IWebkitObserverPtr observer = m_observer.lock(); // if (!observer) // break; // QPoint cursor(LOWORD(lParam), HIWORD(lParam)); // ScreenToClient(m_hwnd, &cursor); // QRect clientRect; // QSize clientSize; // GetClientRect(hwnd, &clientRect); // clientSize.cx = clientRect.width(); // clientSize.cy = clientRect.height(); // EWebkitHitTest hit = observer->onHitTest(QWebkitView(thisView), clientSize, cursor); // switch (hit) // { // case eWebkitHitLeftTop: return HTTOPLEFT; // case eWebkitHitLeft: return HTLEFT; // case eWebkitHitLeftBottom: return HTBOTTOMLEFT; // case eWebkitHitRightTop: return HTTOPRIGHT; // case eWebkitHitRight: return HTRIGHT; // case eWebkitHitRightBottom: return HTBOTTOMRIGHT; // case eWebkitHitTop: return HTTOP; // case eWebkitHitBottom: return HTBOTTOM; // case eWebkitHitCaption: return HTCAPTION; // case eWebkitHitClient: return HTCLIENT; // case eWebkitHitNone: return HTCLIENT; // } // } // break; //case WM_SETCURSOR: // if (IsWindow(m_hwnd) && flagsOff(GetWindowLong(m_hwnd, GWL_STYLE), WS_CAPTION)) // { // WORD hit = LOWORD(lParam); // switch (hit) // { // case HTCAPTION: // case HTSYSMENU: // case HTMENU: // case HTCLIENT: // SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW))); // return TRUE; // case HTTOP: // case HTBOTTOM: // SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENS))); // return TRUE; // case HTLEFT: // case HTRIGHT: // SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE))); // return TRUE; // case HTTOPLEFT: // case HTBOTTOMRIGHT: // SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENWSE))); // return TRUE; // case HTTOPRIGHT: // case HTBOTTOMLEFT: // SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENESW))); // return TRUE; // default: // SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW))); // return TRUE; // } // } // break; //case WM_NCLBUTTONDOWN: // if (IsWindow(m_hwnd) && flagsOff(GetWindowLong(m_hwnd, GWL_STYLE), WS_CAPTION)) // { // int hit = wParam; // switch (hit) // { // case HTTOP: SendMessageW(m_hwnd, WM_SYSCOMMAND, SC_SIZE|WMSZ_TOP, lParam); return 0; // case HTBOTTOM: SendMessageW(m_hwnd, WM_SYSCOMMAND, SC_SIZE|WMSZ_BOTTOM, lParam); return 0; // case HTLEFT: SendMessageW(m_hwnd, WM_SYSCOMMAND, SC_SIZE|WMSZ_LEFT, lParam); return 0; // case HTRIGHT: SendMessageW(m_hwnd, WM_SYSCOMMAND, SC_SIZE|WMSZ_RIGHT, lParam); return 0; // case HTTOPLEFT: SendMessageW(m_hwnd, WM_SYSCOMMAND, SC_SIZE|WMSZ_TOPLEFT, lParam); return 0; // case HTTOPRIGHT: SendMessageW(m_hwnd, WM_SYSCOMMAND, SC_SIZE|WMSZ_TOPRIGHT, lParam); return 0; // case HTBOTTOMLEFT: SendMessageW(m_hwnd, WM_SYSCOMMAND, SC_SIZE|WMSZ_BOTTOMLEFT, lParam); return 0; // case HTBOTTOMRIGHT: SendMessageW(m_hwnd, WM_SYSCOMMAND, SC_SIZE|WMSZ_BOTTOMRIGHT, lParam); return 0; // case HTCAPTION: SendMessageW(m_hwnd, WM_SYSCOMMAND, SC_MOVE|4, lParam); return 0; // } // } // break; //case WM_NCLBUTTONDBLCLK: // if (IsWindow(m_hwnd) && flagsOff(GetWindowLong(m_hwnd, GWL_STYLE), WS_CAPTION)) // { // int hit = wParam; // if (hit == HTCAPTION) // { // if (IsZoomed(m_hwnd)) // SendMessageW(m_hwnd, WM_SYSCOMMAND, SC_RESTORE, lParam); // else // SendMessageW(m_hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, lParam); // return 0; // } // } // break; case WM_KEYDOWN: { unsigned int virtualKeyCode = wParam; unsigned int flags = 0; if (HIWORD(lParam) & KF_REPEAT) flags |= WKE_REPEAT; if (HIWORD(lParam) & KF_EXTENDED) flags |= WKE_EXTENDED; if (wkeFireKeyDownEvent(this, virtualKeyCode, flags, false)) return 0; } break; case WM_KEYUP: { unsigned int virtualKeyCode = wParam; unsigned int flags = 0; if (HIWORD(lParam) & KF_REPEAT) flags |= WKE_REPEAT; if (HIWORD(lParam) & KF_EXTENDED) flags |= WKE_EXTENDED; if (wkeFireKeyUpEvent(this, virtualKeyCode, flags, false)) return 0; } break; case WM_CHAR: { unsigned int charCode = wParam; unsigned int flags = 0; if (HIWORD(lParam) & KF_REPEAT) flags |= WKE_REPEAT; if (HIWORD(lParam) & KF_EXTENDED) flags |= WKE_EXTENDED; if (wkeFireKeyPressEvent(this, charCode, flags, false)) return 0; } break; case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: case WM_LBUTTONDBLCLK: case WM_MBUTTONDBLCLK: case WM_RBUTTONDBLCLK: case WM_LBUTTONUP: case WM_MBUTTONUP: case WM_RBUTTONUP: case WM_MOUSEMOVE: { if (message == WM_LBUTTONDOWN || message == WM_MBUTTONDOWN || message == WM_RBUTTONDOWN) { SetFocus(hwnd); SetCapture(hwnd); } else if (message == WM_LBUTTONUP || message == WM_MBUTTONUP || message == WM_RBUTTONUP) { ReleaseCapture(); } int x = LOWORD(lParam); int y = HIWORD(lParam); unsigned int flags = 0; if (wParam & MK_CONTROL) flags |= WKE_CONTROL; if (wParam & MK_SHIFT) flags |= WKE_SHIFT; if (wParam & MK_LBUTTON) flags |= WKE_LBUTTON; if (wParam & MK_MBUTTON) flags |= WKE_MBUTTON; if (wParam & MK_RBUTTON) flags |= WKE_RBUTTON; if (wkeFireMouseEvent(this, message, x, y, flags)) return 0; } break; case WM_CONTEXTMENU: { POINT pt; pt.x = LOWORD(lParam); pt.y = HIWORD(lParam); if (pt.x != -1 && pt.y != -1) ScreenToClient(hwnd, &pt); unsigned int flags = 0; if (wParam & MK_CONTROL) flags |= WKE_CONTROL; if (wParam & MK_SHIFT) flags |= WKE_SHIFT; if (wParam & MK_LBUTTON) flags |= WKE_LBUTTON; if (wParam & MK_MBUTTON) flags |= WKE_MBUTTON; if (wParam & MK_RBUTTON) flags |= WKE_RBUTTON; if (wkeFireContextMenuEvent(this, pt.x, pt.y, flags)) return 0; } break; case WM_MOUSEWHEEL: { POINT pt; pt.x = LOWORD(lParam); pt.y = HIWORD(lParam); ScreenToClient(hwnd, &pt); int delta = GET_WHEEL_DELTA_WPARAM(wParam); unsigned int flags = 0; if (wParam & MK_CONTROL) flags |= WKE_CONTROL; if (wParam & MK_SHIFT) flags |= WKE_SHIFT; if (wParam & MK_LBUTTON) flags |= WKE_LBUTTON; if (wParam & MK_MBUTTON) flags |= WKE_MBUTTON; if (wParam & MK_RBUTTON) flags |= WKE_RBUTTON; if (wkeFireMouseWheelEvent(this, pt.x, pt.y, delta, flags)) return 0; } break; case WM_SETFOCUS: wkeSetFocus(this); return 0; case WM_KILLFOCUS: wkeKillFocus(this); return 0; case WM_IME_STARTCOMPOSITION: { wkeRect caret = wkeGetCaretRect(this); CANDIDATEFORM form; form.dwIndex = 0; form.dwStyle = CFS_EXCLUDE; form.ptCurrentPos.x = caret.x; form.ptCurrentPos.y = caret.y + caret.h; form.rcArea.top = caret.y; form.rcArea.bottom = caret.y + caret.h; form.rcArea.left = caret.x; form.rcArea.right = caret.x + caret.w; COMPOSITIONFORM compForm; compForm.ptCurrentPos = form.ptCurrentPos; compForm.rcArea = form.rcArea; compForm.dwStyle = CFS_POINT; HIMC hIMC = ImmGetContext(hwnd); ImmSetCandidateWindow(hIMC, &form); ImmSetCompositionWindow(hIMC, &compForm); ImmReleaseContext(hwnd, hIMC); } return 0; } return DefWindowProcW(hwnd, message, wParam, lParam); }
// Window callback function (handles window events) // static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { _GLFWwindow* window = (_GLFWwindow*) GetWindowLongPtrW(hWnd, 0); switch (uMsg) { case WM_NCCREATE: { CREATESTRUCTW* cs = (CREATESTRUCTW*) lParam; SetWindowLongPtrW(hWnd, 0, (LONG_PTR) cs->lpCreateParams); break; } case WM_SETFOCUS: { if (window->cursorMode != GLFW_CURSOR_NORMAL) _glfwPlatformApplyCursorMode(window); if (window->monitor && window->autoIconify) enterFullscreenMode(window); _glfwInputWindowFocus(window, GL_TRUE); return 0; } case WM_KILLFOCUS: { if (window->cursorMode != GLFW_CURSOR_NORMAL) restoreCursor(window); if (window->monitor && window->autoIconify) { _glfwPlatformIconifyWindow(window); leaveFullscreenMode(window); } _glfwInputWindowFocus(window, GL_FALSE); return 0; } case WM_SYSCOMMAND: { switch (wParam & 0xfff0) { case SC_SCREENSAVE: case SC_MONITORPOWER: { if (window->monitor) { // We are running in full screen mode, so disallow // screen saver and screen blanking return 0; } else break; } // User trying to access application menu using ALT? case SC_KEYMENU: return 0; } break; } case WM_CLOSE: { _glfwInputWindowCloseRequest(window); return 0; } case WM_KEYDOWN: case WM_SYSKEYDOWN: { const int scancode = (lParam >> 16) & 0x1ff; const int key = translateKey(wParam, lParam); if (key == _GLFW_KEY_INVALID) break; _glfwInputKey(window, key, scancode, GLFW_PRESS, getKeyMods()); break; } case WM_CHAR: { _glfwInputChar(window, (unsigned int) wParam, getKeyMods(), GL_TRUE); return 0; } case WM_SYSCHAR: { _glfwInputChar(window, (unsigned int) wParam, getKeyMods(), GL_FALSE); return 0; } case WM_UNICHAR: { // This message is not sent by Windows, but is sent by some // third-party input method engines if (wParam == UNICODE_NOCHAR) { // Returning TRUE here announces support for this message return TRUE; } _glfwInputChar(window, (unsigned int) wParam, getKeyMods(), GL_TRUE); return FALSE; } case WM_KEYUP: case WM_SYSKEYUP: { const int mods = getKeyMods(); const int scancode = (lParam >> 16) & 0x1ff; const int key = translateKey(wParam, lParam); if (key == _GLFW_KEY_INVALID) break; if (wParam == VK_SHIFT) { // Release both Shift keys on Shift up event, as only one event // is sent even if both keys are released _glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, scancode, GLFW_RELEASE, mods); _glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, scancode, GLFW_RELEASE, mods); } else if (wParam == VK_SNAPSHOT) { // Key down is not reported for the print screen key _glfwInputKey(window, key, scancode, GLFW_PRESS, mods); _glfwInputKey(window, key, scancode, GLFW_RELEASE, mods); } else _glfwInputKey(window, key, scancode, GLFW_RELEASE, mods); break; } case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: case WM_XBUTTONDOWN: { const int mods = getKeyMods(); SetCapture(hWnd); if (uMsg == WM_LBUTTONDOWN) _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS, mods); else if (uMsg == WM_RBUTTONDOWN) _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS, mods); else if (uMsg == WM_MBUTTONDOWN) _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_MIDDLE, GLFW_PRESS, mods); else { if (HIWORD(wParam) == XBUTTON1) _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_4, GLFW_PRESS, mods); else if (HIWORD(wParam) == XBUTTON2) _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_5, GLFW_PRESS, mods); return TRUE; } return 0; } case WM_LBUTTONUP: case WM_RBUTTONUP: case WM_MBUTTONUP: case WM_XBUTTONUP: { const int mods = getKeyMods(); ReleaseCapture(); if (uMsg == WM_LBUTTONUP) _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE, mods); else if (uMsg == WM_RBUTTONUP) _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE, mods); else if (uMsg == WM_MBUTTONUP) _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_MIDDLE, GLFW_RELEASE, mods); else { if (HIWORD(wParam) == XBUTTON1) _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_4, GLFW_RELEASE, mods); else if (HIWORD(wParam) == XBUTTON2) _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_5, GLFW_RELEASE, mods); return TRUE; } return 0; } case WM_MOUSEMOVE: { const int x = GET_X_LPARAM(lParam); const int y = GET_Y_LPARAM(lParam); if (window->cursorMode == GLFW_CURSOR_DISABLED) { if (_glfw.focusedWindow != window) break; _glfwInputCursorMotion(window, x - window->win32.cursorPosX, y - window->win32.cursorPosY); } else _glfwInputCursorMotion(window, x, y); window->win32.cursorPosX = x; window->win32.cursorPosY = y; if (!window->win32.cursorInside) { TRACKMOUSEEVENT tme; ZeroMemory(&tme, sizeof(tme)); tme.cbSize = sizeof(tme); tme.dwFlags = TME_LEAVE; tme.hwndTrack = window->win32.handle; TrackMouseEvent(&tme); window->win32.cursorInside = GL_TRUE; _glfwInputCursorEnter(window, GL_TRUE); } return 0; } case WM_MOUSELEAVE: { window->win32.cursorInside = GL_FALSE; _glfwInputCursorEnter(window, GL_FALSE); return 0; } case WM_MOUSEWHEEL: { _glfwInputScroll(window, 0.0, (SHORT) HIWORD(wParam) / (double) WHEEL_DELTA); return 0; } case WM_MOUSEHWHEEL: { // This message is only sent on Windows Vista and later // NOTE: The X-axis is inverted for consistency with OS X and X11. _glfwInputScroll(window, -((SHORT) HIWORD(wParam) / (double) WHEEL_DELTA), 0.0); return 0; } case WM_SIZE: { if (_glfw.focusedWindow == window) { if (window->cursorMode == GLFW_CURSOR_DISABLED) updateClipRect(window); } if (!window->win32.iconified && wParam == SIZE_MINIMIZED) { window->win32.iconified = GL_TRUE; _glfwInputWindowIconify(window, GL_TRUE); } else if (window->win32.iconified && (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED)) { window->win32.iconified = GL_FALSE; _glfwInputWindowIconify(window, GL_FALSE); } _glfwInputFramebufferSize(window, LOWORD(lParam), HIWORD(lParam)); _glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam)); return 0; } case WM_MOVE: { if (_glfw.focusedWindow == window) { if (window->cursorMode == GLFW_CURSOR_DISABLED) updateClipRect(window); } // NOTE: This cannot use LOWORD/HIWORD recommended by MSDN, as // those macros do not handle negative window positions correctly _glfwInputWindowPos(window, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); return 0; } case WM_PAINT: { _glfwInputWindowDamage(window); break; } case WM_ERASEBKGND: { return TRUE; } case WM_SETCURSOR: { if (_glfw.focusedWindow == window && LOWORD(lParam) == HTCLIENT) { if (window->cursorMode == GLFW_CURSOR_HIDDEN || window->cursorMode == GLFW_CURSOR_DISABLED) { SetCursor(NULL); return TRUE; } else if (window->cursor) { SetCursor(window->cursor->win32.handle); return TRUE; } } break; } case WM_DEVICECHANGE: { if (DBT_DEVNODES_CHANGED == wParam) { _glfwInputMonitorChange(); return TRUE; } break; } case WM_DWMCOMPOSITIONCHANGED: { if (_glfwIsCompositionEnabled()) { _GLFWwindow* previous = _glfwPlatformGetCurrentContext(); _glfwPlatformMakeContextCurrent(window); _glfwPlatformSwapInterval(0); _glfwPlatformMakeContextCurrent(previous); } // TODO: Restore vsync if compositing was disabled break; } case WM_DROPFILES: { HDROP hDrop = (HDROP) wParam; POINT pt; int i; const int count = DragQueryFileW(hDrop, 0xffffffff, NULL, 0); char** paths = calloc(count, sizeof(char*)); // Move the mouse to the position of the drop DragQueryPoint(hDrop, &pt); _glfwInputCursorMotion(window, pt.x, pt.y); for (i = 0; i < count; i++) { const UINT length = DragQueryFileW(hDrop, i, NULL, 0); WCHAR* buffer = calloc(length + 1, sizeof(WCHAR)); DragQueryFileW(hDrop, i, buffer, length + 1); paths[i] = _glfwCreateUTF8FromWideString(buffer); free(buffer); } _glfwInputDrop(window, count, (const char**) paths); for (i = 0; i < count; i++) free(paths[i]); free(paths); DragFinish(hDrop); return 0; } } return DefWindowProc(hWnd, uMsg, wParam, lParam); }
LRESULT CALLBACK SimulatorWin::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if (!_instance) return 0; switch (uMsg) { case WM_COMMAND: { if (HIWORD(wParam) == 0) { // menu WORD menuId = LOWORD(wParam); PlayerMenuItemWin *menuItem = _instance->_menuService->getItemByCommandId(menuId); if (menuItem) { AppEvent event("APP.EVENT", APP_EVENT_MENU); std::stringstream buf; buf << "{\"data\":\"" << menuItem->getMenuId().c_str() << "\""; buf << ",\"name\":" << "\"menuClicked\"" << "}"; event.setDataString(buf.str()); event.setUserData(menuItem); Director::getInstance()->getEventDispatcher()->dispatchEvent(&event); } if (menuId == ID_HELP_ABOUT) { onHelpAbout(); } } break; } case WM_KEYDOWN: { if (wParam == VK_F5) { PlayerProtocol::getInstance()->relaunch(); } break; } case WM_COPYDATA: { PCOPYDATASTRUCT pMyCDS = (PCOPYDATASTRUCT) lParam; if (pMyCDS->dwData == 1) { const char *szBuf = (const char*)(pMyCDS->lpData); SimulatorWin::getInstance()->writeDebugLog(szBuf); break; } } case WM_DESTROY: { DragAcceptFiles(hWnd, FALSE); break; } case WM_DROPFILES: { HDROP hDrop = (HDROP)wParam; const int count = DragQueryFileW(hDrop, 0xffffffff, NULL, 0); if (count > 0) { int fileIndex = 0; const UINT length = DragQueryFileW(hDrop, fileIndex, NULL, 0); WCHAR* buffer = (WCHAR*)calloc(length + 1, sizeof(WCHAR)); DragQueryFileW(hDrop, fileIndex, buffer, length + 1); char *utf8 = SimulatorWin::convertTCharToUtf8(buffer); std::string firstFile(utf8); CC_SAFE_FREE(utf8); DragFinish(hDrop); // broadcast drop event AppEvent forwardEvent("APP.EVENT.DROP", APP_EVENT_DROP); forwardEvent.setDataString(firstFile); Director::getInstance()->getEventDispatcher()->dispatchEvent(&forwardEvent); } } // WM_DROPFILES } return g_oldWindowProc(hWnd, uMsg, wParam, lParam); }
STDMETHODIMP VBoxDnDDropTarget::Drop(IDataObject *pDataObject, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) { RT_NOREF(pt); AssertPtrReturn(pDataObject, E_INVALIDARG); AssertPtrReturn(pdwEffect, E_INVALIDARG); LogFlowFunc(("mFormatEtc.cfFormat=%RI16 (%s), pDataObject=0x%p, grfKeyState=0x%x, x=%ld, y=%ld\n", mFormatEtc.cfFormat, VBoxDnDDataObject::ClipboardFormatToString(mFormatEtc.cfFormat), pDataObject, grfKeyState, pt.x, pt.y)); HRESULT hr = S_OK; if (mFormatEtc.cfFormat) /* Did we get a supported format yet? */ { /* Make sure the data object's data format is still valid. */ hr = pDataObject->QueryGetData(&mFormatEtc); AssertMsg(SUCCEEDED(hr), ("Data format changed to invalid between DragEnter() and Drop(), cfFormat=%RI16 (%s), hr=%Rhrc\n", mFormatEtc.cfFormat, VBoxDnDDataObject::ClipboardFormatToString(mFormatEtc.cfFormat), hr)); } int rc = VINF_SUCCESS; if (SUCCEEDED(hr)) { STGMEDIUM stgMed; hr = pDataObject->GetData(&mFormatEtc, &stgMed); if (SUCCEEDED(hr)) { /* * First stage: Prepare the access to the storage medium. * For now we only support HGLOBAL stuff. */ PVOID pvData = NULL; /** @todo Put this in an own union? */ switch (mFormatEtc.tymed) { case TYMED_HGLOBAL: pvData = GlobalLock(stgMed.hGlobal); if (!pvData) { LogFlowFunc(("Locking HGLOBAL storage failed with %Rrc\n", RTErrConvertFromWin32(GetLastError()))); rc = VERR_INVALID_HANDLE; hr = E_INVALIDARG; /* Set special hr for OLE. */ } break; default: AssertMsgFailed(("Storage medium type %RI32 supported\n", mFormatEtc.tymed)); rc = VERR_NOT_SUPPORTED; hr = DV_E_TYMED; /* Set special hr for OLE. */ break; } if (RT_SUCCESS(rc)) { /* * Second stage: Do the actual copying of the data object's data, * based on the storage medium type. */ switch (mFormatEtc.cfFormat) { case CF_TEXT: /* Fall through is intentional. */ case CF_UNICODETEXT: { AssertPtr(pvData); size_t cbSize = GlobalSize(pvData); LogFlowFunc(("CF_TEXT/CF_UNICODETEXT 0x%p got %zu bytes\n", pvData, cbSize)); if (cbSize) { char *pszText = NULL; rc = mFormatEtc.cfFormat == CF_TEXT /* ANSI codepage -> UTF-8 */ ? RTStrCurrentCPToUtf8(&pszText, (char *)pvData) /* Unicode -> UTF-8 */ : RTUtf16ToUtf8((PCRTUTF16)pvData, &pszText); if (RT_SUCCESS(rc)) { AssertPtr(pszText); size_t cbText = strlen(pszText) + 1; /* Include termination. */ mpvData = RTMemDup((void *)pszText, cbText); mcbData = cbText; RTStrFree(pszText); pszText = NULL; } } break; } case CF_HDROP: { AssertPtr(pvData); /* Convert to a string list, separated by \r\n. */ DROPFILES *pDropFiles = (DROPFILES *)pvData; AssertPtr(pDropFiles); bool fUnicode = RT_BOOL(pDropFiles->fWide); /* Get the offset of the file list. */ Assert(pDropFiles->pFiles >= sizeof(DROPFILES)); /* Note: This is *not* pDropFiles->pFiles! DragQueryFile only * will work with the plain storage medium pointer! */ HDROP hDrop = (HDROP)(pvData); /* First, get the file count. */ /** @todo Does this work on Windows 2000 / NT4? */ char *pszFiles = NULL; uint32_t cchFiles = 0; UINT cFiles = DragQueryFile(hDrop, UINT32_MAX /* iFile */, NULL /* lpszFile */, 0 /* cchFile */); LogFlowFunc(("CF_HDROP got %RU16 file(s)\n", cFiles)); for (UINT i = 0; i < cFiles; i++) { UINT cch = DragQueryFile(hDrop, i /* File index */, NULL /* Query size first */, 0 /* cchFile */); Assert(cch); if (RT_FAILURE(rc)) break; char *pszFile = NULL; /* UTF-8 version. */ UINT cchFile = 0; if (fUnicode) { /* Allocate enough space (including terminator). */ WCHAR *pwszFile = (WCHAR *)RTMemAlloc((cch + 1) * sizeof(WCHAR)); if (pwszFile) { cchFile = DragQueryFileW(hDrop, i /* File index */, pwszFile, cch + 1 /* Include terminator */); AssertMsg(cchFile == cch, ("cchCopied (%RU16) does not match cchFile (%RU16)\n", cchFile, cch)); rc = RTUtf16ToUtf8(pwszFile, &pszFile); AssertRC(rc); RTMemFree(pwszFile); } else rc = VERR_NO_MEMORY; } else /* ANSI */ { /* Allocate enough space (including terminator). */ pszFile = (char *)RTMemAlloc((cch + 1) * sizeof(char)); if (pszFile) { cchFile = DragQueryFileA(hDrop, i /* File index */, pszFile, cchFile + 1 /* Include terminator */); AssertMsg(cchFile == cch, ("cchCopied (%RU16) does not match cchFile (%RU16)\n", cchFile, cch)); } else rc = VERR_NO_MEMORY; } if (RT_SUCCESS(rc)) { LogFlowFunc(("\tFile: %s (cchFile=%RU32)\n", pszFile, cchFile)); rc = RTStrAAppendExN(&pszFiles, 1 /* cPairs */, pszFile, cchFile); if (RT_SUCCESS(rc)) cchFiles += cchFile; } if (pszFile) RTStrFree(pszFile); if (RT_FAILURE(rc)) break; /* Add separation between filenames. * Note: Also do this for the last element of the list. */ rc = RTStrAAppendExN(&pszFiles, 1 /* cPairs */, "\r\n", 2 /* Bytes */); if (RT_SUCCESS(rc)) cchFiles += 2; /* Include \r\n */ } if (RT_SUCCESS(rc)) { cchFiles += 1; /* Add string termination. */ uint32_t cbFiles = cchFiles * sizeof(char); LogFlowFunc(("cFiles=%u, cchFiles=%RU32, cbFiles=%RU32, pszFiles=0x%p\n", cFiles, cchFiles, cbFiles, pszFiles)); /* Translate the list into URI elements. */ DnDURIList lstURI; rc = lstURI.AppendNativePathsFromList(pszFiles, cbFiles, DNDURILIST_FLAGS_ABSOLUTE_PATHS); if (RT_SUCCESS(rc)) { RTCString strRoot = lstURI.RootToString(); size_t cbRoot = strRoot.length() + 1; /* Include termination */ mpvData = RTMemAlloc(cbRoot); if (mpvData) { memcpy(mpvData, strRoot.c_str(), cbRoot); mcbData = cbRoot; } else rc = VERR_NO_MEMORY; } } LogFlowFunc(("Building CF_HDROP list rc=%Rrc, pszFiles=0x%p, cFiles=%RU16, cchFiles=%RU32\n", rc, pszFiles, cFiles, cchFiles)); if (pszFiles) RTStrFree(pszFiles); break; } default: /* Note: Should not happen due to the checks done in DragEnter(). */ AssertMsgFailed(("Format of type %RI16 (%s) not supported\n", mFormatEtc.cfFormat, VBoxDnDDataObject::ClipboardFormatToString(mFormatEtc.cfFormat))); hr = DV_E_CLIPFORMAT; /* Set special hr for OLE. */ break; } /* * Third stage: Unlock + release access to the storage medium again. */ switch (mFormatEtc.tymed) { case TYMED_HGLOBAL: GlobalUnlock(stgMed.hGlobal); break; default: AssertMsgFailed(("Really should not happen -- see init stage!\n")); break; } } /* Release storage medium again. */ ReleaseStgMedium(&stgMed); /* Signal waiters. */ mDroppedRc = rc; RTSemEventSignal(hEventDrop); } } if (RT_SUCCESS(rc)) { /* Note: pt is not used since we don't need to differentiate within our * proxy window. */ *pdwEffect = VBoxDnDDropTarget::GetDropEffect(grfKeyState, *pdwEffect); } else *pdwEffect = DROPEFFECT_NONE; if (mpWndParent) mpWndParent->hide(); LogFlowFunc(("Returning with hr=%Rhrc (%Rrc), mFormatEtc.cfFormat=%RI16 (%s), *pdwEffect=%RI32\n", hr, rc, mFormatEtc.cfFormat, VBoxDnDDataObject::ClipboardFormatToString(mFormatEtc.cfFormat), *pdwEffect)); return hr; }
STDMETHODIMP CShellExt::InvokeGvim(HWND hParent, LPCSTR /* pszWorkingDir */, LPCSTR /* pszCmd */, LPCSTR /* pszParam */, int /* iShowCmd */) { wchar_t m_szFileUserClickedOn[BUFSIZE]; wchar_t cmdStrW[BUFSIZE]; UINT i; for (i = 0; i < cbFiles; i++) { DragQueryFileW((HDROP)medium.hGlobal, i, m_szFileUserClickedOn, sizeof(m_szFileUserClickedOn)); getGvimInvocationW(cmdStrW); wcscat(cmdStrW, L" \""); if ((wcslen(cmdStrW) + wcslen(m_szFileUserClickedOn) + 2) < BUFSIZE) { wcscat(cmdStrW, m_szFileUserClickedOn); wcscat(cmdStrW, L"\""); STARTUPINFOW si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); // Start the child process. if (!CreateProcessW(NULL, // No module name (use command line). cmdStrW, // Command line. NULL, // Process handle not inheritable. NULL, // Thread handle not inheritable. FALSE, // Set handle inheritance to FALSE. oldenv == NULL ? 0 : CREATE_UNICODE_ENVIRONMENT, oldenv, // Use unmodified environment block. NULL, // Use parent's starting directory. &si, // Pointer to STARTUPINFO structure. &pi) // Pointer to PROCESS_INFORMATION structure. ) { MessageBox( hParent, _("Error creating process: Check if gvim is in your path!"), _("gvimext.dll error"), MB_OK); } else { CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); } } else { MessageBox( hParent, _("Path length too long!"), _("gvimext.dll error"), MB_OK); } } return NOERROR; }
// IShellExtInit::Initialize // Initializes context menu for a file. STDMETHODIMP CWatchedOverlayIcon::Initialize( LPCITEMIDLIST pidlFolder, LPDATAOBJECT ptDataObject, HKEY hProgID ) { try { // Validate arguments if (nullptr == ptDataObject) { return E_INVALIDARG; } FORMATETC tFormat = { CF_HDROP, nullptr, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM tStg = { TYMED_HGLOBAL }; // Look for CF_HDROP data in the data object. If there // is no such data, return an error back to Explorer. if (FAILED(ptDataObject->GetData(&tFormat, &tStg))) { return E_INVALIDARG; } AutoReleaseStg ptStg(&tStg, ReleaseStgMedium); // Get a pointer to the actual data. AutoGlobalUnlock phDrop((HDROP) GlobalLock(tStg.hGlobal), GlobalUnlock); if (nullptr == phDrop) { return E_INVALIDARG; } // Find count of selected files UINT nFiles = DragQueryFileW(phDrop.get(), 0xFFFFFFFF, nullptr, 0); if (0 == nFiles) { return E_INVALIDARG; } _tSelectedFiles.clear(); // Add selected files to the list WCHAR wszFileName[MAX_PATH] = {0}; for (UINT nFile = 0; nFile < nFiles; nFile++) { if (0 == DragQueryFileW(phDrop.get(), nFile, wszFileName, MAX_PATH)) { return E_INVALIDARG; } _tSelectedFiles.push_back(std::wstring(wszFileName)); } return S_OK; } catch (...) { return E_FAIL; } }
// Window callback function (handles window messages) // static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { _GLFWwindow* window = (_GLFWwindow*) GetWindowLongPtrW(hWnd, 0); if (!window) { switch (uMsg) { case WM_NCCREATE: { CREATESTRUCTW* cs = (CREATESTRUCTW*) lParam; SetWindowLongPtrW(hWnd, 0, (LONG_PTR) cs->lpCreateParams); break; } case WM_DEVICECHANGE: { if (wParam == DBT_DEVNODES_CHANGED) { _glfwInputMonitorChange(); return TRUE; } break; } } return DefWindowProcW(hWnd, uMsg, wParam, lParam); } switch (uMsg) { case WM_SETFOCUS: { if (window->cursorMode == GLFW_CURSOR_DISABLED) _glfwPlatformSetCursorMode(window, GLFW_CURSOR_DISABLED); _glfwInputWindowFocus(window, GLFW_TRUE); return 0; } case WM_KILLFOCUS: { if (window->cursorMode == GLFW_CURSOR_DISABLED) _glfwPlatformSetCursorMode(window, GLFW_CURSOR_NORMAL); if (window->monitor && window->autoIconify) _glfwPlatformIconifyWindow(window); _glfwInputWindowFocus(window, GLFW_FALSE); return 0; } case WM_SYSCOMMAND: { switch (wParam & 0xfff0) { case SC_SCREENSAVE: case SC_MONITORPOWER: { if (window->monitor) { // We are running in full screen mode, so disallow // screen saver and screen blanking return 0; } else break; } // User trying to access application menu using ALT? case SC_KEYMENU: return 0; } break; } case WM_CLOSE: { _glfwInputWindowCloseRequest(window); return 0; } case WM_CHAR: case WM_SYSCHAR: case WM_UNICHAR: { const GLFWbool plain = (uMsg != WM_SYSCHAR); if (uMsg == WM_UNICHAR && wParam == UNICODE_NOCHAR) { // WM_UNICHAR is not sent by Windows, but is sent by some // third-party input method engine // Returning TRUE here announces support for this message return TRUE; } _glfwInputChar(window, (unsigned int) wParam, getKeyMods(), plain); return 0; } case WM_KEYDOWN: case WM_SYSKEYDOWN: case WM_KEYUP: case WM_SYSKEYUP: { const int key = translateKey(wParam, lParam); const int scancode = (lParam >> 16) & 0x1ff; const int action = ((lParam >> 31) & 1) ? GLFW_RELEASE : GLFW_PRESS; const int mods = getKeyMods(); if (key == _GLFW_KEY_INVALID) break; if (action == GLFW_RELEASE && wParam == VK_SHIFT) { // Release both Shift keys on Shift up event, as only one event // is sent even if both keys are released _glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, scancode, action, mods); _glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, scancode, action, mods); } else if (wParam == VK_SNAPSHOT) { // Key down is not reported for the Print Screen key _glfwInputKey(window, key, scancode, GLFW_PRESS, mods); _glfwInputKey(window, key, scancode, GLFW_RELEASE, mods); } else _glfwInputKey(window, key, scancode, action, mods); break; } case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: case WM_XBUTTONDOWN: case WM_LBUTTONUP: case WM_RBUTTONUP: case WM_MBUTTONUP: case WM_XBUTTONUP: { int button, action; if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP) button = GLFW_MOUSE_BUTTON_LEFT; else if (uMsg == WM_RBUTTONDOWN || uMsg == WM_RBUTTONUP) button = GLFW_MOUSE_BUTTON_RIGHT; else if (uMsg == WM_MBUTTONDOWN || uMsg == WM_MBUTTONUP) button = GLFW_MOUSE_BUTTON_MIDDLE; else if (GET_XBUTTON_WPARAM(wParam) == XBUTTON1) button = GLFW_MOUSE_BUTTON_4; else button = GLFW_MOUSE_BUTTON_5; if (uMsg == WM_LBUTTONDOWN || uMsg == WM_RBUTTONDOWN || uMsg == WM_MBUTTONDOWN || uMsg == WM_XBUTTONDOWN) { action = GLFW_PRESS; SetCapture(hWnd); } else { action = GLFW_RELEASE; ReleaseCapture(); } _glfwInputMouseClick(window, button, action, getKeyMods()); if (uMsg == WM_XBUTTONDOWN || uMsg == WM_XBUTTONUP) return TRUE; return 0; } case WM_MOUSEMOVE: { const int x = GET_X_LPARAM(lParam); const int y = GET_Y_LPARAM(lParam); if (window->cursorMode == GLFW_CURSOR_DISABLED) { if (_glfw.cursorWindow != window) break; _glfwInputCursorMotion(window, x - window->win32.cursorPosX, y - window->win32.cursorPosY); } else _glfwInputCursorMotion(window, x, y); window->win32.cursorPosX = x; window->win32.cursorPosY = y; if (!window->win32.cursorTracked) { TRACKMOUSEEVENT tme; ZeroMemory(&tme, sizeof(tme)); tme.cbSize = sizeof(tme); tme.dwFlags = TME_LEAVE; tme.hwndTrack = window->win32.handle; TrackMouseEvent(&tme); window->win32.cursorTracked = GLFW_TRUE; _glfwInputCursorEnter(window, GLFW_TRUE); } return 0; } case WM_MOUSELEAVE: { window->win32.cursorTracked = GLFW_FALSE; _glfwInputCursorEnter(window, GLFW_FALSE); return 0; } case WM_MOUSEWHEEL: { _glfwInputScroll(window, 0.0, (SHORT) HIWORD(wParam) / (double) WHEEL_DELTA); return 0; } case WM_MOUSEHWHEEL: { // This message is only sent on Windows Vista and later // NOTE: The X-axis is inverted for consistency with OS X and X11. _glfwInputScroll(window, -((SHORT) HIWORD(wParam) / (double) WHEEL_DELTA), 0.0); return 0; } case WM_SIZE: { if (_glfw.cursorWindow == window) { if (window->cursorMode == GLFW_CURSOR_DISABLED) updateClipRect(window); } if (!window->win32.iconified && wParam == SIZE_MINIMIZED) { window->win32.iconified = GLFW_TRUE; if (window->monitor) leaveFullscreenMode(window); _glfwInputWindowIconify(window, GLFW_TRUE); } else if (window->win32.iconified && (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED)) { window->win32.iconified = GLFW_FALSE; if (window->monitor) enterFullscreenMode(window); _glfwInputWindowIconify(window, GLFW_FALSE); } _glfwInputFramebufferSize(window, LOWORD(lParam), HIWORD(lParam)); _glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam)); return 0; } case WM_MOVE: { if (_glfw.cursorWindow == window) { if (window->cursorMode == GLFW_CURSOR_DISABLED) updateClipRect(window); } // NOTE: This cannot use LOWORD/HIWORD recommended by MSDN, as // those macros do not handle negative window positions correctly _glfwInputWindowPos(window, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); return 0; } case WM_SIZING: { if (window->win32.numer == GLFW_DONT_CARE || window->win32.denom == GLFW_DONT_CARE) { break; } applyAspectRatio(window, (int) wParam, (RECT*) lParam); return TRUE; } case WM_GETMINMAXINFO: { int xoff, yoff; MINMAXINFO* mmi = (MINMAXINFO*) lParam; getFullWindowSize(getWindowStyle(window), getWindowExStyle(window), 0, 0, &xoff, &yoff); if (window->win32.minwidth != GLFW_DONT_CARE && window->win32.minheight != GLFW_DONT_CARE) { mmi->ptMinTrackSize.x = window->win32.minwidth + xoff; mmi->ptMinTrackSize.y = window->win32.minheight + yoff; } if (window->win32.maxwidth != GLFW_DONT_CARE && window->win32.maxheight != GLFW_DONT_CARE) { mmi->ptMaxTrackSize.x = window->win32.maxwidth + xoff; mmi->ptMaxTrackSize.y = window->win32.maxheight + yoff; } return 0; } case WM_PAINT: { _glfwInputWindowDamage(window); break; } case WM_ERASEBKGND: { return TRUE; } case WM_SETCURSOR: { if (_glfw.cursorWindow == window && LOWORD(lParam) == HTCLIENT) { if (window->cursorMode == GLFW_CURSOR_HIDDEN || window->cursorMode == GLFW_CURSOR_DISABLED) { SetCursor(NULL); return TRUE; } else if (window->cursor) { SetCursor(window->cursor->win32.handle); return TRUE; } } break; } case WM_DPICHANGED: { RECT* rect = (RECT*) lParam; SetWindowPos(window->win32.handle, HWND_TOP, rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top, SWP_NOACTIVATE | SWP_NOZORDER); break; } case WM_DROPFILES: { HDROP drop = (HDROP) wParam; POINT pt; int i; const int count = DragQueryFileW(drop, 0xffffffff, NULL, 0); char** paths = calloc(count, sizeof(char*)); // Move the mouse to the position of the drop DragQueryPoint(drop, &pt); _glfwInputCursorMotion(window, pt.x, pt.y); for (i = 0; i < count; i++) { const UINT length = DragQueryFileW(drop, i, NULL, 0); WCHAR* buffer = calloc(length + 1, sizeof(WCHAR)); DragQueryFileW(drop, i, buffer, length + 1); paths[i] = _glfwCreateUTF8FromWideStringWin32(buffer); free(buffer); } _glfwInputDrop(window, count, (const char**) paths); for (i = 0; i < count; i++) free(paths[i]); free(paths); DragFinish(drop); return 0; } } return DefWindowProcW(hWnd, uMsg, wParam, lParam); }
static ws_uint_t drag_query_file(HDROP hdrop, ws_uint_t index, ws_char_w_t* buffer, ws_uint_t cchBuffer) { return DragQueryFileW(hdrop, index, buffer, cchBuffer); }
//------------------------------------------------------------------ LRESULT WinOISInputSupport::windowProc(UINT uMsg, WPARAM wParam, LPARAM lParam) { // The user has dropped files on the window switch(uMsg) { case WM_DROPFILES: { HDROP hDrop = (HDROP)wParam; WCHAR szFile[MAX_PATH] = { 0 }; UINT fcount = DragQueryFileW(hDrop, 0xFFFFFFFF, NULL, 0); for(UINT i = 0; i < fcount; i++) { DragQueryFileW(hDrop, i, szFile, MAX_PATH); String filename; if(sizeof(String::value_type) == sizeof(WCHAR)) { filename.assign( (const String::value_type*) szFile); } else { CodepageConverter::ByteBuffer buf( (const uint8*) szFile, wcslen(szFile) * sizeof(WCHAR) ); mUtf16Converter->bufferToUnicode(filename, buf); } InputSystem::getSingleton()._injectFileDrop( filename ); } ::DragFinish(hDrop); return 0; // the message was processed } // Hide WIN32 cursor when the cursor pos is within the window case WM_SETCURSOR: { int hitTest = LOWORD(lParam); if(hitTest == HTCLIENT) { hideWinCursor(); return TRUE; // to halt further processing } break; } case WM_MOUSELEAVE: { notifyMouseTrackingDisabled(); MouseEvent evt2(mMouseAbsX, mMouseAbsY, mMouseAbsZ); InputSystem::getSingleton()._injectMouseLeave(evt2); break; } case WM_NCMOUSEMOVE: { MouseEvent evt2(mMouseAbsX, mMouseAbsY, mMouseAbsZ); InputSystem::getSingleton()._injectMouseLeave(evt2); break; } case WM_MOUSEMOVE: { enableMouseTracking(); // we need to determine when the cursor moves outside the window int newAbsX = GET_X_LPARAM(lParam); int newAbsY = GET_Y_LPARAM(lParam); if(mMouseAbsX != newAbsX || mMouseAbsY != newAbsY) { mMouseAbsX = GET_X_LPARAM(lParam); mMouseAbsY = GET_Y_LPARAM(lParam); MouseEvent evt2(mMouseAbsX, mMouseAbsY, mMouseAbsZ); InputSystem::getSingleton()._injectMouseMove(evt2); } break; } case WM_MOUSEWHEEL: { mMouseAbsZ += GET_WHEEL_DELTA_WPARAM(wParam); MouseEvent evt2(mMouseAbsX, mMouseAbsY, mMouseAbsZ); InputSystem::getSingleton()._injectMouseMove(evt2); break; } case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: // Double-clicking the left mouse button actually generates a sequence of four messages: WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDBLCLK, and WM_LBUTTONUP (MSDN). { mMousePressed[0] = true; mMouseAbsX = GET_X_LPARAM(lParam); mMouseAbsY = GET_Y_LPARAM(lParam); MouseEvent evt2(mMouseAbsX, mMouseAbsY, mMouseAbsZ, MouseButton::LEFT); InputSystem::getSingleton()._injectMousePress(evt2); break; } case WM_LBUTTONUP: { mMousePressed[0] = false; mMouseAbsX = GET_X_LPARAM(lParam); mMouseAbsY = GET_Y_LPARAM(lParam); MouseEvent evt2(mMouseAbsX, mMouseAbsY, mMouseAbsZ, MouseButton::LEFT); InputSystem::getSingleton()._injectMouseRelease(evt2); break; } case WM_RBUTTONDOWN: { mMousePressed[1] = true; mMouseAbsX = GET_X_LPARAM(lParam); mMouseAbsY = GET_Y_LPARAM(lParam); MouseEvent evt2(mMouseAbsX, mMouseAbsY, mMouseAbsZ, MouseButton::RIGHT); InputSystem::getSingleton()._injectMousePress(evt2); break; } case WM_RBUTTONUP: { mMousePressed[1] = false; mMouseAbsX = GET_X_LPARAM(lParam); mMouseAbsY = GET_Y_LPARAM(lParam); MouseEvent evt2(mMouseAbsX, mMouseAbsY, mMouseAbsZ, MouseButton::RIGHT); InputSystem::getSingleton()._injectMouseRelease(evt2); break; } case WM_MBUTTONDOWN: { mMousePressed[2] = true; mMouseAbsX = GET_X_LPARAM(lParam); mMouseAbsY = GET_Y_LPARAM(lParam); MouseEvent evt2(mMouseAbsX, mMouseAbsY, mMouseAbsZ, MouseButton::MIDDLE); InputSystem::getSingleton()._injectMousePress(evt2); break; } case WM_MBUTTONUP: { mMousePressed[2] = false; mMouseAbsX = GET_X_LPARAM(lParam); mMouseAbsY = GET_Y_LPARAM(lParam); MouseEvent evt2(mMouseAbsX, mMouseAbsY, mMouseAbsZ, MouseButton::MIDDLE); InputSystem::getSingleton()._injectMouseRelease(evt2); break; } } // call Ogre's window procedure return CallWindowProc((WNDPROC)mOldWindowProc, mHwnd, uMsg, wParam, lParam); }
LRESULT MusPlayer_WinAPI::MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_HSCROLL: { if(m_self->m_volume == (HWND)lParam) { switch(LOWORD(wParam)) { case TB_ENDTRACK: case TB_THUMBPOSITION: case TB_THUMBTRACK: case SB_LEFT: case SB_RIGHT: DWORD dwPos;// current position of slider dwPos = SendMessageW(m_self->m_volume, TBM_GETPOS, 0, 0); SendMessageW(m_self->m_volume, TBM_SETPOS, (WPARAM)TRUE, //redraw flag (LPARAM)dwPos); m_self->on_volume_valueChanged(dwPos); break; default: break; } } break; } case WM_COMMAND: { switch(HIWORD(wParam)) { case BN_CLICKED: { switch( LOWORD(wParam) ) { case CMD_Open: m_self->on_open_clicked(); break; case CMD_Play: m_self->on_play_clicked(); break; case CMD_Stop: m_self->on_stop_clicked(); break; case CMD_SetDefault: m_self->on_resetDefaultADLMIDI_clicked(); break; case CMD_RecordWave: { BOOL checked = IsDlgButtonChecked(hWnd, CMD_RecordWave); if (checked) { CheckDlgButton(hWnd, CMD_RecordWave, BST_UNCHECKED); m_self->on_recordWav_clicked(false); } else { CheckDlgButton(hWnd, CMD_RecordWave, BST_CHECKED); m_self->on_recordWav_clicked(true); } break; } case CMD_Reverb: { if (PGE_MusicPlayer::reverbEnabled) { CheckMenuItem(m_self->m_contextMenu, CMD_Reverb, MF_UNCHECKED); Mix_UnregisterEffect(MIX_CHANNEL_POST, reverbEffect); PGE_MusicPlayer::reverbEnabled = false; } else { CheckMenuItem(m_self->m_contextMenu, CMD_Reverb, MF_CHECKED); Mix_RegisterEffect(MIX_CHANNEL_POST, reverbEffect, reverbEffectDone, NULL); PGE_MusicPlayer::reverbEnabled = true; } break; } case CMD_ShowLicense: { ShellExecuteW(0, 0, L"http://www.gnu.org/licenses/gpl", 0, 0 , SW_SHOW); break; } case CMD_ShowSource: { ShellExecuteW(0, 0, L"https://github.com/WohlSoft/PGE-Project", 0, 0 , SW_SHOW); break; } default: break; } break; } } break; } case WM_DROPFILES: { HDROP hDropInfo = (HDROP)wParam; wchar_t sItem[MAX_PATH]; memset(sItem, 0, MAX_PATH*sizeof(wchar_t)); if(DragQueryFileW(hDropInfo, 0, (LPWSTR)sItem, sizeof(sItem))) { m_self->openMusicByArg(Wstr2Str(sItem)); } DragFinish(hDropInfo); break; } case WM_CONTEXTMENU: { SetForegroundWindow(hWnd); TrackPopupMenu(m_self->m_contextMenu,TPM_RIGHTBUTTON|TPM_TOPALIGN|TPM_LEFTALIGN, LOWORD( lParam ), HIWORD( lParam ), 0, hWnd, NULL); break; } //Инфо о минимальном и максимальном размере окна case WM_GETMINMAXINFO: { MINMAXINFO *minMax = (MINMAXINFO*)lParam; minMax->ptMinTrackSize.x = 350; minMax->ptMinTrackSize.y = m_self->m_height; break; } case WM_CREATE: { m_self->initUI(hWnd); break; } //Окно было закрыто case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefWindowProc(hWnd, msg, wParam, lParam); }