KIO
krun_win.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2008 Jarosław Staniek <staniek@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "krun.h" 00021 #include "krun_p.h" 00022 00023 #include <QDir> 00024 #include <QWidget> 00025 00026 #include <windows.h> 00027 00028 // TODO move to a shared lib 00029 static int runDll(WId windowId, const QString& libraryName, const QByteArray& functionName, 00030 const QString& arguments) 00031 { 00032 HMODULE libHandle = LoadLibraryW( (LPCWSTR)libraryName.utf16() ); 00033 if (!libHandle) 00034 return 0; 00035 typedef int (WINAPI *FunctionType)(HWND, HMODULE, LPCWSTR, int); 00036 #ifdef _WIN32_WCE 00037 QString functionNamestr = QString(functionName); 00038 FunctionType function 00039 = (FunctionType)GetProcAddressW( libHandle, functionNamestr.utf16() ); 00040 #else 00041 FunctionType function 00042 = (FunctionType)GetProcAddress( libHandle, functionName.constData() ); 00043 #endif 00044 if (!function) 00045 return 0; 00046 int result = function((HWND)windowId, libHandle, (LPCWSTR)arguments.utf16(), SW_SHOW); 00047 FreeLibrary(libHandle); 00048 return result; 00049 } 00050 00051 static int runDll(WId windowId, const QString& libraryName, const QByteArray& functionName, 00052 const QByteArray& arguments) 00053 { 00054 HMODULE libHandle = LoadLibraryW( (LPCWSTR)libraryName.utf16() ); 00055 if (!libHandle) 00056 return 0; 00057 typedef int (WINAPI *FunctionType)(HWND, HMODULE, LPCSTR, int); 00058 #ifdef _WIN32_WCE 00059 QString functionNamestr = QString(functionName); 00060 FunctionType function 00061 = (FunctionType)GetProcAddressW( libHandle, functionNamestr.utf16() ); 00062 #else 00063 FunctionType function 00064 = (FunctionType)GetProcAddress( libHandle, functionName.constData() ); 00065 #endif 00066 if (!function) 00067 return 0; 00068 int result = function((HWND)windowId, libHandle, (LPCSTR)arguments.constData(), SW_SHOW); 00069 FreeLibrary(libHandle); 00070 return result; 00071 } 00072 00073 // TODO move to a shared lib 00074 static int runDll(QWidget* parent, const QString& libraryName, const QByteArray& functionName, 00075 const QString& arguments) 00076 { 00077 return runDll(parent ? parent->winId() : 0, libraryName, functionName, arguments); 00078 } 00079 00080 00081 // Windows implementation using "OpenAs_RunDLL" entry 00082 bool KRun::KRunPrivate::displayNativeOpenWithDialog( const KUrl::List& lst, QWidget* window, bool tempFiles, 00083 const QString& suggestedFileName, const QByteArray& asn ) 00084 { 00085 Q_UNUSED(tempFiles); 00086 Q_UNUSED(suggestedFileName); 00087 Q_UNUSED(asn); 00088 00089 QStringList fnames; 00090 foreach( const KUrl& url, lst ) 00091 { 00092 fnames += QDir::toNativeSeparators( url.path() ); 00093 } 00094 int result = runDll( window, 00095 QLatin1String("shell32.dll"), 00096 "OpenAs_RunDLLW", 00097 fnames.join(QLatin1String(" ")) ); 00098 return result == 0; 00099 }
KDE 4.6 API Reference