diff options
-rw-r--r-- | plugins/SendScreenshotPlus/docs/credits.txt | 2 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/res/resource.rc | 17 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/res/version.rc | 75 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/Main.cpp | 707 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/Main.h | 113 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/UAboutForm.cpp | 414 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/UAboutForm.h | 124 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/UMainForm.cpp | 2356 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/UMainForm.h | 285 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/ctrl_button.cpp | 1301 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/version.h | 35 |
11 files changed, 2733 insertions, 2696 deletions
diff --git a/plugins/SendScreenshotPlus/docs/credits.txt b/plugins/SendScreenshotPlus/docs/credits.txt index 122042be3b..006c3db1f1 100644 --- a/plugins/SendScreenshotPlus/docs/credits.txt +++ b/plugins/SendScreenshotPlus/docs/credits.txt @@ -7,4 +7,4 @@ Thanks to the "UserinfoEx" programmers group for the nice button class code.
http://code.google.com/p/userinfoex/
-and special thanks to all beta-testers...
+and special thanks to all beta-testers...
\ No newline at end of file diff --git a/plugins/SendScreenshotPlus/res/resource.rc b/plugins/SendScreenshotPlus/res/resource.rc index 8fcc9f5fbc..caa323d60b 100644 --- a/plugins/SendScreenshotPlus/res/resource.rc +++ b/plugins/SendScreenshotPlus/res/resource.rc @@ -7,19 +7,14 @@ //
// Generated from the TEXTINCLUDE 2 resource.
//
-#include "afxres.h"
+#include <WinResrc.h>
+#define IDC_STATIC -1
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
-// Deutsch (Deutschland) resources
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU)
-#ifdef _WIN32
-LANGUAGE LANG_GERMAN, SUBLANG_GERMAN
-#pragma code_page(1252)
-#endif //_WIN32
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
/////////////////////////////////////////////////////////////////////////////
//
@@ -86,8 +81,8 @@ BEGIN CONTROL "Credits >",IDA_CONTRIBLINK,"UInfoButtonClass",WS_GROUP | WS_TABSTOP,5,166,61,14,WS_EX_NOACTIVATE | 0x10000000L
PUSHBUTTON "&Close",IDA_btnClose,149,166,60,14
LTEXT "",IDC_WHITERECT,0,25,213,135,NOT WS_GROUP
- EDITTEXT IDC_LICENSE,5,37,204,95,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER | WS_VSCROLL
- EDITTEXT IDC_CREDIT,5,37,204,95,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER | WS_VSCROLL
+ EDITTEXT IDC_LICENSE,5,27,204,131,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER | WS_VSCROLL
+ EDITTEXT IDC_CREDIT,5,27,204,131,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,0,160,213,1
END
@@ -262,8 +257,6 @@ BEGIN END
END
#endif // APSTUDIO_INVOKED
-
-#endif // Deutsch (Deutschland) resources
/////////////////////////////////////////////////////////////////////////////
diff --git a/plugins/SendScreenshotPlus/res/version.rc b/plugins/SendScreenshotPlus/res/version.rc index 5bfbab4754..8ca158e9d5 100644 --- a/plugins/SendScreenshotPlus/res/version.rc +++ b/plugins/SendScreenshotPlus/res/version.rc @@ -1,38 +1,37 @@ -// Microsoft Visual C++ generated resource script.
-//
-#ifdef APSTUDIO_INVOKED
-#error this file is not editable by Microsoft Visual C++
-#endif //APSTUDIO_INVOKED
-
-#include "afxres.h"
-#include "..\src\version.h"
-
-VS_VERSION_INFO VERSIONINFO
- FILEVERSION __FILEVERSION_STRING
- PRODUCTVERSION __FILEVERSION_STRING
- FILEFLAGSMASK 0x17L
-#ifdef _DEBUG
- FILEFLAGS 0x1L
-#else
- FILEFLAGS 0x0L
-#endif
- FILEOS 0x4L
- FILETYPE 0x0L
- FILESUBTYPE 0x0L
-BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "000004b0"
- BEGIN
- VALUE "FileDescription", __DESCRIPTION
- VALUE "InternalName", __PLUGIN_NAME
- VALUE "LegalCopyright", __COPYRIGHT
- VALUE "OriginalFilename", __FILENAME
- VALUE "ProductName", __PLUGIN_NAME
- END
- END
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x0, 1200
- END
-END
+// Microsoft Visual C++ generated resource script. +// +#ifdef APSTUDIO_INVOKED +#error this file is not editable by Microsoft Visual C++ +#endif //APSTUDIO_INVOKED + +#include "..\src\version.h" + +VS_VERSION_INFO VERSIONINFO + FILEVERSION __FILEVERSION_STRING + PRODUCTVERSION __FILEVERSION_STRING + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "FileDescription", __DESCRIPTION + VALUE "InternalName", __PLUGIN_NAME + VALUE "LegalCopyright", __COPYRIGHT + VALUE "OriginalFilename", __FILENAME + VALUE "ProductName", __PLUGIN_NAME + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END diff --git a/plugins/SendScreenshotPlus/src/Main.cpp b/plugins/SendScreenshotPlus/src/Main.cpp index 0ecd0a691f..162dbd452d 100644 --- a/plugins/SendScreenshotPlus/src/Main.cpp +++ b/plugins/SendScreenshotPlus/src/Main.cpp @@ -1,345 +1,362 @@ -/*
-
-Miranda IM: the free IM client for Microsoft* Windows*
-Copyright 2000-2009 Miranda ICQ/IM project,
-
-This file is part of Send Screenshot Plus, a Miranda IM plugin.
-Copyright (c) 2010 Ing.U.Horn
-
-Parts of this file based on original sorce code
-(c) 2004-2006 Sérgio Vieira Rolanski (portet from Borland C++)
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include "global.h"
-
-// Prototypes ///////////////////////////////////////////////////////////////////////////
-//LIST_INTERFACE li;
-FI_INTERFACE *FIP = 0;
-HINSTANCE hInst; //!< Global reference to the application
-MGLOBAL myGlobals;
-int hLangpack;
-
-
-//Information gathered by Miranda, displayed in the plugin pane of the Option Dialog
-PLUGININFOEX pluginInfo={
- sizeof(PLUGININFOEX),
- __PLUGIN_NAME,
- PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
- __DESCRIPTION,
- __AUTHOR,
- __AUTHOREMAIL,
- __COPYRIGHT,
- __AUTHORWEB,
- UNICODE_AWARE,
- // {ED39AF7C-BECD-404E-9499-4D04F711B9CB}
- {0xed39af7c, 0xbecd, 0x404e, {0x94, 0x99, 0x4d, 0x04, 0xf7, 0x11, 0xb9, 0xcb}}
-};
-
-//static char szSendSS[]=SZ_SENDSS;
-
-HANDLE hsvc_SendScreenshot=0;
-HANDLE hsvc_SendDesktop=0;
-HANDLE hsvc_EditBitmap=0;
-HANDLE hsvc_Send2ImageShack=0;
-
-HANDLE hNetlibUser = 0; //!< Netlib Register User
-HANDLE hFolderScreenshot=0;
-
-// Functions ////////////////////////////////////////////////////////////////////////////
-
-/*---------------------------------------------------------------------------
-* DLL entry point - Required to store the instance handle
-*/
-BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
-{
- hInst = hinstDLL;
- return TRUE;
-}
-
-/*---------------------------------------------------------------------------
-* Called by Miranda to get the information associated to this plugin.
-* It only returns the PLUGININFO structure, without any test on the version
-* @param mirandaVersion The version of the application calling this function
-*/
-extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
-{
- return &pluginInfo;
-}
-
-
-/*---------------------------------------------------------------------------
-* Initializes the services provided and the link to those needed
-* Called when the plugin is loaded into Miranda
-*/
-extern "C" int __declspec(dllexport) Load(void)
-{
- mir_getLP(&pluginInfo);
- INT_PTR result = CallService(MS_IMG_GETINTERFACE, FI_IF_VERSION, (LPARAM)&FIP);
-
- if(FIP == NULL || result != S_OK) {
- MessageBoxEx(NULL, TranslateT("Fatal error, image services not found. Send Screenshot will be disabled."), TranslateT("Error"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0);
- return 1;
- }
-
- // load icon library (use UserInfoEx icon Pack)
- IcoLib_LoadModule();
-
- HookEvent(ME_SYSTEM_MODULESLOADED, hook_ModulesLoaded);
- HookEvent(ME_SYSTEM_PRESHUTDOWN, hook_SystemPShutdown);
-
- AddMenuItems();
- RegisterServices();
-
- return 0;
-}
-
-int hook_ModulesLoaded(WPARAM, LPARAM)
-{
- myGlobals.PopupExist = ServiceExists(MS_POPUP_ADDPOPUP);
- myGlobals.PopupActionsExist = ServiceExists(MS_POPUP_REGISTERACTIONS);
- myGlobals.PluginHTTPExist = ServiceExists(MS_HTTP_ACCEPT_CONNECTIONS);
- myGlobals.PluginFTPExist = ServiceExists(MS_FTPFILE_SHAREFILE);
-
- // Netlib register
- NetlibInit();
-
- // load my button class
- if(!ServiceExists("UserInfo/vCard/Export"))
- CtrlButtonLoadModule();
-
- // Folders plugin support
- hFolderScreenshot = FoldersRegisterCustomPathT(LPGEN("SendSS"), LPGEN("Screenshots"),
- _T(PROFILE_PATH)_T("\\")_T(CURRENT_PROFILE)_T("\\Screenshots"));
-
- return 0;
-}
-
-/*---------------------------------------------------------------------------
-* Prepare the plugin to stop
-* Called by Miranda when it will exit or when the plugin gets deselected
-*/
-
-extern "C" int __declspec(dllexport) Unload(void)
-{
- return 0;
-}
-
-int hook_SystemPShutdown(WPARAM wParam, LPARAM lParam)
-{
- // Netlib unregister
- NetlibClose();
-
- // uninitialize classes
- CtrlButtonUnloadModule();
- return 0;
-}
-
-//---------------------------------------------------------------------------
-// Netlib
-HANDLE NetlibInit(void)
-{
- NETLIBUSER nlu = { sizeof(nlu) };
- nlu.szSettingsModule = __PLUGIN_NAME;
- nlu.ptszDescriptiveName = TranslateT("SendSS HTTP connections");
- nlu.flags = NUF_OUTGOING|NUF_HTTPCONNS|NUF_TCHAR; //|NUF_NOHTTPSOPTION;
- return hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
-}
-
-void NetlibClose(void) {
- Netlib_CloseHandle(hNetlibUser);
-}
-
-
-//---------------------------------------------------------------------------
-// Callback function of service
-// 1. Send a screenshot of the desktop to the selected contact
-// wParam = contact handle
-// lParam = 0
-// 2. Open the capture dialog in take screenshot only mode (it will not be sent)
-// wParam = 0
-// lParam = anything but 0
-INT_PTR service_CaptureAndSendDesktop(WPARAM wParam, LPARAM lParam) {
- TfrmMain *frmMain=new TfrmMain();
- if (!frmMain) {
- MessageBoxEx(NULL, TranslateT("Could not create main dialog."), TranslateT("Error"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0);
- return -1;
- }
- LPTSTR pszPath = GetCustomPath();
- if(pszPath)
- {
- HANDLE hContact = (HANDLE) wParam;
- LPSTR pszProto = GetContactProto(hContact);
- bool bChatRoom = db_get_b(hContact, pszProto, "ChatRoom", 0) != 0;
- frmMain->m_opt_chkTimed = false;
- frmMain->m_opt_tabCapture = 1;
- frmMain->m_opt_cboxDesktop = 0;
- frmMain->m_opt_chkEditor = false;
- frmMain->m_opt_cboxSendBy = bChatRoom ? SS_IMAGESHACK:SS_FILESEND;
- frmMain->Init(pszPath, hContact); // this method create the window hidden.
- frmMain->btnCaptureClick(); // this method will call Close()
- mir_free(pszPath);
- }
- return 0;
-}
-
-//---------------------------------------------------------------------------
-// Callback function of service for contact menu and main menu
-// wParam = contact handle
-// lParam = 0
-INT_PTR service_OpenCaptureDialog(WPARAM wParam, LPARAM lParam) {
- TfrmMain *frmMain=new TfrmMain();
- if (!frmMain) {
- MessageBoxEx(NULL, TranslateT("Could not create main dialog."), TranslateT("Error"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0);
- return -1;
- }
-
- LPTSTR pszPath = GetCustomPath();
- if(pszPath)
- {
- frmMain->Init(pszPath, (HANDLE)wParam);
- mir_free(pszPath);
- }
- frmMain->Show();
- return 0;
-}
-
-//---------------------------------------------------------------------------
-// Edit a in-memory bitmap on the edit window
-// wParam = (SENDSSCB) callback function address to call when editing is done
-// lParam = (HBITMAP) bitmap handle, a copy is made so the calling function can free this handle after the service function returns
-// Returns:
-INT_PTR service_EditBitmap(WPARAM wParam, LPARAM lParam) {
-/* TfrmEdit *frmEdit=new TfrmEdit(NULL);
- if (!frmEdit)
- return -1;
-
- Graphics::TBitmap *bitmap=new Graphics::TBitmap();
- if (!bitmap)
- return -2;
-
- bitmap->Handle = (void*)lParam;
- frmEdit->InitEditor(bitmap); // a copy of the bitmap is made inside this function
- frmEdit->Show();
- delete bitmap;
-*/
- return 0;
-}
-
-//---------------------------------------------------------------------------
-// Callback function of service for sending image to imageshack.us
-// wParam = (char*)filename
-// lParam = (HANDLE)contact (can be null)
-INT_PTR service_Send2ImageShack(WPARAM wParam, LPARAM lParam) {
- LPSTR result = NULL;
- CSendImageShack* cSend = new CSendImageShack(NULL, (HANDLE)lParam, false);
- cSend->m_pszFile = mir_a2t((char*)wParam);
- cSend->m_bDeleteAfterSend = FALSE;
- if (lParam != NULL) {
- cSend->Send();
- return 0;
- }
- cSend->SendSync(TRUE);
- cSend->Send();
- if (cSend->GetURL()) {
- result = mir_strdup(cSend->GetURL());
- }
- else {
- result = cSend->GetError();
- }
- delete cSend;
- return (INT_PTR)result;
-}
-
-//---------------------------------------------------------------------------
-// Add SendSS menu item in contact menu
-void AddMenuItems(void)
-{
- // Common
- CLISTMENUITEM mi = { sizeof(mi) };
- mi.flags = CMIF_ROOTHANDLE | CMIF_TCHAR;
- mi.hParentMenu = HGENMENU_ROOT;
-
- // Add item to contact menu
- mi.position = 1000000;
- mi.ptszName = LPGENT("Send Screenshot");
- mi.hIcon = IcoLib_GetIcon(ICO_PLUG_SSWINDOW2);
- mi.pszService = MS_SENDSS_OPENDIALOG;
- Menu_AddContactMenuItem(&mi);
-
- // Add item to contact menu
- mi.position = 1000001;
- mi.ptszName = LPGENT("Send desktop screenshot");
- mi.hIcon = IcoLib_GetIcon(ICO_PLUG_SSWINDOW2);
- mi.pszService = MS_SENDSS_SENDDESKTOP;
- Menu_AddContactMenuItem(&mi);
-
- // Add item to main menu
- mi.position = 1000001;
- mi.ptszName = LPGENT("Take a screenshot");
- mi.hIcon = IcoLib_GetIcon(ICO_PLUG_SSWINDOW2);
- mi.pszService = MS_SENDSS_OPENDIALOG;
- Menu_AddMainMenuItem(&mi);
-}
-
-//---------------------------------------------------------------------------
-// Register Send screenshot services
-int RegisterServices(void) {
- hsvc_SendScreenshot = CreateServiceFunction(MS_SENDSS_OPENDIALOG, service_OpenCaptureDialog);
- if (!hsvc_SendScreenshot)
- MessageBoxEx(NULL, TranslateT("Could not register miranda service."), _T("MS_SENDSS_OPENDIALOG"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0);
-
- hsvc_SendDesktop = CreateServiceFunction(MS_SENDSS_SENDDESKTOP, service_CaptureAndSendDesktop);
- if (!hsvc_SendDesktop)
- MessageBoxEx(NULL, TranslateT("Could not register miranda service."), _T("MS_SENDSS_SENDDESKTOP"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0);
-
- hsvc_EditBitmap = CreateServiceFunction(MS_SENDSS_EDITBITMAP, service_EditBitmap);
- if (!hsvc_EditBitmap)
- MessageBoxEx(NULL, TranslateT("Could not register miranda service."), _T("MS_SENDSS_EDITBITMAP"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0);
-
- hsvc_Send2ImageShack = CreateServiceFunction(MS_SENDSS_SEND2IMAGESHACK, service_Send2ImageShack);
- if (!hsvc_Send2ImageShack)
- MessageBoxEx(NULL, TranslateT("Could not register miranda service."), _T("MS_SENDSS_SEND2IMAGESHACK"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0);
-
- return 0;
-}
-
-//---------------------------------------------------------------------------
-LPTSTR GetCustomPath() {
- LPTSTR pszPath = Utils_ReplaceVarsT(_T("%miranda_userdata%\\Screenshots"));
- if (hFolderScreenshot) {
- TCHAR szPath[1024] = {'\0'};
- FoldersGetCustomPathT(hFolderScreenshot, szPath, 1024, pszPath);
- mir_freeAndNil(pszPath);
- pszPath = mir_tstrdup(szPath);
- }
- if(pszPath == NULL)
- {
- MessageBox(NULL, _T("Can not retrieve Screenshot path."), _T("Send Screenshot"), MB_OK | MB_ICONERROR | MB_APPLMODAL);
- return 0;
- }
-
- int result = CreateDirectoryTreeT(pszPath);
- if(result != NULL)
- {
- TCHAR szError[MAX_PATH];
- mir_sntprintf(szError,MAX_PATH,TranslateT("Could not create Screenshot folder (error code: %d):\n%s\nDo you have write permissions?"),result,pszPath);
- MessageBox(NULL, szError, _T("Send Screenshot"), MB_OK | MB_ICONERROR | MB_APPLMODAL);
- mir_free(pszPath);
- return 0;
- }
- return pszPath;
-}
+/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Sérgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "global.h" + +// Prototypes /////////////////////////////////////////////////////////////////////////// +//LIST_INTERFACE li; +FI_INTERFACE *FIP = 0; +HINSTANCE hInst; //!< Global reference to the application +MGLOBAL myGlobals; +int hLangpack; + + +//Information gathered by Miranda, displayed in the plugin pane of the Option Dialog +PLUGININFOEX pluginInfo={ + sizeof(PLUGININFOEX), + __PLUGIN_NAME, + PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), + __DESCRIPTION, + __AUTHOR, + __AUTHOREMAIL, + __COPYRIGHT, + __AUTHORWEB, + UNICODE_AWARE, + // {ED39AF7C-BECD-404E-9499-4D04F711B9CB} + {0xed39af7c, 0xbecd, 0x404e, {0x94, 0x99, 0x4d, 0x04, 0xf7, 0x11, 0xb9, 0xcb}} +}; + +//static char szSendSS[]=SZ_SENDSS; + +HANDLE hsvc_SendScreenshot=0; +HANDLE hsvc_SendDesktop=0; +HANDLE hsvc_EditBitmap=0; +HANDLE hsvc_Send2ImageShack=0; + +HANDLE hNetlibUser = 0; //!< Netlib Register User +HANDLE hFolderScreenshot=0; + +// Functions //////////////////////////////////////////////////////////////////////////// + +/*--------------------------------------------------------------------------- +* DLL entry point - Required to store the instance handle +*/ +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + hInst=hinstDLL; + return TRUE; +} + +/*--------------------------------------------------------------------------- +* Called by Miranda to get the information associated to this plugin. +* It only returns the PLUGININFO structure, without any test on the version +* @param mirandaVersion The version of the application calling this function +*/ +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +{ + return &pluginInfo; +} + + +/*--------------------------------------------------------------------------- +* Initializes the services provided and the link to those needed +* Called when the plugin is loaded into Miranda +*/ +HANDLE g_hookModulesLoaded=0; +HANDLE g_hookSystemPreShutdown=0; +extern "C" __declspec(dllexport) int Load(void) +{ + mir_getLP(&pluginInfo); + INT_PTR result = CallService(MS_IMG_GETINTERFACE, FI_IF_VERSION, (LPARAM)&FIP); + + if(FIP == NULL || result != S_OK) { + MessageBoxEx(NULL, TranslateT("Fatal error, image services not found. Send Screenshot will be disabled."), TranslateT("Error"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0); + return 1; + } + + // load icon library (use UserInfoEx icon Pack) + IcoLib_LoadModule(); + + g_hookModulesLoaded=HookEvent(ME_SYSTEM_MODULESLOADED, hook_ModulesLoaded); + g_hookSystemPreShutdown=HookEvent(ME_SYSTEM_PRESHUTDOWN, hook_SystemPreShutdown); + + AddMenuItems(); + RegisterServices(); + + return 0; +} + +int hook_ModulesLoaded(WPARAM, LPARAM) +{ + myGlobals.PopupExist = ServiceExists(MS_POPUP_ADDPOPUP); + myGlobals.PopupActionsExist = ServiceExists(MS_POPUP_REGISTERACTIONS); + myGlobals.PluginHTTPExist = ServiceExists(MS_HTTP_ACCEPT_CONNECTIONS); + myGlobals.PluginFTPExist = ServiceExists(MS_FTPFILE_SHAREFILE); + + // Netlib register + NetlibInit(); + + // load my button class + if(!ServiceExists("UserInfo/vCard/Export")) + CtrlButtonLoadModule(); + + // Folders plugin support + hFolderScreenshot = FoldersRegisterCustomPathT(LPGEN("SendSS"), LPGEN("Screenshots"), + _T(PROFILE_PATH)_T("\\")_T(CURRENT_PROFILE)_T("\\Screenshots")); + + return 0; +} + +/*--------------------------------------------------------------------------- +* Prepare the plugin to stop +* Called by Miranda when it will exit or when the plugin gets deselected +*/ + +extern "C" __declspec(dllexport) int Unload(void) +{ + UnRegisterServices(); + if(g_hookModulesLoaded) UnhookEvent(g_hookModulesLoaded),g_hookModulesLoaded=0; + if(g_hookSystemPreShutdown) UnhookEvent(g_hookSystemPreShutdown),g_hookSystemPreShutdown=0; + return 0; +} + +int hook_SystemPreShutdown(WPARAM wParam, LPARAM lParam) +{ + TfrmAbout::Unload();//crashes if done from "Unload" because of dependencies + TfrmMain::Unload();// " + + // Netlib unregister + NetlibClose(); + + // uninitialize classes + CtrlButtonUnloadModule(); + return 0; +} + +//--------------------------------------------------------------------------- +// Netlib +HANDLE NetlibInit(void) +{ + NETLIBUSER nlu = { sizeof(nlu) }; + nlu.szSettingsModule = __PLUGIN_NAME; + nlu.ptszDescriptiveName = TranslateT("SendSS HTTP connections"); + nlu.flags = NUF_OUTGOING|NUF_HTTPCONNS|NUF_TCHAR; //|NUF_NOHTTPSOPTION; + return hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu); +} + +void NetlibClose(void) { + Netlib_CloseHandle(hNetlibUser); +} + + +//--------------------------------------------------------------------------- +// Callback function of service +// 1. Send a screenshot of the desktop to the selected contact +// wParam = contact handle +// lParam = 0 +// 2. Open the capture dialog in take screenshot only mode (it will not be sent) +// wParam = 0 +// lParam = anything but 0 +INT_PTR service_CaptureAndSendDesktop(WPARAM wParam, LPARAM lParam) { + TfrmMain *frmMain=new TfrmMain(); + if (!frmMain) { + MessageBoxEx(NULL, TranslateT("Could not create main dialog."), TranslateT("Error"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0); + return -1; + } + LPTSTR pszPath = GetCustomPath(); + if(pszPath) + { + HANDLE hContact = (HANDLE) wParam; + LPSTR pszProto = GetContactProto(hContact); + bool bChatRoom = db_get_b(hContact, pszProto, "ChatRoom", 0) != 0; + frmMain->m_opt_chkTimed = false; + frmMain->m_opt_tabCapture = 1; + frmMain->m_opt_cboxDesktop = 0; + frmMain->m_opt_chkEditor = false; + frmMain->m_opt_cboxSendBy = bChatRoom ? SS_IMAGESHACK:SS_FILESEND; + frmMain->Init(pszPath, hContact); // this method create the window hidden. + frmMain->btnCaptureClick(); // this method will call Close() + mir_free(pszPath); + } + return 0; +} + +//--------------------------------------------------------------------------- +// Callback function of service for contact menu and main menu +// wParam = contact handle +// lParam = 0 +INT_PTR service_OpenCaptureDialog(WPARAM wParam, LPARAM lParam) { + TfrmMain *frmMain=new TfrmMain(); + if (!frmMain) { + MessageBoxEx(NULL, TranslateT("Could not create main dialog."), TranslateT("Error"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0); + return -1; + } + + LPTSTR pszPath = GetCustomPath(); + if(pszPath) + { + frmMain->Init(pszPath, (HANDLE)wParam); + mir_free(pszPath); + } + frmMain->Show(); + return 0; +} + +//--------------------------------------------------------------------------- +// Edit a in-memory bitmap on the edit window +// wParam = (SENDSSCB) callback function address to call when editing is done +// lParam = (HBITMAP) bitmap handle, a copy is made so the calling function can free this handle after the service function returns +// Returns: +INT_PTR service_EditBitmap(WPARAM wParam, LPARAM lParam) { +/* TfrmEdit *frmEdit=new TfrmEdit(NULL); + if (!frmEdit) + return -1; + + Graphics::TBitmap *bitmap=new Graphics::TBitmap(); + if (!bitmap) + return -2; + + bitmap->Handle = (void*)lParam; + frmEdit->InitEditor(bitmap); // a copy of the bitmap is made inside this function + frmEdit->Show(); + delete bitmap; +*/ + return 0; +} + +//--------------------------------------------------------------------------- +// Callback function of service for sending image to imageshack.us +// wParam = (char*)filename +// lParam = (HANDLE)contact (can be null) +INT_PTR service_Send2ImageShack(WPARAM wParam, LPARAM lParam) { + LPSTR result = NULL; + CSendImageShack* cSend = new CSendImageShack(NULL, (HANDLE)lParam, false); + cSend->m_pszFile = mir_a2t((char*)wParam); + cSend->m_bDeleteAfterSend = FALSE; + if (lParam != NULL) { + cSend->Send(); + return 0; + } + cSend->SendSync(TRUE); + cSend->Send(); + if (cSend->GetURL()) { + result = mir_strdup(cSend->GetURL()); + } + else { + result = cSend->GetError(); + } + delete cSend; + return (INT_PTR)result; +} + +//--------------------------------------------------------------------------- +// Add SendSS menu item in contact menu +void AddMenuItems(void) +{ + // Common + CLISTMENUITEM mi = { sizeof(mi) }; + mi.flags = CMIF_ROOTHANDLE | CMIF_TCHAR; + mi.hParentMenu = HGENMENU_ROOT; + + // Add item to contact menu + mi.position = 1000000; + mi.ptszName = LPGENT("Send Screenshot"); + mi.hIcon = IcoLib_GetIcon(ICO_PLUG_SSWINDOW2); + mi.pszService = MS_SENDSS_OPENDIALOG; + Menu_AddContactMenuItem(&mi); + + // Add item to contact menu + mi.position = 1000001; + mi.ptszName = LPGENT("Send desktop screenshot"); +// mi.hIcon = IcoLib_GetIcon(ICO_PLUG_SSWINDOW2); + mi.pszService = MS_SENDSS_SENDDESKTOP; + Menu_AddContactMenuItem(&mi); + + // Add item to main menu + mi.position = 1000001; + mi.ptszName = LPGENT("Take a screenshot"); +// mi.hIcon = IcoLib_GetIcon(ICO_PLUG_SSWINDOW2); + mi.pszService = MS_SENDSS_OPENDIALOG; + Menu_AddMainMenuItem(&mi); +} + +//--------------------------------------------------------------------------- +// Register Send screenshot services +int RegisterServices(){ + hsvc_SendScreenshot = CreateServiceFunction(MS_SENDSS_OPENDIALOG, service_OpenCaptureDialog); + if (!hsvc_SendScreenshot) + MessageBoxEx(NULL, TranslateT("Could not register miranda service."), _T("MS_SENDSS_OPENDIALOG"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0); + + hsvc_SendDesktop = CreateServiceFunction(MS_SENDSS_SENDDESKTOP, service_CaptureAndSendDesktop); + if (!hsvc_SendDesktop) + MessageBoxEx(NULL, TranslateT("Could not register miranda service."), _T("MS_SENDSS_SENDDESKTOP"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0); + + hsvc_EditBitmap = CreateServiceFunction(MS_SENDSS_EDITBITMAP, service_EditBitmap); + if (!hsvc_EditBitmap) + MessageBoxEx(NULL, TranslateT("Could not register miranda service."), _T("MS_SENDSS_EDITBITMAP"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0); + + hsvc_Send2ImageShack = CreateServiceFunction(MS_SENDSS_SEND2IMAGESHACK, service_Send2ImageShack); + if (!hsvc_Send2ImageShack) + MessageBoxEx(NULL, TranslateT("Could not register miranda service."), _T("MS_SENDSS_SEND2IMAGESHACK"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0); + + return 0; +} +//--------------------------------------------------------------------------- +// UnRegister Send screenshot services +int UnRegisterServices(){ + if(hsvc_SendScreenshot) DestroyServiceFunction(hsvc_SendScreenshot),hsvc_SendScreenshot=0; + if(hsvc_SendDesktop) DestroyServiceFunction(hsvc_SendDesktop),hsvc_SendDesktop=0; + if(hsvc_EditBitmap) DestroyServiceFunction(hsvc_EditBitmap),hsvc_EditBitmap=0; + if(hsvc_Send2ImageShack) DestroyServiceFunction(hsvc_Send2ImageShack),hsvc_Send2ImageShack=0; + return 0; +} + +//--------------------------------------------------------------------------- +LPTSTR GetCustomPath() { + LPTSTR pszPath = Utils_ReplaceVarsT(_T("%miranda_userdata%\\Screenshots")); + if (hFolderScreenshot) { + TCHAR szPath[1024] = {'\0'}; + FoldersGetCustomPathT(hFolderScreenshot, szPath, 1024, pszPath); + mir_freeAndNil(pszPath); + pszPath = mir_tstrdup(szPath); + } + if(pszPath == NULL) + { + MessageBox(NULL, _T("Can not retrieve Screenshot path."), _T("Send Screenshot"), MB_OK | MB_ICONERROR | MB_APPLMODAL); + return 0; + } + + int result = CreateDirectoryTreeT(pszPath); + if(result != NULL) + { + TCHAR szError[MAX_PATH]; + mir_sntprintf(szError,MAX_PATH,TranslateT("Could not create Screenshot folder (error code: %d):\n%s\nDo you have write permissions?"),result,pszPath); + MessageBox(NULL, szError, _T("Send Screenshot"), MB_OK | MB_ICONERROR | MB_APPLMODAL); + mir_free(pszPath); + return 0; + } + return pszPath; +} diff --git a/plugins/SendScreenshotPlus/src/Main.h b/plugins/SendScreenshotPlus/src/Main.h index a713284617..ef61e1af1d 100644 --- a/plugins/SendScreenshotPlus/src/Main.h +++ b/plugins/SendScreenshotPlus/src/Main.h @@ -1,56 +1,57 @@ -/*
-
-Miranda IM: the free IM client for Microsoft* Windows*
-Copyright 2000-2009 Miranda ICQ/IM project,
-
-This file is part of Send Screenshot Plus, a Miranda IM plugin.
-Copyright (c) 2010 Ing.U.Horn
-
-Parts of this file based on original sorce code
-(c) 2004-2006 Sérgio Vieira Rolanski (portet from Borland C++)
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#ifndef MainH
-#define MainH
-
-//---------------------------------------------------------------------------
-
-extern HANDLE hNetlibUser;
-
-//---------------------------------------------------------------------------
-
-HANDLE NetlibInit(void);
-void NetlibClose(void);
-
-void IcoLib_LoadModule(void);
-void AddMenuItems(void);
-int RegisterServices(void);
-
-int hook_ModulesLoaded(WPARAM, LPARAM);
-int hook_SystemPShutdown(WPARAM wParam, LPARAM lParam);
-
-INT_PTR service_CaptureAndSendDesktop(WPARAM wParam, LPARAM lParam);
-INT_PTR service_OpenCaptureDialog(WPARAM wParam, LPARAM lParam);
-INT_PTR service_EditBitmap(WPARAM wParam, LPARAM lParam);
-INT_PTR service_Send2ImageShack(WPARAM wParam, LPARAM lParam);
-
-int OnSendScreenShot(WPARAM wParam, LPARAM lParam);
-
-LPTSTR GetCustomPath();
-
-//---------------------------------------------------------------------------
-#endif
+/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Sérgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef MainH +#define MainH + +//--------------------------------------------------------------------------- + +extern HANDLE hNetlibUser; + +//--------------------------------------------------------------------------- + +HANDLE NetlibInit(); +void NetlibClose(); + +void IcoLib_LoadModule(); +void AddMenuItems(); +int RegisterServices(); +int UnRegisterServices(); + +int hook_ModulesLoaded(WPARAM, LPARAM); +int hook_SystemPreShutdown(WPARAM wParam, LPARAM lParam); + +INT_PTR service_CaptureAndSendDesktop(WPARAM wParam, LPARAM lParam); +INT_PTR service_OpenCaptureDialog(WPARAM wParam, LPARAM lParam); +INT_PTR service_EditBitmap(WPARAM wParam, LPARAM lParam); +INT_PTR service_Send2ImageShack(WPARAM wParam, LPARAM lParam); + +int OnSendScreenShot(WPARAM wParam, LPARAM lParam); + +LPTSTR GetCustomPath(); + +//--------------------------------------------------------------------------- +#endif diff --git a/plugins/SendScreenshotPlus/src/UAboutForm.cpp b/plugins/SendScreenshotPlus/src/UAboutForm.cpp index 0b112a3803..98a533d4ab 100644 --- a/plugins/SendScreenshotPlus/src/UAboutForm.cpp +++ b/plugins/SendScreenshotPlus/src/UAboutForm.cpp @@ -1,201 +1,213 @@ -/*
-
-Miranda IM: the free IM client for Microsoft* Windows*
-Copyright 2000-2009 Miranda ICQ/IM project,
-
-This file is part of Send Screenshot Plus, a Miranda IM plugin.
-Copyright (c) 2010 Ing.U.Horn
-
-Parts of this file based on original sorce code
-(c) 2004-2006 Sérgio Vieira Rolanski (portet from Borland C++)
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include "global.h"
-
-//---------------------------------------------------------------------------
-TfrmAbout::CHandleMapping TfrmAbout::_HandleMapping;
-
-INT_PTR CALLBACK TfrmAbout::DlgTfrmAbout(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- if (msg == WM_CTLCOLOREDIT || msg == WM_CTLCOLORSTATIC) {
- switch ( GetWindowLongPtr(( HWND )lParam, GWL_ID )) {
- case IDC_WHITERECT:
- case IDC_CREDIT:
- case IDC_LICENSE:
- SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT));
- break;
- default:
- return FALSE;
- }
- SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
- return (LRESULT)GetStockObject(WHITE_BRUSH); //GetSysColorBrush(COLOR_WINDOW);
- }
-
- CHandleMapping::iterator wnd(_HandleMapping.end());
- if (msg == WM_INITDIALOG) {
- wnd = _HandleMapping.insert(CHandleMapping::value_type(hWnd, reinterpret_cast<TfrmAbout*>(lParam))).first;
- reinterpret_cast<TfrmAbout*>(lParam)->m_hWnd = hWnd;
- return wnd->second->wmInitdialog(wParam, lParam);
- }
- else {
- wnd = _HandleMapping.find(hWnd);
- }
- if (wnd == _HandleMapping.end()) { // something screwed up
- return FALSE; //dialog! do not use ::DefWindowProc(hWnd, msg, wParam, lParam);
- }
-
- switch (msg)
- {
- // case WM_INITDIALOG: done on top
- case WM_COMMAND:
- return wnd->second->wmCommand(wParam, lParam);
- break;
- case WM_CLOSE:
- return wnd->second->wmClose(wParam, lParam);
- break;
- case WM_DESTROY:
- delete wnd->second;
- break;
- }
- return FALSE;
-}
-
-//---------------------------------------------------------------------------
-//WM_INITDIALOG:
-LRESULT TfrmAbout::wmInitdialog(WPARAM wParam, LPARAM lParam) {
- char* pszMsg = NULL;
- HRSRC hResInfo;
- DWORD ResSize;
- TCHAR oldTitle[256], newTitle[256];
- LPTSTR temp = NULL;
- LPTSTR pszTitle = NULL;
- // Headerbar
- LPTSTR pszPlug = mir_a2t(__PLUGIN_NAME);
- LPTSTR pszVer = mir_a2t(__VERSION_STRING);
- GetDlgItemText( m_hWnd, IDC_HEADERBAR, oldTitle, SIZEOF( oldTitle ));
- mir_sntprintf( newTitle, SIZEOF(newTitle), oldTitle, pszPlug, pszVer );
- mir_freeAndNil(pszPlug);
- mir_freeAndNil(pszVer);
- SetDlgItemText( m_hWnd, IDC_HEADERBAR, newTitle );
- SendMessage(GetDlgItem(m_hWnd, IDC_HEADERBAR), WM_SETICON, 0, (WPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW1, true));
-
- //License
- { mir_tcsadd(pszTitle ,_T(__COPYRIGHT));
- mir_tcsadd(pszTitle ,_T("\r\n\r\n"));
-
- hResInfo = FindResource(hInst,MAKEINTRESOURCE(IDR_LICENSE),_T("TEXT"));
- ResSize = SizeofResource(hInst,hResInfo);
- pszMsg = (char*)LockResource(LoadResource(hInst,hResInfo));
- temp = mir_a2t(pszMsg);
- temp [ResSize] = 0; //LockResource is not NULL terminatet !!
- mir_tcsadd(pszTitle ,temp);
- mir_freeAndNil(temp);
- SetDlgItemText(m_hWnd,IDC_LICENSE, pszTitle);
- mir_freeAndNil(pszTitle);
- }
-
- //Credit
- {
- hResInfo = FindResource(hInst,MAKEINTRESOURCE(IDR_CREDIT),_T("TEXT"));
- ResSize = SizeofResource(hInst,hResInfo);
- pszMsg = (char*)LockResource(LoadResource(hInst,hResInfo));
- temp = mir_a2t(pszMsg);
- temp [ResSize] = 0; //LockResource is not NULL terminatet !!
- mir_tcsadd(pszTitle ,temp);
- mir_freeAndNil(temp);
- SetDlgItemText(m_hWnd,IDC_CREDIT, pszTitle);
- mir_freeAndNil(pszTitle);
- }
-
- SendMessage(m_hWnd, WM_SETICON, ICON_BIG, (LPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW1, true));
- SendMessage(m_hWnd, WM_SETICON, ICON_SMALL, (LPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW2));
-
- //init controls
- btnPageClick();
- SendMessage(GetDlgItem(m_hWnd, IDA_CONTRIBLINK), BUTTONSETDEFAULT, (WPARAM)1, NULL);
-
- TranslateDialogDefault(m_hWnd);
- return FALSE;
-}
-
-//WM_COMMAND:
-LRESULT TfrmAbout::wmCommand(WPARAM wParam, LPARAM lParam) {
- //---------------------------------------------------------------------------
- if (HIWORD(wParam) == BN_CLICKED) {
- int IDControl = LOWORD(wParam);
- HWND hCtrl = (HWND)lParam;
- switch(IDControl) {
- case IDCANCEL:
- case IDCLOSE:
- break;
- case IDA_btnClose:
- Close();
- break;
- case IDA_CONTRIBLINK:
- m_Page = m_Page ? 0 : 1;
- btnPageClick();
- break;
- default:
- break;
- }
- }
- return FALSE;
-}
-
-//WM_CLOSE:
-LRESULT TfrmAbout::wmClose(WPARAM wParam, LPARAM lParam) {
- SendMessage(m_hWndOwner,UM_CLOSING, (WPARAM)m_hWnd, (LPARAM)IDD_UAboutForm);
- DestroyWindow(m_hWnd);
- return FALSE;
-}
-
-//---------------------------------------------------------------------------
-// Standard konstruktor/destruktor
-TfrmAbout::TfrmAbout(HWND Owner) {
- m_hWndOwner = Owner;
- // create window
- m_hWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_UAboutForm),0, DlgTfrmAbout,(LPARAM)this);
- //register object
- _HandleMapping.insert(CHandleMapping::value_type(m_hWnd, this));
- //init page
- m_Page = 1;
-}
-
-TfrmAbout::~TfrmAbout() {
- _HandleMapping.erase(m_hWnd);
-}
-
-//---------------------------------------------------------------------------
-void TfrmAbout::btnPageClick() {
- HWND hCtrl = GetDlgItem(m_hWnd, IDA_CONTRIBLINK);
- if(!m_Page) {
- ShowWindow(GetDlgItem(m_hWnd, IDC_CREDIT), SW_HIDE);
- ShowWindow(GetDlgItem(m_hWnd, IDC_LICENSE), SW_SHOW);
- SendDlgItemMessage(m_hWnd, IDA_CONTRIBLINK, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Credits >"), MBBF_TCHAR);
- HICON hIcon = IcoLib_GetIcon(ICO_PLUG_ARROWR);
- SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
- SetWindowText(hCtrl, hIcon ? TranslateT("Credits") : TranslateT("Credits >"));
- }
- else {
- ShowWindow(GetDlgItem(m_hWnd, IDC_CREDIT), SW_SHOW);
- ShowWindow(GetDlgItem(m_hWnd, IDC_LICENSE), SW_HIDE);
- SendDlgItemMessage(m_hWnd, IDA_CONTRIBLINK, BUTTONADDTOOLTIP, (WPARAM)TranslateT("< Copyright"), MBBF_TCHAR);
- HICON hIcon = IcoLib_GetIcon(ICO_PLUG_ARROWL);
- SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
- SetWindowText(hCtrl, hIcon ? TranslateT("Copyright") : TranslateT("< Copyright"));
- }
-}
+/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 SĂ©rgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "global.h" + +#include <list> +void TfrmAbout::Unload(){ + std::list<TfrmAbout*> lst; + for(CHandleMapping::iterator iter=_HandleMapping.begin(); iter!=_HandleMapping.end(); ++iter){ + lst.push_back(iter->second);//we can't delete inside loop.. not MT compatible + } + while(!lst.empty()){ + DestroyWindow(lst.front()->m_hWnd);//deletes class + lst.pop_front(); + } +} + +//--------------------------------------------------------------------------- +TfrmAbout::CHandleMapping TfrmAbout::_HandleMapping; + +INT_PTR CALLBACK TfrmAbout::DlgTfrmAbout(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + if (msg == WM_CTLCOLOREDIT || msg == WM_CTLCOLORSTATIC) { + switch ( GetWindowLongPtr(( HWND )lParam, GWL_ID )) { + case IDC_WHITERECT: + case IDC_CREDIT: + case IDC_LICENSE: + SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT)); + break; + default: + return FALSE; + } + SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); + return (LRESULT)GetStockObject(WHITE_BRUSH); //GetSysColorBrush(COLOR_WINDOW); + } + + CHandleMapping::iterator wnd(_HandleMapping.end()); + if (msg == WM_INITDIALOG) { + wnd = _HandleMapping.insert(CHandleMapping::value_type(hWnd, reinterpret_cast<TfrmAbout*>(lParam))).first; + reinterpret_cast<TfrmAbout*>(lParam)->m_hWnd = hWnd; + return wnd->second->wmInitdialog(wParam, lParam); + } + else { + wnd = _HandleMapping.find(hWnd); + } + if (wnd == _HandleMapping.end()) { // something screwed up + return FALSE; //dialog! do not use ::DefWindowProc(hWnd, msg, wParam, lParam); + } + + switch (msg) + { + // case WM_INITDIALOG: done on top + case WM_COMMAND: + return wnd->second->wmCommand(wParam, lParam); + break; + case WM_CLOSE: + return wnd->second->wmClose(wParam, lParam); + break; + case WM_DESTROY: + delete wnd->second; + break; + } + return FALSE; +} + +//--------------------------------------------------------------------------- +//WM_INITDIALOG: +LRESULT TfrmAbout::wmInitdialog(WPARAM wParam, LPARAM lParam) { + char* pszMsg = NULL; + HRSRC hResInfo; + DWORD ResSize; + TCHAR oldTitle[256], newTitle[256]; + LPTSTR temp = NULL; + LPTSTR pszTitle = NULL; + // Headerbar + LPTSTR pszPlug = mir_a2t(__PLUGIN_NAME); + LPTSTR pszVer = mir_a2t(__VERSION_STRING); + GetDlgItemText( m_hWnd, IDC_HEADERBAR, oldTitle, SIZEOF( oldTitle )); + mir_sntprintf( newTitle, SIZEOF(newTitle), oldTitle, pszPlug, pszVer ); + mir_freeAndNil(pszPlug); + mir_freeAndNil(pszVer); + SetDlgItemText( m_hWnd, IDC_HEADERBAR, newTitle ); + SendMessage(GetDlgItem(m_hWnd, IDC_HEADERBAR), WM_SETICON, 0, (WPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW1, true)); + + //License + { mir_tcsadd(pszTitle ,_T(__COPYRIGHT)); + mir_tcsadd(pszTitle ,_T("\r\n\r\n")); + + hResInfo = FindResource(hInst,MAKEINTRESOURCE(IDR_LICENSE),_T("TEXT")); + ResSize = SizeofResource(hInst,hResInfo); + pszMsg = (char*)LockResource(LoadResource(hInst,hResInfo)); + temp = mir_a2t(pszMsg); + temp [ResSize] = 0; //LockResource is not NULL terminatet !! + mir_tcsadd(pszTitle ,temp); + mir_freeAndNil(temp); + SetDlgItemText(m_hWnd,IDC_LICENSE, pszTitle); + mir_freeAndNil(pszTitle); + } + + //Credit + { + hResInfo = FindResource(hInst,MAKEINTRESOURCE(IDR_CREDIT),_T("TEXT")); + ResSize = SizeofResource(hInst,hResInfo); + pszMsg = (char*)LockResource(LoadResource(hInst,hResInfo)); + temp = mir_a2t(pszMsg); + temp [ResSize] = 0; //LockResource is not NULL terminatet !! + mir_tcsadd(pszTitle ,temp); + mir_freeAndNil(temp); + SetDlgItemText(m_hWnd,IDC_CREDIT, pszTitle); + mir_freeAndNil(pszTitle); + } + + SendMessage(m_hWnd, WM_SETICON, ICON_BIG, (LPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW1, true)); + SendMessage(m_hWnd, WM_SETICON, ICON_SMALL, (LPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW2)); + + //init controls + btnPageClick(); + SendMessage(GetDlgItem(m_hWnd, IDA_CONTRIBLINK), BUTTONSETDEFAULT, (WPARAM)1, NULL); + + TranslateDialogDefault(m_hWnd); + return FALSE; +} + +//WM_COMMAND: +LRESULT TfrmAbout::wmCommand(WPARAM wParam, LPARAM lParam) { + //--------------------------------------------------------------------------- + if (HIWORD(wParam) == BN_CLICKED) { + int IDControl = LOWORD(wParam); + HWND hCtrl = (HWND)lParam; + switch(IDControl) { + case IDCANCEL: + case IDCLOSE: + break; + case IDA_btnClose: + Close(); + break; + case IDA_CONTRIBLINK: + m_Page = m_Page ? 0 : 1; + btnPageClick(); + break; + default: + break; + } + } + return FALSE; +} + +//WM_CLOSE: +LRESULT TfrmAbout::wmClose(WPARAM wParam, LPARAM lParam) { + SendMessage(m_hWndOwner,UM_CLOSING, (WPARAM)m_hWnd, (LPARAM)IDD_UAboutForm); + DestroyWindow(m_hWnd); + return FALSE; +} + +//--------------------------------------------------------------------------- +// Standard konstruktor/destruktor +TfrmAbout::TfrmAbout(HWND Owner) { + m_hWndOwner = Owner; + // create window + m_hWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_UAboutForm),0, DlgTfrmAbout,(LPARAM)this); + //register object + _HandleMapping.insert(CHandleMapping::value_type(m_hWnd, this)); + //init page + m_Page = 1; +} + +TfrmAbout::~TfrmAbout() { + _HandleMapping.erase(m_hWnd); +} + +//--------------------------------------------------------------------------- +void TfrmAbout::btnPageClick() { + HWND hCtrl = GetDlgItem(m_hWnd, IDA_CONTRIBLINK); + if(!m_Page) { + ShowWindow(GetDlgItem(m_hWnd, IDC_CREDIT), SW_HIDE); + ShowWindow(GetDlgItem(m_hWnd, IDC_LICENSE), SW_SHOW); + SendDlgItemMessage(m_hWnd, IDA_CONTRIBLINK, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Credits >"), MBBF_TCHAR); + HICON hIcon = IcoLib_GetIcon(ICO_PLUG_ARROWR); + SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + SetWindowText(hCtrl, hIcon ? TranslateT("Credits") : TranslateT("Credits >")); + } + else { + ShowWindow(GetDlgItem(m_hWnd, IDC_CREDIT), SW_SHOW); + ShowWindow(GetDlgItem(m_hWnd, IDC_LICENSE), SW_HIDE); + SendDlgItemMessage(m_hWnd, IDA_CONTRIBLINK, BUTTONADDTOOLTIP, (WPARAM)TranslateT("< Copyright"), MBBF_TCHAR); + HICON hIcon = IcoLib_GetIcon(ICO_PLUG_ARROWL); + SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + SetWindowText(hCtrl, hIcon ? TranslateT("Copyright") : TranslateT("< Copyright")); + } +} diff --git a/plugins/SendScreenshotPlus/src/UAboutForm.h b/plugins/SendScreenshotPlus/src/UAboutForm.h index 2e0042ac21..6b4187fb43 100644 --- a/plugins/SendScreenshotPlus/src/UAboutForm.h +++ b/plugins/SendScreenshotPlus/src/UAboutForm.h @@ -1,61 +1,63 @@ -/*
-
-Miranda IM: the free IM client for Microsoft* Windows*
-Copyright 2000-2009 Miranda ICQ/IM project,
-
-This file is part of Send Screenshot Plus, a Miranda IM plugin.
-Copyright (c) 2010 Ing.U.Horn
-
-Parts of this file based on original sorce code
-(c) 2004-2006 Sérgio Vieira Rolanski (portet from Borland C++)
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#ifndef UAboutFormH
-#define UAboutFormH
-
-//---------------------------------------------------------------------------
-class TfrmAbout{
-
- public:
- // Deklaration Standardkonstruktor/Standarddestructor
- TfrmAbout(HWND Owner);
- ~TfrmAbout();
-
- HWND m_hWndOwner;
- void Show(){ShowWindow(m_hWnd,SW_SHOW);}
- void Hide(){ShowWindow(m_hWnd,SW_HIDE);}
- void Close(){SendMessage(m_hWnd,WM_CLOSE,0,0);}
-
- private:
- HWND m_hWnd;
-
- protected:
- UINT m_Page;
- typedef std::map<HWND, TfrmAbout *> CHandleMapping;
- static CHandleMapping _HandleMapping;
- static INT_PTR CALLBACK DlgTfrmAbout(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
-
- LRESULT wmInitdialog(WPARAM wParam, LPARAM lParam);
- LRESULT wmCommand(WPARAM wParam, LPARAM lParam);
- LRESULT wmClose(WPARAM wParam, LPARAM lParam);
-
- void btnPageClick();
-
-};
-
-//---------------------------------------------------------------------------
-#endif
+/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Sérgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef UAboutFormH +#define UAboutFormH + +//--------------------------------------------------------------------------- +class TfrmAbout{ + + public: + // Deklaration Standardkonstruktor/Standarddestructor + TfrmAbout(HWND Owner); + ~TfrmAbout(); + + HWND m_hWndOwner; + + static void Unload(); + void Show(){ShowWindow(m_hWnd,SW_SHOW);} + void Hide(){ShowWindow(m_hWnd,SW_HIDE);} + void Close(){SendMessage(m_hWnd,WM_CLOSE,0,0);} + + private: + HWND m_hWnd; + + protected: + UINT m_Page; + typedef std::map<HWND, TfrmAbout *> CHandleMapping; + static CHandleMapping _HandleMapping; + static INT_PTR CALLBACK DlgTfrmAbout(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + + LRESULT wmInitdialog(WPARAM wParam, LPARAM lParam); + LRESULT wmCommand(WPARAM wParam, LPARAM lParam); + LRESULT wmClose(WPARAM wParam, LPARAM lParam); + + void btnPageClick(); + +}; + +//--------------------------------------------------------------------------- +#endif diff --git a/plugins/SendScreenshotPlus/src/UMainForm.cpp b/plugins/SendScreenshotPlus/src/UMainForm.cpp index a07e027932..b925da9f52 100644 --- a/plugins/SendScreenshotPlus/src/UMainForm.cpp +++ b/plugins/SendScreenshotPlus/src/UMainForm.cpp @@ -1,1172 +1,1184 @@ -/*
-
-Miranda IM: the free IM client for Microsoft* Windows*
-Copyright 2000-2009 Miranda ICQ/IM project,
-
-This file is part of Send Screenshot Plus, a Miranda IM plugin.
-Copyright (c) 2010 Ing.U.Horn
-
-Parts of this file based on original sorce code
-(c) 2004-2006 Sérgio Vieira Rolanski (portet from Borland C++)
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include "global.h"
-
-//---------------------------------------------------------------------------
-INT_PTR CALLBACK TfrmMain::DlgProc_CaptureWindow(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
-// main message handling is done inside TfrmMain::DlgTfrmMain
- switch (uMsg) {
- case WM_INITDIALOG:
- Static_SetIcon(GetDlgItem(hDlg, ID_imgTarget), IcoLib_GetIcon(ICO_PLUG_SSTARGET));
- SetDlgItemText(hDlg, ID_edtCaption, TranslateT("Drag&&Drop the target on the desired window."));
- TranslateDialogDefault(hDlg);
- break;
- case WM_CTLCOLOREDIT: //ctrl is NOT read-only or disabled
- case WM_CTLCOLORSTATIC: //ctrl is read-only or disabled
- // make the rectangle on the top white
- switch (GetWindowLongPtr((HWND)lParam, GWL_ID)) {
- case IDC_WHITERECT:
- case ID_chkClientArea:
- case ID_lblDropInfo:
- case ID_edtCaption:
- case ID_edtCaptionLabel:
- case ID_edtSize:
- case ID_edtSizeLabel:
- case ID_bvlTarget:
- case ID_imgTarget:
- SetBkColor((HDC)wParam,GetSysColor(COLOR_WINDOW));
- SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT));
-
- //SetBkMode((HDC)wParam,OPAQUE);
- //return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
- return (LRESULT)GetStockObject(WHITE_BRUSH);
- break;
- default:
- SetBkMode((HDC)wParam, TRANSPARENT);
- return (LRESULT)GetStockObject(NULL_BRUSH);
- break;
- }
- break; //this return false
- case WM_COMMAND:
- SendMessage(GetParent(hDlg), uMsg, wParam, lParam);
- break;
- case WM_MOUSEMOVE:
- SendMessage(GetParent(hDlg), UM_TAB1, uMsg, 0);
- break;
- case WM_NOTIFY:
- SendMessage(GetParent(hDlg), uMsg, wParam, lParam);
- break;
- case WM_DESTROY:
- break;
- }
- return FALSE;
-}
-
-//---------------------------------------------------------------------------
-INT_PTR CALLBACK TfrmMain::DlgProc_CaptureDesktop(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
-// main message handling is done inside TfrmMain::DlgTfrmMain
- switch (uMsg) {
- case WM_INITDIALOG:
- Static_SetIcon(GetDlgItem(hDlg, ID_imgTarget), IcoLib_GetIcon(ICO_PLUG_SSMONITOR));
- break;
- case WM_CTLCOLOREDIT:
- case WM_CTLCOLORSTATIC:
- // make the rectangle on the top white
- switch (GetWindowLongPtr((HWND)lParam, GWL_ID)) {
- case IDC_WHITERECT:
- case ID_lblDropInfo:
- case ID_edtCaption:
- case ID_edtCaptionLabel:
- case ID_edtSize:
- case ID_edtSizeLabel:
- case ID_bvlTarget:
- case ID_imgTarget:
- SetBkColor((HDC)wParam,GetSysColor(COLOR_WINDOW));
- SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT));
- return (LRESULT)GetStockObject(WHITE_BRUSH);
- break;
- default:
- SetBkMode((HDC)wParam, TRANSPARENT);
- return (LRESULT)GetStockObject(NULL_BRUSH);
- break;
- }
- break;
- case WM_COMMAND:
- SendMessage(GetParent(hDlg), uMsg, wParam, lParam);
- break;
- case WM_NOTIFY:
- SendMessage(GetParent(hDlg), uMsg, wParam, lParam);
- break;
- case WM_DESTROY:
- break;
- }
- return FALSE;
-}
-
-//---------------------------------------------------------------------------
-
-TfrmMain::CHandleMapping TfrmMain::_HandleMapping;
-
-LRESULT CALLBACK TfrmMain::DlgTfrmMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- if (msg == WM_CTLCOLOREDIT || msg == WM_CTLCOLORSTATIC) {
- switch ( GetWindowLongPtr(( HWND )lParam, GWL_ID )) {
- /* case IDC_WHITERECT:*/
- case IDC_HEADERBAR:
- SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT));
- break;
- default:
- return FALSE;
- }
- SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
- return (LRESULT)GetStockObject(WHITE_BRUSH); //GetSysColorBrush(COLOR_WINDOW);
- }
-
- CHandleMapping::iterator wnd(_HandleMapping.end());
- if (msg == WM_INITDIALOG) {
- wnd = _HandleMapping.insert(CHandleMapping::value_type(hWnd, reinterpret_cast<TfrmMain*>(lParam))).first;
- reinterpret_cast<TfrmMain*>(lParam)->m_hWnd = hWnd;
- return wnd->second->wmInitdialog(wParam, lParam);
- }
- else {
- wnd = _HandleMapping.find(hWnd);
- }
- if (wnd == _HandleMapping.end()) { // something screwed up
- return FALSE; //dialog! do not use ::DefWindowProc(hWnd, msg, wParam, lParam);
- }
-
- switch (msg)
- {
- // case WM_INITDIALOG: done on top
- case WM_COMMAND:
- return wnd->second->wmCommand(wParam, lParam);
- break;
- case WM_CLOSE:
- return wnd->second->wmClose(wParam, lParam);
- break;
- case WM_DESTROY:
- delete wnd->second;
- break;
- case UM_TAB1:
- return wnd->second->UMTab1(wParam, lParam);
- break;
- case WM_NOTIFY:
- return wnd->second->wmNotify(wParam, lParam);
- break;
- case WM_TIMER:
- return wnd->second->wmTimer(wParam, lParam);
- break;
- case UM_CLOSING:
- return wnd->second->UMClosing(wParam, lParam);
- break;
- case UM_EVENT:
- return wnd->second->UMevent(wParam, lParam);
- break;
- }
- return FALSE;
-}
-
-//---------------------------------------------------------------------------
-//WM_INITDIALOG:
-LRESULT TfrmMain::wmInitdialog(WPARAM wParam, LPARAM lParam) {
- HWND hCtrl;
- //Taskbar and Window icon
- SendMessage(m_hWnd, WM_SETICON, ICON_BIG, (LPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW1, true));
- SendMessage(m_hWnd, WM_SETICON, ICON_SMALL, (LPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW2));
- LPTSTR pt = mir_a2t(__PLUGIN_NAME);
- SetWindowText(m_hWnd, pt);
- mir_freeAndNil(pt);
-
- // Headerbar
- pt = mir_tstrdup((LPTSTR)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)m_hContact, (LPARAM)GCDNF_TCHAR));
- if (pt && (m_hContact != 0)) {
- LPTSTR lptString = NULL;
- mir_tcsadd(lptString , TranslateT("Send screenshot to\n"));
- mir_tcsadd(lptString , pt);
- SetDlgItemText(m_hWnd, IDC_HEADERBAR, lptString);
- mir_free(lptString);
- }
- mir_freeAndNil(pt);
-
- SendMessage(GetDlgItem(m_hWnd, IDC_HEADERBAR), WM_SETICON, 0, (WPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW1, true));
-
- //Timed controls
- CheckDlgButton(m_hWnd,ID_chkTimed, m_opt_chkTimed ? BST_CHECKED : BST_UNCHECKED);
- SetDlgItemInt (m_hWnd,ID_edtTimed, (UINT)m_opt_edtTimed, FALSE);
- SendDlgItemMessage(m_hWnd, ID_upTimed, UDM_SETRANGE, 0, (LPARAM)MAKELONG(250, 1));
- chkTimedClick(); //enable disable Timed controls
-
- //create Image list for tab control
- if(m_himlTab == 0){
- //m_himlTab = ImageList_Create(16, 16, PluginConfig.m_bIsXP ? ILC_COLOR32 | ILC_MASK : ILC_COLOR8 | ILC_MASK, 2, 0);
- m_himlTab = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 2, 0);
- ImageList_AddIcon(m_himlTab, IcoLib_GetIcon(ICO_PLUG_SSWINDOW2));
- ImageList_AddIcon(m_himlTab, IcoLib_GetIcon(ICO_PLUG_SSWINDOW2));
- }
-
- //create the tab control.
- {
- TAB_INFO itab;
- RECT rcClient, rcTab;
- m_hwndTab = GetDlgItem(m_hWnd, IDC_CAPTURETAB);
- TabCtrl_SetItemExtra(m_hwndTab, sizeof(TAB_INFO) - sizeof(TCITEMHEADER));
-
- ZeroMemory(&itab, sizeof(itab));
- itab.hwndMain = m_hWnd;
- itab.hwndTab = m_hwndTab;
-
- GetWindowRect(m_hwndTab, &rcTab);
- GetWindowRect(m_hWnd, &rcClient);
-
- TabCtrl_SetImageList(m_hwndTab, m_himlTab);
-
- // Add a tab for each of the three child dialog boxes.
- itab.tcih.mask = TCIF_PARAM|TCIF_TEXT|TCIF_IMAGE;
-
- itab.tcih.pszText = TranslateT("Window");
- itab.tcih.iImage = 0;
- itab.hwndTabPage = CreateDialog(hInst,MAKEINTRESOURCE(IDD_UMain_CaptureWindow), m_hWnd,DlgProc_CaptureWindow);
- TabCtrl_InsertItem(m_hwndTab, 0, &itab);
- MoveWindow(itab.hwndTabPage, (rcTab.left - rcClient.left)+2, (rcTab.top - rcClient.top), (rcTab.right - rcTab.left) - 2*5, (rcTab.bottom - rcTab.top) - 2*20, TRUE);
- ShowWindow(itab.hwndTabPage, SW_HIDE);
- CheckDlgButton(itab.hwndTabPage, ID_chkClientArea, m_opt_chkClientArea ? BST_CHECKED : BST_UNCHECKED);
-
- itab.tcih.pszText = TranslateT("Desktop");
- itab.tcih.iImage = 1;
- itab.hwndTabPage = CreateDialog(hInst,MAKEINTRESOURCE(IDD_UMain_CaptureDesktop), m_hWnd, DlgProc_CaptureDesktop);
- TabCtrl_InsertItem(m_hwndTab, 1, &itab);
- MoveWindow(itab.hwndTabPage, (rcTab.left - rcClient.left)+2, (rcTab.top - rcClient.top), (rcTab.right - rcTab.left) - 2*5, (rcTab.bottom - rcTab.top) - 2*20, TRUE);
- ShowWindow(itab.hwndTabPage, SW_HIDE);
-
- hCtrl = GetDlgItem(itab.hwndTabPage, ID_edtCaption);
- ComboBox_ResetContent(hCtrl);
- ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("<entire desktop>")) ,0);
- ComboBox_SetCurSel (hCtrl,0);
- if(m_MonitorCount >1) {
- TCHAR tszTemp[120];
- for (size_t i = 0; i < m_MonitorCount; ++i) {
- mir_sntprintf(tszTemp, SIZEOF(tszTemp),_T("%i. %s%s"),
- i+1,
- TranslateT("Monitor"),
- (m_Monitors[i].dwFlags & MONITORINFOF_PRIMARY) ? TranslateT(" (primary)") : _T("")
- );
- ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, tszTemp) , i+1);
- }
- ComboBox_SelectItemData (hCtrl, -1, m_opt_cboxDesktop); //use Workaround for MS bug ComboBox_SelectItemData
- }
- PostMessage(m_hWnd, WM_COMMAND, MAKEWPARAM(ID_edtCaption, CBN_SELCHANGE),(LPARAM)hCtrl);
-
- //select tab and set m_hwndTabPage
- TabCtrl_SetCurSel(m_hwndTab, m_opt_tabCapture);
- ZeroMemory(&itab, sizeof(itab));
- itab.tcih.mask = TCIF_PARAM;
- TabCtrl_GetItem(m_hwndTab,TabCtrl_GetCurSel(m_hwndTab),&itab);
- ShowWindow(itab.hwndTabPage,SW_SHOW);
- m_hwndTabPage = itab.hwndTabPage;
- }
- //init Format combo box
- {
- hCtrl = GetDlgItem(m_hWnd, ID_cboxFormat);
- ComboBox_ResetContent(hCtrl);
- ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("PNG")),0);
- ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("JPG")),1);
- ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("BMP")),2);
- ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("TIF")),3);
- ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("GIF")),4);
- ComboBox_SelectItemData (hCtrl, -1, m_opt_cboxFormat); //use Workaround for MS bug ComboBox_SelectItemData
- }
- //init SendBy combo box
- {
- hCtrl = GetDlgItem(m_hWnd, ID_cboxSendBy);
- ComboBox_ResetContent(hCtrl);
- ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("<Only save>")) ,SS_JUSTSAVE);
- if (m_hContact) {
- ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("File Transfer")),SS_FILESEND);
- }
- else if(m_opt_cboxSendBy == SS_FILESEND) {
- m_opt_cboxSendBy = SS_IMAGESHACK;
- }
- ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("E-mail")) ,SS_EMAIL);
- if (myGlobals.PluginHTTPExist) {
- ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("HTTP Server")) ,SS_HTTPSERVER);
- }
- else if(m_opt_cboxSendBy == SS_HTTPSERVER) {
- m_opt_cboxSendBy = SS_IMAGESHACK;
- }
- if (myGlobals.PluginFTPExist) {
- ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("FTP File")) ,SS_FTPFILE);
- }
- else if(m_opt_cboxSendBy == SS_FTPFILE) {
- m_opt_cboxSendBy = SS_IMAGESHACK;
- }
- ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("ImageShack")) ,(BYTE)SS_IMAGESHACK);
- ComboBox_SelectItemData (hCtrl, -1, m_opt_cboxSendBy); //use Workaround for MS bug ComboBox_SelectItemData
- cboxSendByChange(); //enable disable controls
- }
- //init footer options
- CheckDlgButton(m_hWnd,ID_chkOpenAgain, m_opt_chkOpenAgain ? BST_CHECKED : BST_UNCHECKED);
-
- if (hCtrl = GetDlgItem(m_hWnd, ID_btnAbout)) {
- SendDlgItemMessage(m_hWnd, ID_btnAbout, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Information"), MBBF_TCHAR);
- HICON hIcon = IcoLib_GetIcon(ICO_PLUG_SSHELP);
- SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
- SetWindowText(hCtrl, hIcon ? _T("") : _T("?"));
- }
-
- if (hCtrl = GetDlgItem(m_hWnd, ID_btnExplore)) {
- SendDlgItemMessage(m_hWnd, ID_btnExplore, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Open Folder"), MBBF_TCHAR);
- HICON hIcon = IcoLib_GetIcon(ICO_PLUG_SSFOLDERO);
- SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
- SetWindowText(hCtrl, hIcon ? _T("") : _T("..."));
- }
-
- if (hCtrl = GetDlgItem(m_hWnd, ID_btnDesc)) {
- SendDlgItemMessage(m_hWnd, ID_btnDesc, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Fill description textbox."), MBBF_TCHAR);
- HICON hIcon = IcoLib_GetIcon(m_opt_btnDesc ? ICO_PLUG_SSDESKON : ICO_PLUG_SSDESKOFF);
- SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
- SetWindowText(hCtrl, hIcon ? _T("") : _T("D"));
- SendMessage(hCtrl, BM_SETCHECK, m_opt_btnDesc ? BST_CHECKED : BST_UNCHECKED, NULL);
- }
-
- if (hCtrl = GetDlgItem(m_hWnd, ID_btnDeleteAfterSend)) {
- SendDlgItemMessage(m_hWnd, ID_btnDeleteAfterSend, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Delete after send"), MBBF_TCHAR);
- HICON hIcon = IcoLib_GetIcon(m_opt_btnDeleteAfterSend ? ICO_PLUG_SSDELON : ICO_PLUG_SSDELOFF);
- SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
- SetWindowText(hCtrl, hIcon ? _T("") : _T("X"));
- SendMessage(hCtrl, BM_SETCHECK, m_opt_btnDeleteAfterSend ? BST_CHECKED : BST_UNCHECKED, NULL);
- }
-
- if (hCtrl = GetDlgItem(m_hWnd, ID_btnCapture)) {
- SendDlgItemMessage(m_hWnd, ID_btnCapture, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Capture"), MBBF_TCHAR);
- HICON hIcon = IcoLib_GetIcon(ICO_PLUG_OK);
- SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
- SetWindowText(hCtrl, TranslateT("&Capture"));
- SendMessage(hCtrl, BUTTONSETDEFAULT, (WPARAM)1, NULL);
- }
-
-// CheckDlgButton(m_hWnd,ID_chkEditor, m_opt_chkEditor ? BST_CHECKED : BST_UNCHECKED);
- TranslateDialogDefault(m_hWnd);
- return FALSE;
-}
-
-//WM_COMMAND:
-LRESULT TfrmMain::wmCommand(WPARAM wParam, LPARAM lParam) {
- //---------------------------------------------------------------------------
- int IDControl = LOWORD(wParam);
- switch (HIWORD(wParam)) {
- case BN_CLICKED: //Button controls
- switch(IDControl) {
- case IDCANCEL:
- case IDCLOSE:
- break;
-
- case ID_chkTimed:
- m_opt_chkTimed = (BYTE)Button_GetCheck((HWND)lParam);
- TfrmMain::chkTimedClick();
- break;
- case ID_chkClientArea:
- m_opt_chkClientArea = (BYTE)Button_GetCheck((HWND)lParam);
- if(m_hTargetWindow)
- edtSizeUpdate(m_hTargetWindow, m_opt_chkClientArea, GetParent((HWND)lParam), ID_edtSize);
- break;
- case ID_chkOpenAgain:
- m_opt_chkOpenAgain = (BYTE)Button_GetCheck((HWND)lParam);
- break;
- case ID_chkEditor:
- m_opt_chkEditor = (BYTE)Button_GetCheck((HWND)lParam);
- break;
-
- case ID_btnAbout:
- TfrmMain::btnAboutClick();
- break;
- case ID_btnExplore:
- TfrmMain::btnExploreClick();
- break;
- case ID_btnDesc:
- {
- m_opt_btnDesc = (m_opt_btnDesc == 0);
- HICON hIcon = IcoLib_GetIcon(m_opt_btnDesc ? ICO_PLUG_SSDESKON : ICO_PLUG_SSDESKOFF);
- SendMessage((HWND)lParam, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
- }
- break;
- case ID_btnDeleteAfterSend:
- {
- m_opt_btnDeleteAfterSend = (m_opt_btnDeleteAfterSend == 0);
- HICON hIcon = IcoLib_GetIcon(m_opt_btnDeleteAfterSend ? ICO_PLUG_SSDELON : ICO_PLUG_SSDELOFF);
- SendMessage((HWND)lParam, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
- if(m_cSend) m_cSend->m_bDeleteAfterSend = m_opt_btnDeleteAfterSend;
- }
- break;
- case ID_btnCapture:
- TfrmMain::btnCaptureClick();
- break;
- default:
- break;
- }
- break;
- case CBN_SELCHANGE: //ComboBox controls
- switch(IDControl) {
- //lParam = Handle to the control
- case ID_cboxFormat: //not finish
- m_opt_cboxFormat = (BYTE)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam));
- break;
- case ID_cboxSendBy:
- m_opt_cboxSendBy = (BYTE)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam));
- cboxSendByChange();
- break;
- case ID_edtCaption: //cboxDesktopChange
- m_opt_cboxDesktop = (BYTE)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam));
- m_hTargetWindow = 0;
- if (m_opt_cboxDesktop > 0) {
- edtSizeUpdate(m_Monitors[m_opt_cboxDesktop-1].rcMonitor, GetParent((HWND)lParam), ID_edtSize);
- }
- else {
- edtSizeUpdate(m_VirtualScreen, GetParent((HWND)lParam), ID_edtSize);
- }
- break;
- default:
- break;
- }
- break;
- case EN_CHANGE: //Edit controls
- switch(IDControl) {
- //lParam = Handle to the control
- case ID_edtQuality:
- m_opt_edtQuality = (BYTE)GetDlgItemInt(m_hWnd, ID_edtQuality, NULL, FALSE);
- break;
- case ID_edtTimed:
- m_opt_edtTimed = (BYTE)GetDlgItemInt(m_hWnd, ID_edtTimed, NULL, FALSE);
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
- return FALSE;
-}
-
-//WM_CLOSE:
-LRESULT TfrmMain::wmClose(WPARAM wParam, LPARAM lParam) {
- DestroyWindow(m_hWnd);
- return FALSE;
-}
-
-//WM_TIMER:
-LRESULT TfrmMain::wmTimer(WPARAM wParam, LPARAM lParam) {
- if (wParam == ID_bvlTarget) { // Timer for Target selector
- if (m_hCursor) { //imgTarget is activ
- //LmouseButton = false
- if (!GetLmouse()) {
- TfrmMain::imgTargetMouseUp();
- return FALSE;
- }
- //Timer action if LmouseButton = true
- m_hLastWin = m_hTargetWindow;
- POINT point={0};
- GetCursorPos(&point);
- HWND hCurrentWin = WindowFromPoint(point);
- while (GetParent(hCurrentWin)) {
- hCurrentWin = GetParent(hCurrentWin);
- }
- if (m_hLastWin != hCurrentWin) {
- LPTSTR lpTitle = NULL;
- if (m_hLastWin) {
- DrawBorderInverted(m_hLastWin);
- }
- int Count = GetWindowTextLength(hCurrentWin)+1;
- if(Count > 1){
- lpTitle = (LPTSTR)mir_alloc(Count*sizeof(TCHAR));
- GetWindowText(hCurrentWin, lpTitle, Count);
- }
- else {
- //no WindowText present, use WindowClass
- lpTitle = (LPTSTR)mir_alloc(MAX_PATH*sizeof(TCHAR));
- RealGetWindowClass(hCurrentWin, lpTitle, MAX_PATH);
- }
- SetDlgItemText(m_hwndTabPage, ID_edtCaption, lpTitle);
- mir_free(lpTitle);
- edtSizeUpdate(hCurrentWin, m_opt_chkClientArea, m_hwndTabPage, ID_edtSize);
- DrawBorderInverted(hCurrentWin);
- m_hTargetWindow = hCurrentWin;
- }
- return FALSE;
- }
- //imgTarget is not activ (check if cursor is over ID_bvlTarget control)
- RECT rc;
- POINT pt;
- GetWindowRect(GetDlgItem(m_hwndTabPage, wParam),&rc);
- GetCursorPos(&pt);
- //check Mouse cursor
- if(!PtInRect(&rc,pt)) { // mouse must be gone, trigger mouse leave
- //PostMessage(m_hWnd,WM_MOUSELEAVE,wParam,lParam);
- KillTimer(m_hWnd,wParam);
- }
- else if (GetLmouse() && !m_hCursor) { //mouse hover + LButton
- TfrmMain::imgTargetMouseDown();
- }
- }
- if (wParam == ID_chkTimed) { // Timer for Screenshot
- #ifdef _DEBUG
- OutputDebugStringA("SS Bitmap Timer Start\r\n" );
- #endif
- if(!m_bCapture) { //only start once
- if (m_Screenshot) {
- FIP->FI_Unload(m_Screenshot);
- m_Screenshot = NULL;
- }
- m_bCapture = true;
- switch (m_opt_tabCapture) {
- case 0:
- m_Screenshot = CaptureWindow(m_hTargetWindow, (BOOL)m_opt_chkClientArea);
- break;
- case 1:
- m_Screenshot = CaptureMonitor((m_opt_cboxDesktop > 0) ? m_Monitors[m_opt_cboxDesktop-1].szDevice : NULL);
- break;
- default:
- KillTimer(m_hWnd,wParam);
- m_bCapture = false;
- #ifdef _DEBUG
- OutputDebugStringA("SS Bitmap Timer Stop (no tabCapture)\r\n" );
- #endif
- return FALSE;
- }
- if (!m_Screenshot) m_bCapture = false;
- }
- if (m_Screenshot) {
- KillTimer(m_hWnd,wParam);
- m_bCapture = false;
- #ifdef _DEBUG
- OutputDebugStringA("SS Bitmap Timer Stop (CaptureDone)\r\n" );
- #endif
- SendMessage(m_hWnd,UM_EVENT, 0, (LPARAM)EVT_CaptureDone);
- }
- }
- return FALSE;
-}
-
-//WM_NOTIFY:
-LRESULT TfrmMain::wmNotify(WPARAM wParam, LPARAM lParam) {
- switch(((LPNMHDR)lParam)->idFrom) {
- case IDC_CAPTURETAB: //TabControl IDC_CAPTURETAB
- switch (((LPNMHDR)lParam)->code) {
- // HWND hwndFrom; = member is handle to the tab control
- // UINT_PTR idFrom; = member is the child window identifier of the tab control.
- // UINT code; = member is TCN_SELCHANGE
- case TCN_SELCHANGING:
- {
- TAB_INFO itab;
- ZeroMemory(&itab, sizeof(itab));
- itab.tcih.mask = TCIF_PARAM;
- TabCtrl_GetItem(m_hwndTab,TabCtrl_GetCurSel(m_hwndTab),&itab);
- ShowWindow(itab.hwndTabPage,SW_HIDE);
- m_hwndTabPage = NULL;
- }
- break;
-
- case TCN_SELCHANGE:
- {
- TAB_INFO itab;
- ZeroMemory(&itab, sizeof(itab));
- itab.tcih.mask = TCIF_PARAM;
- m_opt_tabCapture = TabCtrl_GetCurSel(m_hwndTab);
- TabCtrl_GetItem(m_hwndTab, m_opt_tabCapture, &itab);
- ShowWindow(itab.hwndTabPage, SW_SHOW);
- m_hwndTabPage = itab.hwndTabPage;
- }
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
- return FALSE;
-}
-
-//UM_CLOSING:
-LRESULT TfrmMain::UMClosing(WPARAM wParam, LPARAM lParam) {
- HWND hWnd = (HWND)wParam;
- switch (lParam) {
- case IDD_UAboutForm:
- btnAboutOnCloseWindow(hWnd);
- break;
- case IDD_UEditForm:
- ;
- break;
- default:
- break;
- }
- return FALSE;
-}
-
-//UM_TAB1:
-LRESULT TfrmMain::UMTab1(WPARAM wParam, LPARAM lParam) {
- switch (wParam) {
- case WM_MOUSEMOVE:
- if (m_opt_tabCapture == 0) {
- // Call timer, used to start cheesy TrackMouseEvent faker
- SetTimer(m_hWnd,ID_bvlTarget,BUTTON_POLLDELAY,NULL);
- }
- break;
- default:
- break;
- }
- return FALSE;
-}
-
-//UM_EVENT:
-LRESULT TfrmMain::UMevent(WPARAM wParam, LPARAM lParam) {
- //HWND hWnd = (HWND)wParam;
- switch (lParam) {
- case EVT_CaptureDone:
- if (!m_Screenshot) {
- TCHAR *err = TranslateT("Can't create a Screenshot");
- MessageBox(m_hWnd,err,ERROR_TITLE,MB_OK|MB_ICONWARNING);
- Show();
- return FALSE;
- }
- if (m_opt_chkEditor) {
- /* TfrmEdit *frmEdit=new TfrmEdit(this);
- m_bFormEdit = true;
-
- frmEdit->mniClose->Enabled = !chkJustSaveIt->Checked;
- frmEdit->mniCloseSend->Enabled = frmEdit->mniClose->Enabled;
- frmEdit->OnClose = OnCloseEditWindow;
- frmEdit->InitEditor(Screenshot); // Screenshot is copied to another in-memory bitmap inside this method
- frmEdit->Show();
- delete Screenshot; // This way we can delete it after the method returns
- Screenshot = NULL;
- */
- return FALSE;
- }
- else {
- FormClose();
- }
- break;
- case EVT_SendFileDone:
- break;
- case EVT_CheckOpenAgain:
- if (m_opt_chkOpenAgain) {
- if (m_Screenshot) {
- FIP->FI_Unload(m_Screenshot);
- m_Screenshot = NULL;
- }
- m_hTargetWindow = m_hLastWin = NULL;
- Show();
- }
- else {
- // Saving Options and close
- SaveOptions();
- Close();
- }
- break;
- default:
- break;
- }
- return FALSE;
-}
-
-//---------------------------------------------------------------------------
-// Standard konstruktor/destruktor
-TfrmMain::TfrmMain() {
- m_hWnd = NULL;
- m_hContact = NULL;
- m_hTargetWindow = NULL;
- m_hCursor = NULL;
- m_Screenshot = NULL;
- m_pszFile = m_pszFileDesc = m_FDestFolder = NULL;
- m_bFormAbout = m_bFormEdit = m_bDeleteAfterSend = m_bSelectingWindow = false;
- m_cSend = NULL;
- m_bOnExitSave = TRUE;
- LoadOptions();
- m_bCapture = false;
- m_himlTab = NULL;
- m_Monitors = NULL;
- m_MonitorCount = MonitorInfoEnum(m_Monitors, m_VirtualScreen);
-
-}
-
-TfrmMain::~TfrmMain() {
- _HandleMapping.erase(m_hWnd);
- mir_free(m_pszFile);
- mir_free(m_FDestFolder);
- mir_free(m_pszFileDesc);
- mir_free(m_Monitors);
- if (m_Screenshot) FIP->FI_Unload(m_Screenshot);
- if (m_cSend) delete m_cSend;
-}
-
-//---------------------------------------------------------------------------
-// Load / Saving options from miranda's database
-void TfrmMain::LoadOptions(void) {
- DWORD rgb = db_get_dw(NULL, SZ_SENDSS, "AlphaColor", 16777215);
- m_AlphaColor.rgbRed = GetRValue(rgb);
- m_AlphaColor.rgbGreen = GetGValue(rgb);
- m_AlphaColor.rgbBlue = GetBValue(rgb);
- m_AlphaColor.rgbReserved = 0;
-
-// m_opt_chkEmulateClick = db_get_b(NULL, SZ_SENDSS, "AutoSend", 1);
- m_opt_edtQuality = db_get_b(NULL, SZ_SENDSS, "JpegQuality", 75);
-
- m_opt_tabCapture = db_get_b(NULL, SZ_SENDSS, "Capture", 0);
- m_opt_chkClientArea = db_get_b(NULL, SZ_SENDSS, "ClientArea", 0);
- m_opt_cboxDesktop = db_get_b(NULL, SZ_SENDSS, "Desktop", 0);
-
- m_opt_chkTimed = db_get_b(NULL, SZ_SENDSS, "TimedCap", 0);
- m_opt_edtTimed = db_get_b(NULL, SZ_SENDSS, "CapTime", 3);
- m_opt_cboxFormat = db_get_b(NULL, SZ_SENDSS, "OutputFormat", 3);
- m_opt_cboxSendBy = db_get_b(NULL, SZ_SENDSS, "SendBy", 0);
-
- m_opt_chkEditor = db_get_b(NULL, SZ_SENDSS, "Preview", 0);
- m_opt_btnDesc = db_get_b(NULL, SZ_SENDSS, "AutoDescription", 1);
- m_opt_btnDeleteAfterSend = db_get_b(NULL, SZ_SENDSS, "DelAfterSend", 1);
- m_opt_chkOpenAgain = db_get_b(NULL, SZ_SENDSS, "OpenAgain", 0);
-}
-
-void TfrmMain::SaveOptions(void) {
- if(m_bOnExitSave) {
- db_set_dw(NULL, SZ_SENDSS, "AlphaColor",
- (DWORD)RGB(m_AlphaColor.rgbRed, m_AlphaColor.rgbGreen, m_AlphaColor.rgbBlue));
-
-// db_set_b(NULL, SZ_SENDSS, "AutoSend", m_opt_chkEmulateClick);
- db_set_b(NULL, SZ_SENDSS, "JpegQuality", m_opt_edtQuality);
-
- db_set_b(NULL, SZ_SENDSS, "Capture", m_opt_tabCapture);
- db_set_b(NULL, SZ_SENDSS, "ClientArea", m_opt_chkClientArea);
- db_set_b(NULL, SZ_SENDSS, "Desktop", m_opt_cboxDesktop);
-
- db_set_b(NULL, SZ_SENDSS, "TimedCap", m_opt_chkTimed);
- db_set_b(NULL, SZ_SENDSS, "CapTime", m_opt_edtTimed);
- db_set_b(NULL, SZ_SENDSS, "OutputFormat", m_opt_cboxFormat);
- db_set_b(NULL, SZ_SENDSS, "SendBy", m_opt_cboxSendBy);
-
- db_set_b(NULL, SZ_SENDSS, "AutoDescription", m_opt_btnDesc);
- db_set_b(NULL, SZ_SENDSS, "DelAfterSend", m_opt_btnDeleteAfterSend);
- db_set_b(NULL, SZ_SENDSS, "OpenAgain", m_opt_chkOpenAgain);
- db_set_b(NULL, SZ_SENDSS, "Preview", m_opt_chkEditor);
- }
-}
-
-//---------------------------------------------------------------------------
-void TfrmMain::Init(LPTSTR DestFolder, HANDLE Contact) {
- if(DestFolder)
- {
- m_FDestFolder = mir_tstrdup(DestFolder);
- m_hContact = Contact;
- if(!m_hContact) m_opt_cboxSendBy = SS_JUSTSAVE;
-
- // create window
- m_hWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_UMainForm),0, (DLGPROC)DlgTfrmMain,(LPARAM)this);
- //register object
- _HandleMapping.insert(CHandleMapping::value_type(m_hWnd, this));
-
- //check Contact
- if(m_cSend) m_cSend->SetContact(Contact);
- }
-}
-
-//---------------------------------------------------------------------------
-void TfrmMain::btnCaptureClick() {
- m_bFormEdit = false; //until UEditForm is includet
-
- if (m_opt_tabCapture == 0 && m_hTargetWindow == 0) {
- TCHAR *err = TranslateT("Select a target window.");
- MessageBox(m_hWnd,err,ERROR_TITLE,MB_OK|MB_ICONWARNING);
- return;
- }
- TfrmMain::Hide();
-
- if (!m_hTargetWindow) m_hTargetWindow = GetDesktopWindow();
-
- if (m_opt_chkTimed) {
- SetTimer(m_hWnd, ID_chkTimed, m_opt_edtTimed ? m_opt_edtTimed*1000 : 500, NULL);
- }
- else if (m_opt_tabCapture == 1){
- //desktop need always time to update from TfrmMain::Hide()
- SetTimer(m_hWnd, ID_chkTimed, 500, NULL);
- }
- else {
- m_Screenshot = CaptureWindow(m_hTargetWindow, (BOOL)(m_opt_chkClientArea));
- SendMessage(m_hWnd,UM_EVENT, 0, (LPARAM)EVT_CaptureDone);
- }
-}
-
-//---------------------------------------------------------------------------
-void TfrmMain::chkTimedClick() {
- Button_Enable(GetDlgItem(m_hWnd, ID_edtTimedLabel), (BOOL)m_opt_chkTimed);
- Button_Enable(GetDlgItem(m_hWnd, ID_edtTimed), (BOOL)m_opt_chkTimed);
- Button_Enable(GetDlgItem(m_hWnd, ID_upTimed), (BOOL)m_opt_chkTimed);
-}
-
-//---------------------------------------------------------------------------
-void TfrmMain::imgTargetMouseDown() {
- //if (Button != mbLeft) return;
- m_hCursor = CopyCursor(GetCursor()); //backup cursor
- //SetSystemCursor need a copy coz it destroy the handle
- SetSystemCursor(CopyCursor(IcoLib_GetIcon(ICO_PLUG_SSTARGET)),OCR_NORMAL);
- m_bSelectingWindow = true;
- m_hTargetWindow = NULL;
- Hide();
- SetCapture(m_hWnd);
-}
-
-//---------------------------------------------------------------------------
-void TfrmMain::imgTargetMouseUp() {
- //if (Button == mbLeft && m_bSelectingWindow && TimerCheckFocus->Enabled)
- if (m_bSelectingWindow && m_hCursor) {
- Show();
- ReleaseCapture();
- SetSystemCursor(m_hCursor, OCR_NORMAL);
- m_hCursor = NULL;
- if (m_hTargetWindow){
- DrawBorderInverted(m_hTargetWindow);
- }
- m_bSelectingWindow = false;
- }
-}
-
-//---------------------------------------------------------------------------
-void TfrmMain::cboxSendByChange() {
- BOOL bState;
- HICON hIcon;
- BYTE itemFlag = SS_DLG_DESCRIPTION; //SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND |
- if (m_cSend && !m_cSend->m_bFreeOnExit) {
- delete m_cSend;
- m_cSend = NULL;
- }
- switch(m_opt_cboxSendBy) {
- case SS_FILESEND: //"File Transfer"
- m_cSend = new CSendFile(m_hWnd, m_hContact, false);
- break;
- case SS_EMAIL: //"E-mail"
- m_cSend = new CSendEmail(m_hWnd, m_hContact, false);
- break;
- case SS_HTTPSERVER: //"HTTP Server"
- m_cSend = new CSendHTTPServer(m_hWnd, m_hContact, false);
- break;
- case SS_FTPFILE: //"FTP File"
- m_cSend = new CSendFTPFile(m_hWnd, m_hContact, false);
- break;
- case SS_IMAGESHACK: //"ImageShack"
- m_cSend = new CSendImageShack(m_hWnd, m_hContact, false);
- break;
- default: //SS_JUSTSAVE - "Just save it "
- m_cSend = NULL;
- break;
- }
- if(m_cSend){
- itemFlag = m_cSend->GetEnableItem();
- m_cSend->m_bDeleteAfterSend = m_opt_btnDeleteAfterSend;
- }
- bState = ((itemFlag & SS_DLG_DELETEAFTERSSEND) == SS_DLG_DELETEAFTERSSEND);
- hIcon = IcoLib_GetIcon(m_opt_btnDeleteAfterSend ? ICO_PLUG_SSDELON : ICO_PLUG_SSDELOFF);
- SendMessage(GetDlgItem(m_hWnd, ID_btnDeleteAfterSend), BM_SETIMAGE, IMAGE_ICON, (LPARAM)(bState ? hIcon : 0));
- Button_Enable(GetDlgItem(m_hWnd, ID_btnDeleteAfterSend), bState);
-
- bState = ((itemFlag & SS_DLG_DESCRIPTION) == SS_DLG_DESCRIPTION);
- hIcon = IcoLib_GetIcon(m_opt_btnDesc ? ICO_PLUG_SSDESKON : ICO_PLUG_SSDESKOFF);
- SendMessage(GetDlgItem(m_hWnd, ID_btnDesc), BM_SETIMAGE, IMAGE_ICON, (LPARAM)(bState ? hIcon : 0));
- Button_Enable(GetDlgItem(m_hWnd, ID_btnDesc), bState);
-}
-
-//---------------------------------------------------------------------------
-void TfrmMain::btnAboutClick() {
- if (m_bFormAbout) return;
-
- TfrmAbout *frmAbout=new TfrmAbout(m_hWnd);
- frmAbout->Show();
- m_bFormAbout = true;
-}
-
-// Edit window call this event before it closes
-void TfrmMain::btnAboutOnCloseWindow(HWND hWnd) {
- m_bFormAbout = false;
-}
-
-//---------------------------------------------------------------------------
-void TfrmMain::btnExploreClick() {
- if (m_FDestFolder)
- ShellExecute(NULL, _T("explore"), m_FDestFolder, NULL, NULL, SW_SHOW);
-}
-
-//---------------------------------------------------------------------------
-void TfrmMain::edtSizeUpdate(HWND hWnd, BOOL ClientArea, HWND hTarget, UINT Ctrl) {
- // get window dimensions
- RECT rect = {0};
- RECT cliRect = {0};
- TCHAR B[33], H[16];
- GetWindowRect(hWnd, &rect);
- if (ClientArea) {
- POINT pt = {0};
- GetClientRect(hWnd, &cliRect);
- pt.x = cliRect.left;
- pt.y = cliRect.top;
- ClientToScreen(hWnd, &pt);
- pt.x = pt.x - rect.left; //offset x for client area
- pt.y = pt.y - rect.top; //offset y for client area
- rect = cliRect;
- }
-// _itot_s(rect.right - rect.left, B, 33, 10);
- _itot(rect.right - rect.left, B, 10);
-// _itot_s(rect.bottom - rect.top, H, 16, 10);
- _itot(rect.bottom - rect.top, H, 10);
- mir_tcsncat(B, _T("x"), 33);
- mir_tcsncat(B, H, 33);
- SetDlgItemText(hTarget, Ctrl, B);
-}
-
-void TfrmMain::edtSizeUpdate(RECT rect, HWND hTarget, UINT Ctrl) {
- TCHAR B[33], H[16];
-// _itot_s(ABS(rect.right - rect.left), B, 33, 10);
- _itot(ABS(rect.right - rect.left), B, 10);
-// _itot_s(ABS(rect.bottom - rect.top), H, 16, 10);
- _itot(ABS(rect.bottom - rect.top), H, 10);
- mir_tcsncat(B, _T("x"), 33);
- mir_tcsncat(B, H, 33);
- SetDlgItemText(hTarget, Ctrl, B);
-}
-
-//---------------------------------------------------------------------------
-INT_PTR TfrmMain::SaveScreenshot(FIBITMAP* dib) {
- //generate File name
- FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
- LPTSTR ret = NULL;
- LPTSTR path = NULL;
- LPTSTR pszFilename = NULL;
- LPTSTR pszFileDesc = NULL;
- if (!dib) return 1; //error
-
- //Generate FileName
- mir_tcsadd(path, m_FDestFolder);
- if (path[_tcslen(path)-1] != _T('\\')) mir_tcsadd(path, _T("\\"));
- mir_tcsadd(path, _T("shot%.5ld"));
- int FileNumber=db_get_dw(NULL, SZ_SENDSS, "FileNumber", 0) + 1;
- // '00000'-'%.5ld'=0 (add more or less len if differ from 5
- size_t len = (_tcslen(path)+0+1);
- pszFilename = (LPTSTR)mir_alloc(sizeof(TCHAR)*(len));
- mir_sntprintf(pszFilename, len, path, FileNumber);
- mir_free(path);
-
- //Generate a description according to the screenshot
- TCHAR winText[1024];
- mir_tcsadd(pszFileDesc, TranslateT("Screenshot "));
- if (m_opt_tabCapture == 0 && m_opt_chkClientArea) {
- mir_tcsadd(pszFileDesc, TranslateT("for Client area "));
- }
- mir_tcsadd(pszFileDesc, TranslateT("of \""));
- GetDlgItemText(m_hwndTabPage, ID_edtCaption, winText, 1024);
- mir_tcsadd(pszFileDesc, winText);
- mir_tcsadd(pszFileDesc, TranslateT("\" Window"));
-
- // convert to 32Bits (make shure it is 32bit)
- FIBITMAP *dib_new = FIP->FI_ConvertTo32Bits(dib);
- //RGBQUAD appColor = { 245, 0, 254, 0 }; //bgr0 schwarz
- //FIP->FI_SetBackgroundColor(dib_new, &appColor);
- FIP->FI_SetTransparent(dib_new,TRUE);
-
- // Investigates the color type of the bitmap (test for RGB or CMYK colour space)
- switch (FREE_IMAGE_COLOR_TYPE ColTye=FIP->FI_GetColorType(dib_new)) {
- case FIC_MINISBLACK:
- //Monochrome bitmap (1-bit) : first palette entry is black.
- //Palletised bitmap (4 or 8-bit) and single channel non standard bitmap: the bitmap has a greyscale palette
- case FIC_MINISWHITE:
- //Monochrome bitmap (1-bit) : first palette entry is white.
- //Palletised bitmap (4 or 8-bit) : the bitmap has an inverted greyscale palette
- case FIC_PALETTE:
- //Palettized bitmap (1, 4 or 8 bit)
- case FIC_RGB:
- //High-color bitmap (16, 24 or 32 bit), RGB16 or RGBF
- case FIC_RGBALPHA:
- //High-color bitmap with an alpha channel (32 bit bitmap, RGBA16 or RGBAF)
- case FIC_CMYK:
- //CMYK bitmap (32 bit only)
- default:
- break;
- }
-
-
- if ((FIP->FI_GetICCProfile(dib_new)->flags & FIICC_COLOR_IS_CMYK) == FIICC_COLOR_IS_CMYK) {
- // we are in CMYK colour space
- bool bDummy = false;
- }
- else {
- // we are in RGB colour space
- bool bDummy = true;
- }
-
- FIBITMAP *dib32 = NULL;
- FIBITMAP *dib24 = NULL;
- HWND hwndCombo = GetDlgItem(m_hWnd, ID_cboxFormat);
- switch (ComboBox_GetItemData(hwndCombo, ComboBox_GetCurSel(hwndCombo))) {
- case 0: //PNG
- ret = SaveImage(fif,dib_new, pszFilename, _T("png"));
- break;
-
- case 1: //JPG
- /*
- #define JPEG_QUALITYSUPERB 0x80 // save with superb quality (100:1)
- #define JPEG_QUALITYGOOD 0x0100 // save with good quality (75:1)
- #define JPEG_QUALITYNORMAL 0x0200 // save with normal quality (50:1)
- #define JPEG_QUALITYAVERAGE 0x0400 // save with average quality (25:1)
- #define JPEG_QUALITYBAD 0x0800 // save with bad quality (10:1)
- #define JPEG_PROGRESSIVE 0x2000 // save as a progressive-JPEG (use | to combine with other save flags)
- */
- dib32 = FIP->FI_Composite(dib_new,FALSE,&m_AlphaColor,NULL);
- dib24 = FIP->FI_ConvertTo24Bits(dib32);
- FIP->FI_Unload(dib32); dib32 = NULL;
- ret = SaveImage(fif,dib24, pszFilename, _T("jpg"));
- FIP->FI_Unload(dib24); dib24 = NULL;
- break;
-
- case 2: //BMP
- // ret = SaveImage(FIF_BMP,dib_new, pszFilename, _T("bmp")); //32bit alpha BMP
- dib32 = FIP->FI_Composite(dib_new,FALSE,&m_AlphaColor,NULL);
- dib24 = FIP->FI_ConvertTo24Bits(dib32);
- FIP->FI_Unload(dib32); dib32 = NULL;
- ret = SaveImage(FIF_BMP,dib24, pszFilename, _T("bmp"));
- FIP->FI_Unload(dib24); dib24 = NULL;
- break;
-
- case 3: //TIFF (miranda freeimage interface do not support save tiff, we udse GDI+)
- {
- LPTSTR pszFile = NULL;
- mir_tcsadd(pszFile, pszFilename);
- mir_tcsadd(pszFile, _T(".tif"));
-
- dib32 = FIP->FI_Composite(dib_new,FALSE,&m_AlphaColor,NULL);
- dib24 = FIP->FI_ConvertTo24Bits(dib32);
- FIP->FI_Unload(dib32); dib32 = NULL;
-
- HBITMAP hBmp = FIP->FI_CreateHBITMAPFromDIB(dib24);
- FIP->FI_Unload(dib24); dib24 = NULL;
- ret = SaveTIF(hBmp, pszFile) ? NULL : pszFile;
- DeleteObject(hBmp);
- }
- break;
-
- case 4: //GIF
- {
- //dib24 = FIP->FI_ConvertTo8Bits(dib_new);
- //ret = SaveImage(FIF_GIF,dib24, pszFilename, _T("gif"));
- //FIP->FI_Unload(dib24); dib24 = NULL;
- LPTSTR pszFile = NULL;
- mir_tcsadd(pszFile, pszFilename);
- mir_tcsadd(pszFile, _T(".gif"));
- HBITMAP hBmp = FIP->FI_CreateHBITMAPFromDIB(dib_new);
- SaveGIF(hBmp, pszFile);
- ret = pszFile;
- DeleteObject(hBmp);
- }
- break;
-
- default:
- break;
- }
-/* //load PNG and save file in user format (if differ)
- //this get better result for transparent aereas
- //LPTSTR pszFormat = (LPTSTR)ComboBox_GetItemData(hwndCombo, ComboBox_GetCurSel(hwndCombo));
- TCHAR pszFormat[6];
- ComboBox_GetText(hwndCombo, pszFormat, 6);
- if(ret && (_tcsicmp (pszFormat,_T("png")) != 0)) {
-
- fif = FIP->FI_GetFIFFromFilenameU(ret);
- dib_new = FIP->FI_LoadU(fif, ret,0);
-
-
- if(dib_new) {
- DeleteFile(ret);
- mir_freeAndNil(ret);
- FIBITMAP *dib_save = FIP->FI_ConvertTo24Bits(dib_new);
- ret = SaveImage(FIF_UNKNOWN,dib_save, pszFilename, pszFormat);
- FIP->FI_Unload(dib_new); dib_new = NULL;
- FIP->FI_Unload(dib_save); dib_save = NULL;
- }
- }*/
- FIP->FI_Unload(dib_new); dib_new = NULL;
- mir_freeAndNil(pszFilename);
-
- if (ret) {
- db_set_dw(NULL, SZ_SENDSS, "FileNumber", (DWORD)FileNumber);
- mir_freeAndNil(m_pszFile);
- mir_freeAndNil(m_pszFileDesc);
- m_pszFile = ret;
- if (IsWindowEnabled(GetDlgItem(m_hWnd, ID_btnDesc)) && m_opt_btnDesc) {
- m_pszFileDesc = pszFileDesc;
- }
- else {
- mir_tcsadd(m_pszFileDesc, _T(""));
- }
-
- if(m_cSend) {
- mir_freeAndNil(m_cSend->m_pszFile);
- mir_freeAndNil(m_cSend->m_pszFileDesc);
- m_cSend->m_pszFile = mir_tstrdup(m_pszFile);
- m_cSend->m_pszFileDesc = mir_tstrdup(m_pszFileDesc);
- }
- return 0; //OK
- }
- mir_freeAndNil(ret);
- mir_freeAndNil(pszFileDesc);
- return 1; //error
-}
-
-//---------------------------------------------------------------------------
-void TfrmMain::FormClose() {
-
- // Saving the screenshot
- if (SaveScreenshot(m_Screenshot)) {
- Show(); // Error from SaveScreenshot
- return;
- }
-
- if (m_cSend && m_pszFile && m_hContact && !m_bFormEdit) {
- m_cSend->Send();
- if (m_cSend->m_bFreeOnExit) cboxSendByChange();
-// Not finish delete this if events from m_opt_cboxSendBy implementet
- SendMessage(m_hWnd,UM_EVENT, 0, (LPARAM)EVT_CheckOpenAgain);
- }
- else {
- SendMessage(m_hWnd,UM_EVENT, 0, (LPARAM)EVT_CheckOpenAgain);
- }
-}
-
-//---------------------------------------------------------------------------
-/*/ Edit window call this event before it closes
-void TfrmMain::OnCloseEditWindow(TObject *Sender, TCloseAction &Action) {
- TfrmEdit *form=dynamic_cast<TfrmEdit*>(Sender);
- form->Hide();
-
- // delete the form automatically,after this event returns
- Action = caFree;
-
- // This will saves settings, free resources, ...
- form->CallBeforeClose(Action);
-
- // User selected "Capture" on action menu of edit window
- if (form->ModalResult == mrCancel) {
- this->Show();
- } else {
- Screenshot = form->Screen;
- bFormEdit = form->DontSend;
- this->Close();
- }
-}*/
-
-//---------------------------------------------------------------------------
+/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Sérgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "global.h" + +#include <list> +void TfrmMain::Unload(){ + std::list<TfrmMain*> lst; + for(CHandleMapping::iterator iter=_HandleMapping.begin(); iter!=_HandleMapping.end(); ++iter){ + lst.push_back(iter->second);//we can't delete inside loop.. not MT compatible + } + while(!lst.empty()){ + DestroyWindow(lst.front()->m_hWnd);//deletes class + lst.pop_front(); + } +} + +//--------------------------------------------------------------------------- +INT_PTR CALLBACK TfrmMain::DlgProc_CaptureWindow(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { +// main message handling is done inside TfrmMain::DlgTfrmMain + switch (uMsg) { + case WM_INITDIALOG: + Static_SetIcon(GetDlgItem(hDlg, ID_imgTarget), IcoLib_GetIcon(ICO_PLUG_SSTARGET)); + SetDlgItemText(hDlg, ID_edtCaption, TranslateT("Drag&Drop the target on the desired window.")); + TranslateDialogDefault(hDlg); + break; + case WM_CTLCOLOREDIT: //ctrl is NOT read-only or disabled + case WM_CTLCOLORSTATIC: //ctrl is read-only or disabled + // make the rectangle on the top white + switch (GetWindowLongPtr((HWND)lParam, GWL_ID)) { + case IDC_WHITERECT: + case ID_chkClientArea: + case ID_lblDropInfo: + case ID_edtCaption: + case ID_edtCaptionLabel: + case ID_edtSize: + case ID_edtSizeLabel: + case ID_bvlTarget: + case ID_imgTarget: + SetBkColor((HDC)wParam,GetSysColor(COLOR_WINDOW)); + SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT)); + + //SetBkMode((HDC)wParam,OPAQUE); + //return (INT_PTR)GetSysColorBrush(COLOR_WINDOW); + return (LRESULT)GetStockObject(WHITE_BRUSH); + break; + default: + SetBkMode((HDC)wParam, TRANSPARENT); + return (LRESULT)GetStockObject(NULL_BRUSH); + break; + } + break; //this return false + case WM_COMMAND: + SendMessage(GetParent(hDlg), uMsg, wParam, lParam); + break; + case WM_MOUSEMOVE: + SendMessage(GetParent(hDlg), UM_TAB1, uMsg, 0); + break; + case WM_NOTIFY: + SendMessage(GetParent(hDlg), uMsg, wParam, lParam); + break; + case WM_DESTROY: + break; + } + return FALSE; +} + +//--------------------------------------------------------------------------- +INT_PTR CALLBACK TfrmMain::DlgProc_CaptureDesktop(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { +// main message handling is done inside TfrmMain::DlgTfrmMain + switch (uMsg) { + case WM_INITDIALOG: + Static_SetIcon(GetDlgItem(hDlg, ID_imgTarget), IcoLib_GetIcon(ICO_PLUG_SSMONITOR)); + break; + case WM_CTLCOLOREDIT: + case WM_CTLCOLORSTATIC: + // make the rectangle on the top white + switch (GetWindowLongPtr((HWND)lParam, GWL_ID)) { + case IDC_WHITERECT: + case ID_lblDropInfo: + case ID_edtCaption: + case ID_edtCaptionLabel: + case ID_edtSize: + case ID_edtSizeLabel: + case ID_bvlTarget: + case ID_imgTarget: + SetBkColor((HDC)wParam,GetSysColor(COLOR_WINDOW)); + SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT)); + return (LRESULT)GetStockObject(WHITE_BRUSH); + break; + default: + SetBkMode((HDC)wParam, TRANSPARENT); + return (LRESULT)GetStockObject(NULL_BRUSH); + break; + } + break; + case WM_COMMAND: + SendMessage(GetParent(hDlg), uMsg, wParam, lParam); + break; + case WM_NOTIFY: + SendMessage(GetParent(hDlg), uMsg, wParam, lParam); + break; + case WM_DESTROY: + break; + } + return FALSE; +} + +//--------------------------------------------------------------------------- + +TfrmMain::CHandleMapping TfrmMain::_HandleMapping; + +LRESULT CALLBACK TfrmMain::DlgTfrmMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + if (msg == WM_CTLCOLOREDIT || msg == WM_CTLCOLORSTATIC) { + switch ( GetWindowLongPtr(( HWND )lParam, GWL_ID )) { + /* case IDC_WHITERECT:*/ + case IDC_HEADERBAR: + SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT)); + break; + default: + return FALSE; + } + SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); + return (LRESULT)GetStockObject(WHITE_BRUSH); //GetSysColorBrush(COLOR_WINDOW); + } + + CHandleMapping::iterator wnd(_HandleMapping.end()); + if (msg == WM_INITDIALOG) { + wnd = _HandleMapping.insert(CHandleMapping::value_type(hWnd, reinterpret_cast<TfrmMain*>(lParam))).first; + reinterpret_cast<TfrmMain*>(lParam)->m_hWnd = hWnd; + return wnd->second->wmInitdialog(wParam, lParam); + } + else { + wnd = _HandleMapping.find(hWnd); + } + if (wnd == _HandleMapping.end()) { // something screwed up + return FALSE; //dialog! do not use ::DefWindowProc(hWnd, msg, wParam, lParam); + } + + switch (msg) + { + // case WM_INITDIALOG: done on top + case WM_COMMAND: + return wnd->second->wmCommand(wParam, lParam); + break; + case WM_CLOSE: + return wnd->second->wmClose(wParam, lParam); + break; + case WM_DESTROY: + delete wnd->second; + break; + case UM_TAB1: + return wnd->second->UMTab1(wParam, lParam); + break; + case WM_NOTIFY: + return wnd->second->wmNotify(wParam, lParam); + break; + case WM_TIMER: + return wnd->second->wmTimer(wParam, lParam); + break; + case UM_CLOSING: + return wnd->second->UMClosing(wParam, lParam); + break; + case UM_EVENT: + return wnd->second->UMevent(wParam, lParam); + break; + } + return FALSE; +} + +//--------------------------------------------------------------------------- +//WM_INITDIALOG: +LRESULT TfrmMain::wmInitdialog(WPARAM wParam, LPARAM lParam) { + HWND hCtrl; + //Taskbar and Window icon + SendMessage(m_hWnd, WM_SETICON, ICON_BIG, (LPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW1, true)); + SendMessage(m_hWnd, WM_SETICON, ICON_SMALL, (LPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW2)); + LPTSTR pt = mir_a2t(__PLUGIN_NAME); + SetWindowText(m_hWnd, pt); + mir_freeAndNil(pt); + + // Headerbar + pt = mir_tstrdup((LPTSTR)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)m_hContact, (LPARAM)GCDNF_TCHAR)); + if (pt && (m_hContact != 0)) { + LPTSTR lptString = NULL; + mir_tcsadd(lptString , TranslateT("Send screenshot to\n")); + mir_tcsadd(lptString , pt); + SetDlgItemText(m_hWnd, IDC_HEADERBAR, lptString); + mir_free(lptString); + } + mir_freeAndNil(pt); + + SendMessage(GetDlgItem(m_hWnd, IDC_HEADERBAR), WM_SETICON, 0, (WPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW1, true)); + + //Timed controls + CheckDlgButton(m_hWnd,ID_chkTimed, m_opt_chkTimed ? BST_CHECKED : BST_UNCHECKED); + SetDlgItemInt (m_hWnd,ID_edtTimed, (UINT)m_opt_edtTimed, FALSE); + SendDlgItemMessage(m_hWnd, ID_upTimed, UDM_SETRANGE, 0, (LPARAM)MAKELONG(250, 1)); + chkTimedClick(); //enable disable Timed controls + + //create Image list for tab control + if(m_himlTab == 0){ + //m_himlTab = ImageList_Create(16, 16, PluginConfig.m_bIsXP ? ILC_COLOR32 | ILC_MASK : ILC_COLOR8 | ILC_MASK, 2, 0); + m_himlTab = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 2, 0); + ImageList_AddIcon(m_himlTab, IcoLib_GetIcon(ICO_PLUG_SSWINDOW2)); + ImageList_AddIcon(m_himlTab, IcoLib_GetIcon(ICO_PLUG_SSWINDOW2)); + } + + //create the tab control. + { + TAB_INFO itab; + RECT rcClient, rcTab; + m_hwndTab = GetDlgItem(m_hWnd, IDC_CAPTURETAB); + TabCtrl_SetItemExtra(m_hwndTab, sizeof(TAB_INFO) - sizeof(TCITEMHEADER)); + + ZeroMemory(&itab, sizeof(itab)); + itab.hwndMain = m_hWnd; + itab.hwndTab = m_hwndTab; + + GetWindowRect(m_hwndTab, &rcTab); + GetWindowRect(m_hWnd, &rcClient); + + TabCtrl_SetImageList(m_hwndTab, m_himlTab); + + // Add a tab for each of the three child dialog boxes. + itab.tcih.mask = TCIF_PARAM|TCIF_TEXT|TCIF_IMAGE; + + itab.tcih.pszText = TranslateT("Window"); + itab.tcih.iImage = 0; + itab.hwndTabPage = CreateDialog(hInst,MAKEINTRESOURCE(IDD_UMain_CaptureWindow), m_hWnd,DlgProc_CaptureWindow); + TabCtrl_InsertItem(m_hwndTab, 0, &itab); + MoveWindow(itab.hwndTabPage, (rcTab.left - rcClient.left)+2, (rcTab.top - rcClient.top), (rcTab.right - rcTab.left) - 2*5, (rcTab.bottom - rcTab.top) - 2*20, TRUE); + ShowWindow(itab.hwndTabPage, SW_HIDE); + CheckDlgButton(itab.hwndTabPage, ID_chkClientArea, m_opt_chkClientArea ? BST_CHECKED : BST_UNCHECKED); + + itab.tcih.pszText = TranslateT("Desktop"); + itab.tcih.iImage = 1; + itab.hwndTabPage = CreateDialog(hInst,MAKEINTRESOURCE(IDD_UMain_CaptureDesktop), m_hWnd, DlgProc_CaptureDesktop); + TabCtrl_InsertItem(m_hwndTab, 1, &itab); + MoveWindow(itab.hwndTabPage, (rcTab.left - rcClient.left)+2, (rcTab.top - rcClient.top), (rcTab.right - rcTab.left) - 2*5, (rcTab.bottom - rcTab.top) - 2*20, TRUE); + ShowWindow(itab.hwndTabPage, SW_HIDE); + + hCtrl = GetDlgItem(itab.hwndTabPage, ID_edtCaption); + ComboBox_ResetContent(hCtrl); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("<entire desktop>")) ,0); + ComboBox_SetCurSel (hCtrl,0); + if(m_MonitorCount >1) { + TCHAR tszTemp[120]; + for (size_t i = 0; i < m_MonitorCount; ++i) { + mir_sntprintf(tszTemp, SIZEOF(tszTemp),_T("%i. %s%s"), + i+1, + TranslateT("Monitor"), + (m_Monitors[i].dwFlags & MONITORINFOF_PRIMARY) ? TranslateT(" (primary)") : _T("") + ); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, tszTemp) , i+1); + } + ComboBox_SelectItemData (hCtrl, -1, m_opt_cboxDesktop); //use Workaround for MS bug ComboBox_SelectItemData + } + PostMessage(m_hWnd, WM_COMMAND, MAKEWPARAM(ID_edtCaption, CBN_SELCHANGE),(LPARAM)hCtrl); + + //select tab and set m_hwndTabPage + TabCtrl_SetCurSel(m_hwndTab, m_opt_tabCapture); + ZeroMemory(&itab, sizeof(itab)); + itab.tcih.mask = TCIF_PARAM; + TabCtrl_GetItem(m_hwndTab,TabCtrl_GetCurSel(m_hwndTab),&itab); + ShowWindow(itab.hwndTabPage,SW_SHOW); + m_hwndTabPage = itab.hwndTabPage; + } + //init Format combo box + { + hCtrl = GetDlgItem(m_hWnd, ID_cboxFormat); + ComboBox_ResetContent(hCtrl); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("PNG")),0); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("JPG")),1); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("BMP")),2); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("TIF")),3); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("GIF")),4); + ComboBox_SelectItemData (hCtrl, -1, m_opt_cboxFormat); //use Workaround for MS bug ComboBox_SelectItemData + } + //init SendBy combo box + { + hCtrl = GetDlgItem(m_hWnd, ID_cboxSendBy); + ComboBox_ResetContent(hCtrl); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("<Only save>")) ,SS_JUSTSAVE); + if (m_hContact) { + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("File Transfer")),SS_FILESEND); + } + else if(m_opt_cboxSendBy == SS_FILESEND) { + m_opt_cboxSendBy = SS_IMAGESHACK; + } + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("E-mail")) ,SS_EMAIL); + if (myGlobals.PluginHTTPExist) { + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("HTTP Server")) ,SS_HTTPSERVER); + } + else if(m_opt_cboxSendBy == SS_HTTPSERVER) { + m_opt_cboxSendBy = SS_IMAGESHACK; + } + if (myGlobals.PluginFTPExist) { + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("FTP File")) ,SS_FTPFILE); + } + else if(m_opt_cboxSendBy == SS_FTPFILE) { + m_opt_cboxSendBy = SS_IMAGESHACK; + } + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("ImageShack")) ,(BYTE)SS_IMAGESHACK); + ComboBox_SelectItemData (hCtrl, -1, m_opt_cboxSendBy); //use Workaround for MS bug ComboBox_SelectItemData + cboxSendByChange(); //enable disable controls + } + //init footer options + CheckDlgButton(m_hWnd,ID_chkOpenAgain, m_opt_chkOpenAgain ? BST_CHECKED : BST_UNCHECKED); + + if (hCtrl = GetDlgItem(m_hWnd, ID_btnAbout)) { + SendDlgItemMessage(m_hWnd, ID_btnAbout, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Information"), MBBF_TCHAR); + HICON hIcon = IcoLib_GetIcon(ICO_PLUG_SSHELP); + SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + SetWindowText(hCtrl, hIcon ? _T("") : _T("?")); + } + + if (hCtrl = GetDlgItem(m_hWnd, ID_btnExplore)) { + SendDlgItemMessage(m_hWnd, ID_btnExplore, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Open Folder"), MBBF_TCHAR); + HICON hIcon = IcoLib_GetIcon(ICO_PLUG_SSFOLDERO); + SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + SetWindowText(hCtrl, hIcon ? _T("") : _T("...")); + } + + if (hCtrl = GetDlgItem(m_hWnd, ID_btnDesc)) { + SendDlgItemMessage(m_hWnd, ID_btnDesc, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Fill description textbox."), MBBF_TCHAR); + HICON hIcon = IcoLib_GetIcon(m_opt_btnDesc ? ICO_PLUG_SSDESKON : ICO_PLUG_SSDESKOFF); + SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + SetWindowText(hCtrl, hIcon ? _T("") : _T("D")); + SendMessage(hCtrl, BM_SETCHECK, m_opt_btnDesc ? BST_CHECKED : BST_UNCHECKED, NULL); + } + + if (hCtrl = GetDlgItem(m_hWnd, ID_btnDeleteAfterSend)) { + SendDlgItemMessage(m_hWnd, ID_btnDeleteAfterSend, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Delete after send"), MBBF_TCHAR); + HICON hIcon = IcoLib_GetIcon(m_opt_btnDeleteAfterSend ? ICO_PLUG_SSDELON : ICO_PLUG_SSDELOFF); + SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + SetWindowText(hCtrl, hIcon ? _T("") : _T("X")); + SendMessage(hCtrl, BM_SETCHECK, m_opt_btnDeleteAfterSend ? BST_CHECKED : BST_UNCHECKED, NULL); + } + + if (hCtrl = GetDlgItem(m_hWnd, ID_btnCapture)) { + SendDlgItemMessage(m_hWnd, ID_btnCapture, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Capture"), MBBF_TCHAR); + HICON hIcon = IcoLib_GetIcon(ICO_PLUG_OK); + SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + SetWindowText(hCtrl, TranslateT("&Capture")); + SendMessage(hCtrl, BUTTONSETDEFAULT, (WPARAM)1, NULL); + } + +// CheckDlgButton(m_hWnd,ID_chkEditor, m_opt_chkEditor ? BST_CHECKED : BST_UNCHECKED); + TranslateDialogDefault(m_hWnd); + return FALSE; +} + +//WM_COMMAND: +LRESULT TfrmMain::wmCommand(WPARAM wParam, LPARAM lParam) { + //--------------------------------------------------------------------------- + int IDControl = LOWORD(wParam); + switch (HIWORD(wParam)) { + case BN_CLICKED: //Button controls + switch(IDControl) { + case IDCANCEL: + case IDCLOSE: + break; + + case ID_chkTimed: + m_opt_chkTimed = (BYTE)Button_GetCheck((HWND)lParam); + TfrmMain::chkTimedClick(); + break; + case ID_chkClientArea: + m_opt_chkClientArea = (BYTE)Button_GetCheck((HWND)lParam); + if(m_hTargetWindow) + edtSizeUpdate(m_hTargetWindow, m_opt_chkClientArea, GetParent((HWND)lParam), ID_edtSize); + break; + case ID_chkOpenAgain: + m_opt_chkOpenAgain = (BYTE)Button_GetCheck((HWND)lParam); + break; + case ID_chkEditor: + m_opt_chkEditor = (BYTE)Button_GetCheck((HWND)lParam); + break; + + case ID_btnAbout: + TfrmMain::btnAboutClick(); + break; + case ID_btnExplore: + TfrmMain::btnExploreClick(); + break; + case ID_btnDesc: + { + m_opt_btnDesc = (m_opt_btnDesc == 0); + HICON hIcon = IcoLib_GetIcon(m_opt_btnDesc ? ICO_PLUG_SSDESKON : ICO_PLUG_SSDESKOFF); + SendMessage((HWND)lParam, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + } + break; + case ID_btnDeleteAfterSend: + { + m_opt_btnDeleteAfterSend = (m_opt_btnDeleteAfterSend == 0); + HICON hIcon = IcoLib_GetIcon(m_opt_btnDeleteAfterSend ? ICO_PLUG_SSDELON : ICO_PLUG_SSDELOFF); + SendMessage((HWND)lParam, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + if(m_cSend) m_cSend->m_bDeleteAfterSend = m_opt_btnDeleteAfterSend; + } + break; + case ID_btnCapture: + TfrmMain::btnCaptureClick(); + break; + default: + break; + } + break; + case CBN_SELCHANGE: //ComboBox controls + switch(IDControl) { + //lParam = Handle to the control + case ID_cboxFormat: //not finish + m_opt_cboxFormat = (BYTE)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam)); + break; + case ID_cboxSendBy: + m_opt_cboxSendBy = (BYTE)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam)); + cboxSendByChange(); + break; + case ID_edtCaption: //cboxDesktopChange + m_opt_cboxDesktop = (BYTE)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam)); + m_hTargetWindow = 0; + if (m_opt_cboxDesktop > 0) { + edtSizeUpdate(m_Monitors[m_opt_cboxDesktop-1].rcMonitor, GetParent((HWND)lParam), ID_edtSize); + } + else { + edtSizeUpdate(m_VirtualScreen, GetParent((HWND)lParam), ID_edtSize); + } + break; + default: + break; + } + break; + case EN_CHANGE: //Edit controls + switch(IDControl) { + //lParam = Handle to the control + case ID_edtQuality: + m_opt_edtQuality = (BYTE)GetDlgItemInt(m_hWnd, ID_edtQuality, NULL, FALSE); + break; + case ID_edtTimed: + m_opt_edtTimed = (BYTE)GetDlgItemInt(m_hWnd, ID_edtTimed, NULL, FALSE); + break; + default: + break; + } + break; + default: + break; + } + return FALSE; +} + +//WM_CLOSE: +LRESULT TfrmMain::wmClose(WPARAM wParam, LPARAM lParam) { + DestroyWindow(m_hWnd); + return FALSE; +} + +//WM_TIMER: +LRESULT TfrmMain::wmTimer(WPARAM wParam, LPARAM lParam) { + if (wParam == ID_bvlTarget) { // Timer for Target selector + if (m_hCursor) { //imgTarget is activ + //LmouseButton = false + if (!GetLmouse()) { + TfrmMain::imgTargetMouseUp(); + return FALSE; + } + //Timer action if LmouseButton = true + m_hLastWin = m_hTargetWindow; + POINT point={0}; + GetCursorPos(&point); + HWND hCurrentWin = WindowFromPoint(point); + while (GetParent(hCurrentWin)) { + hCurrentWin = GetParent(hCurrentWin); + } + if (m_hLastWin != hCurrentWin) { + LPTSTR lpTitle = NULL; + if (m_hLastWin) { + DrawBorderInverted(m_hLastWin); + } + int Count = GetWindowTextLength(hCurrentWin)+1; + if(Count > 1){ + lpTitle = (LPTSTR)mir_alloc(Count*sizeof(TCHAR)); + GetWindowText(hCurrentWin, lpTitle, Count); + } + else { + //no WindowText present, use WindowClass + lpTitle = (LPTSTR)mir_alloc(MAX_PATH*sizeof(TCHAR)); + RealGetWindowClass(hCurrentWin, lpTitle, MAX_PATH); + } + SetDlgItemText(m_hwndTabPage, ID_edtCaption, lpTitle); + mir_free(lpTitle); + edtSizeUpdate(hCurrentWin, m_opt_chkClientArea, m_hwndTabPage, ID_edtSize); + DrawBorderInverted(hCurrentWin); + m_hTargetWindow = hCurrentWin; + } + return FALSE; + } + //imgTarget is not activ (check if cursor is over ID_bvlTarget control) + RECT rc; + POINT pt; + GetWindowRect(GetDlgItem(m_hwndTabPage, wParam),&rc); + GetCursorPos(&pt); + //check Mouse cursor + if(!PtInRect(&rc,pt)) { // mouse must be gone, trigger mouse leave + //PostMessage(m_hWnd,WM_MOUSELEAVE,wParam,lParam); + KillTimer(m_hWnd,wParam); + } + else if (GetLmouse() && !m_hCursor) { //mouse hover + LButton + TfrmMain::imgTargetMouseDown(); + } + } + if (wParam == ID_chkTimed) { // Timer for Screenshot + #ifdef _DEBUG + OutputDebugStringA("SS Bitmap Timer Start\r\n" ); + #endif + if(!m_bCapture) { //only start once + if (m_Screenshot) { + FIP->FI_Unload(m_Screenshot); + m_Screenshot = NULL; + } + m_bCapture = true; + switch (m_opt_tabCapture) { + case 0: + m_Screenshot = CaptureWindow(m_hTargetWindow, (BOOL)m_opt_chkClientArea); + break; + case 1: + m_Screenshot = CaptureMonitor((m_opt_cboxDesktop > 0) ? m_Monitors[m_opt_cboxDesktop-1].szDevice : NULL); + break; + default: + KillTimer(m_hWnd,wParam); + m_bCapture = false; + #ifdef _DEBUG + OutputDebugStringA("SS Bitmap Timer Stop (no tabCapture)\r\n" ); + #endif + return FALSE; + } + if (!m_Screenshot) m_bCapture = false; + } + if (m_Screenshot) { + KillTimer(m_hWnd,wParam); + m_bCapture = false; + #ifdef _DEBUG + OutputDebugStringA("SS Bitmap Timer Stop (CaptureDone)\r\n" ); + #endif + SendMessage(m_hWnd,UM_EVENT, 0, (LPARAM)EVT_CaptureDone); + } + } + return FALSE; +} + +//WM_NOTIFY: +LRESULT TfrmMain::wmNotify(WPARAM wParam, LPARAM lParam) { + switch(((LPNMHDR)lParam)->idFrom) { + case IDC_CAPTURETAB: //TabControl IDC_CAPTURETAB + switch (((LPNMHDR)lParam)->code) { + // HWND hwndFrom; = member is handle to the tab control + // UINT_PTR idFrom; = member is the child window identifier of the tab control. + // UINT code; = member is TCN_SELCHANGE + case TCN_SELCHANGING: + { + TAB_INFO itab; + ZeroMemory(&itab, sizeof(itab)); + itab.tcih.mask = TCIF_PARAM; + TabCtrl_GetItem(m_hwndTab,TabCtrl_GetCurSel(m_hwndTab),&itab); + ShowWindow(itab.hwndTabPage,SW_HIDE); + m_hwndTabPage = NULL; + } + break; + + case TCN_SELCHANGE: + { + TAB_INFO itab; + ZeroMemory(&itab, sizeof(itab)); + itab.tcih.mask = TCIF_PARAM; + m_opt_tabCapture = TabCtrl_GetCurSel(m_hwndTab); + TabCtrl_GetItem(m_hwndTab, m_opt_tabCapture, &itab); + ShowWindow(itab.hwndTabPage, SW_SHOW); + m_hwndTabPage = itab.hwndTabPage; + } + break; + default: + break; + } + break; + default: + break; + } + return FALSE; +} + +//UM_CLOSING: +LRESULT TfrmMain::UMClosing(WPARAM wParam, LPARAM lParam) { + HWND hWnd = (HWND)wParam; + switch (lParam) { + case IDD_UAboutForm: + btnAboutOnCloseWindow(hWnd); + break; + case IDD_UEditForm: + ; + break; + default: + break; + } + return FALSE; +} + +//UM_TAB1: +LRESULT TfrmMain::UMTab1(WPARAM wParam, LPARAM lParam) { + switch (wParam) { + case WM_MOUSEMOVE: + if (m_opt_tabCapture == 0) { + // Call timer, used to start cheesy TrackMouseEvent faker + SetTimer(m_hWnd,ID_bvlTarget,BUTTON_POLLDELAY,NULL); + } + break; + default: + break; + } + return FALSE; +} + +//UM_EVENT: +LRESULT TfrmMain::UMevent(WPARAM wParam, LPARAM lParam) { + //HWND hWnd = (HWND)wParam; + switch (lParam) { + case EVT_CaptureDone: + if (!m_Screenshot) { + TCHAR *err = TranslateT("Can't create a Screenshot"); + MessageBox(m_hWnd,err,ERROR_TITLE,MB_OK|MB_ICONWARNING); + Show(); + return FALSE; + } + if (m_opt_chkEditor) { + /* TfrmEdit *frmEdit=new TfrmEdit(this); + m_bFormEdit = true; + + frmEdit->mniClose->Enabled = !chkJustSaveIt->Checked; + frmEdit->mniCloseSend->Enabled = frmEdit->mniClose->Enabled; + frmEdit->OnClose = OnCloseEditWindow; + frmEdit->InitEditor(Screenshot); // Screenshot is copied to another in-memory bitmap inside this method + frmEdit->Show(); + delete Screenshot; // This way we can delete it after the method returns + Screenshot = NULL; + */ + return FALSE; + } + else { + FormClose(); + } + break; + case EVT_SendFileDone: + break; + case EVT_CheckOpenAgain: + if (m_opt_chkOpenAgain) { + if (m_Screenshot) { + FIP->FI_Unload(m_Screenshot); + m_Screenshot = NULL; + } + m_hTargetWindow = m_hLastWin = NULL; + Show(); + } + else { + // Saving Options and close + SaveOptions(); + Close(); + } + break; + default: + break; + } + return FALSE; +} + +//--------------------------------------------------------------------------- +// Standard konstruktor/destruktor +TfrmMain::TfrmMain() { + m_hWnd = NULL; + m_hContact = NULL; + m_hTargetWindow = NULL; + m_hCursor = NULL; + m_Screenshot = NULL; + m_pszFile = m_pszFileDesc = m_FDestFolder = NULL; + m_bFormAbout = m_bFormEdit = m_bDeleteAfterSend = m_bSelectingWindow = false; + m_cSend = NULL; + m_bOnExitSave = TRUE; + LoadOptions(); + m_bCapture = false; + m_himlTab = NULL; + m_Monitors = NULL; + m_MonitorCount = MonitorInfoEnum(m_Monitors, m_VirtualScreen); + +} + +TfrmMain::~TfrmMain() { + _HandleMapping.erase(m_hWnd); + mir_free(m_pszFile); + mir_free(m_FDestFolder); + mir_free(m_pszFileDesc); + mir_free(m_Monitors); + if (m_Screenshot) FIP->FI_Unload(m_Screenshot); + if (m_cSend) delete m_cSend; +} + +//--------------------------------------------------------------------------- +// Load / Saving options from miranda's database +void TfrmMain::LoadOptions(void) { + DWORD rgb = db_get_dw(NULL, SZ_SENDSS, "AlphaColor", 16777215); + m_AlphaColor.rgbRed = GetRValue(rgb); + m_AlphaColor.rgbGreen = GetGValue(rgb); + m_AlphaColor.rgbBlue = GetBValue(rgb); + m_AlphaColor.rgbReserved = 0; + +// m_opt_chkEmulateClick = db_get_b(NULL, SZ_SENDSS, "AutoSend", 1); + m_opt_edtQuality = db_get_b(NULL, SZ_SENDSS, "JpegQuality", 75); + + m_opt_tabCapture = db_get_b(NULL, SZ_SENDSS, "Capture", 0); + m_opt_chkClientArea = db_get_b(NULL, SZ_SENDSS, "ClientArea", 0); + m_opt_cboxDesktop = db_get_b(NULL, SZ_SENDSS, "Desktop", 0); + + m_opt_chkTimed = db_get_b(NULL, SZ_SENDSS, "TimedCap", 0); + m_opt_edtTimed = db_get_b(NULL, SZ_SENDSS, "CapTime", 3); + m_opt_cboxFormat = db_get_b(NULL, SZ_SENDSS, "OutputFormat", 3); + m_opt_cboxSendBy = db_get_b(NULL, SZ_SENDSS, "SendBy", 0); + + m_opt_chkEditor = db_get_b(NULL, SZ_SENDSS, "Preview", 0); + m_opt_btnDesc = db_get_b(NULL, SZ_SENDSS, "AutoDescription", 1); + m_opt_btnDeleteAfterSend = db_get_b(NULL, SZ_SENDSS, "DelAfterSend", 1); + m_opt_chkOpenAgain = db_get_b(NULL, SZ_SENDSS, "OpenAgain", 0); +} + +void TfrmMain::SaveOptions(void) { + if(m_bOnExitSave) { + db_set_dw(NULL, SZ_SENDSS, "AlphaColor", + (DWORD)RGB(m_AlphaColor.rgbRed, m_AlphaColor.rgbGreen, m_AlphaColor.rgbBlue)); + +// db_set_b(NULL, SZ_SENDSS, "AutoSend", m_opt_chkEmulateClick); + db_set_b(NULL, SZ_SENDSS, "JpegQuality", m_opt_edtQuality); + + db_set_b(NULL, SZ_SENDSS, "Capture", m_opt_tabCapture); + db_set_b(NULL, SZ_SENDSS, "ClientArea", m_opt_chkClientArea); + db_set_b(NULL, SZ_SENDSS, "Desktop", m_opt_cboxDesktop); + + db_set_b(NULL, SZ_SENDSS, "TimedCap", m_opt_chkTimed); + db_set_b(NULL, SZ_SENDSS, "CapTime", m_opt_edtTimed); + db_set_b(NULL, SZ_SENDSS, "OutputFormat", m_opt_cboxFormat); + db_set_b(NULL, SZ_SENDSS, "SendBy", m_opt_cboxSendBy); + + db_set_b(NULL, SZ_SENDSS, "AutoDescription", m_opt_btnDesc); + db_set_b(NULL, SZ_SENDSS, "DelAfterSend", m_opt_btnDeleteAfterSend); + db_set_b(NULL, SZ_SENDSS, "OpenAgain", m_opt_chkOpenAgain); + db_set_b(NULL, SZ_SENDSS, "Preview", m_opt_chkEditor); + } +} + +//--------------------------------------------------------------------------- +void TfrmMain::Init(LPTSTR DestFolder, HANDLE Contact) { + if(DestFolder) + { + m_FDestFolder = mir_tstrdup(DestFolder); + m_hContact = Contact; + if(!m_hContact) m_opt_cboxSendBy = SS_JUSTSAVE; + + // create window + m_hWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_UMainForm),0, (DLGPROC)DlgTfrmMain,(LPARAM)this); + //register object + _HandleMapping.insert(CHandleMapping::value_type(m_hWnd, this)); + + //check Contact + if(m_cSend) m_cSend->SetContact(Contact); + } +} + +//--------------------------------------------------------------------------- +void TfrmMain::btnCaptureClick() { + m_bFormEdit = false; //until UEditForm is includet + + if (m_opt_tabCapture == 0 && m_hTargetWindow == 0) { + TCHAR *err = TranslateT("Select a target window."); + MessageBox(m_hWnd,err,ERROR_TITLE,MB_OK|MB_ICONWARNING); + return; + } + TfrmMain::Hide(); + + if (!m_hTargetWindow) m_hTargetWindow = GetDesktopWindow(); + + if (m_opt_chkTimed) { + SetTimer(m_hWnd, ID_chkTimed, m_opt_edtTimed ? m_opt_edtTimed*1000 : 500, NULL); + } + else if (m_opt_tabCapture == 1){ + //desktop need always time to update from TfrmMain::Hide() + SetTimer(m_hWnd, ID_chkTimed, 500, NULL); + } + else { + m_Screenshot = CaptureWindow(m_hTargetWindow, (BOOL)(m_opt_chkClientArea)); + SendMessage(m_hWnd,UM_EVENT, 0, (LPARAM)EVT_CaptureDone); + } +} + +//--------------------------------------------------------------------------- +void TfrmMain::chkTimedClick() { + Button_Enable(GetDlgItem(m_hWnd, ID_edtTimedLabel), (BOOL)m_opt_chkTimed); + Button_Enable(GetDlgItem(m_hWnd, ID_edtTimed), (BOOL)m_opt_chkTimed); + Button_Enable(GetDlgItem(m_hWnd, ID_upTimed), (BOOL)m_opt_chkTimed); +} + +//--------------------------------------------------------------------------- +void TfrmMain::imgTargetMouseDown() { + //if (Button != mbLeft) return; + m_hCursor = CopyCursor(GetCursor()); //backup cursor + //SetSystemCursor need a copy coz it destroy the handle + SetSystemCursor(CopyCursor(IcoLib_GetIcon(ICO_PLUG_SSTARGET)),OCR_NORMAL); + m_bSelectingWindow = true; + m_hTargetWindow = NULL; + Hide(); + SetCapture(m_hWnd); +} + +//--------------------------------------------------------------------------- +void TfrmMain::imgTargetMouseUp() { + //if (Button == mbLeft && m_bSelectingWindow && TimerCheckFocus->Enabled) + if (m_bSelectingWindow && m_hCursor) { + Show(); + ReleaseCapture(); + SetSystemCursor(m_hCursor, OCR_NORMAL); + m_hCursor = NULL; + if (m_hTargetWindow){ + DrawBorderInverted(m_hTargetWindow); + } + m_bSelectingWindow = false; + } +} + +//--------------------------------------------------------------------------- +void TfrmMain::cboxSendByChange() { + BOOL bState; + HICON hIcon; + BYTE itemFlag = SS_DLG_DESCRIPTION; //SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND | + if (m_cSend && !m_cSend->m_bFreeOnExit) { + delete m_cSend; + m_cSend = NULL; + } + switch(m_opt_cboxSendBy) { + case SS_FILESEND: //"File Transfer" + m_cSend = new CSendFile(m_hWnd, m_hContact, false); + break; + case SS_EMAIL: //"E-mail" + m_cSend = new CSendEmail(m_hWnd, m_hContact, false); + break; + case SS_HTTPSERVER: //"HTTP Server" + m_cSend = new CSendHTTPServer(m_hWnd, m_hContact, false); + break; + case SS_FTPFILE: //"FTP File" + m_cSend = new CSendFTPFile(m_hWnd, m_hContact, false); + break; + case SS_IMAGESHACK: //"ImageShack" + m_cSend = new CSendImageShack(m_hWnd, m_hContact, false); + break; + default: //SS_JUSTSAVE - "Just save it " + m_cSend = NULL; + break; + } + if(m_cSend){ + itemFlag = m_cSend->GetEnableItem(); + m_cSend->m_bDeleteAfterSend = m_opt_btnDeleteAfterSend; + } + bState = ((itemFlag & SS_DLG_DELETEAFTERSSEND) == SS_DLG_DELETEAFTERSSEND); + hIcon = IcoLib_GetIcon(m_opt_btnDeleteAfterSend ? ICO_PLUG_SSDELON : ICO_PLUG_SSDELOFF); + SendMessage(GetDlgItem(m_hWnd, ID_btnDeleteAfterSend), BM_SETIMAGE, IMAGE_ICON, (LPARAM)(bState ? hIcon : 0)); + Button_Enable(GetDlgItem(m_hWnd, ID_btnDeleteAfterSend), bState); + + bState = ((itemFlag & SS_DLG_DESCRIPTION) == SS_DLG_DESCRIPTION); + hIcon = IcoLib_GetIcon(m_opt_btnDesc ? ICO_PLUG_SSDESKON : ICO_PLUG_SSDESKOFF); + SendMessage(GetDlgItem(m_hWnd, ID_btnDesc), BM_SETIMAGE, IMAGE_ICON, (LPARAM)(bState ? hIcon : 0)); + Button_Enable(GetDlgItem(m_hWnd, ID_btnDesc), bState); +} + +//--------------------------------------------------------------------------- +void TfrmMain::btnAboutClick() { + if (m_bFormAbout) return; + + TfrmAbout *frmAbout=new TfrmAbout(m_hWnd); + frmAbout->Show(); + m_bFormAbout = true; +} + +// Edit window call this event before it closes +void TfrmMain::btnAboutOnCloseWindow(HWND hWnd) { + m_bFormAbout = false; +} + +//--------------------------------------------------------------------------- +void TfrmMain::btnExploreClick() { + if (m_FDestFolder) + ShellExecute(NULL, _T("explore"), m_FDestFolder, NULL, NULL, SW_SHOW); +} + +//--------------------------------------------------------------------------- +void TfrmMain::edtSizeUpdate(HWND hWnd, BOOL ClientArea, HWND hTarget, UINT Ctrl) { + // get window dimensions + RECT rect = {0}; + RECT cliRect = {0}; + TCHAR B[33], H[16]; + GetWindowRect(hWnd, &rect); + if (ClientArea) { + POINT pt = {0}; + GetClientRect(hWnd, &cliRect); + pt.x = cliRect.left; + pt.y = cliRect.top; + ClientToScreen(hWnd, &pt); + pt.x = pt.x - rect.left; //offset x for client area + pt.y = pt.y - rect.top; //offset y for client area + rect = cliRect; + } +// _itot_s(rect.right - rect.left, B, 33, 10); + _itot(rect.right - rect.left, B, 10); +// _itot_s(rect.bottom - rect.top, H, 16, 10); + _itot(rect.bottom - rect.top, H, 10); + mir_tcsncat(B, _T("x"), 33); + mir_tcsncat(B, H, 33); + SetDlgItemText(hTarget, Ctrl, B); +} + +void TfrmMain::edtSizeUpdate(RECT rect, HWND hTarget, UINT Ctrl) { + TCHAR B[33], H[16]; +// _itot_s(ABS(rect.right - rect.left), B, 33, 10); + _itot(ABS(rect.right - rect.left), B, 10); +// _itot_s(ABS(rect.bottom - rect.top), H, 16, 10); + _itot(ABS(rect.bottom - rect.top), H, 10); + mir_tcsncat(B, _T("x"), 33); + mir_tcsncat(B, H, 33); + SetDlgItemText(hTarget, Ctrl, B); +} + +//--------------------------------------------------------------------------- +INT_PTR TfrmMain::SaveScreenshot(FIBITMAP* dib) { + //generate File name + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + LPTSTR ret = NULL; + LPTSTR path = NULL; + LPTSTR pszFilename = NULL; + LPTSTR pszFileDesc = NULL; + if (!dib) return 1; //error + + //Generate FileName + mir_tcsadd(path, m_FDestFolder); + if (path[_tcslen(path)-1] != _T('\\')) mir_tcsadd(path, _T("\\")); + mir_tcsadd(path, _T("shot%.5ld")); + int FileNumber=db_get_dw(NULL, SZ_SENDSS, "FileNumber", 0) + 1; + // '00000'-'%.5ld'=0 (add more or less len if differ from 5 + size_t len = (_tcslen(path)+0+1); + pszFilename = (LPTSTR)mir_alloc(sizeof(TCHAR)*(len)); + mir_sntprintf(pszFilename, len, path, FileNumber); + mir_free(path); + + //Generate a description according to the screenshot + TCHAR winText[1024]; + mir_tcsadd(pszFileDesc, TranslateT("Screenshot ")); + if (m_opt_tabCapture == 0 && m_opt_chkClientArea) { + mir_tcsadd(pszFileDesc, TranslateT("for Client area ")); + } + mir_tcsadd(pszFileDesc, TranslateT("of \"")); + GetDlgItemText(m_hwndTabPage, ID_edtCaption, winText, 1024); + mir_tcsadd(pszFileDesc, winText); + mir_tcsadd(pszFileDesc, TranslateT("\" Window")); + + // convert to 32Bits (make shure it is 32bit) + FIBITMAP *dib_new = FIP->FI_ConvertTo32Bits(dib); + //RGBQUAD appColor = { 245, 0, 254, 0 }; //bgr0 schwarz + //FIP->FI_SetBackgroundColor(dib_new, &appColor); + FIP->FI_SetTransparent(dib_new,TRUE); + + // Investigates the color type of the bitmap (test for RGB or CMYK colour space) + switch (FREE_IMAGE_COLOR_TYPE ColTye=FIP->FI_GetColorType(dib_new)) { + case FIC_MINISBLACK: + //Monochrome bitmap (1-bit) : first palette entry is black. + //Palletised bitmap (4 or 8-bit) and single channel non standard bitmap: the bitmap has a greyscale palette + case FIC_MINISWHITE: + //Monochrome bitmap (1-bit) : first palette entry is white. + //Palletised bitmap (4 or 8-bit) : the bitmap has an inverted greyscale palette + case FIC_PALETTE: + //Palettized bitmap (1, 4 or 8 bit) + case FIC_RGB: + //High-color bitmap (16, 24 or 32 bit), RGB16 or RGBF + case FIC_RGBALPHA: + //High-color bitmap with an alpha channel (32 bit bitmap, RGBA16 or RGBAF) + case FIC_CMYK: + //CMYK bitmap (32 bit only) + default: + break; + } + + + if ((FIP->FI_GetICCProfile(dib_new)->flags & FIICC_COLOR_IS_CMYK) == FIICC_COLOR_IS_CMYK) { + // we are in CMYK colour space + bool bDummy = false; + } + else { + // we are in RGB colour space + bool bDummy = true; + } + + FIBITMAP *dib32 = NULL; + FIBITMAP *dib24 = NULL; + HWND hwndCombo = GetDlgItem(m_hWnd, ID_cboxFormat); + switch (ComboBox_GetItemData(hwndCombo, ComboBox_GetCurSel(hwndCombo))) { + case 0: //PNG + ret = SaveImage(fif,dib_new, pszFilename, _T("png")); + break; + + case 1: //JPG + /* + #define JPEG_QUALITYSUPERB 0x80 // save with superb quality (100:1) + #define JPEG_QUALITYGOOD 0x0100 // save with good quality (75:1) + #define JPEG_QUALITYNORMAL 0x0200 // save with normal quality (50:1) + #define JPEG_QUALITYAVERAGE 0x0400 // save with average quality (25:1) + #define JPEG_QUALITYBAD 0x0800 // save with bad quality (10:1) + #define JPEG_PROGRESSIVE 0x2000 // save as a progressive-JPEG (use | to combine with other save flags) + */ + dib32 = FIP->FI_Composite(dib_new,FALSE,&m_AlphaColor,NULL); + dib24 = FIP->FI_ConvertTo24Bits(dib32); + FIP->FI_Unload(dib32); dib32 = NULL; + ret = SaveImage(fif,dib24, pszFilename, _T("jpg")); + FIP->FI_Unload(dib24); dib24 = NULL; + break; + + case 2: //BMP + // ret = SaveImage(FIF_BMP,dib_new, pszFilename, _T("bmp")); //32bit alpha BMP + dib32 = FIP->FI_Composite(dib_new,FALSE,&m_AlphaColor,NULL); + dib24 = FIP->FI_ConvertTo24Bits(dib32); + FIP->FI_Unload(dib32); dib32 = NULL; + ret = SaveImage(FIF_BMP,dib24, pszFilename, _T("bmp")); + FIP->FI_Unload(dib24); dib24 = NULL; + break; + + case 3: //TIFF (miranda freeimage interface do not support save tiff, we udse GDI+) + { + LPTSTR pszFile = NULL; + mir_tcsadd(pszFile, pszFilename); + mir_tcsadd(pszFile, _T(".tif")); + + dib32 = FIP->FI_Composite(dib_new,FALSE,&m_AlphaColor,NULL); + dib24 = FIP->FI_ConvertTo24Bits(dib32); + FIP->FI_Unload(dib32); dib32 = NULL; + + HBITMAP hBmp = FIP->FI_CreateHBITMAPFromDIB(dib24); + FIP->FI_Unload(dib24); dib24 = NULL; + ret = SaveTIF(hBmp, pszFile) ? NULL : pszFile; + DeleteObject(hBmp); + } + break; + + case 4: //GIF + { + //dib24 = FIP->FI_ConvertTo8Bits(dib_new); + //ret = SaveImage(FIF_GIF,dib24, pszFilename, _T("gif")); + //FIP->FI_Unload(dib24); dib24 = NULL; + LPTSTR pszFile = NULL; + mir_tcsadd(pszFile, pszFilename); + mir_tcsadd(pszFile, _T(".gif")); + HBITMAP hBmp = FIP->FI_CreateHBITMAPFromDIB(dib_new); + SaveGIF(hBmp, pszFile); + ret = pszFile; + DeleteObject(hBmp); + } + break; + + default: + break; + } +/* //load PNG and save file in user format (if differ) + //this get better result for transparent aereas + //LPTSTR pszFormat = (LPTSTR)ComboBox_GetItemData(hwndCombo, ComboBox_GetCurSel(hwndCombo)); + TCHAR pszFormat[6]; + ComboBox_GetText(hwndCombo, pszFormat, 6); + if(ret && (_tcsicmp (pszFormat,_T("png")) != 0)) { + + fif = FIP->FI_GetFIFFromFilenameU(ret); + dib_new = FIP->FI_LoadU(fif, ret,0); + + + if(dib_new) { + DeleteFile(ret); + mir_freeAndNil(ret); + FIBITMAP *dib_save = FIP->FI_ConvertTo24Bits(dib_new); + ret = SaveImage(FIF_UNKNOWN,dib_save, pszFilename, pszFormat); + FIP->FI_Unload(dib_new); dib_new = NULL; + FIP->FI_Unload(dib_save); dib_save = NULL; + } + }*/ + FIP->FI_Unload(dib_new); dib_new = NULL; + mir_freeAndNil(pszFilename); + + if (ret) { + db_set_dw(NULL, SZ_SENDSS, "FileNumber", (DWORD)FileNumber); + mir_freeAndNil(m_pszFile); + mir_freeAndNil(m_pszFileDesc); + m_pszFile = ret; + if (IsWindowEnabled(GetDlgItem(m_hWnd, ID_btnDesc)) && m_opt_btnDesc) { + m_pszFileDesc = pszFileDesc; + } + else { + mir_tcsadd(m_pszFileDesc, _T("")); + } + + if(m_cSend) { + mir_freeAndNil(m_cSend->m_pszFile); + mir_freeAndNil(m_cSend->m_pszFileDesc); + m_cSend->m_pszFile = mir_tstrdup(m_pszFile); + m_cSend->m_pszFileDesc = mir_tstrdup(m_pszFileDesc); + } + return 0; //OK + } + mir_freeAndNil(ret); + mir_freeAndNil(pszFileDesc); + return 1; //error +} + +//--------------------------------------------------------------------------- +void TfrmMain::FormClose() { + + // Saving the screenshot + if (SaveScreenshot(m_Screenshot)) { + Show(); // Error from SaveScreenshot + return; + } + + if (m_cSend && m_pszFile && m_hContact && !m_bFormEdit) { + m_cSend->Send(); + if (m_cSend->m_bFreeOnExit) cboxSendByChange(); +// Not finish delete this if events from m_opt_cboxSendBy implementet + SendMessage(m_hWnd,UM_EVENT, 0, (LPARAM)EVT_CheckOpenAgain); + } + else { + SendMessage(m_hWnd,UM_EVENT, 0, (LPARAM)EVT_CheckOpenAgain); + } +} + +//--------------------------------------------------------------------------- +/*/ Edit window call this event before it closes +void TfrmMain::OnCloseEditWindow(TObject *Sender, TCloseAction &Action) { + TfrmEdit *form=dynamic_cast<TfrmEdit*>(Sender); + form->Hide(); + + // delete the form automatically,after this event returns + Action = caFree; + + // This will saves settings, free resources, ... + form->CallBeforeClose(Action); + + // User selected "Capture" on action menu of edit window + if (form->ModalResult == mrCancel) { + this->Show(); + } else { + Screenshot = form->Screen; + bFormEdit = form->DontSend; + this->Close(); + } +}*/ + +//--------------------------------------------------------------------------- diff --git a/plugins/SendScreenshotPlus/src/UMainForm.h b/plugins/SendScreenshotPlus/src/UMainForm.h index 92a2bdff47..f49aa546ff 100644 --- a/plugins/SendScreenshotPlus/src/UMainForm.h +++ b/plugins/SendScreenshotPlus/src/UMainForm.h @@ -1,142 +1,143 @@ -/*
-
-Miranda IM: the free IM client for Microsoft* Windows*
-Copyright 2000-2009 Miranda ICQ/IM project,
-
-This file is part of Send Screenshot Plus, a Miranda IM plugin.
-Copyright (c) 2010 Ing.U.Horn
-
-Parts of this file based on original sorce code
-(c) 2004-2006 Sérgio Vieira Rolanski (portet from Borland C++)
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#ifndef UMainFormH
-#define UMainFormH
-
-#define SS_JUSTSAVE 0
-#define SS_FILESEND 1
-#define SS_EMAIL 2
-#define SS_HTTPSERVER 3
-#define SS_FTPFILE 4
-#define SS_IMAGESHACK 5
-
-// Used for our own cheap TrackMouseEvent
-#define BUTTON_POLLDELAY 50
-
-// User Events
-#define EVT_CaptureDone 1
-#define EVT_SendFileDone 2
-#define EVT_CheckOpenAgain 3
-
-extern FI_INTERFACE *FIP;
-
-typedef struct MyTabData {
- TCITEMHEADER tcih;
- HWND hwndMain; //main window
- HWND hwndTab; //tab control
- HWND hwndTabPage; //current child dialog box
-}TAB_INFO;
-
-//---------------------------------------------------------------------------
-class TfrmMain{
-
- public:
- // Deklaration Standardkonstruktor/Standarddestructor
- TfrmMain();
- ~TfrmMain();
-
- BYTE m_opt_tabCapture; //capure tab page
- BYTE m_opt_btnDesc; //TCheckBox *chkDesc;
- BYTE m_opt_cboxDesktop; //TRadioButton *rbtnDesktop;
- BYTE m_opt_chkEditor; //TCheckBox *chkEditor;
- BYTE m_opt_chkTimed; //TCheckBox *chkTimed;
- BYTE m_opt_cboxSendBy; //TComboBox *cboxSendBy;
- bool m_bOnExitSave;
-
- void Show(){ShowWindow(m_hWnd,SW_SHOW);}
- void Hide(){ShowWindow(m_hWnd,SW_HIDE);}
- void Close(){SendMessage(m_hWnd,WM_CLOSE,0,0);}
- void Init(LPTSTR DestFolder, HANDLE Contact);
- void btnCaptureClick();
- void cboxSendByChange();
-
- private:
- HWND m_hWnd;
- HANDLE m_hContact;
- bool m_bSelectingWindow, m_bDeleteAfterSend;
- bool m_bFormAbout, m_bFormEdit;
- HWND m_hTargetWindow, m_hLastWin;
- LPTSTR m_FDestFolder;
- LPTSTR m_pszFile;
- LPTSTR m_pszFileDesc;
- FIBITMAP* m_Screenshot; //Graphics::TBitmap *Screenshot;
- RGBQUAD m_AlphaColor; //
- HCURSOR m_hCursor;
- CSend* m_cSend;
-
- void chkTimedClick();
- void imgTargetMouseDown();
- void imgTargetMouseUp();
- void btnAboutClick();
- void btnAboutOnCloseWindow(HWND hWnd);
- void btnExploreClick();
- void LoadOptions(void);
- void SaveOptions(void);
- INT_PTR SaveScreenshot(FIBITMAP* dib);
- void FormClose();
- static void edtSizeUpdate(HWND hWnd, BOOL ClientArea, HWND hTarget, UINT Ctrl);
- static void edtSizeUpdate(RECT rect, HWND hTarget, UINT Ctrl);
-
- protected:
- size_t m_MonitorCount;
- MONITORINFOEX* m_Monitors;
- RECT m_VirtualScreen;
-
- BYTE m_opt_chkOpenAgain; //TCheckBox *chkOpenAgain;
- BYTE m_opt_chkClientArea; //TCheckBox *chkClientArea;
- BYTE m_opt_edtQuality; //TLabeledEdit *edtQuality;
- BYTE m_opt_btnDeleteAfterSend; //TCheckBox *chkDeleteAfterSend;
- BYTE m_opt_cboxFormat; //TComboBox *cboxFormat;
- BYTE m_opt_edtTimed; //TLabeledEdit *edtTimed;
- bool m_bCapture; //is capture activ
-
- typedef std::map<HWND, TfrmMain *> CHandleMapping;
- static CHandleMapping _HandleMapping;
- static LRESULT CALLBACK DlgTfrmMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
-
- LRESULT wmInitdialog(WPARAM wParam, LPARAM lParam);
- LRESULT wmCommand(WPARAM wParam, LPARAM lParam);
- LRESULT wmClose(WPARAM wParam, LPARAM lParam);
- LRESULT wmNotify(WPARAM wParam, LPARAM lParam);
- LRESULT wmTimer(WPARAM wParam, LPARAM lParam);
-
- LRESULT UMevent(WPARAM wParam, LPARAM lParam);
- LRESULT UMClosing(WPARAM wParam, LPARAM lParam);
- LRESULT UMTab1(WPARAM wParam, LPARAM lParam);
-
- HWND m_hwndTab; //TabControl handle
- HWND m_hwndTabPage; //TabControl activ page handle
- HIMAGELIST m_himlTab; //TabControl imagelist
- static INT_PTR CALLBACK DlgProc_CaptureWindow (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
- static INT_PTR CALLBACK DlgProc_CaptureDesktop(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
-// LRESULT CALLBACK DlgProc_UseLastFile (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
-
-};
-
-//---------------------------------------------------------------------------
-
-#endif
+/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Sérgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef UMainFormH +#define UMainFormH + +#define SS_JUSTSAVE 0 +#define SS_FILESEND 1 +#define SS_EMAIL 2 +#define SS_HTTPSERVER 3 +#define SS_FTPFILE 4 +#define SS_IMAGESHACK 5 + +// Used for our own cheap TrackMouseEvent +#define BUTTON_POLLDELAY 50 + +// User Events +#define EVT_CaptureDone 1 +#define EVT_SendFileDone 2 +#define EVT_CheckOpenAgain 3 + +extern FI_INTERFACE *FIP; + +typedef struct MyTabData { + TCITEMHEADER tcih; + HWND hwndMain; //main window + HWND hwndTab; //tab control + HWND hwndTabPage; //current child dialog box +}TAB_INFO; + +//--------------------------------------------------------------------------- +class TfrmMain{ + + public: + // Deklaration Standardkonstruktor/Standarddestructor + TfrmMain(); + ~TfrmMain(); + + BYTE m_opt_tabCapture; //capure tab page + BYTE m_opt_btnDesc; //TCheckBox *chkDesc; + BYTE m_opt_cboxDesktop; //TRadioButton *rbtnDesktop; + BYTE m_opt_chkEditor; //TCheckBox *chkEditor; + BYTE m_opt_chkTimed; //TCheckBox *chkTimed; + BYTE m_opt_cboxSendBy; //TComboBox *cboxSendBy; + bool m_bOnExitSave; + + static void Unload(); + void Show(){ShowWindow(m_hWnd,SW_SHOW);} + void Hide(){ShowWindow(m_hWnd,SW_HIDE);} + void Close(){SendMessage(m_hWnd,WM_CLOSE,0,0);} + void Init(LPTSTR DestFolder, HANDLE Contact); + void btnCaptureClick(); + void cboxSendByChange(); + + private: + HWND m_hWnd; + HANDLE m_hContact; + bool m_bSelectingWindow, m_bDeleteAfterSend; + bool m_bFormAbout, m_bFormEdit; + HWND m_hTargetWindow, m_hLastWin; + LPTSTR m_FDestFolder; + LPTSTR m_pszFile; + LPTSTR m_pszFileDesc; + FIBITMAP* m_Screenshot; //Graphics::TBitmap *Screenshot; + RGBQUAD m_AlphaColor; // + HCURSOR m_hCursor; + CSend* m_cSend; + + void chkTimedClick(); + void imgTargetMouseDown(); + void imgTargetMouseUp(); + void btnAboutClick(); + void btnAboutOnCloseWindow(HWND hWnd); + void btnExploreClick(); + void LoadOptions(void); + void SaveOptions(void); + INT_PTR SaveScreenshot(FIBITMAP* dib); + void FormClose(); + static void edtSizeUpdate(HWND hWnd, BOOL ClientArea, HWND hTarget, UINT Ctrl); + static void edtSizeUpdate(RECT rect, HWND hTarget, UINT Ctrl); + + protected: + size_t m_MonitorCount; + MONITORINFOEX* m_Monitors; + RECT m_VirtualScreen; + + BYTE m_opt_chkOpenAgain; //TCheckBox *chkOpenAgain; + BYTE m_opt_chkClientArea; //TCheckBox *chkClientArea; + BYTE m_opt_edtQuality; //TLabeledEdit *edtQuality; + BYTE m_opt_btnDeleteAfterSend; //TCheckBox *chkDeleteAfterSend; + BYTE m_opt_cboxFormat; //TComboBox *cboxFormat; + BYTE m_opt_edtTimed; //TLabeledEdit *edtTimed; + bool m_bCapture; //is capture activ + + typedef std::map<HWND, TfrmMain *> CHandleMapping; + static CHandleMapping _HandleMapping; + static LRESULT CALLBACK DlgTfrmMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + + LRESULT wmInitdialog(WPARAM wParam, LPARAM lParam); + LRESULT wmCommand(WPARAM wParam, LPARAM lParam); + LRESULT wmClose(WPARAM wParam, LPARAM lParam); + LRESULT wmNotify(WPARAM wParam, LPARAM lParam); + LRESULT wmTimer(WPARAM wParam, LPARAM lParam); + + LRESULT UMevent(WPARAM wParam, LPARAM lParam); + LRESULT UMClosing(WPARAM wParam, LPARAM lParam); + LRESULT UMTab1(WPARAM wParam, LPARAM lParam); + + HWND m_hwndTab; //TabControl handle + HWND m_hwndTabPage; //TabControl activ page handle + HIMAGELIST m_himlTab; //TabControl imagelist + static INT_PTR CALLBACK DlgProc_CaptureWindow (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + static INT_PTR CALLBACK DlgProc_CaptureDesktop(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); +// LRESULT CALLBACK DlgProc_UseLastFile (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + +}; + +//--------------------------------------------------------------------------- + +#endif diff --git a/plugins/SendScreenshotPlus/src/ctrl_button.cpp b/plugins/SendScreenshotPlus/src/ctrl_button.cpp index 152e3b17db..3552517c67 100644 --- a/plugins/SendScreenshotPlus/src/ctrl_button.cpp +++ b/plugins/SendScreenshotPlus/src/ctrl_button.cpp @@ -1,651 +1,650 @@ -/*
-Miranda IM
-Copyright (C) 2002 Robert Rainwater
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include "global.h"
-
-// Used for our own cheap TrackMouseEvent
-#define BUTTON_POLLID 100
-#define BUTTON_POLLDELAY 50
-
-typedef struct TMBCtrl{
- HWND hwnd;
- HANDLE hThemeButton;
- HANDLE hThemeToolbar;
-
- HICON hIcon;
- HICON arrow; // uses down arrow
- HBITMAP hBitmap;
- HFONT hFont; // font
-
- DWORD dwStyle;
- BOOLEAN bFocus;
-
- INT stateId; // button state
- INT defbutton; // default button
- INT pbState;
- TCHAR cHot;
-} BTNCTRL, *LPBTNCTRL;
-
-// External theme methods and properties
-CRITICAL_SECTION csTips;
-HWND hwndToolTips = NULL;
-
-/**
- * name: DestroyTheme
- * desc: destroys theme data for buttons
- * param: ctl - BTNCTRL structure with the information about the theme to close
- * return: nothing
- **/
-static VOID __fastcall DestroyTheme(BTNCTRL *ctl)
-{
- if (ctl->hThemeButton) {
- CloseThemeData(ctl->hThemeButton);
- ctl->hThemeButton = NULL;
- }
- if (ctl->hThemeToolbar) {
- CloseThemeData(ctl->hThemeToolbar);
- ctl->hThemeToolbar = NULL;
- }
-}
-
-/**
- * name: LoadTheme
- * desc: load theme data for buttons if supported by os
- * param: ctl - BTNCTRL structure with the information about the theme to load
- * return: nothing
- **/
-static VOID __fastcall LoadTheme(BTNCTRL *ctl)
-{
- DestroyTheme(ctl);
- ctl->hThemeButton = OpenThemeData(ctl->hwnd,L"BUTTON");
- ctl->hThemeToolbar = OpenThemeData(ctl->hwnd,L"TOOLBAR");
-}
-
-/**
- * name: TBStateConvert2Flat
- * desc: convert button stateIDs
- * param: state - state id for the normal theme button
- * return: stateID for the flat theme button
- **/
-static INT __fastcall TBStateConvert2Flat(INT state) {
- switch (state) {
- case PBS_NORMAL: return TS_NORMAL;
- case PBS_HOT: return TS_HOT;
- case PBS_PRESSED: return TS_PRESSED;
- case PBS_DISABLED: return TS_DISABLED;
- case PBS_DEFAULTED: return TS_NORMAL;
- }
- return TS_NORMAL;
-}
-
-/**
- * name: PaintIcon
- * desc: Draws the Icon of the button
- * param: ctl - BTNCTRL structure for the button
- * hdcMem - device context to draw to
- * ccText - character count of the text of the button
- * rcClient - rectangle of the whole button
- * rcText - rectangle of the text to draw later on
- * return: nothing
- **/
-static VOID __fastcall PaintIcon(BTNCTRL *ctl, HDC hdcMem, LPWORD ccText, LPRECT rcClient, LPRECT rcText)
-{
- RECT rcImage;
-
- // draw icon on the left of the button
- if (ctl->hIcon) {
- rcImage.right = GetSystemMetrics(SM_CXSMICON);
- rcImage.bottom = GetSystemMetrics(SM_CYSMICON);
- rcImage.left = (rcClient->right - rcClient->left) / 2 - ((rcImage.right + rcText->right + (*ccText > 0 ? 4 : 0) + (ctl->arrow ? rcImage.right : 0)) / 2);
- rcImage.top = (rcClient->bottom - rcClient->top - rcImage.bottom) / 2;
- rcImage.right += rcImage.left;
- rcImage.bottom += rcImage.top;
-
- OffsetRect(rcText, rcImage.right + 4, 0);
- if (ctl->stateId == PBS_PRESSED) OffsetRect(&rcImage, 1, 1);
-
- DrawState(hdcMem, NULL, NULL, (LPARAM)ctl->hIcon, 0,
- rcImage.left, rcImage.top,
- rcImage.right - rcImage.left, rcImage.bottom - rcImage.top,
- IsWindowEnabled(ctl->hwnd) ? DST_ICON | DSS_NORMAL : DST_ICON | DSS_DISABLED);
- }
-
- // draw arrow on the right of the button
- if (ctl->arrow) {
- rcImage.right = GetSystemMetrics(SM_CXSMICON);
- rcImage.left = (*ccText > 0 || ctl->hIcon)
- ? rcClient->right - GetSystemMetrics(SM_CXSMICON)
- : (rcClient->right - rcClient->left - rcImage.right) / 2;
- rcImage.right += rcImage.left;
- rcImage.bottom = GetSystemMetrics(SM_CYSMICON);
- rcImage.top = (rcClient->bottom - rcClient->top - rcImage.bottom) / 2;
- if (ctl->stateId == PBS_PRESSED) OffsetRect(&rcImage, 1, 1);
-
- DrawState(hdcMem, NULL, NULL, (LPARAM)ctl->arrow, 0,
- rcImage.left, rcImage.top,
- rcImage.right - rcImage.left, rcImage.bottom - rcImage.top,
- IsWindowEnabled(ctl->hwnd) ? DST_ICON | DSS_NORMAL : DST_ICON | DSS_DISABLED);
- }
-}
-
-/**
- * name: PaintThemeButton
- * desc: Draws the themed button
- * param: ctl - BTNCTRL structure for the button
- * hdcMem - device context to draw to
- * rcClient - rectangle of the whole button
- * return: nothing
- **/
-static VOID __fastcall PaintThemeButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClient)
-{
- RECT rcText = { 0, 0, 0, 0 };
- WCHAR wszText[MAX_PATH] = { 0 };
- WORD ccText;
-
- // Draw the flat button
- if ((ctl->dwStyle & MBS_FLAT) && ctl->hThemeToolbar) {
- INT state = IsWindowEnabled(ctl->hwnd)
- ? (ctl->stateId == PBS_NORMAL && ctl->defbutton
- ? PBS_DEFAULTED
- : ctl->stateId)
- : PBS_DISABLED;
- if (IsThemeBackgroundPartiallyTransparent(ctl->hThemeToolbar, TP_BUTTON, TBStateConvert2Flat(state))) {
- if (SUCCEEDED(DrawThemeParentBackground(ctl->hwnd, hdcMem, rcClient)))
- DrawThemeParentBackground(GetParent(ctl->hwnd), hdcMem, rcClient);
- }
- DrawThemeBackground(ctl->hThemeToolbar, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), rcClient, rcClient);
- }
- else {
- // draw themed button background
- if (ctl->hThemeButton) {
- INT state = IsWindowEnabled(ctl->hwnd)
- ? (ctl->stateId == PBS_NORMAL && ctl->defbutton
- ? PBS_DEFAULTED
- : ctl->stateId)
- : PBS_DISABLED;
- if (IsThemeBackgroundPartiallyTransparent(ctl->hThemeButton, BP_PUSHBUTTON, state)) {
- if (SUCCEEDED(DrawThemeParentBackground(ctl->hwnd, hdcMem, rcClient)))
- DrawThemeParentBackground(GetParent(ctl->hwnd), hdcMem, rcClient);
- }
- DrawThemeBackground(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, state, rcClient, rcClient);
- }
- }
-
- // calculate text rect
- {
- RECT sizeText;
- HFONT hOldFont;
-
- ccText = GetWindowTextW(ctl->hwnd, wszText, sizeof(wszText) / sizeof(WCHAR));
-
- if (ccText > 0) {
- hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont);
-
- GetThemeTextExtent(
- ctl->hThemeButton,
- hdcMem,
- BP_PUSHBUTTON,
- IsWindowEnabled(ctl->hwnd) ? ctl->stateId : PBS_DISABLED,
- wszText,
- ccText,
- DST_PREFIXTEXT,
- NULL,
- &sizeText);
-
- if (ctl->cHot) {
- RECT rcHot;
-
- GetThemeTextExtent(ctl->hThemeButton,
- hdcMem,
- BP_PUSHBUTTON,
- IsWindowEnabled(ctl->hwnd) ? ctl->stateId : PBS_DISABLED,
- L"&",
- 1,
- DST_PREFIXTEXT,
- NULL,
- &rcHot);
-
- sizeText.right -= (rcHot.right - rcHot.left);
- }
- SelectObject(hdcMem, hOldFont);
-
- rcText.left = (ctl->hIcon) ? 0 : (rcClient->right - rcClient->left - (sizeText.right - sizeText.left)) / 2;
- rcText.top = (rcClient->bottom - rcClient->top - (sizeText.bottom - sizeText.top)) / 2;
- rcText.right = rcText.left + (sizeText.right - sizeText.left);
- rcText.bottom = rcText.top + (sizeText.bottom - sizeText.top);
- if (ctl->stateId == PBS_PRESSED) {
- OffsetRect(&rcText, 1, 1);
- }
- }
- }
- PaintIcon(ctl, hdcMem, &ccText, rcClient, &rcText);
- // draw text
- if (ccText > 0 && ctl->hThemeButton) {
- HFONT hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont);
- DrawThemeText(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, IsWindowEnabled(ctl->hwnd) ? ctl->stateId : PBS_DISABLED, wszText, ccText, DST_PREFIXTEXT, 0, &rcText);
- SelectObject(hdcMem, hOldFont);
- }
-}
-
-/**
- * name: PaintThemeButton
- * desc: Draws the none themed button
- * param: ctl - BTNCTRL structure for the button
- * hdcMem - device context to draw to
- * rcClient - rectangle of the whole button
- * return: nothing
- **/
-static VOID __fastcall PaintButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClient)
-{
- RECT rcText = { 0, 0, 0, 0 };
- TCHAR szText[MAX_PATH] = { 0 };
- WORD ccText;
-
- // Draw the flat button
- if (ctl->dwStyle & MBS_FLAT) {
- HBRUSH hbr = NULL;
-
- if (ctl->stateId == PBS_PRESSED || ctl->stateId == PBS_HOT)
- hbr = GetSysColorBrush(COLOR_3DLIGHT);
- else {
- HDC dc;
- HWND hwndParent;
-
- hwndParent = GetParent(ctl->hwnd);
- if (dc = GetDC(hwndParent)) {
- hbr = (HBRUSH)SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM)dc, (LPARAM)hwndParent);
- ReleaseDC(hwndParent, dc);
- }
- }
- if (hbr) {
- FillRect(hdcMem, rcClient, hbr);
- DeleteObject(hbr);
- }
- if (ctl->stateId == PBS_HOT || ctl->bFocus) {
- if (ctl->pbState) DrawEdge(hdcMem, rcClient, EDGE_ETCHED, BF_RECT|BF_SOFT);
- else DrawEdge(hdcMem, rcClient, BDR_RAISEDOUTER, BF_RECT|BF_SOFT|BF_FLAT);
- }
- else
- if (ctl->stateId == PBS_PRESSED)
- DrawEdge(hdcMem, rcClient, BDR_SUNKENOUTER, BF_RECT|BF_SOFT);
- }
- else {
- UINT uState = DFCS_BUTTONPUSH|((ctl->stateId == PBS_HOT) ? DFCS_HOT : 0)|((ctl->stateId == PBS_PRESSED) ? DFCS_PUSHED : 0);
- if (ctl->defbutton&&ctl->stateId==PBS_NORMAL) uState |= DLGC_DEFPUSHBUTTON;
- DrawFrameControl(hdcMem, rcClient, DFC_BUTTON, uState);
- // Draw focus rectangle if button has focus
- if (ctl->bFocus) {
- RECT focusRect = *rcClient;
- InflateRect(&focusRect, -3, -3);
- DrawFocusRect(hdcMem, &focusRect);
- }
- }
- // calculate text rect
- {
- SIZE sizeText;
- HFONT hOldFont;
-
- ccText = GetWindowText(ctl->hwnd, szText, SIZEOF(szText));
-
- if (ccText > 0) {
- hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont);
- GetTextExtentPoint32(hdcMem, szText, ccText, &sizeText);
- if (ctl->cHot) {
- SIZE sizeHot;
-
- GetTextExtentPoint32A(hdcMem, "&", 1, &sizeHot);
- sizeText.cx -= sizeHot.cx;
- }
- SelectObject(hdcMem, hOldFont);
-
- rcText.left = (ctl->hIcon) ? 0 : (rcClient->right - rcClient->left - sizeText.cx) / 2;
- rcText.top = (rcClient->bottom - rcClient->top - sizeText.cy) / 2;
- rcText.right = rcText.left + sizeText.cx;
- rcText.bottom = rcText.top + sizeText.cy;
- if (ctl->stateId == PBS_PRESSED)
- OffsetRect(&rcText, 1, 1);
- }
- }
- PaintIcon(ctl, hdcMem, &ccText, rcClient, &rcText);
-
- // draw text
- if (ccText > 0) {
- HFONT hOldFont;
-
- hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont);
-
- SetBkMode(hdcMem, TRANSPARENT);
- SetTextColor(hdcMem,
- IsWindowEnabled(ctl->hwnd) || !ctl->hThemeButton
- ? ctl->stateId == PBS_HOT
- ? GetSysColor(COLOR_HOTLIGHT)
- : GetSysColor(COLOR_BTNTEXT)
- : GetSysColor(COLOR_GRAYTEXT));
-
- DrawState(hdcMem, NULL, NULL, (LPARAM)szText, 0,
- rcText.left, rcText.top, rcText.right - rcText.left, rcText.bottom - rcText.top,
- IsWindowEnabled(ctl->hwnd) || ctl->hThemeButton ? DST_PREFIXTEXT | DSS_NORMAL : DST_PREFIXTEXT | DSS_DISABLED);
- SelectObject(hdcMem, hOldFont);
- }
-}
-
-/**
- * name: Button_WndProc
- * desc: window procedure for the button class
- * param: hwndBtn - window handle to the button
- * uMsg - message to handle
- * wParam - message specific parameter
- * lParam - message specific parameter
- * return: message specific
- **/
-static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, LPARAM lParam) {
- LPBTNCTRL bct = (LPBTNCTRL)GetWindowLongPtr(hwndBtn, 0);
-
- switch (uMsg) {
- case WM_NCCREATE:
- {
- LPCREATESTRUCT cs = (LPCREATESTRUCT)lParam;
-
- cs->style |= BS_OWNERDRAW;
- if (!(bct = (LPBTNCTRL)malloc(sizeof(BTNCTRL))))
- return FALSE;
- ZeroMemory(bct, sizeof(BTNCTRL));
- bct->hwnd = hwndBtn;
- bct->stateId = PBS_NORMAL;
- bct->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
- bct->dwStyle = cs->style;
- if (cs->style & MBS_DOWNARROW)
- bct->arrow = IcoLib_GetIcon(ICO_PLUG_DOWNARROW);
- LoadTheme(bct);
- SetWindowLongPtr(hwndBtn, 0, (LONG_PTR)bct);
- if (cs->lpszName) SetWindowText(hwndBtn, cs->lpszName);
- return TRUE;
- }
- case WM_DESTROY:
- if (bct) {
- EnterCriticalSection(&csTips);
- if (hwndToolTips) {
- TOOLINFO ti;
-
- ZeroMemory(&ti, sizeof(ti));
- ti.cbSize = sizeof(ti);
- ti.uFlags = TTF_IDISHWND;
- ti.hwnd = bct->hwnd;
- ti.uId = (UINT)bct->hwnd;
- if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti)) {
- SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti);
- }
- if (SendMessage(hwndToolTips, TTM_GETTOOLCOUNT, 0, (LPARAM)&ti) == 0) {
- DestroyWindow(hwndToolTips);
- hwndToolTips = NULL;
- }
- }
- LeaveCriticalSection(&csTips);
- DestroyTheme(bct);
- free(bct);
- }
- SetWindowLongPtr(hwndBtn, 0, NULL);
- break;
- case WM_SETTEXT:
- bct->cHot = 0;
- if ((LPTSTR)lParam) {
- LPTSTR tmp = (LPTSTR)lParam;
-
- while (*tmp) {
- if (*tmp=='&' && *(tmp+1)) {
- bct->cHot = _totlower(*(tmp+1));
- break;
- }
- tmp++;
- }
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- break;
- case WM_SYSKEYUP:
- if (bct->stateId != PBS_DISABLED && bct->cHot && bct->cHot == _totlower((TCHAR)wParam)) {
- if (bct->dwStyle & MBS_PUSHBUTTON) {
- if (bct->pbState) bct->pbState = 0;
- else bct->pbState = 1;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- else
- SetFocus(hwndBtn);
- SendMessage(GetParent(hwndBtn), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndBtn), BN_CLICKED), (LPARAM)hwndBtn);
- return 0;
- }
- break;
- case WM_THEMECHANGED:
- {
- // themed changed, reload theme object
- LoadTheme(bct);
- InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it
- break;
- }
- case WM_SETFONT: // remember the font so we can use it later
- bct->hFont = (HFONT)wParam; // maybe we should redraw?
- break;
- case WM_NCPAINT:
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
- HDC hdcPaint;
- HDC hdcMem;
- HBITMAP hbmMem;
- HDC hOld;
- RECT rcClient;
-
- if (hdcPaint = BeginPaint(hwndBtn, &ps)) {
- GetClientRect(bct->hwnd, &rcClient);
- hdcMem = CreateCompatibleDC(hdcPaint);
- hbmMem = CreateCompatibleBitmap(hdcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
- hOld = (HDC)SelectObject(hdcMem, hbmMem);
-
- // If its a push button, check to see if it should stay pressed
- if ((bct->dwStyle & MBS_PUSHBUTTON) && bct->pbState) bct->stateId = PBS_PRESSED;
-
- if ((bct->dwStyle & MBS_FLAT) && bct->hThemeToolbar || bct->hThemeButton)
- PaintThemeButton(bct, hdcMem, &rcClient);
- else
- PaintButton(bct, hdcMem, &rcClient);
-
- BitBlt(hdcPaint, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, hdcMem, 0, 0, SRCCOPY);
- SelectObject(hdcMem, hOld);
- DeleteObject(hbmMem);
- DeleteDC(hdcMem);
- EndPaint(hwndBtn, &ps);
- }
- return 0;
- }
- case BM_SETIMAGE:
- if (wParam == IMAGE_ICON) {
- bct->hIcon = (HICON)lParam;
- bct->hBitmap = NULL;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- else if (wParam == IMAGE_BITMAP) {
- bct->hIcon = NULL;
- bct->hBitmap = (HBITMAP)lParam;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- else if (wParam == NULL && lParam == NULL) {
- bct->hIcon = NULL;
- bct->hBitmap = NULL;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- break;
- case BM_SETCHECK:
- if (!(bct->dwStyle & MBS_PUSHBUTTON)) break;
- if (wParam == BST_CHECKED) {
- bct->pbState = 1;
- bct->stateId = PBS_PRESSED;
- }
- else if (wParam == BST_UNCHECKED) {
- bct->pbState = 0;
- bct->stateId = PBS_NORMAL;
- }
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case BM_GETCHECK:
- if (bct->dwStyle & MBS_PUSHBUTTON) return bct->pbState ? BST_CHECKED : BST_UNCHECKED;
- return 0;
- case BUTTONSETDEFAULT:
- bct->defbutton = wParam ? 1 : 0;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case BUTTONADDTOOLTIP:
- {
- if (!wParam) break;
- EnterCriticalSection(&csTips);
- if (!hwndToolTips) {
- hwndToolTips = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL);
- }
-
- if (lParam == MBBF_UNICODE) {
- TOOLINFOW ti;
-
- ZeroMemory(&ti, sizeof(TOOLINFOW));
- ti.cbSize = sizeof(TOOLINFOW);
- ti.uFlags = TTF_IDISHWND;
- ti.hwnd = bct->hwnd;
- ti.uId = (UINT)bct->hwnd;
- if (SendMessage(hwndToolTips, TTM_GETTOOLINFOW, 0, (LPARAM)&ti)) {
- SendMessage(hwndToolTips, TTM_DELTOOLW, 0, (LPARAM)&ti);
- }
- ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS;
- ti.uId = (UINT)bct->hwnd;
- ti.lpszText=(LPWSTR)wParam;
- SendMessage(hwndToolTips, TTM_ADDTOOLW, 0, (LPARAM)&ti);
- }
- else {
- TOOLINFOA ti;
-
- ZeroMemory(&ti, sizeof(TOOLINFOA));
- ti.cbSize = sizeof(TOOLINFOA);
- ti.uFlags = TTF_IDISHWND;
- ti.hwnd = bct->hwnd;
- ti.uId = (UINT)bct->hwnd;
- if (SendMessage(hwndToolTips, TTM_GETTOOLINFOA, 0, (LPARAM)&ti)) {
- SendMessage(hwndToolTips, TTM_DELTOOLA, 0, (LPARAM)&ti);
- }
- ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS;
- ti.uId = (UINT)bct->hwnd;
- ti.lpszText=(LPSTR)wParam;
- SendMessage(hwndToolTips, TTM_ADDTOOLA, 0, (LPARAM)&ti);
- }
- LeaveCriticalSection(&csTips);
- break;
- }
- case BUTTONTRANSLATE:
- {
- TCHAR szButton[MAX_PATH];
- GetWindowText(bct->hwnd, szButton, MAX_PATH);
- SetWindowText(bct->hwnd, TranslateTS(szButton));
- break;
- }
- case WM_SETFOCUS: // set keybord bFocus and redraw
- bct->bFocus = 1;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case WM_KILLFOCUS: // kill bFocus and redraw
- bct->bFocus = 0;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case WM_WINDOWPOSCHANGED:
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case WM_ENABLE: // windows tells us to enable/disable
- bct->stateId = wParam ? PBS_NORMAL : PBS_DISABLED;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case WM_MOUSELEAVE: // faked by the WM_TIMER
- if (bct->stateId != PBS_DISABLED) { // don't change states if disabled
- bct->stateId = PBS_NORMAL;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- break;
- case WM_LBUTTONDOWN:
- if (bct->stateId != PBS_DISABLED) { // don't change states if disabled
- bct->stateId = PBS_PRESSED;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- break;
- case WM_LBUTTONUP:
- if (bct->stateId != PBS_DISABLED) { // don't change states if disabled
- BOOLEAN bPressed = bct->stateId == PBS_PRESSED;
-
- if (bct->dwStyle & MBS_PUSHBUTTON) {
- if (bct->pbState) bct->pbState = 0;
- else bct->pbState = 1;
- }
- bct->stateId = PBS_HOT;
-
- // Tell your daddy you got clicked, if mouse is still over the button.
- if ((bct->dwStyle & MBS_PUSHBUTTON) || bPressed)
- SendMessage(GetParent(hwndBtn), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndBtn), BN_CLICKED), (LPARAM)hwndBtn);
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- break;
- case WM_MOUSEMOVE:
- if (bct->stateId == PBS_NORMAL) {
- bct->stateId = PBS_HOT;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- // Call timer, used to start cheesy TrackMouseEvent faker
- SetTimer(hwndBtn, BUTTON_POLLID, BUTTON_POLLDELAY, NULL);
- break;
- case WM_TIMER: // use a timer to check if they have did a mouseout
- if (wParam == BUTTON_POLLID) {
- RECT rc;
- POINT pt;
-
- GetWindowRect(hwndBtn, &rc);
- GetCursorPos(&pt);
- if (!PtInRect(&rc, pt)) { // mouse must be gone, trigger mouse leave
- PostMessage(hwndBtn, WM_MOUSELEAVE, 0, 0L);
- KillTimer(hwndBtn, BUTTON_POLLID);
- }
- }
- break;
- case WM_ERASEBKGND:
- return 1;
- }
- return DefWindowProc(hwndBtn, uMsg, wParam, lParam);
-}
-
-VOID CtrlButtonUnloadModule()
-{
- DeleteCriticalSection(&csTips);
- UnregisterClass(UINFOBUTTONCLASS, hInst);
-}
-
-VOID CtrlButtonLoadModule()
-{
- WNDCLASSEX wc;
-
- ZeroMemory(&wc, sizeof(wc));
- wc.cbSize = sizeof(wc);
- wc.lpszClassName = UINFOBUTTONCLASS;
- wc.lpfnWndProc = Button_WndProc;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.cbWndExtra = sizeof(LPBTNCTRL);
- wc.style = CS_GLOBALCLASS;
- RegisterClassEx(&wc);
- InitializeCriticalSection(&csTips);
-}
-
+/* +Miranda IM +Copyright (C) 2002 Robert Rainwater + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "global.h" + +// Used for our own cheap TrackMouseEvent +#define BUTTON_POLLID 100 +#define BUTTON_POLLDELAY 50 + +typedef struct TMBCtrl{ + HWND hwnd; + HANDLE hThemeButton; + HANDLE hThemeToolbar; + + HICON hIcon; + HICON arrow; // uses down arrow + HBITMAP hBitmap; + HFONT hFont; // font + + DWORD dwStyle; + BOOLEAN bFocus; + + INT stateId; // button state + INT defbutton; // default button + INT pbState; + TCHAR cHot; +} BTNCTRL, *LPBTNCTRL; + +// External theme methods and properties +CRITICAL_SECTION csTips; +HWND hwndToolTips = NULL; + +/** + * name: DestroyTheme + * desc: destroys theme data for buttons + * param: ctl - BTNCTRL structure with the information about the theme to close + * return: nothing + **/ +static VOID __fastcall DestroyTheme(BTNCTRL *ctl) +{ + if (ctl->hThemeButton) { + CloseThemeData(ctl->hThemeButton); + ctl->hThemeButton = NULL; + } + if (ctl->hThemeToolbar) { + CloseThemeData(ctl->hThemeToolbar); + ctl->hThemeToolbar = NULL; + } +} + +/** + * name: LoadTheme + * desc: load theme data for buttons if supported by os + * param: ctl - BTNCTRL structure with the information about the theme to load + * return: nothing + **/ +static VOID __fastcall LoadTheme(BTNCTRL *ctl) +{ + DestroyTheme(ctl); + ctl->hThemeButton = OpenThemeData(ctl->hwnd,L"BUTTON"); + ctl->hThemeToolbar = OpenThemeData(ctl->hwnd,L"TOOLBAR"); +} + +/** + * name: TBStateConvert2Flat + * desc: convert button stateIDs + * param: state - state id for the normal theme button + * return: stateID for the flat theme button + **/ +static INT __fastcall TBStateConvert2Flat(INT state) { + switch (state) { + case PBS_NORMAL: return TS_NORMAL; + case PBS_HOT: return TS_HOT; + case PBS_PRESSED: return TS_PRESSED; + case PBS_DISABLED: return TS_DISABLED; + case PBS_DEFAULTED: return TS_NORMAL; + } + return TS_NORMAL; +} + +/** + * name: PaintIcon + * desc: Draws the Icon of the button + * param: ctl - BTNCTRL structure for the button + * hdcMem - device context to draw to + * ccText - character count of the text of the button + * rcClient - rectangle of the whole button + * rcText - rectangle of the text to draw later on + * return: nothing + **/ +static VOID __fastcall PaintIcon(BTNCTRL *ctl, HDC hdcMem, LPWORD ccText, LPRECT rcClient, LPRECT rcText) +{ + RECT rcImage; + + // draw icon on the left of the button + if (ctl->hIcon) { + rcImage.right = GetSystemMetrics(SM_CXSMICON); + rcImage.bottom = GetSystemMetrics(SM_CYSMICON); + rcImage.left = (rcClient->right - rcClient->left) / 2 - ((rcImage.right + rcText->right + (*ccText > 0 ? 4 : 0) + (ctl->arrow ? rcImage.right : 0)) / 2); + rcImage.top = (rcClient->bottom - rcClient->top - rcImage.bottom) / 2; + rcImage.right += rcImage.left; + rcImage.bottom += rcImage.top; + + OffsetRect(rcText, rcImage.right + 4, 0); + if (ctl->stateId == PBS_PRESSED) OffsetRect(&rcImage, 1, 1); + + DrawState(hdcMem, NULL, NULL, (LPARAM)ctl->hIcon, 0, + rcImage.left, rcImage.top, + rcImage.right - rcImage.left, rcImage.bottom - rcImage.top, + IsWindowEnabled(ctl->hwnd) ? DST_ICON | DSS_NORMAL : DST_ICON | DSS_DISABLED); + } + + // draw arrow on the right of the button + if (ctl->arrow) { + rcImage.right = GetSystemMetrics(SM_CXSMICON); + rcImage.left = (*ccText > 0 || ctl->hIcon) + ? rcClient->right - GetSystemMetrics(SM_CXSMICON) + : (rcClient->right - rcClient->left - rcImage.right) / 2; + rcImage.right += rcImage.left; + rcImage.bottom = GetSystemMetrics(SM_CYSMICON); + rcImage.top = (rcClient->bottom - rcClient->top - rcImage.bottom) / 2; + if (ctl->stateId == PBS_PRESSED) OffsetRect(&rcImage, 1, 1); + + DrawState(hdcMem, NULL, NULL, (LPARAM)ctl->arrow, 0, + rcImage.left, rcImage.top, + rcImage.right - rcImage.left, rcImage.bottom - rcImage.top, + IsWindowEnabled(ctl->hwnd) ? DST_ICON | DSS_NORMAL : DST_ICON | DSS_DISABLED); + } +} + +/** + * name: PaintThemeButton + * desc: Draws the themed button + * param: ctl - BTNCTRL structure for the button + * hdcMem - device context to draw to + * rcClient - rectangle of the whole button + * return: nothing + **/ +static VOID __fastcall PaintThemeButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClient) +{ + RECT rcText = { 0, 0, 0, 0 }; + WCHAR wszText[MAX_PATH] = { 0 }; + WORD ccText; + + // Draw the flat button + if ((ctl->dwStyle & MBS_FLAT) && ctl->hThemeToolbar) { + INT state = IsWindowEnabled(ctl->hwnd) + ? (ctl->stateId == PBS_NORMAL && ctl->defbutton + ? PBS_DEFAULTED + : ctl->stateId) + : PBS_DISABLED; + if (IsThemeBackgroundPartiallyTransparent(ctl->hThemeToolbar, TP_BUTTON, TBStateConvert2Flat(state))) { + if (SUCCEEDED(DrawThemeParentBackground(ctl->hwnd, hdcMem, rcClient))) + DrawThemeParentBackground(GetParent(ctl->hwnd), hdcMem, rcClient); + } + DrawThemeBackground(ctl->hThemeToolbar, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), rcClient, rcClient); + } + else { + // draw themed button background + if (ctl->hThemeButton) { + INT state = IsWindowEnabled(ctl->hwnd) + ? (ctl->stateId == PBS_NORMAL && ctl->defbutton + ? PBS_DEFAULTED + : ctl->stateId) + : PBS_DISABLED; + if (IsThemeBackgroundPartiallyTransparent(ctl->hThemeButton, BP_PUSHBUTTON, state)) { + if (SUCCEEDED(DrawThemeParentBackground(ctl->hwnd, hdcMem, rcClient))) + DrawThemeParentBackground(GetParent(ctl->hwnd), hdcMem, rcClient); + } + DrawThemeBackground(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, state, rcClient, rcClient); + } + } + + // calculate text rect + { + RECT sizeText; + HFONT hOldFont; + + ccText = GetWindowTextW(ctl->hwnd, wszText, sizeof(wszText) / sizeof(WCHAR)); + + if (ccText > 0) { + hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont); + + GetThemeTextExtent( + ctl->hThemeButton, + hdcMem, + BP_PUSHBUTTON, + IsWindowEnabled(ctl->hwnd) ? ctl->stateId : PBS_DISABLED, + wszText, + ccText, + DST_PREFIXTEXT, + NULL, + &sizeText); + + if (ctl->cHot) { + RECT rcHot; + + GetThemeTextExtent(ctl->hThemeButton, + hdcMem, + BP_PUSHBUTTON, + IsWindowEnabled(ctl->hwnd) ? ctl->stateId : PBS_DISABLED, + L"&", + 1, + DST_PREFIXTEXT, + NULL, + &rcHot); + + sizeText.right -= (rcHot.right - rcHot.left); + } + SelectObject(hdcMem, hOldFont); + + rcText.left = (ctl->hIcon) ? 0 : (rcClient->right - rcClient->left - (sizeText.right - sizeText.left)) / 2; + rcText.top = (rcClient->bottom - rcClient->top - (sizeText.bottom - sizeText.top)) / 2; + rcText.right = rcText.left + (sizeText.right - sizeText.left); + rcText.bottom = rcText.top + (sizeText.bottom - sizeText.top); + if (ctl->stateId == PBS_PRESSED) { + OffsetRect(&rcText, 1, 1); + } + } + } + PaintIcon(ctl, hdcMem, &ccText, rcClient, &rcText); + // draw text + if (ccText > 0 && ctl->hThemeButton) { + HFONT hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont); + DrawThemeText(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, IsWindowEnabled(ctl->hwnd) ? ctl->stateId : PBS_DISABLED, wszText, ccText, DST_PREFIXTEXT, 0, &rcText); + SelectObject(hdcMem, hOldFont); + } +} + +/** + * name: PaintThemeButton + * desc: Draws the none themed button + * param: ctl - BTNCTRL structure for the button + * hdcMem - device context to draw to + * rcClient - rectangle of the whole button + * return: nothing + **/ +static VOID __fastcall PaintButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClient) +{ + RECT rcText = { 0, 0, 0, 0 }; + TCHAR szText[MAX_PATH] = { 0 }; + WORD ccText; + + // Draw the flat button + if (ctl->dwStyle & MBS_FLAT) { + HBRUSH hbr = NULL; + + if (ctl->stateId == PBS_PRESSED || ctl->stateId == PBS_HOT) + hbr = GetSysColorBrush(COLOR_3DLIGHT); + else { + HDC dc; + HWND hwndParent; + + hwndParent = GetParent(ctl->hwnd); + if (dc = GetDC(hwndParent)) { + hbr = (HBRUSH)SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM)dc, (LPARAM)hwndParent); + ReleaseDC(hwndParent, dc); + } + } + if (hbr) { + FillRect(hdcMem, rcClient, hbr); + DeleteObject(hbr); + } + if (ctl->stateId == PBS_HOT || ctl->bFocus) { + if (ctl->pbState) DrawEdge(hdcMem, rcClient, EDGE_ETCHED, BF_RECT|BF_SOFT); + else DrawEdge(hdcMem, rcClient, BDR_RAISEDOUTER, BF_RECT|BF_SOFT|BF_FLAT); + } + else + if (ctl->stateId == PBS_PRESSED) + DrawEdge(hdcMem, rcClient, BDR_SUNKENOUTER, BF_RECT|BF_SOFT); + } + else { + UINT uState = DFCS_BUTTONPUSH|((ctl->stateId == PBS_HOT) ? DFCS_HOT : 0)|((ctl->stateId == PBS_PRESSED) ? DFCS_PUSHED : 0); + if (ctl->defbutton&&ctl->stateId==PBS_NORMAL) uState |= DLGC_DEFPUSHBUTTON; + DrawFrameControl(hdcMem, rcClient, DFC_BUTTON, uState); + // Draw focus rectangle if button has focus + if (ctl->bFocus) { + RECT focusRect = *rcClient; + InflateRect(&focusRect, -3, -3); + DrawFocusRect(hdcMem, &focusRect); + } + } + // calculate text rect + { + SIZE sizeText; + HFONT hOldFont; + + ccText = GetWindowText(ctl->hwnd, szText, SIZEOF(szText)); + + if (ccText > 0) { + hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont); + GetTextExtentPoint32(hdcMem, szText, ccText, &sizeText); + if (ctl->cHot) { + SIZE sizeHot; + + GetTextExtentPoint32A(hdcMem, "&", 1, &sizeHot); + sizeText.cx -= sizeHot.cx; + } + SelectObject(hdcMem, hOldFont); + + rcText.left = (ctl->hIcon) ? 0 : (rcClient->right - rcClient->left - sizeText.cx) / 2; + rcText.top = (rcClient->bottom - rcClient->top - sizeText.cy) / 2; + rcText.right = rcText.left + sizeText.cx; + rcText.bottom = rcText.top + sizeText.cy; + if (ctl->stateId == PBS_PRESSED) + OffsetRect(&rcText, 1, 1); + } + } + PaintIcon(ctl, hdcMem, &ccText, rcClient, &rcText); + + // draw text + if (ccText > 0) { + HFONT hOldFont; + + hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont); + + SetBkMode(hdcMem, TRANSPARENT); + SetTextColor(hdcMem, + IsWindowEnabled(ctl->hwnd) || !ctl->hThemeButton + ? ctl->stateId == PBS_HOT + ? GetSysColor(COLOR_HOTLIGHT) + : GetSysColor(COLOR_BTNTEXT) + : GetSysColor(COLOR_GRAYTEXT)); + + DrawState(hdcMem, NULL, NULL, (LPARAM)szText, 0, + rcText.left, rcText.top, rcText.right - rcText.left, rcText.bottom - rcText.top, + IsWindowEnabled(ctl->hwnd) || ctl->hThemeButton ? DST_PREFIXTEXT | DSS_NORMAL : DST_PREFIXTEXT | DSS_DISABLED); + SelectObject(hdcMem, hOldFont); + } +} + +/** + * name: Button_WndProc + * desc: window procedure for the button class + * param: hwndBtn - window handle to the button + * uMsg - message to handle + * wParam - message specific parameter + * lParam - message specific parameter + * return: message specific + **/ +static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, LPARAM lParam) { + LPBTNCTRL bct = (LPBTNCTRL)GetWindowLongPtr(hwndBtn, 0); + + switch (uMsg) { + case WM_NCCREATE: + { + LPCREATESTRUCT cs = (LPCREATESTRUCT)lParam; + + cs->style |= BS_OWNERDRAW; + if (!(bct = (LPBTNCTRL)malloc(sizeof(BTNCTRL)))) + return FALSE; + ZeroMemory(bct, sizeof(BTNCTRL)); + bct->hwnd = hwndBtn; + bct->stateId = PBS_NORMAL; + bct->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); + bct->dwStyle = cs->style; + if (cs->style & MBS_DOWNARROW) + bct->arrow = IcoLib_GetIcon(ICO_PLUG_DOWNARROW); + LoadTheme(bct); + SetWindowLongPtr(hwndBtn, 0, (LONG_PTR)bct); + if (cs->lpszName) SetWindowText(hwndBtn, cs->lpszName); + return TRUE; + } + case WM_DESTROY: + if (bct) { + EnterCriticalSection(&csTips); + if (hwndToolTips) { + TOOLINFO ti; + + ZeroMemory(&ti, sizeof(ti)); + ti.cbSize = sizeof(ti); + ti.uFlags = TTF_IDISHWND; + ti.hwnd = bct->hwnd; + ti.uId = (UINT_PTR)bct->hwnd; + if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti)) { + SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti); + } + if (SendMessage(hwndToolTips, TTM_GETTOOLCOUNT, 0, (LPARAM)&ti) == 0) { + DestroyWindow(hwndToolTips); + hwndToolTips = NULL; + } + } + LeaveCriticalSection(&csTips); + DestroyTheme(bct); + free(bct); + } + SetWindowLongPtr(hwndBtn, 0, NULL); + break; + case WM_SETTEXT: + bct->cHot = 0; + if ((LPTSTR)lParam) { + LPTSTR tmp = (LPTSTR)lParam; + + while (*tmp) { + if (*tmp=='&' && *(tmp+1)) { + bct->cHot = _totlower(*(tmp+1)); + break; + } + tmp++; + } + InvalidateRect(bct->hwnd, NULL, TRUE); + } + break; + case WM_SYSKEYUP: + if (bct->stateId != PBS_DISABLED && bct->cHot && bct->cHot == _totlower((TCHAR)wParam)) { + if (bct->dwStyle & MBS_PUSHBUTTON) { + if (bct->pbState) bct->pbState = 0; + else bct->pbState = 1; + InvalidateRect(bct->hwnd, NULL, TRUE); + } + else + SetFocus(hwndBtn); + SendMessage(GetParent(hwndBtn), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndBtn), BN_CLICKED), (LPARAM)hwndBtn); + return 0; + } + break; + case WM_THEMECHANGED: + { + // themed changed, reload theme object + LoadTheme(bct); + InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it + break; + } + case WM_SETFONT: // remember the font so we can use it later + bct->hFont = (HFONT)wParam; // maybe we should redraw? + break; + case WM_NCPAINT: + case WM_PAINT: + { + PAINTSTRUCT ps; + HDC hdcPaint; + HDC hdcMem; + HBITMAP hbmMem; + HDC hOld; + RECT rcClient; + + if (hdcPaint = BeginPaint(hwndBtn, &ps)) { + GetClientRect(bct->hwnd, &rcClient); + hdcMem = CreateCompatibleDC(hdcPaint); + hbmMem = CreateCompatibleBitmap(hdcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top); + hOld = (HDC)SelectObject(hdcMem, hbmMem); + + // If its a push button, check to see if it should stay pressed + if ((bct->dwStyle & MBS_PUSHBUTTON) && bct->pbState) bct->stateId = PBS_PRESSED; + + if ((bct->dwStyle & MBS_FLAT) && bct->hThemeToolbar || bct->hThemeButton) + PaintThemeButton(bct, hdcMem, &rcClient); + else + PaintButton(bct, hdcMem, &rcClient); + + BitBlt(hdcPaint, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, hdcMem, 0, 0, SRCCOPY); + SelectObject(hdcMem, hOld); + DeleteObject(hbmMem); + DeleteDC(hdcMem); + EndPaint(hwndBtn, &ps); + } + return 0; + } + case BM_SETIMAGE: + if (wParam == IMAGE_ICON) { + bct->hIcon = (HICON)lParam; + bct->hBitmap = NULL; + InvalidateRect(bct->hwnd, NULL, TRUE); + } + else if (wParam == IMAGE_BITMAP) { + bct->hIcon = NULL; + bct->hBitmap = (HBITMAP)lParam; + InvalidateRect(bct->hwnd, NULL, TRUE); + } + else if (wParam == NULL && lParam == NULL) { + bct->hIcon = NULL; + bct->hBitmap = NULL; + InvalidateRect(bct->hwnd, NULL, TRUE); + } + break; + case BM_SETCHECK: + if (!(bct->dwStyle & MBS_PUSHBUTTON)) break; + if (wParam == BST_CHECKED) { + bct->pbState = 1; + bct->stateId = PBS_PRESSED; + } + else if (wParam == BST_UNCHECKED) { + bct->pbState = 0; + bct->stateId = PBS_NORMAL; + } + InvalidateRect(bct->hwnd, NULL, TRUE); + break; + case BM_GETCHECK: + if (bct->dwStyle & MBS_PUSHBUTTON) return bct->pbState ? BST_CHECKED : BST_UNCHECKED; + return 0; + case BUTTONSETDEFAULT: + bct->defbutton = wParam ? 1 : 0; + InvalidateRect(bct->hwnd, NULL, TRUE); + break; + case BUTTONADDTOOLTIP: + { + if (!wParam) break; + EnterCriticalSection(&csTips); + if (!hwndToolTips) { + hwndToolTips = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL); + } + + if (lParam == MBBF_UNICODE) { + TOOLINFOW ti; + + ZeroMemory(&ti, sizeof(TOOLINFOW)); + ti.cbSize = sizeof(TOOLINFOW); + ti.uFlags = TTF_IDISHWND; + ti.hwnd = bct->hwnd; + ti.uId = (UINT_PTR)bct->hwnd; + if (SendMessage(hwndToolTips, TTM_GETTOOLINFOW, 0, (LPARAM)&ti)) { + SendMessage(hwndToolTips, TTM_DELTOOLW, 0, (LPARAM)&ti); + } + ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS; + ti.uId = (UINT_PTR)bct->hwnd; + ti.lpszText=(LPWSTR)wParam; + SendMessage(hwndToolTips, TTM_ADDTOOLW, 0, (LPARAM)&ti); + } else { + TOOLINFOA ti; + + ZeroMemory(&ti, sizeof(TOOLINFOA)); + ti.cbSize = sizeof(TOOLINFOA); + ti.uFlags = TTF_IDISHWND; + ti.hwnd = bct->hwnd; + ti.uId = (UINT_PTR)bct->hwnd; + if (SendMessage(hwndToolTips, TTM_GETTOOLINFOA, 0, (LPARAM)&ti)) { + SendMessage(hwndToolTips, TTM_DELTOOLA, 0, (LPARAM)&ti); + } + ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS; + ti.uId = (UINT_PTR)bct->hwnd; + ti.lpszText=(LPSTR)wParam; + SendMessage(hwndToolTips, TTM_ADDTOOLA, 0, (LPARAM)&ti); + } + LeaveCriticalSection(&csTips); + break; + } + case BUTTONTRANSLATE: + { + TCHAR szButton[MAX_PATH]; + GetWindowText(bct->hwnd, szButton, MAX_PATH); + SetWindowText(bct->hwnd, TranslateTS(szButton)); + break; + } + case WM_SETFOCUS: // set keybord bFocus and redraw + bct->bFocus = 1; + InvalidateRect(bct->hwnd, NULL, TRUE); + break; + case WM_KILLFOCUS: // kill bFocus and redraw + bct->bFocus = 0; + InvalidateRect(bct->hwnd, NULL, TRUE); + break; + case WM_WINDOWPOSCHANGED: + InvalidateRect(bct->hwnd, NULL, TRUE); + break; + case WM_ENABLE: // windows tells us to enable/disable + bct->stateId = wParam ? PBS_NORMAL : PBS_DISABLED; + InvalidateRect(bct->hwnd, NULL, TRUE); + break; + case WM_MOUSELEAVE: // faked by the WM_TIMER + if (bct->stateId != PBS_DISABLED) { // don't change states if disabled + bct->stateId = PBS_NORMAL; + InvalidateRect(bct->hwnd, NULL, TRUE); + } + break; + case WM_LBUTTONDOWN: + if (bct->stateId != PBS_DISABLED) { // don't change states if disabled + bct->stateId = PBS_PRESSED; + InvalidateRect(bct->hwnd, NULL, TRUE); + } + break; + case WM_LBUTTONUP: + if (bct->stateId != PBS_DISABLED) { // don't change states if disabled + BOOLEAN bPressed = bct->stateId == PBS_PRESSED; + + if (bct->dwStyle & MBS_PUSHBUTTON) { + if (bct->pbState) bct->pbState = 0; + else bct->pbState = 1; + } + bct->stateId = PBS_HOT; + + // Tell your daddy you got clicked, if mouse is still over the button. + if ((bct->dwStyle & MBS_PUSHBUTTON) || bPressed) + SendMessage(GetParent(hwndBtn), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndBtn), BN_CLICKED), (LPARAM)hwndBtn); + InvalidateRect(bct->hwnd, NULL, TRUE); + } + break; + case WM_MOUSEMOVE: + if (bct->stateId == PBS_NORMAL) { + bct->stateId = PBS_HOT; + InvalidateRect(bct->hwnd, NULL, TRUE); + } + // Call timer, used to start cheesy TrackMouseEvent faker + SetTimer(hwndBtn, BUTTON_POLLID, BUTTON_POLLDELAY, NULL); + break; + case WM_TIMER: // use a timer to check if they have did a mouseout + if (wParam == BUTTON_POLLID) { + RECT rc; + POINT pt; + + GetWindowRect(hwndBtn, &rc); + GetCursorPos(&pt); + if (!PtInRect(&rc, pt)) { // mouse must be gone, trigger mouse leave + PostMessage(hwndBtn, WM_MOUSELEAVE, 0, 0L); + KillTimer(hwndBtn, BUTTON_POLLID); + } + } + break; + case WM_ERASEBKGND: + return 1; + } + return DefWindowProc(hwndBtn, uMsg, wParam, lParam); +} + +VOID CtrlButtonUnloadModule() +{ + DeleteCriticalSection(&csTips); + UnregisterClass(UINFOBUTTONCLASS, hInst); +} + +VOID CtrlButtonLoadModule() +{ + WNDCLASSEX wc; + + ZeroMemory(&wc, sizeof(wc)); + wc.cbSize = sizeof(wc); + wc.lpszClassName = UINFOBUTTONCLASS; + wc.lpfnWndProc = Button_WndProc; + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.cbWndExtra = sizeof(LPBTNCTRL); + wc.style = CS_GLOBALCLASS; + RegisterClassEx(&wc); + InitializeCriticalSection(&csTips); +} + diff --git a/plugins/SendScreenshotPlus/src/version.h b/plugins/SendScreenshotPlus/src/version.h index 05484596d1..24ddf38ced 100644 --- a/plugins/SendScreenshotPlus/src/version.h +++ b/plugins/SendScreenshotPlus/src/version.h @@ -1,17 +1,18 @@ -#define __MAJOR_VERSION 0
-#define __MINOR_VERSION 8
-#define __RELEASE_NUM 0
-#define __BUILD_NUM 0
-
-#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM
-#define __TOSTRING(x) #x
-#define __VERSION_STRING __TOSTRING(__FILEVERSION_STRING)
-
-#define __PLUGIN_NAME "Send screenshot+"
-#define __FILENAME "SendSS.dll"
-#define __DESCRIPTION "Take a screenshot and send it to a contact."
-#define __AUTHOR "Merlin"
-#define __AUTHOREMAIL "ing.u.horn@googlemail.com"
-#define __AUTHORWEB "http://miranda-ng.org/p/SendSS/"
-#define __COPYRIGHT "© 2010 Merlin, 2004-2006 Sergio Vieira Rolanski"
-#define __USER_AGENT_STRING __PLUGIN_NAME##" v"##__VERSION_STRING
+#define __MAJOR_VERSION 0 +#define __MINOR_VERSION 8 +#define __RELEASE_NUM 2 +#define __BUILD_NUM 0 + +#define __DEF2STR_(s) #s +#define __DEF2STR(s) __DEF2STR_(s) +#define __FILEVERSION_STRING __MAJOR_VERSION.__MINOR_VERSION.__RELEASE_NUM.__BUILD_NUM +#define __VERSION_STRING __DEF2STR(__FILEVERSION_STRING) + +#define __PLUGIN_NAME "Send ScreenShot+" +#define __FILENAME "SendSS.dll" +#define __DESCRIPTION "Take a screenshot and send it to a contact." +#define __AUTHOR "Merlin" +#define __AUTHOREMAIL "ing.u.horn@googlemail.com" +#define __AUTHORWEB "http://miranda-ng.org/p/SendSS/" +#define __COPYRIGHT "© 2010 Merlin, 2004-2006 Sergio Vieira Rolanski" +#define __USER_AGENT_STRING __PLUGIN_NAME##" v"##__VERSION_STRING |