diff options
author | George Hazan <george.hazan@gmail.com> | 2015-07-29 21:18:27 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-07-29 21:18:27 +0000 |
commit | 1271802f514d41e8e06df7714d1f1e4a430b417b (patch) | |
tree | 5bd4ef52613333cba786f1246414e422a5e4c95a /plugins/SendScreenshotPlus/src | |
parent | 14d0ed2003485ebf19d45672b065a7dd2bf5274a (diff) |
- warning fixes;
- code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@14757 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/SendScreenshotPlus/src')
18 files changed, 1946 insertions, 1818 deletions
diff --git a/plugins/SendScreenshotPlus/src/CSend.cpp b/plugins/SendScreenshotPlus/src/CSend.cpp index 9386894343..24a2f3de56 100644 --- a/plugins/SendScreenshotPlus/src/CSend.cpp +++ b/plugins/SendScreenshotPlus/src/CSend.cpp @@ -31,30 +31,31 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //--------------------------------------------------------------------------- CSend::CSend(HWND /*Owner*/, MCONTACT hContact, bool bAsync, bool bSilent) : - m_bDeleteAfterSend(false), - m_bAsync(bAsync), - m_bSilent(bSilent), - m_pszFile(NULL), - m_pszFileDesc(NULL), - m_URL(NULL), - m_URLthumb(NULL), - m_pszSendTyp(NULL), - m_pszProto(NULL), +m_bDeleteAfterSend(false), +m_bAsync(bAsync), +m_bSilent(bSilent), +m_pszFile(NULL), +m_pszFileDesc(NULL), +m_URL(NULL), +m_URLthumb(NULL), +m_pszSendTyp(NULL), +m_pszProto(NULL), // m_hContact(hContact), // initialized below - m_EnableItem(0), - m_ChatRoom(0), +m_EnableItem(0), +m_ChatRoom(0), // m_PFflag(0), - m_cbEventMsg(0), - m_szEventMsg(NULL), - m_hSend(0), - m_hOnSend(0), - m_ErrorMsg(NULL), - m_ErrorTitle(NULL) +m_cbEventMsg(0), +m_szEventMsg(NULL), +m_hSend(0), +m_hOnSend(0), +m_ErrorMsg(NULL), +m_ErrorTitle(NULL) { SetContact(hContact); } -CSend::~CSend(){ +CSend::~CSend() +{ mir_free(m_pszFile); mir_free(m_pszFileDesc); mir_free(m_URL); @@ -62,13 +63,14 @@ CSend::~CSend(){ mir_free(m_szEventMsg); mir_free(m_ErrorMsg); mir_free(m_ErrorTitle); - if(m_hOnSend) UnhookEvent(m_hOnSend); + if (m_hOnSend) UnhookEvent(m_hOnSend); } //--------------------------------------------------------------------------- -void CSend::SetContact(MCONTACT hContact) { +void CSend::SetContact(MCONTACT hContact) +{ m_hContact = hContact; - if(hContact){ + if (hContact) { m_pszProto = GetContactProto(hContact); m_ChatRoom = db_get_b(hContact, m_pszProto, "ChatRoom", 0); /* @@ -81,139 +83,150 @@ void CSend::SetContact(MCONTACT hContact) { //--------------------------------------------------------------------------- /*bool CSend::hasCap(unsigned int Flag) { return (Flag & CallContactService(m_hContact, PS_GETCAPS, PFLAGNUM_1, NULL)) == Flag; -}// */ + }// */ //--------------------------------------------------------------------------- -INT_PTR CALLBACK CSend::ResultDialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam){ - switch(uMsg){ - case WM_INITDIALOG:{ - SendMessage(hwndDlg,WM_SETICON,ICON_BIG,(LPARAM)GetIcon(ICO_MAIN)); - CSend* self=(CSend*)lParam; - TCHAR* tmp=mir_tstrdup(TranslateT("Resulting URL from\n")); - mir_tstradd(tmp,self->m_pszSendTyp); - SetDlgItemText(hwndDlg,IDC_HEADERBAR,tmp); - mir_free(tmp); - SendDlgItemMessage(hwndDlg,IDC_HEADERBAR,WM_SETICON,ICON_BIG,(LPARAM)GetIconBtn(ICO_BTN_ARROWR)); - SetDlgItemTextA(hwndDlg,ID_edtURL,self->m_URL); - if(self->m_URLthumb){ - SetDlgItemTextA(hwndDlg,ID_edtURLthumb,self->m_URLthumb); - }else{ - SetDlgItemTextA(hwndDlg,ID_edtURLthumb,"-"); - for(int i=ID_btnThumbCopy; i<=ID_edtURLthumb; ++i){ - EnableWindow(GetDlgItem(hwndDlg,i),FALSE); +INT_PTR CALLBACK CSend::ResultDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + { + SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)GetIcon(ICO_MAIN)); + CSend* self = (CSend*)lParam; + TCHAR* tmp = mir_tstrdup(TranslateT("Resulting URL from\n")); + mir_tstradd(tmp, self->m_pszSendTyp); + SetDlgItemText(hwndDlg, IDC_HEADERBAR, tmp); + mir_free(tmp); + SendDlgItemMessage(hwndDlg, IDC_HEADERBAR, WM_SETICON, ICON_BIG, (LPARAM)GetIconBtn(ICO_BTN_ARROWR)); + SetDlgItemTextA(hwndDlg, ID_edtURL, self->m_URL); + if (self->m_URLthumb) { + SetDlgItemTextA(hwndDlg, ID_edtURLthumb, self->m_URLthumb); } - } - if(!self->m_pszFileDesc) - SetDlgItemText(hwndDlg,ID_bvlDesc,self->m_ErrorTitle); - else - SetDlgItemText(hwndDlg,ID_bvlDesc,self->m_pszFileDesc); - SendDlgItemMessage(hwndDlg,IDOK,BM_SETIMAGE,IMAGE_ICON,(LPARAM)GetIconBtn(ICO_BTN_COPY)); - SendDlgItemMessage(hwndDlg,IDOK,BUTTONTRANSLATE,0,0); - SendDlgItemMessage(hwndDlg,IDCANCEL,BM_SETIMAGE,IMAGE_ICON,(LPARAM)GetIconBtn(ICO_BTN_CANCEL)); - SendDlgItemMessage(hwndDlg,IDCANCEL,BUTTONTRANSLATE,0,0); - for(int i=ID_btnCopy; i<=ID_btnThumbBBC2; ++i){ - SendDlgItemMessage(hwndDlg,i,BUTTONSETASTHEMEDBTN,0,0); - SendDlgItemMessage(hwndDlg,i,BUTTONSETASFLATBTN,1,0); - switch(i){ - case ID_btnCopy: - case ID_btnThumbCopy: - SendDlgItemMessage(hwndDlg,i,BM_SETIMAGE,IMAGE_ICON,(LPARAM)GetIconBtn(ICO_BTN_COPY)); - SendDlgItemMessage(hwndDlg,i,BUTTONADDTOOLTIP,(WPARAM)LPGENT("Copy"),BATF_TCHAR); - break; - case ID_btnBBC: - case ID_btnThumbBBC: - SendDlgItemMessage(hwndDlg,i,BM_SETIMAGE,IMAGE_ICON,(LPARAM)GetIconBtn(ICO_BTN_BBC)); - SendDlgItemMessage(hwndDlg,i,BUTTONADDTOOLTIP,(WPARAM)LPGENT("Copy BBCode"),BATF_TCHAR); - break; - default: - SendDlgItemMessage(hwndDlg,i,BM_SETIMAGE,IMAGE_ICON,(LPARAM)GetIconBtn(ICO_BTN_BBCLNK)); - SendDlgItemMessage(hwndDlg,i,BUTTONADDTOOLTIP,(WPARAM)LPGENT("Copy BBCode w/ link"),BATF_TCHAR); + else { + SetDlgItemTextA(hwndDlg, ID_edtURLthumb, "-"); + for (int i = ID_btnThumbCopy; i <= ID_edtURLthumb; ++i) { + EnableWindow(GetDlgItem(hwndDlg, i), FALSE); + } + } + if (!self->m_pszFileDesc) + SetDlgItemText(hwndDlg, ID_bvlDesc, self->m_ErrorTitle); + else + SetDlgItemText(hwndDlg, ID_bvlDesc, self->m_pszFileDesc); + SendDlgItemMessage(hwndDlg, IDOK, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetIconBtn(ICO_BTN_COPY)); + SendDlgItemMessage(hwndDlg, IDOK, BUTTONTRANSLATE, 0, 0); + SendDlgItemMessage(hwndDlg, IDCANCEL, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetIconBtn(ICO_BTN_CANCEL)); + SendDlgItemMessage(hwndDlg, IDCANCEL, BUTTONTRANSLATE, 0, 0); + for (int i = ID_btnCopy; i <= ID_btnThumbBBC2; ++i) { + SendDlgItemMessage(hwndDlg, i, BUTTONSETASTHEMEDBTN, 0, 0); + SendDlgItemMessage(hwndDlg, i, BUTTONSETASFLATBTN, 1, 0); + switch (i) { + case ID_btnCopy: + case ID_btnThumbCopy: + SendDlgItemMessage(hwndDlg, i, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetIconBtn(ICO_BTN_COPY)); + SendDlgItemMessage(hwndDlg, i, BUTTONADDTOOLTIP, (WPARAM)LPGENT("Copy"), BATF_TCHAR); + break; + case ID_btnBBC: + case ID_btnThumbBBC: + SendDlgItemMessage(hwndDlg, i, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetIconBtn(ICO_BTN_BBC)); + SendDlgItemMessage(hwndDlg, i, BUTTONADDTOOLTIP, (WPARAM)LPGENT("Copy BBCode"), BATF_TCHAR); + break; + default: + SendDlgItemMessage(hwndDlg, i, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetIconBtn(ICO_BTN_BBCLNK)); + SendDlgItemMessage(hwndDlg, i, BUTTONADDTOOLTIP, (WPARAM)LPGENT("Copy BBCode w/ link"), BATF_TCHAR); + } } } - TranslateDialogDefault(hwndDlg); - return TRUE;} + return TRUE; + case WM_COMMAND: - switch(LOWORD(wParam)) { + switch (LOWORD(wParam)) { + case IDCANCEL: + DestroyWindow(hwndDlg); + return TRUE; + case IDOK: case ID_btnCopy: case ID_btnThumbCopy: case ID_btnBBC: case ID_btnThumbBBC: - case ID_btnThumbBBC2:{ + case ID_btnThumbBBC2: TCHAR tmp[2048]; - int edtID=ID_edtURL; - int bbc=0; - switch(LOWORD(wParam)){ + int edtID = ID_edtURL; + int bbc = 0; + switch (LOWORD(wParam)) { case ID_btnThumbBBC2: ++bbc; case ID_btnThumbBBC: ++bbc; case ID_btnThumbCopy: - edtID=ID_edtURLthumb; + edtID = ID_edtURLthumb; break; case ID_btnBBC: ++bbc; break; } size_t len; - if(bbc){ - if(bbc==1){ - memcpy(tmp,_T("[img]"),5*sizeof(TCHAR)); len=5; - len+=GetDlgItemText(hwndDlg,edtID,tmp+len,2048-11); - memcpy(tmp+len,_T("[/img]"),7*sizeof(TCHAR)); len+=7; - }else{ - memcpy(tmp,_T("[url="),5*sizeof(TCHAR)); len=5; - len+=GetDlgItemText(hwndDlg,ID_edtURL,tmp+len,1024); - memcpy(tmp+len,_T("][img]"),6*sizeof(TCHAR)); len+=6; - len+=GetDlgItemText(hwndDlg,edtID,tmp+len,1024); - memcpy(tmp+len,_T("[/img][/url]"),13*sizeof(TCHAR)); len+=12; + if (bbc) { + if (bbc == 1) { + memcpy(tmp, _T("[img]"), 5 * sizeof(TCHAR)); len = 5; + len += GetDlgItemText(hwndDlg, edtID, tmp + len, 2048 - 11); + memcpy(tmp + len, _T("[/img]"), 7 * sizeof(TCHAR)); len += 7; } - }else - len=GetDlgItemText(hwndDlg,edtID,tmp,_countof(tmp)); - int retries=3; - do{ - if(!OpenClipboard(hwndDlg)){ + else { + memcpy(tmp, _T("[url="), 5 * sizeof(TCHAR)); len = 5; + len += GetDlgItemText(hwndDlg, ID_edtURL, tmp + len, 1024); + memcpy(tmp + len, _T("][img]"), 6 * sizeof(TCHAR)); len += 6; + len += GetDlgItemText(hwndDlg, edtID, tmp + len, 1024); + memcpy(tmp + len, _T("[/img][/url]"), 13 * sizeof(TCHAR)); len += 12; + } + } + else + len = GetDlgItemText(hwndDlg, edtID, tmp, _countof(tmp)); + int retries = 3; + do { + if (!OpenClipboard(hwndDlg)) { Sleep(100); continue; } EmptyClipboard(); - HGLOBAL clipbuffer=GlobalAlloc(GMEM_MOVEABLE, len*sizeof(TCHAR)+sizeof(TCHAR)); - TCHAR* tmp2=(TCHAR*)GlobalLock(clipbuffer); - mir_tstrncpy(tmp2,tmp,len+1); tmp2[len]='\0'; + HGLOBAL clipbuffer = GlobalAlloc(GMEM_MOVEABLE, len*sizeof(TCHAR) + sizeof(TCHAR)); + TCHAR* tmp2 = (TCHAR*)GlobalLock(clipbuffer); + mir_tstrncpy(tmp2, tmp, len + 1); tmp2[len] = '\0'; GlobalUnlock(clipbuffer); - SetClipboardData(CF_UNICODETEXT,clipbuffer); + SetClipboardData(CF_UNICODETEXT, clipbuffer); CloseClipboard(); break; - }while(--retries); - if(LOWORD(wParam)==IDOK) + } while (--retries); + + if (LOWORD(wParam) == IDOK) DestroyWindow(hwndDlg); - return TRUE;} - case IDCANCEL: - DestroyWindow(hwndDlg); return TRUE; } } return FALSE; } -void CSend::svcSendMsgExit(const char* szMessage) { - if(m_bSilent){ + +void CSend::svcSendMsgExit(const char* szMessage) +{ + if (m_bSilent) { Exit(ACKRESULT_SUCCESS); return; } - if(!m_hContact){ - if(!m_pszFileDesc) - m_pszFileDesc=mir_a2t(szMessage); + if (!m_hContact) { + if (!m_pszFileDesc) + m_pszFileDesc = mir_a2t(szMessage); Exit(CSEND_DIALOG); return; } - if(m_ChatRoom){ + if (m_ChatRoom) { TCHAR* tmp = mir_a2t(szMessage); if (m_pszFileDesc) { mir_tstradd(tmp, _T("\r\n")); mir_tstradd(tmp, m_pszFileDesc); } - GC_INFO gci = {0}; + GC_INFO gci = { 0 }; int res = GC_RESULT_NOSESSION; int cnt = (int)CallService(MS_GC_GETSESSIONCOUNT, 0, (LPARAM)m_pszProto); //loop on all gc session to get the right (save) ptszID for the chatroom from m_hContact gci.pszModule = m_pszProto; - for (int i = 0; i < cnt ; i++ ) { + for (int i = 0; i < cnt; i++) { gci.iItem = i; gci.Flags = GCF_BYINDEX | GCF_HCONTACT | GCF_ID; CallService(MS_GC_GETINFO, 0, (LPARAM)&gci); @@ -231,17 +244,18 @@ void CSend::svcSendMsgExit(const char* szMessage) { } } Exit(res); return; - }else{ + } + else { mir_freeAndNil(m_szEventMsg); - m_cbEventMsg = (DWORD)mir_strlen(szMessage)+1; + m_cbEventMsg = (DWORD)mir_strlen(szMessage) + 1; m_szEventMsg = (char*)mir_realloc(m_szEventMsg, (sizeof(char) * m_cbEventMsg)); memset(m_szEventMsg, 0, (sizeof(char) * m_cbEventMsg)); - mir_strcpy(m_szEventMsg,szMessage); + mir_strcpy(m_szEventMsg, szMessage); if (m_pszFileDesc && m_pszFileDesc[0] != NULL) { char *temp = mir_t2a(m_pszFileDesc); mir_stradd(m_szEventMsg, "\r\n"); mir_stradd(m_szEventMsg, temp); - m_cbEventMsg = (DWORD)mir_strlen(m_szEventMsg)+1; + m_cbEventMsg = (DWORD)mir_strlen(m_szEventMsg) + 1; mir_free(temp); } //create a HookEventObj on ME_PROTO_ACK @@ -259,29 +273,30 @@ void CSend::svcSendMsgExit(const char* szMessage) { } } -void CSend::svcSendFileExit() { -//szMessage should be encoded as the File followed by the description, the -//separator being a single nul (\0). If there is no description, do not forget -//to end the File with two nuls. - if(m_bSilent){ +void CSend::svcSendFileExit() +{ + //szMessage should be encoded as the File followed by the description, the + //separator being a single nul (\0). If there is no description, do not forget + //to end the File with two nuls. + if (m_bSilent) { Exit(ACKRESULT_SUCCESS); return; } - if(!m_hContact){ + if (!m_hContact) { Error(LPGENT("%s requires a valid contact!"), m_pszSendTyp); Exit(ACKRESULT_FAILED); return; } mir_freeAndNil(m_szEventMsg); char* szFile = mir_t2a(m_pszFile); - m_cbEventMsg = (DWORD)mir_strlen(szFile)+2; - m_szEventMsg=(char*)mir_realloc(m_szEventMsg, (sizeof(char) * m_cbEventMsg)); + m_cbEventMsg = (DWORD)mir_strlen(szFile) + 2; + m_szEventMsg = (char*)mir_realloc(m_szEventMsg, (sizeof(char) * m_cbEventMsg)); memset(m_szEventMsg, 0, (sizeof(char) * m_cbEventMsg)); - mir_strcpy(m_szEventMsg,szFile); + mir_strcpy(m_szEventMsg, szFile); if (m_pszFileDesc && m_pszFileDesc[0] != NULL) { char* temp = mir_t2a(m_pszFileDesc); m_cbEventMsg += (DWORD)mir_strlen(temp); - m_szEventMsg=(char*)mir_realloc(m_szEventMsg, sizeof(char)*m_cbEventMsg); - mir_strcpy(m_szEventMsg+mir_strlen(szFile)+1,temp); - m_szEventMsg[m_cbEventMsg-1] = 0; + m_szEventMsg = (char*)mir_realloc(m_szEventMsg, sizeof(char)*m_cbEventMsg); + mir_strcpy(m_szEventMsg + mir_strlen(szFile) + 1, temp); + m_szEventMsg[m_cbEventMsg - 1] = 0; mir_free(temp); } mir_free(szFile); @@ -292,9 +307,9 @@ void CSend::svcSendFileExit() { } // Start miranda PSS_FILE based on mir ver (T) - TCHAR* ppFile[2]={0,0}; + TCHAR* ppFile[2] = { 0, 0 }; TCHAR* pDesc = mir_tstrdup(m_pszFileDesc); - ppFile[0] = mir_tstrdup (m_pszFile); + ppFile[0] = mir_tstrdup(m_pszFile); ppFile[1] = NULL; m_hSend = (HANDLE)CallContactService(m_hContact, PSS_FILE, (WPARAM)pDesc, (LPARAM)ppFile); mir_free(pDesc); @@ -309,17 +324,18 @@ void CSend::svcSendFileExit() { } //--------------------------------------------------------------------------- -int CSend::OnSend(void *obj, WPARAM wParam, LPARAM lParam){ - CSend* self=(CSend*)obj; - ACKDATA *ack=(ACKDATA*)lParam; - if(ack->hProcess!= self->m_hSend) return 0; - /* if(dat->waitingForAcceptance) { - SetTimer(hwndDlg,1,1000,NULL); - dat->waitingForAcceptance=0; +int CSend::OnSend(void *obj, WPARAM, LPARAM lParam) +{ + CSend* self = (CSend*)obj; + ACKDATA *ack = (ACKDATA*)lParam; + if (ack->hProcess != self->m_hSend) return 0; + /* if(dat->waitingForAcceptance) { + SetTimer(hwndDlg,1,1000,NULL); + dat->waitingForAcceptance=0; } - */ + */ - switch(ack->result) { + switch (ack->result) { case ACKRESULT_INITIALISING: //SetFtStatus(hwndDlg, LPGENT("Initialising..."), FTS_TEXT); break; case ACKRESULT_CONNECTING: //SetFtStatus(hwndDlg, LPGENT("Connecting..."), FTS_TEXT); break; case ACKRESULT_CONNECTPROXY: //SetFtStatus(hwndDlg, LPGENT("Connecting to proxy..."), FTS_TEXT); break; @@ -343,7 +359,7 @@ int CSend::OnSend(void *obj, WPARAM wParam, LPARAM lParam){ break; case ACKRESULT_SUCCESS: self->Unhook(); - switch(ack->type) { + switch (ack->type) { case ACKTYPE_CHAT: break; case ACKTYPE_MESSAGE: @@ -353,8 +369,8 @@ int CSend::OnSend(void *obj, WPARAM wParam, LPARAM lParam){ self->DB_EventAdd((WORD)EVENTTYPE_URL); break; case ACKTYPE_FILE: - self->m_szEventMsg = (char*) mir_realloc(self->m_szEventMsg, sizeof(DWORD) + self->m_cbEventMsg); - memmove(self->m_szEventMsg+sizeof(DWORD), self->m_szEventMsg, self->m_cbEventMsg); + self->m_szEventMsg = (char*)mir_realloc(self->m_szEventMsg, sizeof(DWORD) + self->m_cbEventMsg); + memmove(self->m_szEventMsg + sizeof(DWORD), self->m_szEventMsg, self->m_cbEventMsg); self->m_cbEventMsg += sizeof(DWORD); self->DB_EventAdd((WORD)EVENTTYPE_FILE); break; @@ -373,16 +389,17 @@ void CSend::DB_EventAdd(WORD EventType) dbei.flags = DBEF_SENT; dbei.timestamp = time(NULL); dbei.flags |= DBEF_UTF; - dbei.cbBlob= m_cbEventMsg; + dbei.cbBlob = m_cbEventMsg; dbei.pBlob = (PBYTE)m_szEventMsg; db_event_add(m_hContact, &dbei); } //--------------------------------------------------------------------------- -void CSend::Error(LPCTSTR pszFormat, ...) { +void CSend::Error(LPCTSTR pszFormat, ...) +{ TCHAR tszMsg[MAX_SECONDLINE]; - mir_sntprintf(tszMsg, _countof(tszMsg),_T("%s - %s") ,_T(SZ_SENDSS), TranslateT("Error")); + mir_sntprintf(tszMsg, _countof(tszMsg), _T("%s - %s"), _T(SZ_SENDSS), TranslateT("Error")); mir_free(m_ErrorTitle), m_ErrorTitle = mir_tstrdup(tszMsg); va_list vl; @@ -392,377 +409,401 @@ void CSend::Error(LPCTSTR pszFormat, ...) { mir_free(m_ErrorMsg), m_ErrorMsg = mir_tstrdup(tszMsg); memset(&m_box, 0, sizeof(MSGBOX)); - m_box.cbSize = sizeof(MSGBOX); - m_box.hParent = NULL; - m_box.hiLogo = GetIcon(ICO_MAIN); - m_box.hiMsg = NULL; - m_box.ptszTitle = m_ErrorTitle; - m_box.ptszMsg = m_ErrorMsg; - m_box.uType = MB_OK|MB_ICON_ERROR; + m_box.cbSize = sizeof(MSGBOX); + m_box.hParent = NULL; + m_box.hiLogo = GetIcon(ICO_MAIN); + m_box.hiMsg = NULL; + m_box.ptszTitle = m_ErrorTitle; + m_box.ptszMsg = m_ErrorMsg; + m_box.uType = MB_OK | MB_ICON_ERROR; } //--------------------------------------------------------------------------- -void CSend::Exit(unsigned int Result) { - if(!m_bSilent){ +void CSend::Exit(unsigned int Result) +{ + if (!m_bSilent) { bool err = true; - switch(Result) { - case CSEND_DIALOG: - SkinPlaySound("FileDone"); - DialogBoxParam(g_hSendSS, MAKEINTRESOURCE(IDD_UResultForm),0, ResultDialogProc,(LPARAM)this); - err = false; - break; - case ACKRESULT_SUCCESS: - case GC_RESULT_SUCCESS: - SkinPlaySound("FileDone"); - err = false; - break; - case ACKRESULT_DENIED: - SkinPlaySound("FileDenied"); - Error(_T("%s (%i):\nFile transfer denied."),TranslateTS(m_pszSendTyp),Result); - MsgBoxService(NULL, (LPARAM)&m_box); - err = false; - break; - case GC_RESULT_WRONGVER: //.You appear to be using the wrong version of GC API. - Error(_T("%s (%i):\nYou appear to be using the wrong version of GC API"),TranslateT("GCHAT error"),Result); - break; - case GC_RESULT_ERROR: // An internal GC error occurred. - Error(_T("%s (%i):\nAn internal GC error occurred."),TranslateT("GCHAT error"),Result); - break; - case GC_RESULT_NOSESSION: // contact has no open GC session - Error(_T("%s (%i):\nContact has no open GC session."),TranslateT("GCHAT error"),Result); - break; - case ACKRESULT_FAILED: - default: - break; + switch (Result) { + case CSEND_DIALOG: + SkinPlaySound("FileDone"); + DialogBoxParam(g_hSendSS, MAKEINTRESOURCE(IDD_UResultForm), 0, ResultDialogProc, (LPARAM)this); + err = false; + break; + case ACKRESULT_SUCCESS: + case GC_RESULT_SUCCESS: + SkinPlaySound("FileDone"); + err = false; + break; + case ACKRESULT_DENIED: + SkinPlaySound("FileDenied"); + Error(_T("%s (%i):\nFile transfer denied."), TranslateTS(m_pszSendTyp), Result); + MsgBoxService(NULL, (LPARAM)&m_box); + err = false; + break; + case GC_RESULT_WRONGVER: //.You appear to be using the wrong version of GC API. + Error(_T("%s (%i):\nYou appear to be using the wrong version of GC API"), TranslateT("GCHAT error"), Result); + break; + case GC_RESULT_ERROR: // An internal GC error occurred. + Error(_T("%s (%i):\nAn internal GC error occurred."), TranslateT("GCHAT error"), Result); + break; + case GC_RESULT_NOSESSION: // contact has no open GC session + Error(_T("%s (%i):\nContact has no open GC session."), TranslateT("GCHAT error"), Result); + break; + case ACKRESULT_FAILED: + default: + break; } - if(err){ + if (err) { SkinPlaySound("FileFailed"); - if(m_ErrorMsg) MsgBoxService(NULL, (LPARAM)&m_box); + if (m_ErrorMsg) MsgBoxService(NULL, (LPARAM)&m_box); else MsgErr(NULL, LPGENT("An unknown error has occurred.")); } } - if(m_pszFile && *m_pszFile && m_bDeleteAfterSend && m_EnableItem&SS_DLG_DELETEAFTERSSEND) { - DeleteFile(m_pszFile), m_pszFile=NULL; + if (m_pszFile && *m_pszFile && m_bDeleteAfterSend && m_EnableItem&SS_DLG_DELETEAFTERSSEND) { + DeleteFile(m_pszFile), m_pszFile = NULL; } - if(m_bAsync) + if (m_bAsync) delete this;/// deletes derived class since destructor is virtual (which also auto-calls base dtor) } /// helper functions used for HTTP uploads //--------------------------------------------------------------------------- #define snprintf _snprintf -const char* CSend::GetHTMLContent(char* str, const char* startTag, const char* endTag) { - char* begin=strstr(str,startTag); - if(!begin) return NULL; - begin+=mir_strlen(startTag)-1; - for(; *begin!='>' && *begin; ++begin); - if(*begin){ - char* end=strstr(++begin,endTag); - if(end) *end=0; + +const char* CSend::GetHTMLContent(char* str, const char* startTag, const char* endTag) +{ + char* begin = strstr(str, startTag); + if (!begin) return NULL; + begin += mir_strlen(startTag) - 1; + for (; *begin != '>' && *begin; ++begin); + if (*begin) { + char* end = strstr(++begin, endTag); + if (end) *end = 0; } return begin; } -int JSON_ParseData_(const char** jsondata,size_t jsonlen,const char** rawdata){ - const char* c=*jsondata; - const char* jsonend=*jsondata+jsonlen; - int len=0; - *rawdata=NULL; - if(c==jsonend) + +int JSON_ParseData_(const char** jsondata, size_t jsonlen, const char** rawdata) +{ + const char* c = *jsondata; + const char* jsonend = *jsondata + jsonlen; + int len = 0; + *rawdata = NULL; + if (c == jsonend) return 0; - if(*c=='{'){ // scope (object) - *rawdata=c; - do{ - if(*c=='{') ++len; - else if(*c=='}') --len; - if(++c==jsonend) + if (*c == '{') { // scope (object) + *rawdata = c; + do { + if (*c == '{') ++len; + else if (*c == '}') --len; + if (++c == jsonend) return 0; - }while(len>0); - len=c-*rawdata; - if(*c==',') ++c; - }else if(*c=='"' || *c=='\''){ // string - char needle=*c; - if(++c==jsonend) + } while (len > 0); + len = c - *rawdata; + if (*c == ',') ++c; + } + else if (*c == '"' || *c == '\'') { // string + char needle = *c; + if (++c == jsonend) return 0; - *rawdata=c; - do{ - if(c==jsonend || (*c=='\\' && ++c==jsonend)) + *rawdata = c; + do { + if (c == jsonend || (*c == '\\' && ++c == jsonend)) return 0; - }while(*c++!=needle); - len=c-*rawdata-1; - if(*c==',') ++c; - }else{ // other - for(*rawdata=c; c<jsonend && *c++!=','; ); - len=c-*rawdata; - if(c[-1]==',') --len; + } while (*c++ != needle); + len = c - *rawdata - 1; + if (*c == ',') ++c; + } + else { // other + for (*rawdata = c; c < jsonend && *c++ != ',';); + len = c - *rawdata; + if (c[-1] == ',') --len; } - *jsondata=c; + *jsondata = c; return len; } -int JSON_Get_(const char* json, size_t jsonlen, const char* variable, const char** value) { + +int JSON_Get_(const char* json, size_t jsonlen, const char* variable, const char** value) +{ char needle[32]; const char* needlechild; char var[32]; char* tmp; const char* c; - const char* jsonend=json+jsonlen; + const char* jsonend = json + jsonlen; /// get needle - if(!jsonlen || *json!='{') + if (!jsonlen || *json != '{') return 0; - for(tmp=needle,c=*variable=='['?variable+1:variable; *c!='[' && *c!=']'; ++c){ - if(c==jsonend) + for (tmp = needle, c = *variable == '[' ? variable + 1 : variable; *c != '[' && *c != ']'; ++c) { + if (c == jsonend) return 0; - if(tmp<needle+sizeof(needle)-1) *tmp++=*c; + if (tmp < needle + sizeof(needle) - 1) *tmp++ = *c; } - *tmp='\0'; + *tmp = '\0'; /// get child needle (if any) - if(*c==']') ++c; - if(c==jsonend) + if (*c == ']') ++c; + if (c == jsonend) return 0; - needlechild=c; + needlechild = c; /// parse JSON - for(c=json+1; c<jsonend && (*c=='"' || *c=='\''); ){ - for(++c,tmp=var; c<jsonend && (*c!='"' && *c!='\''); ++c) - if(tmp<var+sizeof(var)-1) *tmp++=*c; - *tmp='\0'; - if(c+2>=jsonend || *++c!=':') break; + for (c = json + 1; c < jsonend && (*c == '"' || *c == '\'');) { + for (++c, tmp = var; c < jsonend && (*c != '"' && *c != '\''); ++c) + if (tmp < var + sizeof(var) - 1) *tmp++ = *c; + *tmp = '\0'; + if (c + 2 >= jsonend || *++c != ':') break; /// read data ++c; - if(!mir_strcmp(var,needle)){ - int datalen=JSON_ParseData_(&c,jsonend-c,value); - if(!datalen) + if (!mir_strcmp(var, needle)) { + int datalen = JSON_ParseData_(&c, jsonend - c, value); + if (!datalen) return 0; - if(*needlechild && **value=='{'){ // we need a child value, parse child object - return JSON_Get_(*value,datalen,needlechild,value); + if (*needlechild && **value == '{') { // we need a child value, parse child object + return JSON_Get_(*value, datalen, needlechild, value); } return datalen; - }else{ - JSON_ParseData_(&c,jsonend-c,value); + } + else { + JSON_ParseData_(&c, jsonend - c, value); } } - *value=NULL; + *value = NULL; return 0; } -int CSend::GetJSONString(const char* json, size_t jsonlen, const char* variable, char* value, size_t valuesize) { - if(!jsonlen || !valuesize) + +int CSend::GetJSONString(const char* json, size_t jsonlen, const char* variable, char* value, size_t valuesize) +{ + if (!jsonlen || !valuesize) return 0; const char* rawvalue; - int rawlen=JSON_Get_(json,jsonlen,variable,&rawvalue); - if(rawlen){ - size_t out=0; + int rawlen = JSON_Get_(json, jsonlen, variable, &rawvalue); + if (rawlen) { + size_t out = 0; --valuesize; /// copy & parse escape sequences - for(int in=0; in<rawlen && out<valuesize; ++in,++out){ - if(rawvalue[in]=='\\'){ - if(++in==rawlen) + for (int in = 0; in < rawlen && out < valuesize; ++in, ++out) { + if (rawvalue[in] == '\\') { + if (++in == rawlen) break; - switch(rawvalue[in]){ - case 's': value[out]=' '; break; - case 't': value[out]='\t'; break; - case 'n': value[out]='\n'; break; - case 'r': value[out]='\r'; break; - default: value[out]=rawvalue[in]; + switch (rawvalue[in]) { + case 's': value[out] = ' '; break; + case 't': value[out] = '\t'; break; + case 'n': value[out] = '\n'; break; + case 'r': value[out] = '\r'; break; + default: value[out] = rawvalue[in]; } continue; } - value[out]=rawvalue[in]; + value[out] = rawvalue[in]; } - value[out]='\0'; + value[out] = '\0'; return 1; } - *value='\0'; + *value = '\0'; return 0; } -int CSend::GetJSONInteger(const char* json, size_t jsonlen, const char* variable,int defvalue) { + +int CSend::GetJSONInteger(const char* json, size_t jsonlen, const char* variable, int defvalue) +{ const char* rawvalue; - int rawlen=JSON_Get_(json,jsonlen,variable,&rawvalue); - if(rawlen){ - defvalue=0; - for(int offset=0; offset<rawlen; ++offset){ - if(rawvalue[offset]<'0' || rawvalue[offset]>'9') break; - defvalue*=10; - defvalue+=rawvalue[offset]-'0'; + int rawlen = JSON_Get_(json, jsonlen, variable, &rawvalue); + if (rawlen) { + defvalue = 0; + for (int offset = 0; offset < rawlen; ++offset) { + if (rawvalue[offset]<'0' || rawvalue[offset]>'9') break; + defvalue *= 10; + defvalue += rawvalue[offset] - '0'; } } return defvalue; } -bool CSend::GetJSONBool(const char* json, size_t jsonlen, const char* variable) { + +bool CSend::GetJSONBool(const char* json, size_t jsonlen, const char* variable) +{ const char* rawvalue; - int rawlen=JSON_Get_(json,jsonlen,variable,&rawvalue); - if(rawlen){ - if(rawlen==4 && !memcmp(rawvalue,"true",4)) + int rawlen = JSON_Get_(json, jsonlen, variable, &rawvalue); + if (rawlen) { + if (rawlen == 4 && !memcmp(rawvalue, "true", 4)) return true; - if(*rawvalue>'0' && *rawvalue<='9') + if (*rawvalue > '0' && *rawvalue <= '9') return true; } return false; } -static void HTTPFormAppendData(NETLIBHTTPREQUEST* nlhr, size_t* dataMax, char** dataPos, const char* data,size_t len){ - nlhr->dataLength=(*dataPos-nlhr->pData); - if(nlhr->dataLength+len >= *dataMax){ - *dataPos=nlhr->pData; - *dataMax+=0x1000+0x1000*(len>>12); - nlhr->pData=(char*)mir_realloc(nlhr->pData,*dataMax); - if(!nlhr->pData) mir_free(*dataPos); - *dataPos=nlhr->pData; - if(!*dataPos) +static void HTTPFormAppendData(NETLIBHTTPREQUEST* nlhr, size_t* dataMax, char** dataPos, const char* data, size_t len) +{ + nlhr->dataLength = (*dataPos - nlhr->pData); + if (nlhr->dataLength + len >= *dataMax) { + *dataPos = nlhr->pData; + *dataMax += 0x1000 + 0x1000 * (len >> 12); + nlhr->pData = (char*)mir_realloc(nlhr->pData, *dataMax); + if (!nlhr->pData) mir_free(*dataPos); + *dataPos = nlhr->pData; + if (!*dataPos) return; - *dataPos+=nlhr->dataLength; + *dataPos += nlhr->dataLength; } - if(data){ - memcpy(*dataPos,data,sizeof(char)*len); *dataPos+=len; + if (data) { + memcpy(*dataPos, data, sizeof(char)*len); *dataPos += len; nlhr->dataLength += (int)len; // not necessary } } + void CSend::HTTPFormDestroy(NETLIBHTTPREQUEST* nlhr) { - mir_free(nlhr->headers[0].szValue), nlhr->headers[0].szValue=NULL; - mir_free(nlhr->headers), nlhr->headers=NULL; - mir_free(nlhr->pData), nlhr->pData=NULL; + mir_free(nlhr->headers[0].szValue), nlhr->headers[0].szValue = NULL; + mir_free(nlhr->headers), nlhr->headers = NULL; + mir_free(nlhr->pData), nlhr->pData = NULL; } -int CSend::HTTPFormCreate(NETLIBHTTPREQUEST* nlhr,int requestType,char* url,HTTPFormData* frm,size_t frmNum) + +int CSend::HTTPFormCreate(NETLIBHTTPREQUEST* nlhr, int requestType, char* url, HTTPFormData* frm, size_t frmNum) { char boundary[16]; - memcpy(boundary,"--M461C/",8); + memcpy(boundary, "--M461C/", 8); { - union{ + union + { DWORD num; unsigned char cr[4]; - };num=GetTickCount()^0x8000; - for(int i=0; i<4; ++i){ - unsigned char chcode=cr[i]>>4; - boundary[8+i*2]=(chcode<0x0a ? '0' : 'a'-0x0a)+chcode; - chcode=cr[i]&0x0f; - boundary[9+i*2]=(chcode<0x0a ? '0' : 'a'-0x0a)+chcode; + }; num = GetTickCount() ^ 0x8000; + for (int i = 0; i < 4; ++i) { + unsigned char chcode = cr[i] >> 4; + boundary[8 + i * 2] = (chcode < 0x0a ? '0' : 'a' - 0x0a) + chcode; + chcode = cr[i] & 0x0f; + boundary[9 + i * 2] = (chcode < 0x0a ? '0' : 'a' - 0x0a) + chcode; } } - nlhr->cbSize =sizeof(NETLIBHTTPREQUEST); - nlhr->requestType =requestType; - nlhr->flags =NLHRF_HTTP11; - if(!strncmp(url,"https://",8)) nlhr->flags|=NLHRF_SSL; - nlhr->szUrl =url; - nlhr->headersCount =3; - for(HTTPFormData* iter=frm,* end=frm+frmNum; iter!=end; ++iter){ - if(!(iter->flags&HTTPFF_HEADER)) break; + nlhr->cbSize = sizeof(NETLIBHTTPREQUEST); + nlhr->requestType = requestType; + nlhr->flags = NLHRF_HTTP11; + if (!strncmp(url, "https://", 8)) nlhr->flags |= NLHRF_SSL; + nlhr->szUrl = url; + nlhr->headersCount = 3; + for (HTTPFormData* iter = frm, *end = frm + frmNum; iter != end; ++iter) { + if (!(iter->flags&HTTPFF_HEADER)) break; ++nlhr->headersCount; } - nlhr->headers =(NETLIBHTTPHEADER*)mir_alloc(sizeof(NETLIBHTTPHEADER)*nlhr->headersCount); + nlhr->headers = (NETLIBHTTPHEADER*)mir_alloc(sizeof(NETLIBHTTPHEADER)*nlhr->headersCount); { - char* contenttype=(char*)mir_alloc(sizeof(char)*(30+1+sizeof(boundary))); - memcpy(contenttype,"multipart/form-data; boundary=",30); - memcpy(contenttype+30,boundary,sizeof(boundary)); - contenttype[30+sizeof(boundary)]='\0'; - nlhr->headers[0].szName ="Content-Type"; - nlhr->headers[0].szValue =contenttype; - nlhr->headers[1].szName ="User-Agent"; - nlhr->headers[1].szValue =__USER_AGENT_STRING; - nlhr->headers[2].szName ="Accept-Language"; - nlhr->headers[2].szValue ="en-us,en;q=0.8"; - int i=3; - for(HTTPFormData* iter=frm,* end=frm+frmNum; iter!=end; ++iter){ - if(!(iter->flags&HTTPFF_HEADER)) break; - nlhr->headers[i].szName=(char*)iter->name; - nlhr->headers[i++].szValue=(char*)iter->value_str; + char* contenttype = (char*)mir_alloc(sizeof(char)*(30 + 1 + sizeof(boundary))); + memcpy(contenttype, "multipart/form-data; boundary=", 30); + memcpy(contenttype + 30, boundary, sizeof(boundary)); + contenttype[30 + sizeof(boundary)] = '\0'; + nlhr->headers[0].szName = "Content-Type"; + nlhr->headers[0].szValue = contenttype; + nlhr->headers[1].szName = "User-Agent"; + nlhr->headers[1].szValue = __USER_AGENT_STRING; + nlhr->headers[2].szName = "Accept-Language"; + nlhr->headers[2].szValue = "en-us,en;q=0.8"; + int i = 3; + for (HTTPFormData* iter = frm, *end = frm + frmNum; iter != end; ++iter) { + if (!(iter->flags&HTTPFF_HEADER)) break; + nlhr->headers[i].szName = (char*)iter->name; + nlhr->headers[i++].szValue = (char*)iter->value_str; } } - char* dataPos=nlhr->pData; - size_t dataMax=0; - for(HTTPFormData* iter=frm,* end=frm+frmNum; iter!=end; ++iter){ - if(iter->flags&HTTPFF_HEADER) continue; - HTTPFormAppendData(nlhr,&dataMax,&dataPos,NULL,2+sizeof(boundary)+40); - memset(dataPos,'-',2); dataPos+=2; - memcpy(dataPos,boundary,sizeof(boundary)); dataPos+=sizeof(boundary); - memcpy(dataPos,"\r\nContent-Disposition: form-data; name=\"",40); dataPos+=40; - size_t namelen=mir_strlen(iter->name), valuelen; - if(!(iter->flags&HTTPFF_INT)) - valuelen=mir_strlen(iter->value_str); - if(iter->flags&HTTPFF_FILE){ - const char* filename =strrchr(iter->value_str,'\\'); - if(!filename) filename =strrchr(iter->value_str,'/'); - if(!filename) filename =iter->value_str; + char* dataPos = nlhr->pData; + size_t dataMax = 0; + for (HTTPFormData* iter = frm, *end = frm + frmNum; iter != end; ++iter) { + if (iter->flags&HTTPFF_HEADER) continue; + HTTPFormAppendData(nlhr, &dataMax, &dataPos, NULL, 2 + sizeof(boundary) + 40); + memset(dataPos, '-', 2); dataPos += 2; + memcpy(dataPos, boundary, sizeof(boundary)); dataPos += sizeof(boundary); + memcpy(dataPos, "\r\nContent-Disposition: form-data; name=\"", 40); dataPos += 40; + size_t namelen = mir_strlen(iter->name), valuelen = 0; + if (!(iter->flags&HTTPFF_INT)) + valuelen = mir_strlen(iter->value_str); + if (iter->flags&HTTPFF_FILE) { + const char* filename = strrchr(iter->value_str, '\\'); + if (!filename) filename = strrchr(iter->value_str, '/'); + if (!filename) filename = iter->value_str; else ++filename; - valuelen=mir_strlen(filename); - HTTPFormAppendData(nlhr,&dataMax,&dataPos,NULL,namelen+13+valuelen+17); - memcpy(dataPos,iter->name,namelen); dataPos+=namelen; - memcpy(dataPos,"\"; filename=\"",13); dataPos+=13; - memcpy(dataPos,filename,valuelen); dataPos+=valuelen; - memcpy(dataPos,"\"\r\nContent-Type: ",17); dataPos+=17; + valuelen = mir_strlen(filename); + HTTPFormAppendData(nlhr, &dataMax, &dataPos, NULL, namelen + 13 + valuelen + 17); + memcpy(dataPos, iter->name, namelen); dataPos += namelen; + memcpy(dataPos, "\"; filename=\"", 13); dataPos += 13; + memcpy(dataPos, filename, valuelen); dataPos += valuelen; + memcpy(dataPos, "\"\r\nContent-Type: ", 17); dataPos += 17; /// add mime type - const char* mime="application/octet-stream"; - const char* fileext=strrchr(filename,'.'); - if(fileext){ - if(!mir_strcmp(fileext,".jpg") || !mir_strcmp(fileext,".jpeg") || !mir_strcmp(fileext,".jpe")) - mime="image/jpeg"; - else if(!mir_strcmp(fileext,".bmp")) - mime="image/bmp"; - else if(!mir_strcmp(fileext,".png")) - mime="image/png"; - else if(!mir_strcmp(fileext,".gif")) - mime="image/gif"; - else if(!mir_strcmp(fileext,".tif") || !mir_strcmp(fileext,".tiff")) - mime="image/tiff"; + const char* mime = "application/octet-stream"; + const char* fileext = strrchr(filename, '.'); + if (fileext) { + if (!mir_strcmp(fileext, ".jpg") || !mir_strcmp(fileext, ".jpeg") || !mir_strcmp(fileext, ".jpe")) + mime = "image/jpeg"; + else if (!mir_strcmp(fileext, ".bmp")) + mime = "image/bmp"; + else if (!mir_strcmp(fileext, ".png")) + mime = "image/png"; + else if (!mir_strcmp(fileext, ".gif")) + mime = "image/gif"; + else if (!mir_strcmp(fileext, ".tif") || !mir_strcmp(fileext, ".tiff")) + mime = "image/tiff"; } - HTTPFormAppendData(nlhr,&dataMax,&dataPos,mime,mir_strlen(mime)); - HTTPFormAppendData(nlhr,&dataMax,&dataPos,"\r\n\r\n",4); + HTTPFormAppendData(nlhr, &dataMax, &dataPos, mime, mir_strlen(mime)); + HTTPFormAppendData(nlhr, &dataMax, &dataPos, "\r\n\r\n", 4); /// add file content - size_t filesize=0; - FILE* fp=fopen(iter->value_str,"rb"); - if(fp){ - fseek(fp,0,SEEK_END); - filesize=ftell(fp); fseek(fp,0,SEEK_SET); - HTTPFormAppendData(nlhr,&dataMax,&dataPos,NULL,filesize+2); - if(fread(dataPos,1,filesize,fp)!=filesize){ - fclose(fp), fp=NULL; + size_t filesize = 0; + FILE* fp = fopen(iter->value_str, "rb"); + if (fp) { + fseek(fp, 0, SEEK_END); + filesize = ftell(fp); fseek(fp, 0, SEEK_SET); + HTTPFormAppendData(nlhr, &dataMax, &dataPos, NULL, filesize + 2); + if (fread(dataPos, 1, filesize, fp) != filesize) { + fclose(fp), fp = NULL; } } - if(!fp){ + if (!fp) { HTTPFormDestroy(nlhr); Error(_T("Error occurred when opening local file.\nAborting file upload...")); Exit(ACKRESULT_FAILED); return 1; - }else + } + else fclose(fp); - dataPos+=filesize; - memcpy(dataPos,"\r\n",2); dataPos+=2; - }else if(iter->flags&HTTPFF_8BIT){ - HTTPFormAppendData(nlhr,&dataMax,&dataPos,NULL,namelen+38+valuelen+2); - memcpy(dataPos,iter->name,namelen); dataPos+=namelen; - memcpy(dataPos,"\"\r\nContent-Transfer-Encoding: 8bit\r\n\r\n",38); dataPos+=38; - memcpy(dataPos,iter->value_str,valuelen); dataPos+=valuelen; - memcpy(dataPos,"\r\n",2); dataPos+=2; - }else if(iter->flags&HTTPFF_INT){ - HTTPFormAppendData(nlhr,&dataMax,&dataPos,NULL,namelen+5+17/*max numbers*/+2); - memcpy(dataPos,iter->name,namelen); dataPos+=namelen; - memcpy(dataPos,"\"\r\n\r\n",5); dataPos+=5; - int ret=snprintf(dataPos,17,"%Id",iter->value_int); - if(ret<17 && ret>0) dataPos+=ret; - memcpy(dataPos,"\r\n",2); dataPos+=2; - }else{ - HTTPFormAppendData(nlhr,&dataMax,&dataPos,NULL,namelen+5+valuelen+2); - memcpy(dataPos,iter->name,namelen); dataPos+=namelen; - memcpy(dataPos,"\"\r\n\r\n",5); dataPos+=5; - memcpy(dataPos,iter->value_str,valuelen); dataPos+=valuelen; - memcpy(dataPos,"\r\n",2); dataPos+=2; + dataPos += filesize; + memcpy(dataPos, "\r\n", 2); dataPos += 2; + } + else if (iter->flags&HTTPFF_8BIT) { + HTTPFormAppendData(nlhr, &dataMax, &dataPos, NULL, namelen + 38 + valuelen + 2); + memcpy(dataPos, iter->name, namelen); dataPos += namelen; + memcpy(dataPos, "\"\r\nContent-Transfer-Encoding: 8bit\r\n\r\n", 38); dataPos += 38; + memcpy(dataPos, iter->value_str, valuelen); dataPos += valuelen; + memcpy(dataPos, "\r\n", 2); dataPos += 2; + } + else if (iter->flags&HTTPFF_INT) { + HTTPFormAppendData(nlhr, &dataMax, &dataPos, NULL, namelen + 5 + 17/*max numbers*/ + 2); + memcpy(dataPos, iter->name, namelen); dataPos += namelen; + memcpy(dataPos, "\"\r\n\r\n", 5); dataPos += 5; + int ret = snprintf(dataPos, 17, "%Id", iter->value_int); + if (ret < 17 && ret>0) dataPos += ret; + memcpy(dataPos, "\r\n", 2); dataPos += 2; + } + else { + HTTPFormAppendData(nlhr, &dataMax, &dataPos, NULL, namelen + 5 + valuelen + 2); + memcpy(dataPos, iter->name, namelen); dataPos += namelen; + memcpy(dataPos, "\"\r\n\r\n", 5); dataPos += 5; + memcpy(dataPos, iter->value_str, valuelen); dataPos += valuelen; + memcpy(dataPos, "\r\n", 2); dataPos += 2; } } - HTTPFormAppendData(nlhr,&dataMax,&dataPos,NULL,2+sizeof(boundary)+4); - memset(dataPos,'-',2); dataPos+=2; - memcpy(dataPos,boundary,sizeof(boundary)); dataPos+=sizeof(boundary); - memcpy(dataPos,"--\r\n",4); dataPos+=4; - nlhr->dataLength=dataPos-nlhr->pData; - #ifdef _DEBUG /// print request content to "_sendss_tmp" file for debugging + HTTPFormAppendData(nlhr, &dataMax, &dataPos, NULL, 2 + sizeof(boundary) + 4); + memset(dataPos, '-', 2); dataPos += 2; + memcpy(dataPos, boundary, sizeof(boundary)); dataPos += sizeof(boundary); + memcpy(dataPos, "--\r\n", 4); dataPos += 4; + nlhr->dataLength = dataPos - nlhr->pData; +#ifdef _DEBUG /// print request content to "_sendss_tmp" file for debugging { - FILE* fp=fopen("_sendss_tmp","wb"); - if(fp){ - fprintf(fp,"--Target-- %s\n",nlhr->szUrl); - for(int i=0; i<nlhr->headersCount; ++i){ - fprintf(fp,"%s: %s\n",nlhr->headers[i].szName,nlhr->headers[i].szValue); + FILE* fp = fopen("_sendss_tmp", "wb"); + if (fp) { + fprintf(fp, "--Target-- %s\n", nlhr->szUrl); + for (int i = 0; i < nlhr->headersCount; ++i) { + fprintf(fp, "%s: %s\n", nlhr->headers[i].szName, nlhr->headers[i].szValue); } - fprintf(fp,"\n\n"); - fwrite(nlhr->pData,1,nlhr->dataLength,fp); + fprintf(fp, "\n\n"); + fwrite(nlhr->pData, 1, nlhr->dataLength, fp); fclose(fp); } } - #endif // _DEBUG +#endif // _DEBUG return 0; } diff --git a/plugins/SendScreenshotPlus/src/CSendDropbox.cpp b/plugins/SendScreenshotPlus/src/CSendDropbox.cpp index b6eaf6764f..507d61497a 100644 --- a/plugins/SendScreenshotPlus/src/CSendDropbox.cpp +++ b/plugins/SendScreenshotPlus/src/CSendDropbox.cpp @@ -31,18 +31,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //--------------------------------------------------------------------------- CSendDropbox::CSendDropbox(HWND Owner, MCONTACT hContact, bool bAsync) -: CSend(Owner, hContact, bAsync){ -/// @todo : re-enable SS_DLG_DELETEAFTERSSEND with full implemention of Dropbox upload with progress, msg and sounds + : CSend(Owner, hContact, bAsync) +{ + /// @todo : re-enable SS_DLG_DELETEAFTERSSEND with full implemention of Dropbox upload with progress, msg and sounds m_EnableItem = SS_DLG_DESCRIPTION | SS_DLG_AUTOSEND/* | SS_DLG_DELETEAFTERSSEND*/; m_pszSendTyp = LPGENT("Dropbox transfer"); } -CSendDropbox::~CSendDropbox(){ +CSendDropbox::~CSendDropbox() +{ } //--------------------------------------------------------------------------- -int CSendDropbox::Send() { - if(!m_bAsync){ + +int CSendDropbox::Send() +{ + if (!m_bAsync) { SendThread(); return 1; } @@ -52,22 +56,23 @@ int CSendDropbox::Send() { //--------------------------------------------------------------------------- - -void CSendDropbox::SendThread() { -/// @todo : SS_DLG_DESCRIPTION and SS_DLG_DELETEAFTERSSEND are of no use as of now since we don't track upload progress - INT_PTR ret=0; - if(!m_hContact) +void CSendDropbox::SendThread() +{ + /// @todo : SS_DLG_DESCRIPTION and SS_DLG_DELETEAFTERSSEND are of no use as of now since we don't track upload progress + INT_PTR ret = 0; + if (!m_hContact) SetContact(db_find_first("Dropbox")); - if(m_hContact) + if (m_hContact) ret = CallService(MS_DROPBOX_SEND_FILE, (WPARAM)m_hContact, (LPARAM)m_pszFile); - if(!ret) { - Error(LPGENT("%s (%i):\nCould not add a share to the Dropbox plugin."),TranslateTS(m_pszSendTyp),ret); + if (!ret) { + Error(LPGENT("%s (%i):\nCould not add a share to the Dropbox plugin."), TranslateTS(m_pszSendTyp), ret); Exit(ACKRESULT_FAILED); return; } - m_bSilent=true; + m_bSilent = true; Exit(ACKRESULT_SUCCESS); } -void CSendDropbox::SendThreadWrapper(void * Obj) { +void CSendDropbox::SendThreadWrapper(void * Obj) +{ reinterpret_cast<CSendDropbox*>(Obj)->SendThread(); } diff --git a/plugins/SendScreenshotPlus/src/CSendEmail.cpp b/plugins/SendScreenshotPlus/src/CSendEmail.cpp index ee5628e420..548fa055cf 100644 --- a/plugins/SendScreenshotPlus/src/CSendEmail.cpp +++ b/plugins/SendScreenshotPlus/src/CSendEmail.cpp @@ -30,18 +30,21 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" //--------------------------------------------------------------------------- + CSendEmail::CSendEmail(HWND Owner, MCONTACT hContact, bool /*bAsync*/) -: CSend(Owner, hContact, true){ - m_EnableItem = SS_DLG_DESCRIPTION | SS_DLG_DELETEAFTERSSEND; // SS_DLG_AUTOSEND | ; - m_pszSendTyp = LPGENT("Email transfer"); - m_pszFileA = NULL; - m_pszFileName = NULL; - m_Email = NULL; - m_FriendlyName = NULL; - m_Subject = NULL; + : CSend(Owner, hContact, true) +{ + m_EnableItem = SS_DLG_DESCRIPTION | SS_DLG_DELETEAFTERSSEND; // SS_DLG_AUTOSEND | ; + m_pszSendTyp = LPGENT("Email transfer"); + m_pszFileA = NULL; + m_pszFileName = NULL; + m_Email = NULL; + m_FriendlyName = NULL; + m_Subject = NULL; } -CSendEmail::~CSendEmail(){ +CSendEmail::~CSendEmail() +{ mir_free(m_pszFileA); mir_free(m_pszFileName); mir_free(m_Email); @@ -50,9 +53,10 @@ CSendEmail::~CSendEmail(){ } //--------------------------------------------------------------------------- + int CSendEmail::Send() { - if(!m_hContact) return 1; + if (!m_hContact) return 1; mir_free(m_pszFileName); m_pszFileName = GetFileNameA(m_pszFile); @@ -60,19 +64,19 @@ int CSendEmail::Send() m_pszFileA = mir_t2a(m_pszFile); -// AnsiString Email, Subject, FriendlyName; - CONTACTINFO ci={0}; + // AnsiString Email, Subject, FriendlyName; + CONTACTINFO ci = { 0 }; ci.cbSize = sizeof(ci); ci.hContact = m_hContact; ci.szProto = m_pszProto; //ci.dwFlag = CNF_TCHAR; ci.dwFlag = CNF_EMAIL | CNF_TCHAR; - CallService(MS_CONTACT_GETCONTACTINFO,0,(LPARAM)&ci); + CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci); m_Email = mir_t2a(ci.pszVal); ci.dwFlag = CNF_DISPLAY | CNF_TCHAR; - CallService(MS_CONTACT_GETCONTACTINFO,0,(LPARAM)&ci); + CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci); m_FriendlyName = mir_t2a(ci.pszVal); mir_free(ci.pszVal); @@ -86,14 +90,15 @@ int CSendEmail::Send() return 0; } -void CSendEmail::SendThread() { +void CSendEmail::SendThread() +{ //This code based on SentTo.exe application. //The default mail client for Simple MAPI or MAPI calls is defined by the //HKLM\Software\Clients\Mail::(default) registry value. MapiFileDesc arrfileDesc[1]; - typedef ULONG (FAR PASCAL *MAPIFUNC)(LHANDLE,ULONG,lpMapiMessage,FLAGS,ULONG); + typedef ULONG(FAR PASCAL *MAPIFUNC)(LHANDLE, ULONG, lpMapiMessage, FLAGS, ULONG); MapiMessage Msg; MAPIFUNC lpMAPISendMail; @@ -131,7 +136,7 @@ void CSendEmail::SendThread() { recip.ulReserved = 0; recip.ulRecipClass = MAPI_TO; - if (m_FriendlyName && m_FriendlyName[0]!= NULL) { + if (m_FriendlyName && m_FriendlyName[0] != NULL) { recip.lpszName = m_FriendlyName; //friendly name set to contact's name } else { @@ -144,61 +149,62 @@ void CSendEmail::SendThread() { Msg.lpRecips = &recip; try { - int res = lpMAPISendMail(NULL, NULL, &Msg, MAPI_LOGON_UI|MAPI_DIALOG, 0); + int res = lpMAPISendMail(NULL, NULL, &Msg, MAPI_LOGON_UI | MAPI_DIALOG, 0); ::FreeLibrary(hMAPILib); TCHAR* err; switch (res) { - case SUCCESS_SUCCESS: - //The call succeeded and the message was sent. - Exit(ACKRESULT_SUCCESS); return; + case SUCCESS_SUCCESS: + //The call succeeded and the message was sent. + Exit(ACKRESULT_SUCCESS); return; // No message was sent - case MAPI_E_AMBIGUOUS_RECIPIENT: - err = LPGENT("A recipient matched more than one of the recipient descriptor structures and MAPI_DIALOG was not set"); - break; - case MAPI_E_ATTACHMENT_NOT_FOUND: - err = LPGENT("The specified attachment was not found"); - break; - case MAPI_E_ATTACHMENT_OPEN_FAILURE: - err = LPGENT("The specified attachment could not be opened"); - break; - case MAPI_E_BAD_RECIPTYPE: - err = LPGENT("The type of a recipient was not MAPI_TO, MAPI_CC, or MAPI_BCC"); - break; - case MAPI_E_FAILURE: - err = LPGENT("One or more unspecified errors occurred"); - break; - case MAPI_E_INSUFFICIENT_MEMORY: - err = LPGENT("There was insufficient memory to proceed"); - break; - case MAPI_E_INVALID_RECIPS: - err = LPGENT("One or more recipients were invalid or did not resolve to any address"); - break; - case MAPI_E_LOGIN_FAILURE: - err = LPGENT("There was no default logon, and the user failed to log on successfully when the logon dialog box was displayed"); - break; - case MAPI_E_TEXT_TOO_LARGE: - err = LPGENT("The text in the message was too large"); - break; - case MAPI_E_TOO_MANY_FILES: - err = LPGENT("There were too many file attachments"); - break; - case MAPI_E_TOO_MANY_RECIPIENTS: - err = LPGENT("There were too many recipients"); - break; - case MAPI_E_UNKNOWN_RECIPIENT: - err = LPGENT("A recipient did not appear in the address list"); - break; - case MAPI_E_USER_ABORT: - err = LPGENT("The user canceled one of the dialog boxes"); - break; - default: - err = LPGENT("Unknown Error"); - break; + case MAPI_E_AMBIGUOUS_RECIPIENT: + err = LPGENT("A recipient matched more than one of the recipient descriptor structures and MAPI_DIALOG was not set"); + break; + case MAPI_E_ATTACHMENT_NOT_FOUND: + err = LPGENT("The specified attachment was not found"); + break; + case MAPI_E_ATTACHMENT_OPEN_FAILURE: + err = LPGENT("The specified attachment could not be opened"); + break; + case MAPI_E_BAD_RECIPTYPE: + err = LPGENT("The type of a recipient was not MAPI_TO, MAPI_CC, or MAPI_BCC"); + break; + case MAPI_E_FAILURE: + err = LPGENT("One or more unspecified errors occurred"); + break; + case MAPI_E_INSUFFICIENT_MEMORY: + err = LPGENT("There was insufficient memory to proceed"); + break; + case MAPI_E_INVALID_RECIPS: + err = LPGENT("One or more recipients were invalid or did not resolve to any address"); + break; + case MAPI_E_LOGIN_FAILURE: + err = LPGENT("There was no default logon, and the user failed to log on successfully when the logon dialog box was displayed"); + break; + case MAPI_E_TEXT_TOO_LARGE: + err = LPGENT("The text in the message was too large"); + break; + case MAPI_E_TOO_MANY_FILES: + err = LPGENT("There were too many file attachments"); + break; + case MAPI_E_TOO_MANY_RECIPIENTS: + err = LPGENT("There were too many recipients"); + break; + case MAPI_E_UNKNOWN_RECIPIENT: + err = LPGENT("A recipient did not appear in the address list"); + break; + case MAPI_E_USER_ABORT: + err = LPGENT("The user canceled one of the dialog boxes"); + break; + default: + err = LPGENT("Unknown Error"); + break; } Error(SS_ERR_MAPI, res, err); Exit(ACKRESULT_FAILED); - } catch (...) { + } + catch (...) { ::FreeLibrary(hMAPILib); Error(SS_ERR_INIT, m_pszSendTyp); Exit(ACKRESULT_FAILED); @@ -206,7 +212,8 @@ void CSendEmail::SendThread() { } } -void CSendEmail::SendThreadWrapper(void * Obj) { +void CSendEmail::SendThreadWrapper(void * Obj) +{ reinterpret_cast<CSendEmail*>(Obj)->SendThread(); } diff --git a/plugins/SendScreenshotPlus/src/CSendFTPFile.cpp b/plugins/SendScreenshotPlus/src/CSendFTPFile.cpp index e1fa16f726..75dd81e1cb 100644 --- a/plugins/SendScreenshotPlus/src/CSendFTPFile.cpp +++ b/plugins/SendScreenshotPlus/src/CSendFTPFile.cpp @@ -29,23 +29,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //--------------------------------------------------------------------------- #include "stdafx.h" - //--------------------------------------------------------------------------- + CSendFTPFile::CSendFTPFile(HWND Owner, MCONTACT hContact, bool /*bAsync*/) -: CSend(Owner, hContact, true){ - m_EnableItem = 0 ; //SS_DLG_DESCRIPTION | SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND; - m_pszSendTyp = LPGENT("FTPFile transfer"); - m_pszFileName = NULL; + : CSend(Owner, hContact, true) +{ + m_EnableItem = 0; //SS_DLG_DESCRIPTION | SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND; + m_pszSendTyp = LPGENT("FTPFile transfer"); + m_pszFileName = NULL; } -CSendFTPFile::~CSendFTPFile(){ +CSendFTPFile::~CSendFTPFile() +{ mir_free(m_pszFileName); } //--------------------------------------------------------------------------- int CSendFTPFile::Send() { - if(!m_hContact) return 1; + if (!m_hContact) return 1; /********************************************************************************************* * Send file (files) to the FTP server and copy file URL * to message log or clipboard (according to plugin setting) @@ -58,20 +60,21 @@ int CSendFTPFile::Send() ********************************************************************************************/ mir_free(m_pszFileName); m_pszFileName = GetFileNameA(m_pszFile); - size_t size = sizeof(char)*(mir_strlen(m_pszFileName)+2); + size_t size = sizeof(char)*(mir_strlen(m_pszFileName) + 2); m_pszFileName = (char*)mir_realloc(m_pszFileName, size); - m_pszFileName[size-1] = NULL; + m_pszFileName[size - 1] = NULL; //start Send thread mir_forkthread(&CSendFTPFile::SendThreadWrapper, this); return 0; } -void CSendFTPFile::SendThread() { +void CSendFTPFile::SendThread() +{ - INT_PTR ret = FTPFileUploadA(m_hContact, FNUM_DEFAULT, FMODE_RAWFILE, &m_pszFileName,1); + INT_PTR ret = FTPFileUploadA(m_hContact, FNUM_DEFAULT, FMODE_RAWFILE, &m_pszFileName, 1); if (ret != 0) { - Error(LPGENT("%s (%i):\nCould not add a share to the FTP File plugin."),TranslateTS(m_pszSendTyp),ret); + Error(LPGENT("%s (%i):\nCould not add a share to the FTP File plugin."), TranslateTS(m_pszSendTyp), ret); Exit(ret); return; } @@ -84,7 +87,8 @@ void CSendFTPFile::SendThread() { Exit(ACKRESULT_FAILED); } -void CSendFTPFile::SendThreadWrapper(void * Obj) { +void CSendFTPFile::SendThreadWrapper(void * Obj) +{ reinterpret_cast<CSendFTPFile*>(Obj)->SendThread(); } diff --git a/plugins/SendScreenshotPlus/src/CSendFile.cpp b/plugins/SendScreenshotPlus/src/CSendFile.cpp index adaf83e63d..24e8bfb68f 100644 --- a/plugins/SendScreenshotPlus/src/CSendFile.cpp +++ b/plugins/SendScreenshotPlus/src/CSendFile.cpp @@ -31,16 +31,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //--------------------------------------------------------------------------- CSendFile::CSendFile(HWND Owner, MCONTACT hContact, bool /*bAsync*/) -: CSend(Owner, hContact, true){ - m_EnableItem = SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND | SS_DLG_DESCRIPTION; - m_pszSendTyp = LPGENT("File transfer"); + : CSend(Owner, hContact, true) +{ + m_EnableItem = SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND | SS_DLG_DESCRIPTION; + m_pszSendTyp = LPGENT("File transfer"); } -CSendFile::~CSendFile(){ +CSendFile::~CSendFile() +{ } //--------------------------------------------------------------------------- -int CSendFile::Send() { +int CSendFile::Send() +{ svcSendFileExit(); return 0; } diff --git a/plugins/SendScreenshotPlus/src/CSendHTTPServer.cpp b/plugins/SendScreenshotPlus/src/CSendHTTPServer.cpp index 2f50e7a6c5..8248afe514 100644 --- a/plugins/SendScreenshotPlus/src/CSendHTTPServer.cpp +++ b/plugins/SendScreenshotPlus/src/CSendHTTPServer.cpp @@ -29,7 +29,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //--------------------------------------------------------------------------- #include "stdafx.h" -INT_PTR (*g_MirCallService)(const char *, WPARAM, LPARAM)=NULL; +INT_PTR(*g_MirCallService)(const char *, WPARAM, LPARAM) = NULL; //INT_PTR (*CallService)(const char *,WPARAM,LPARAM); @@ -37,11 +37,11 @@ INT_PTR (*g_MirCallService)(const char *, WPARAM, LPARAM)=NULL; CSendHTTPServer::CSendHTTPServer(HWND Owner, MCONTACT hContact, bool /*bAsync*/) : CSend(Owner, hContact, true) { - m_EnableItem = SS_DLG_DESCRIPTION ; //| SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND; - m_pszSendTyp = LPGENT("HTTPServer transfer"); - m_pszFileName = NULL; - m_fsi_pszSrvPath = NULL; - m_fsi_pszRealPath = NULL; + m_EnableItem = SS_DLG_DESCRIPTION; //| SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND; + m_pszSendTyp = LPGENT("HTTPServer transfer"); + m_pszFileName = NULL; + m_fsi_pszSrvPath = NULL; + m_fsi_pszRealPath = NULL; } CSendHTTPServer::~CSendHTTPServer() @@ -54,7 +54,7 @@ CSendHTTPServer::~CSendHTTPServer() //--------------------------------------------------------------------------- int CSendHTTPServer::Send() { - if(!m_hContact) return 1; + if (!m_hContact) return 1; if (CallService(MS_HTTP_ACCEPT_CONNECTIONS, TRUE, 0) != 0) { Error(LPGENT("Could not start the HTTP Server plugin.")); Exit(ACKRESULT_FAILED); @@ -71,11 +71,10 @@ int CSendHTTPServer::Send() replaceStr(m_fsi_pszRealPath, _T2A(m_pszFile)); memset(&m_fsi, 0, sizeof(m_fsi)); - m_fsi.lStructSize = sizeof(STFileShareInfo); - m_fsi.pszSrvPath = m_fsi_pszSrvPath; - m_fsi.nMaxDownloads = -1; // -1 = infinite - m_fsi.pszRealPath = m_fsi_pszRealPath; - //m_fsi.dwOptions = NULL; //OPT_SEND_LINK only work on single chat; + m_fsi.lStructSize = sizeof(STFileShareInfo); + m_fsi.pszSrvPath = m_fsi_pszSrvPath; + m_fsi.nMaxDownloads = -1; // -1 = infinite + m_fsi.pszRealPath = m_fsi_pszRealPath; //start Send thread mir_forkthread(&CSendHTTPServer::SendThreadWrapper, this); @@ -96,14 +95,14 @@ void CSendHTTPServer::SendThread() } else { //original plugin - m_fsi.dwOptions = OPT_SEND_LINK; + m_fsi.dwOptions = OPT_SEND_LINK; //send DATA and wait for reply ret = CallService(MS_HTTP_ADD_CHANGE_REMOVE, (WPARAM)m_hContact, (LPARAM)&m_fsi); } if (ret != 0) { - Error(LPGENT("%s (%i):\nCould not add a share to the HTTP Server plugin."),TranslateTS(m_pszSendTyp),ret); + Error(LPGENT("%s (%i):\nCould not add a share to the HTTP Server plugin."), TranslateTS(m_pszSendTyp), ret); Exit(ret); return; } diff --git a/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp b/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp index a0f03d11eb..a1bdcc4fa1 100644 --- a/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp +++ b/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp @@ -31,36 +31,39 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //--------------------------------------------------------------------------- CSendHost_ImageShack::CSendHost_ImageShack(HWND Owner, MCONTACT hContact, bool bAsync) -: CSend(Owner, hContact, bAsync) { - m_EnableItem = SS_DLG_DESCRIPTION | SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND; - m_pszSendTyp = LPGENT("Image upload"); + : CSend(Owner, hContact, bAsync) +{ + m_EnableItem = SS_DLG_DESCRIPTION | SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND; + m_pszSendTyp = LPGENT("Image upload"); } -CSendHost_ImageShack::~CSendHost_ImageShack(){ +CSendHost_ImageShack::~CSendHost_ImageShack() +{ }; //--------------------------------------------------------------------------- -int CSendHost_ImageShack::Send() { - if(!g_hNetlibUser){ /// check Netlib +int CSendHost_ImageShack::Send() +{ + if (!g_hNetlibUser) { /// check Netlib Error(SS_ERR_INIT, m_pszSendTyp); Exit(ACKRESULT_FAILED); return !m_bAsync; } memset(&m_nlhr, 0, sizeof(m_nlhr)); - char* tmp; tmp=mir_t2a(m_pszFile); - HTTPFormData frm[]={ -// {"Referer",HTTPFORM_HEADER("http://www.imageshack.us/upload_api.php")}, - {"fileupload",HTTPFORM_FILE(tmp)}, + char* tmp; tmp = mir_t2a(m_pszFile); + HTTPFormData frm[] = { + // {"Referer",HTTPFORM_HEADER("http://www.imageshack.us/upload_api.php")}, + { "fileupload", HTTPFORM_FILE(tmp) }, //{"rembar","yes"},// no info bar on thumb - {"public","no"}, - {"key",HTTPFORM_8BIT(DEVKEY_IMAGESHACK)}, + { "public", "no" }, + { "key", HTTPFORM_8BIT(DEVKEY_IMAGESHACK) }, }; - int error=HTTPFormCreate(&m_nlhr,REQUEST_POST,"http://imageshack.us/upload_api.php",frm,sizeof(frm)/sizeof(HTTPFormData)); + int error = HTTPFormCreate(&m_nlhr, REQUEST_POST, "http://imageshack.us/upload_api.php", frm, sizeof(frm) / sizeof(HTTPFormData)); mir_free(tmp); - if(error) + if (error) return !m_bAsync; /// start upload thread - if(m_bAsync){ + if (m_bAsync) { mir_forkthread(&CSendHost_ImageShack::SendThreadWrapper, this); return 0; } @@ -68,52 +71,55 @@ int CSendHost_ImageShack::Send() { return 1; } -void CSendHost_ImageShack::SendThread() { +void CSendHost_ImageShack::SendThread() +{ /// send DATA and wait for m_nlreply - NETLIBHTTPREQUEST* reply=(NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)g_hNetlibUser, (LPARAM)&m_nlhr); + NETLIBHTTPREQUEST* reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)g_hNetlibUser, (LPARAM)&m_nlhr); HTTPFormDestroy(&m_nlhr); - if(reply){ - if(reply->resultCode>=200 && reply->resultCode<300 && reply->dataLength){ - reply->pData[reply->dataLength-1]='\0';/// make sure its null terminated - const char* url=NULL; - url=GetHTMLContent(reply->pData,"<image_link>","</image_link>"); - if(url && *url){ - mir_free(m_URL), m_URL=mir_strdup(url); - mir_free(m_URLthumb), m_URLthumb=mir_strdup(m_URL); + if (reply) { + if (reply->resultCode >= 200 && reply->resultCode < 300 && reply->dataLength) { + reply->pData[reply->dataLength - 1] = '\0';/// make sure its null terminated + const char* url = NULL; + url = GetHTMLContent(reply->pData, "<image_link>", "</image_link>"); + if (url && *url) { + mir_free(m_URL), m_URL = mir_strdup(url); + mir_free(m_URLthumb), m_URLthumb = mir_strdup(m_URL); size_t extlen; - char* pos=strrchr(m_URLthumb,'.'); - if(pos && (extlen=mir_strlen(pos))>2){ - char* tmp=mir_strdup(pos); - memcpy(pos,".th",3); - memcpy(pos+3,tmp,extlen-3); - mir_stradd(m_URLthumb,tmp+extlen-3); + char* pos = strrchr(m_URLthumb, '.'); + if (pos && (extlen = mir_strlen(pos))>2) { + char* tmp = mir_strdup(pos); + memcpy(pos, ".th", 3); + memcpy(pos + 3, tmp, extlen - 3); + mir_stradd(m_URLthumb, tmp + extlen - 3); mir_free(tmp); - }else{ - mir_freeAndNil(m_URLthumb); } - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)reply); + else mir_freeAndNil(m_URLthumb); + + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply); svcSendMsgExit(url); return; - }else{/// check error mess from server - url=GetHTMLContent(reply->pData,"<error ","</error>"); - TCHAR* err=NULL; - if(url) err=mir_a2t(url); - if (!err || !*err){/// fallback to server response mess + } + else {/// check error mess from server + url = GetHTMLContent(reply->pData, "<error ", "</error>"); + TCHAR* err = NULL; + if (url) err = mir_a2t(url); + if (!err || !*err) {/// fallback to server response mess mir_free(err); - err=mir_a2t(reply->pData); + err = mir_a2t(reply->pData); } - Error(_T("%s"),err); + Error(_T("%s"), err); mir_free(err); } - }else{ - Error(SS_ERR_RESPONSE,m_pszSendTyp,reply->resultCode); } - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)reply); - }else{ - Error(SS_ERR_NORESPONSE,m_pszSendTyp,m_nlhr.resultCode); + else Error(SS_ERR_RESPONSE, m_pszSendTyp, reply->resultCode); + + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply); } + else Error(SS_ERR_NORESPONSE, m_pszSendTyp, m_nlhr.resultCode); + Exit(ACKRESULT_FAILED); } -void CSendHost_ImageShack::SendThreadWrapper(void * Obj) { +void CSendHost_ImageShack::SendThreadWrapper(void * Obj) +{ reinterpret_cast<CSendHost_ImageShack*>(Obj)->SendThread(); } diff --git a/plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp b/plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp index 6b1b638083..d3fe40ce74 100644 --- a/plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp +++ b/plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp @@ -16,38 +16,39 @@ #include "stdafx.h" CSendHost_Imgur::CSendHost_Imgur(HWND Owner, MCONTACT hContact, bool bAsync) - : CSend(Owner,hContact,bAsync) + : CSend(Owner, hContact, bAsync) { - m_EnableItem=SS_DLG_DESCRIPTION|SS_DLG_AUTOSEND|SS_DLG_DELETEAFTERSSEND; - m_pszSendTyp=LPGENT("Image upload"); + m_EnableItem = SS_DLG_DESCRIPTION | SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND; + m_pszSendTyp = LPGENT("Image upload"); } CSendHost_Imgur::~CSendHost_Imgur() -{} +{ +} //--------------------------------------------------------------------------- int CSendHost_Imgur::Send() { - if(!g_hNetlibUser){ /// check Netlib + if (!g_hNetlibUser) { /// check Netlib Error(SS_ERR_INIT, m_pszSendTyp); Exit(ACKRESULT_FAILED); return !m_bAsync; } memset(&m_nlhr, 0, sizeof(m_nlhr)); - char* tmp; tmp=mir_t2a(m_pszFile); - HTTPFormData frm[]={ - {"Authorization",HTTPFORM_HEADER("Client-ID 2a7303d78abe041")}, - {"image",HTTPFORM_FILE(tmp)}, -// {"name",""},// filename (detected if multipart / form-data) -// {"title",""}, -// {"description",""}, + char* tmp; tmp = mir_t2a(m_pszFile); + HTTPFormData frm[] = { + { "Authorization", HTTPFORM_HEADER("Client-ID 2a7303d78abe041") }, + { "image", HTTPFORM_FILE(tmp) }, + // {"name",""},// filename (detected if multipart / form-data) + // {"title",""}, + // {"description",""}, }; - int error=HTTPFormCreate(&m_nlhr,REQUEST_POST,"https://api.imgur.com/3/image",frm,sizeof(frm)/sizeof(HTTPFormData)); + int error = HTTPFormCreate(&m_nlhr, REQUEST_POST, "https://api.imgur.com/3/image", frm, sizeof(frm) / sizeof(HTTPFormData)); mir_free(tmp); - if(error) + if (error) return !m_bAsync; /// start upload thread - if(m_bAsync){ + if (m_bAsync) { mir_forkthread(&CSendHost_Imgur::SendThread, this); return 0; } @@ -57,39 +58,37 @@ int CSendHost_Imgur::Send() void CSendHost_Imgur::SendThread(void* obj) { - CSendHost_Imgur* self=(CSendHost_Imgur*)obj; + CSendHost_Imgur* self = (CSendHost_Imgur*)obj; /// send DATA and wait for m_nlreply - NETLIBHTTPREQUEST* reply=(NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION,(WPARAM)g_hNetlibUser,(LPARAM)&self->m_nlhr); + NETLIBHTTPREQUEST* reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)g_hNetlibUser, (LPARAM)&self->m_nlhr); self->HTTPFormDestroy(&self->m_nlhr); - if(reply){ - if(reply->dataLength){ + if (reply) { + if (reply->dataLength) { char buf[128]; -// GetJSONInteger(reply->pData,reply->dataLength,"status",0) - if(GetJSONBool(reply->pData,reply->dataLength,"success")){ -// GetJSONString(reply->pData,reply->dataLength,"data[id]",buf,sizeof(buf)); - GetJSONString(reply->pData,reply->dataLength,"data[link]",buf,sizeof(buf)); -// GetJSONString(reply->pData,reply->dataLength,"[data][deletehash]",buf,sizeof(buf)); - mir_free(self->m_URL), self->m_URL=mir_strdup(buf); - char* ext=strrchr(self->m_URL,'.'); - if(ext){ - size_t thumblen=mir_strlen(self->m_URL)+2; - mir_free(self->m_URLthumb), self->m_URLthumb=(char*)mir_alloc(thumblen); - thumblen=ext-self->m_URL; - memcpy(self->m_URLthumb,self->m_URL,thumblen); - self->m_URLthumb[thumblen]='m'; // 320x320, see http://api.imgur.com/models/image - mir_strcpy(self->m_URLthumb+thumblen+1,self->m_URL+thumblen); + + if (GetJSONBool(reply->pData, reply->dataLength, "success")) { + GetJSONString(reply->pData, reply->dataLength, "data[link]", buf, sizeof(buf)); + + mir_free(self->m_URL), self->m_URL = mir_strdup(buf); + char* ext = strrchr(self->m_URL, '.'); + if (ext) { + size_t thumblen = mir_strlen(self->m_URL) + 2; + mir_free(self->m_URLthumb), self->m_URLthumb = (char*)mir_alloc(thumblen); + thumblen = ext - self->m_URL; + memcpy(self->m_URLthumb, self->m_URL, thumblen); + self->m_URLthumb[thumblen] = 'm'; // 320x320, see http://api.imgur.com/models/image + mir_strcpy(self->m_URLthumb + thumblen + 1, self->m_URL + thumblen); } - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)reply); + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply); self->svcSendMsgExit(self->m_URL); return; - }else{ - self->Error(SS_ERR_RESPONSE,self->m_pszSendTyp,GetJSONInteger(reply->pData,reply->dataLength,"status",0)); } - }else{ - self->Error(SS_ERR_RESPONSE,self->m_pszSendTyp,reply->resultCode); + else self->Error(SS_ERR_RESPONSE, self->m_pszSendTyp, GetJSONInteger(reply->pData, reply->dataLength, "status", 0)); } - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)reply); - }else{ - self->Error(SS_ERR_NORESPONSE,self->m_pszSendTyp,self->m_nlhr.resultCode); + else self->Error(SS_ERR_RESPONSE, self->m_pszSendTyp, reply->resultCode); + + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply); } + else self->Error(SS_ERR_NORESPONSE, self->m_pszSendTyp, self->m_nlhr.resultCode); + self->Exit(ACKRESULT_FAILED); } diff --git a/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp b/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp index 68aae59b29..e1c44a831a 100644 --- a/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp +++ b/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp @@ -16,30 +16,31 @@ #include "stdafx.h" CSendHost_UploadPie::CSendHost_UploadPie(HWND Owner, MCONTACT hContact, bool bAsync, int expire) - : m_expire(expire), CSend(Owner,hContact,bAsync) + : m_expire(expire), CSend(Owner, hContact, bAsync) { - m_EnableItem=SS_DLG_DESCRIPTION|SS_DLG_AUTOSEND|SS_DLG_DELETEAFTERSSEND; - m_pszSendTyp=LPGENT("Image upload"); + m_EnableItem = SS_DLG_DESCRIPTION | SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND; + m_pszSendTyp = LPGENT("Image upload"); } CSendHost_UploadPie::~CSendHost_UploadPie() -{} +{ +} //--------------------------------------------------------------------------- int CSendHost_UploadPie::Send() { - if(!g_hNetlibUser){ /// check Netlib + if (!g_hNetlibUser) { /// check Netlib Error(SS_ERR_INIT, m_pszSendTyp); Exit(ACKRESULT_FAILED); return !m_bAsync; } memset(&m_nlhr, 0, sizeof(m_nlhr)); - char* tmp; tmp=mir_t2a(m_pszFile); - HTTPFormData frm[]={ - {"MAX_FILE_SIZE",HTTPFORM_INT(3145728)},// ?? - {"upload",HTTPFORM_INT(1)},// ?? - {"uploadedfile",HTTPFORM_FILE(tmp)}, - {"expire",HTTPFORM_INT(m_expire)},// 30m + char* tmp; tmp = mir_t2a(m_pszFile); + HTTPFormData frm[] = { + { "MAX_FILE_SIZE", HTTPFORM_INT(3145728) },// ?? + { "upload", HTTPFORM_INT(1) },// ?? + { "uploadedfile", HTTPFORM_FILE(tmp) }, + { "expire", HTTPFORM_INT(m_expire) },// 30m //{"expire",HTTPFORM_INT(2,},// 1h //{"expire",HTTPFORM_INT(3)},// 6h //{"expire",HTTPFORM_INT(4)},// 1d @@ -47,12 +48,12 @@ int CSendHost_UploadPie::Send() //{"x",HTTPFORM_INT(130)},// ?? //{"y",HTTPFORM_INT(17)},// ?? }; - int error=HTTPFormCreate(&m_nlhr,REQUEST_POST,"http://uploadpie.com/",frm,sizeof(frm)/sizeof(HTTPFormData)); + int error = HTTPFormCreate(&m_nlhr, REQUEST_POST, "http://uploadpie.com/", frm, sizeof(frm) / sizeof(HTTPFormData)); mir_free(tmp); - if(error) + if (error) return !m_bAsync; /// start upload thread - if(m_bAsync){ + if (m_bAsync) { mir_forkthread(&CSendHost_UploadPie::SendThread, this); return 0; } @@ -62,45 +63,47 @@ int CSendHost_UploadPie::Send() void CSendHost_UploadPie::SendThread(void* obj) { - CSendHost_UploadPie* self=(CSendHost_UploadPie*)obj; + CSendHost_UploadPie* self = (CSendHost_UploadPie*)obj; /// send DATA and wait for m_nlreply - NETLIBHTTPREQUEST* reply=(NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION,(WPARAM)g_hNetlibUser,(LPARAM)&self->m_nlhr); + NETLIBHTTPREQUEST* reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)g_hNetlibUser, (LPARAM)&self->m_nlhr); self->HTTPFormDestroy(&self->m_nlhr); - if(reply){ - if(reply->resultCode>=200 && reply->resultCode<300 && reply->dataLength){ - reply->pData[reply->dataLength-1]='\0';/// make sure its null terminated - char* url=reply->pData; - do{ + if (reply) { + if (reply->resultCode >= 200 && reply->resultCode < 300 && reply->dataLength) { + reply->pData[reply->dataLength - 1] = '\0';/// make sure its null terminated + char* url = reply->pData; + do { char* pos; - if((url=strstr(url,"http://uploadpie.com/"))){ - for(pos=url+21; (*pos>='0'&&*pos<='9') || (*pos>='a'&&*pos<='z') || (*pos>='A'&&*pos<='Z') || *pos=='_' || *pos=='-' || *pos=='"' || *pos=='\''; ++pos){ - if(*pos=='"' || *pos=='\'') break; + if ((url = strstr(url, "http://uploadpie.com/"))) { + for (pos = url + 21; (*pos >= '0'&&*pos <= '9') || (*pos >= 'a'&&*pos <= 'z') || (*pos >= 'A'&&*pos <= 'Z') || *pos == '_' || *pos == '-' || *pos == '"' || *pos == '\''; ++pos) { + if (*pos == '"' || *pos == '\'') break; } - if(url+21!=pos && (*pos=='"' || *pos=='\'')){ - *pos='\0'; + if (url + 21 != pos && (*pos == '"' || *pos == '\'')) { + *pos = '\0'; break; } ++url; } - }while(url); - if(url){ - mir_free(self->m_URL), self->m_URL=mir_strdup(url); - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)reply); + } while (url); + + if (url) { + mir_free(self->m_URL), self->m_URL = mir_strdup(url); + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply); self->svcSendMsgExit(url); return; - }else{/// check error mess from server - const char* err=GetHTMLContent(reply->pData,"<p id=\"error\"","</p>"); + } + else {/// check error mess from server + const char* err = GetHTMLContent(reply->pData, "<p id=\"error\"", "</p>"); TCHAR* werr; - if(err) werr=mir_a2t(err); - else werr=mir_a2t(reply->pData); - self->Error(_T("%s"),werr); + if (err) werr = mir_a2t(err); + else werr = mir_a2t(reply->pData); + self->Error(_T("%s"), werr); mir_free(werr); } - }else{ - self->Error(SS_ERR_RESPONSE,self->m_pszSendTyp,reply->resultCode); } - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)reply); - }else{ - self->Error(SS_ERR_NORESPONSE,self->m_pszSendTyp,self->m_nlhr.resultCode); + else self->Error(SS_ERR_RESPONSE, self->m_pszSendTyp, reply->resultCode); + + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply); } + else self->Error(SS_ERR_NORESPONSE, self->m_pszSendTyp, self->m_nlhr.resultCode); + self->Exit(ACKRESULT_FAILED); } diff --git a/plugins/SendScreenshotPlus/src/Main.cpp b/plugins/SendScreenshotPlus/src/Main.cpp index 4474b47732..717cdfa04c 100644 --- a/plugins/SendScreenshotPlus/src/Main.cpp +++ b/plugins/SendScreenshotPlus/src/Main.cpp @@ -37,50 +37,54 @@ HANDLE g_hNetlibUser=0;//!< Netlib Register User FI_INTERFACE* FIP=NULL; int hLangpack;//Miranda NG langpack used by translate functions, filled by mir_getLP() -IconItem ICONS[ICO_END_]={ - {LPGEN("Main Icon"),"main",IDI_MAIN,32}, - {LPGEN("Main Icon"),"mainxs",IDI_MAIN}, - {LPGEN("Target Cursor"),"target",IDI_TARGET,32}, - {LPGEN("Target Desktop"),"monitor",IDI_MONITOR,32}, +IconItem ICONS[ICO_END_] = +{ + { LPGEN("Main Icon"), "main", IDI_MAIN, 32 }, + { LPGEN("Main Icon"), "mainxs", IDI_MAIN }, + { LPGEN("Target Cursor"), "target", IDI_TARGET, 32 }, + { LPGEN("Target Desktop"), "monitor", IDI_MONITOR, 32 }, }; -IconItem ICONS_BTN[ICO_BTN_END_]={ - {LPGEN("Help"),"help",IDI_HELP}, - {LPGEN("Open Folder"),"folder",IDI_FOLDER}, - {LPGEN("Description off"),"desc",IDI_DESC}, - {LPGEN("Description on"),"descon",IDI_DESCON}, - {LPGEN("Delete off"),"del",IDI_DEL}, - {LPGEN("Delete on"),"delon",IDI_DELON}, - {LPGEN("Prev"),"arrowl",IDI_ARROWL}, - {LPGEN("Next"),"arrowr",IDI_ARROWR}, - {LPGEN("Update"),"update",IDI_UPDATE}, - {LPGEN("OK"),"ok",IDI_OK}, - {LPGEN("Cancel"),"cancel",IDI_CANCEL}, -// {LPGEN("Apply"),"apply",IDI_APPLY}, - {LPGEN("Edit"),"edit",IDI_EDIT}, - {LPGEN("Edit on"),"editon",IDI_EDITON}, - {LPGEN("Copy"),"copy",IDI_COPY}, - {LPGEN("BBC"),"bbc",IDI_BBC}, - {LPGEN("BBC link"),"bbclnk",IDI_BBC2}, - {LPGEN("Down arrow"),"downarrow",IDI_DOWNARROW}, + +IconItem ICONS_BTN[ICO_BTN_END_] = +{ + { LPGEN("Help"), "help", IDI_HELP }, + { LPGEN("Open Folder"), "folder", IDI_FOLDER }, + { LPGEN("Description off"), "desc", IDI_DESC }, + { LPGEN("Description on"), "descon", IDI_DESCON }, + { LPGEN("Delete off"), "del", IDI_DEL }, + { LPGEN("Delete on"), "delon", IDI_DELON }, + { LPGEN("Prev"), "arrowl", IDI_ARROWL }, + { LPGEN("Next"), "arrowr", IDI_ARROWR }, + { LPGEN("Update"), "update", IDI_UPDATE }, + { LPGEN("OK"), "ok", IDI_OK }, + { LPGEN("Cancel"), "cancel", IDI_CANCEL }, + // {LPGEN("Apply"),"apply",IDI_APPLY}, + { LPGEN("Edit"), "edit", IDI_EDIT }, + { LPGEN("Edit on"), "editon", IDI_EDITON }, + { LPGEN("Copy"), "copy", IDI_COPY }, + { LPGEN("BBC"), "bbc", IDI_BBC }, + { LPGEN("BBC link"), "bbclnk", IDI_BBC2 }, + { LPGEN("Down arrow"), "downarrow", IDI_DOWNARROW }, }; -static HANDLE m_hFolderScreenshot=0; -TCHAR* GetCustomPath() { +static HANDLE m_hFolderScreenshot = 0; +TCHAR* GetCustomPath() +{ TCHAR* pszPath = Utils_ReplaceVarsT(_T("%miranda_userdata%\\Screenshots")); - if(m_hFolderScreenshot){ - TCHAR szPath[1024]={0}; + if (m_hFolderScreenshot) { + TCHAR szPath[1024] = { 0 }; FoldersGetCustomPathT(m_hFolderScreenshot, szPath, 1024, pszPath); mir_free(pszPath); pszPath = mir_tstrdup(szPath); } - if(!pszPath){ + if (!pszPath) { MessageBox(NULL, _T("Can not retrieve screenshot path."), _T("SendSS"), MB_OK | MB_ICONERROR | MB_APPLMODAL); return 0; } int result = CreateDirectoryTreeT(pszPath); - if(result){ + if (result) { 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); + 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("SendSS"), MB_OK | MB_ICONERROR | MB_APPLMODAL); mir_free(pszPath); return 0; @@ -88,28 +92,29 @@ TCHAR* GetCustomPath() { return pszPath; } /// services -static HANDLE m_hOpenCaptureDialog=0; -static HANDLE m_hSendDesktop=0; -static HANDLE m_hEditBitmap=0; -static HANDLE m_hSend2ImageShack=0; +static HANDLE m_hOpenCaptureDialog = 0; +static HANDLE m_hSendDesktop = 0; +static HANDLE m_hEditBitmap = 0; +static HANDLE m_hSend2ImageShack = 0; //--------------------------------------------------------------------------- // Callback function of service for contact menu and main menu // wParam = contact handle // lParam = 0 (or 0xFFFF to preselect window under cursor) -INT_PTR service_OpenCaptureDialog(WPARAM wParam, LPARAM lParam){ - TfrmMain* frmMain=new TfrmMain(); - if(!frmMain) { +INT_PTR service_OpenCaptureDialog(WPARAM wParam, LPARAM lParam) +{ + TfrmMain* frmMain = new TfrmMain(); + if (!frmMain) { MessageBox(NULL, TranslateT("Could not create main dialog."), TranslateT("Error"), MB_OK | MB_ICONERROR | MB_APPLMODAL); return -1; } - TCHAR* pszPath=GetCustomPath(); - if(!pszPath){ + TCHAR* pszPath = GetCustomPath(); + if (!pszPath) { delete frmMain; return -1; } frmMain->Init(pszPath, wParam); mir_free(pszPath); - if(lParam==0xFFFF){ + if (lParam == 0xFFFF) { frmMain->SetTargetWindow(NULL); } frmMain->Show(); @@ -123,26 +128,27 @@ INT_PTR service_OpenCaptureDialog(WPARAM wParam, LPARAM lParam){ // 2. Open the capture dialog in take screenshot only mode (it will not be sent) // wParam = 0 // lParam = anything but 0 -INT_PTR service_SendDesktop(WPARAM wParam, LPARAM lParam) { - TfrmMain* frmMain=new TfrmMain(); - if(!frmMain) { +INT_PTR service_SendDesktop(WPARAM wParam, LPARAM) +{ + TfrmMain* frmMain = new TfrmMain(); + if (!frmMain) { MessageBox(NULL, TranslateT("Could not create main dialog."), TranslateT("Error"), MB_OK | MB_ICONERROR | MB_APPLMODAL); return -1; } - TCHAR* pszPath=GetCustomPath(); - if(!pszPath){ + TCHAR* pszPath = GetCustomPath(); + if (!pszPath) { delete frmMain; return -1; } - MCONTACT hContact = (MCONTACT) wParam; + MCONTACT hContact = (MCONTACT)wParam; char* 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->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. mir_free(pszPath); frmMain->btnCaptureClick(); // this method will call Close() return 0; @@ -152,82 +158,85 @@ INT_PTR service_SendDesktop(WPARAM wParam, LPARAM lParam) { // 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) +INT_PTR service_EditBitmap(WPARAM, LPARAM) +{ + /* TfrmEdit *frmEdit=new TfrmEdit(NULL); + if (!frmEdit) return -1; - Graphics::TBitmap *bitmap=new Graphics::TBitmap(); - if (!bitmap) + 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; -*/ + 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) { +INT_PTR service_Send2ImageShack(WPARAM wParam, LPARAM lParam) +{ char* result = NULL; CSendHost_ImageShack* cSend = new CSendHost_ImageShack(NULL, lParam, false); cSend->m_bDeleteAfterSend = false; cSend->SetFile((char*)wParam); if (lParam != NULL) { - if(cSend->Send()) delete cSend; + if (cSend->Send()) delete cSend; return NULL; } cSend->SendSilent(); if (cSend->GetURL()) { - result=mir_strdup(cSend->GetURL()); - }else{ - result=mir_t2a(cSend->GetErrorMsg()); + result = mir_strdup(cSend->GetURL()); + } + else { + result = mir_t2a(cSend->GetErrorMsg()); } delete cSend; return (INT_PTR)result; } // Functions //////////////////////////////////////////////////////////////////////////// -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) { - g_hSendSS=hinstDLL; + g_hSendSS = hinstDLL; return TRUE; } -static const PLUGININFOEX pluginInfo={ +static const PLUGININFOEX pluginInfo = { sizeof(PLUGININFOEX), __PLUGIN_NAME, PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), __DESCRIPTION, - __AUTHOR,__AUTHOREMAIL, + __AUTHOR, __AUTHOREMAIL, __COPYRIGHT, __AUTHORWEB, UNICODE_AWARE, // {ED39AF7C-BECD-404E-9499-4D04F711B9CB} - {0xed39af7c, 0xbecd, 0x404e, {0x94, 0x99, 0x4d, 0x04, 0xf7, 0x11, 0xb9, 0xcb}} + { 0xed39af7c, 0xbecd, 0x404e, { 0x94, 0x99, 0x4d, 0x04, 0xf7, 0x11, 0xb9, 0xcb } } }; -DLL_EXPORT PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +DLL_EXPORT PLUGININFOEX* MirandaPluginInfoEx(DWORD) { return const_cast<PLUGININFOEX*>(&pluginInfo); } /// hooks -static HANDLE m_hookModulesLoaded=0; -static HANDLE m_hookSystemPreShutdown=0; +static HANDLE m_hookModulesLoaded = 0; +static HANDLE m_hookSystemPreShutdown = 0; int hook_ModulesLoaded(WPARAM, LPARAM) { - g_myGlobals.PopupExist = ServiceExists(MS_POPUP_ADDPOPUPT); - g_myGlobals.PopupActionsExist = ServiceExists(MS_POPUP_REGISTERACTIONS); - g_myGlobals.PluginHTTPExist = ServiceExists(MS_HTTP_ACCEPT_CONNECTIONS); - g_myGlobals.PluginFTPExist = ServiceExists(MS_FTPFILE_SHAREFILE); - g_myGlobals.PluginDropboxExist = ServiceExists(MS_DROPBOX_SEND_FILE); + g_myGlobals.PopupExist = ServiceExists(MS_POPUP_ADDPOPUPT); + g_myGlobals.PopupActionsExist = ServiceExists(MS_POPUP_REGISTERACTIONS); + g_myGlobals.PluginHTTPExist = ServiceExists(MS_HTTP_ACCEPT_CONNECTIONS); + g_myGlobals.PluginFTPExist = ServiceExists(MS_FTPFILE_SHAREFILE); + g_myGlobals.PluginDropboxExist = ServiceExists(MS_DROPBOX_SEND_FILE); // Netlib register NETLIBUSER nlu = { sizeof(nlu) }; nlu.szSettingsModule = __PLUGIN_NAME; nlu.ptszDescriptiveName = TranslateT("SendSS HTTP connections"); - nlu.flags = NUF_OUTGOING|NUF_HTTPCONNS|NUF_TCHAR; //|NUF_NOHTTPSOPTION; + nlu.flags = NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR; //|NUF_NOHTTPSOPTION; g_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu); // load my button class / or use UInfoEx CtrlButtonLoadModule(); @@ -236,7 +245,7 @@ int hook_ModulesLoaded(WPARAM, LPARAM) _T(PROFILE_PATH)_T("\\")_T(CURRENT_PROFILE)_T("\\Screenshots")); return 0; } -int hook_SystemPreShutdown(WPARAM wParam, LPARAM lParam) +int hook_SystemPreShutdown(WPARAM, LPARAM) { TfrmAbout::Unload();//crashes if done from "Unload" because of dependencies TfrmMain::Unload();// " @@ -247,38 +256,38 @@ int hook_SystemPreShutdown(WPARAM wParam, LPARAM lParam) return 0; } -ATOM g_clsTargetHighlighter=0; +ATOM g_clsTargetHighlighter = 0; DLL_EXPORT int Load(void) { mir_getLP(&pluginInfo); mir_getCLI(); - INT_PTR result=CallService(MS_IMG_GETINTERFACE,FI_IF_VERSION,(LPARAM)&FIP); - if(FIP==NULL || result!=S_OK) { + INT_PTR result = CallService(MS_IMG_GETINTERFACE, FI_IF_VERSION, (LPARAM)&FIP); + if (FIP == NULL || result != S_OK) { MessageBox(NULL, TranslateT("Image services (AdvaImg) not found.\nSendSS disabled."), TranslateT("SendSS"), MB_OK | MB_ICONERROR | MB_APPLMODAL); return 1; } /// hook events - m_hookModulesLoaded=HookEvent(ME_SYSTEM_MODULESLOADED,hook_ModulesLoaded); - m_hookSystemPreShutdown=HookEvent(ME_SYSTEM_PRESHUTDOWN,hook_SystemPreShutdown); + m_hookModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, hook_ModulesLoaded); + m_hookSystemPreShutdown = HookEvent(ME_SYSTEM_PRESHUTDOWN, hook_SystemPreShutdown); /// icons - Icon_Register(g_hSendSS,SZ_SENDSS,ICONS,sizeof(ICONS)/sizeof(IconItem),SZ_SENDSS); - Icon_Register(g_hSendSS,SZ_SENDSS "/" LPGEN("Buttons"),ICONS_BTN,sizeof(ICONS_BTN)/sizeof(IconItem),SZ_SENDSS); + Icon_Register(g_hSendSS, SZ_SENDSS, ICONS, sizeof(ICONS) / sizeof(IconItem), SZ_SENDSS); + Icon_Register(g_hSendSS, SZ_SENDSS "/" LPGEN("Buttons"), ICONS_BTN, sizeof(ICONS_BTN) / sizeof(IconItem), SZ_SENDSS); /// services - #define srv_reg(name) do{\ +#define srv_reg(name) do{\ m_h##name=CreateServiceFunction(SZ_SENDSS "/" #name, service_##name);\ if(!m_h##name) MessageBoxA(NULL,Translate("Could not register Miranda service."),SZ_SENDSS "/" #name,MB_OK|MB_ICONERROR|MB_APPLMODAL);\ - }while(0) + }while(0) srv_reg(OpenCaptureDialog); srv_reg(SendDesktop); srv_reg(EditBitmap); srv_reg(Send2ImageShack); - + // menu items CMenuItem mi; mi.flags = CMIF_TCHAR; mi.hIcolibItem = GetIconHandle(ICO_MAINXS); - + mi.name.t = LPGENT("Take a screenshot"); mi.pszService = MS_SENDSS_OPENDIALOG; mi.position = 1000001; @@ -295,19 +304,19 @@ DLL_EXPORT int Load(void) Menu_AddContactMenuItem(&mi); /// hotkey's - HOTKEYDESC hkd={sizeof(hkd)}; - hkd.pszName="Open SendSS+"; - hkd.ptszDescription=LPGENT("Open SendSS+"); - hkd.ptszSection=_T("SendSS+"); - hkd.pszService=MS_SENDSS_OPENDIALOG; + HOTKEYDESC hkd = { sizeof(hkd) }; + hkd.pszName = "Open SendSS+"; + hkd.ptszDescription = LPGENT("Open SendSS+"); + hkd.ptszSection = _T("SendSS+"); + hkd.pszService = MS_SENDSS_OPENDIALOG; //hkd.DefHotKey=HOTKEYCODE(HOTKEYF_CONTROL, VK_F10) | HKF_MIRANDA_LOCAL; - hkd.lParam=0xFFFF; + hkd.lParam = 0xFFFF; hkd.dwFlags = HKD_TCHAR; Hotkey_Register(&hkd); /// register highlighter window class - HBRUSH brush=CreateSolidBrush(0x0000FF00);//owned by class - WNDCLASS wndclass={CS_HREDRAW|CS_VREDRAW,DefWindowProc,0,0,g_hSendSS,NULL,NULL,brush,NULL,L"SendSSHighlighter"}; - g_clsTargetHighlighter=RegisterClass(&wndclass); + HBRUSH brush = CreateSolidBrush(0x0000FF00);//owned by class + WNDCLASS wndclass = { CS_HREDRAW | CS_VREDRAW, DefWindowProc, 0, 0, g_hSendSS, NULL, NULL, brush, NULL, L"SendSSHighlighter" }; + g_clsTargetHighlighter = RegisterClass(&wndclass); return 0; } /*--------------------------------------------------------------------------- @@ -316,15 +325,15 @@ DLL_EXPORT int Load(void) */ DLL_EXPORT int Unload(void) {//as "ghazan" says, it's useless to unregister services or unhook events, let's still do it for now :P - CallService(MS_HOTKEY_UNREGISTER,0,(LPARAM)"Open SendSS+"); + CallService(MS_HOTKEY_UNREGISTER, 0, (LPARAM)"Open SendSS+"); /// deregister services - #define srv_dereg(name) do{ if(m_h##name) DestroyServiceFunction(m_h##name),m_h##name=0; }while(0) +#define srv_dereg(name) do{ if(m_h##name) DestroyServiceFunction(m_h##name),m_h##name=0; }while(0) srv_dereg(OpenCaptureDialog); srv_dereg(SendDesktop); srv_dereg(EditBitmap); srv_dereg(Send2ImageShack); - if(m_hookModulesLoaded) UnhookEvent(m_hookModulesLoaded),m_hookModulesLoaded=0; - if(m_hookSystemPreShutdown) UnhookEvent(m_hookSystemPreShutdown),m_hookSystemPreShutdown=0; - if(g_clsTargetHighlighter) UnregisterClass((TCHAR*)g_clsTargetHighlighter,g_hSendSS),g_clsTargetHighlighter=0; + if (m_hookModulesLoaded) UnhookEvent(m_hookModulesLoaded), m_hookModulesLoaded = 0; + if (m_hookSystemPreShutdown) UnhookEvent(m_hookSystemPreShutdown), m_hookSystemPreShutdown = 0; + if (g_clsTargetHighlighter) UnregisterClass((TCHAR*)g_clsTargetHighlighter, g_hSendSS), g_clsTargetHighlighter = 0; return 0; } diff --git a/plugins/SendScreenshotPlus/src/UAboutForm.cpp b/plugins/SendScreenshotPlus/src/UAboutForm.cpp index f3b50a740d..d21b8deaeb 100644 --- a/plugins/SendScreenshotPlus/src/UAboutForm.cpp +++ b/plugins/SendScreenshotPlus/src/UAboutForm.cpp @@ -29,12 +29,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" #include <list> -void TfrmAbout::Unload(){ +void TfrmAbout::Unload() +{ std::list<TfrmAbout*> lst; - for(CHandleMapping::iterator iter=_HandleMapping.begin(); iter!=_HandleMapping.end(); ++iter){ + 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()){ + while (!lst.empty()) { DestroyWindow(lst.front()->m_hWnd);//deletes class lst.pop_front(); } @@ -46,13 +47,13 @@ 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_CREDIT: - case IDC_LICENSE: - SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT)); - break; - default: - return FALSE; + switch (GetWindowLongPtr((HWND)lParam, GWL_ID)) { + case IDC_CREDIT: + case IDC_LICENSE: + SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT)); + break; + default: + return FALSE; } return (INT_PTR)GetStockObject(WHITE_BRUSH); //GetSysColorBrush(COLOR_WINDOW); } @@ -63,30 +64,30 @@ INT_PTR CALLBACK TfrmAbout::DlgTfrmAbout(HWND hWnd, UINT msg, WPARAM wParam, LPA reinterpret_cast<TfrmAbout*>(lParam)->m_hWnd = hWnd; return wnd->second->wmInitdialog(wParam, lParam); } - wnd=_HandleMapping.find(hWnd); - if (wnd==_HandleMapping.end()) { // something screwed up + wnd = _HandleMapping.find(hWnd); + if (wnd == _HandleMapping.end()) { // something screwed up return FALSE; //dialog! do not use ::DefWindowProc(hWnd, msg, wParam, lParam); } - switch (msg) - { + 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 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) { +LRESULT TfrmAbout::wmInitdialog(WPARAM, LPARAM) +{ // Headerbar SendDlgItemMessage(m_hWnd, IDC_HEADERBAR, WM_SETICON, ICON_BIG, (LPARAM)GetIcon(ICO_MAIN)); @@ -96,34 +97,34 @@ LRESULT TfrmAbout::wmInitdialog(WPARAM wParam, LPARAM lParam) { mir_tstradd(pszText, _T(__COPYRIGHT)); mir_tstradd(pszText, _T("\r\n\r\n")); - HRSRC hRes = FindResource(g_hSendSS,MAKEINTRESOURCE(IDR_LICENSE),_T("TEXT")); - DWORD size = SizeofResource(g_hSendSS,hRes); - char* data = (char*)mir_alloc(size+1); - memcpy(data,LockResource(LoadResource(g_hSendSS,hRes)),size); + HRSRC hRes = FindResource(g_hSendSS, MAKEINTRESOURCE(IDR_LICENSE), _T("TEXT")); + DWORD size = SizeofResource(g_hSendSS, hRes); + char* data = (char*)mir_alloc(size + 1); + memcpy(data, LockResource(LoadResource(g_hSendSS, hRes)), size); data[size] = '\0'; TCHAR* pszCopyright = mir_a2t(data); mir_free(data); mir_tstradd(pszText, pszCopyright); mir_free(pszCopyright); - SetDlgItemText(m_hWnd,IDC_LICENSE, pszText); + SetDlgItemText(m_hWnd, IDC_LICENSE, pszText); mir_free(pszText); } //Credit { - HRSRC hRes = FindResource(g_hSendSS,MAKEINTRESOURCE(IDR_CREDIT),_T("TEXT")); - DWORD size = SizeofResource(g_hSendSS,hRes); - char* data = (char*)mir_alloc(size+1); - memcpy(data,LockResource(LoadResource(g_hSendSS,hRes)),size); + HRSRC hRes = FindResource(g_hSendSS, MAKEINTRESOURCE(IDR_CREDIT), _T("TEXT")); + DWORD size = SizeofResource(g_hSendSS, hRes); + char* data = (char*)mir_alloc(size + 1); + memcpy(data, LockResource(LoadResource(g_hSendSS, hRes)), size); data[size] = '\0'; TCHAR* pszText = mir_a2t(data); mir_free(data); - SetDlgItemText(m_hWnd,IDC_CREDIT, pszText); + SetDlgItemText(m_hWnd, IDC_CREDIT, pszText); mir_free(pszText); } - SendMessage(m_hWnd, WM_SETICON, ICON_BIG, (LPARAM)GetIcon(ICO_MAIN)); - SendMessage(m_hWnd, WM_SETICON, ICON_SMALL, (LPARAM)GetIcon(ICO_MAINXS)); + SendMessage(m_hWnd, WM_SETICON, ICON_BIG, (LPARAM)GetIcon(ICO_MAIN)); + SendMessage(m_hWnd, WM_SETICON, ICON_SMALL, (LPARAM)GetIcon(ICO_MAINXS)); //init controls btnPageClick(); @@ -133,75 +134,81 @@ LRESULT TfrmAbout::wmInitdialog(WPARAM wParam, LPARAM lParam) { } //WM_COMMAND: -LRESULT TfrmAbout::wmCommand(WPARAM wParam, LPARAM lParam) { +LRESULT TfrmAbout::wmCommand(WPARAM wParam, LPARAM) +{ //--------------------------------------------------------------------------- if (HIWORD(wParam) == BN_CLICKED) { - switch(LOWORD(wParam)) { - case IDCANCEL: // ESC pressed - this->Close(); - break; - case IDA_btnClose: - Close(); - break; - case IDA_CONTRIBLINK: - m_Page = !m_Page; - btnPageClick(); - break; - default: - break; + switch (LOWORD(wParam)) { + case IDCANCEL: // ESC pressed + this->Close(); + break; + case IDA_btnClose: + Close(); + break; + case IDA_CONTRIBLINK: + m_Page = !m_Page; + 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); +LRESULT TfrmAbout::wmClose(WPARAM, LPARAM) +{ + SendMessage(m_hWndOwner, UM_CLOSING, (WPARAM)m_hWnd, (LPARAM)IDD_UAboutForm); DestroyWindow(m_hWnd); return FALSE; } //--------------------------------------------------------------------------- -TfrmAbout::TfrmAbout(HWND Owner) { +TfrmAbout::TfrmAbout(HWND Owner) +{ m_hWndOwner = Owner; m_Page = 1; // create window - m_hWnd = CreateDialogParam(g_hSendSS, MAKEINTRESOURCE(IDD_UAboutForm),0, DlgTfrmAbout,(LPARAM)this); + m_hWnd = CreateDialogParam(g_hSendSS, MAKEINTRESOURCE(IDD_UAboutForm), 0, DlgTfrmAbout, (LPARAM)this); //register object _HandleMapping.insert(CHandleMapping::value_type(m_hWnd, this)); } -TfrmAbout::~TfrmAbout() { +TfrmAbout::~TfrmAbout() +{ _HandleMapping.erase(m_hWnd); } //--------------------------------------------------------------------------- -void TfrmAbout::btnPageClick() { +void TfrmAbout::btnPageClick() +{ HWND hCtrl = GetDlgItem(m_hWnd, IDA_CONTRIBLINK); - const TCHAR* credits=TranslateT("Credits"); - const TCHAR* copyright=TranslateT("Copyright"); + const TCHAR* credits = TranslateT("Credits"); + const TCHAR* copyright = TranslateT("Copyright"); const TCHAR* title; const TCHAR* button; - if(!m_Page) { + if (!m_Page) { ShowWindow(GetDlgItem(m_hWnd, IDC_CREDIT), SW_HIDE); ShowWindow(GetDlgItem(m_hWnd, IDC_LICENSE), SW_SHOW); SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetIconBtn(ICO_BTN_ARROWR)); - title=copyright; - button=credits; - } else { + title = copyright; + button = credits; + } + else { ShowWindow(GetDlgItem(m_hWnd, IDC_CREDIT), SW_SHOW); ShowWindow(GetDlgItem(m_hWnd, IDC_LICENSE), SW_HIDE); SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetIconBtn(ICO_BTN_ARROWL)); - title=credits; - button=copyright; + title = credits; + button = copyright; } SetWindowText(hCtrl, button); TCHAR newTitle[128]; TCHAR* pszPlug = mir_a2t(__PLUGIN_NAME); - TCHAR* pszVer = mir_a2t(__VERSION_STRING_DOTS); - mir_sntprintf(newTitle,_countof(newTitle), _T("%s - %s\nv%s"), pszPlug, title , pszVer); + TCHAR* pszVer = mir_a2t(__VERSION_STRING_DOTS); + mir_sntprintf(newTitle, _countof(newTitle), _T("%s - %s\nv%s"), pszPlug, title, pszVer); mir_free(pszPlug); mir_free(pszVer); SetDlgItemText(m_hWnd, IDC_HEADERBAR, newTitle); - InvalidateRect(GetDlgItem(m_hWnd,IDC_HEADERBAR),NULL,1); + InvalidateRect(GetDlgItem(m_hWnd, IDC_HEADERBAR), NULL, 1); } diff --git a/plugins/SendScreenshotPlus/src/UMainForm.cpp b/plugins/SendScreenshotPlus/src/UMainForm.cpp index c887f14c12..06f8d641ba 100644 --- a/plugins/SendScreenshotPlus/src/UMainForm.cpp +++ b/plugins/SendScreenshotPlus/src/UMainForm.cpp @@ -29,23 +29,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" #include <list> -void TfrmMain::Unload(){ +void TfrmMain::Unload() +{ std::list<TfrmMain*> lst; - for(CHandleMapping::iterator iter=_HandleMapping.begin(); iter!=_HandleMapping.end(); ++iter){ + 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()){ + while (!lst.empty()) { DestroyWindow(lst.front()->m_hWnd);//deletes class lst.pop_front(); } } //--------------------------------------------------------------------------- -INT_PTR CALLBACK TfrmMain::DlgProc_CaptureTabPage(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { -// main message handling is done inside TfrmMain::DlgTfrmMain +INT_PTR CALLBACK TfrmMain::DlgProc_CaptureTabPage(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + // main message handling is done inside TfrmMain::DlgTfrmMain switch (uMsg) { case WM_INITDIALOG: - switch(lParam){ + switch (lParam) { case IDD_UMain_CaptureWindow: Static_SetIcon(GetDlgItem(hDlg, ID_imgTarget), GetIcon(ICO_TARGET)); SetDlgItemText(hDlg, ID_edtCaption, TranslateT("Drag&Drop the target on the desired window.")); @@ -62,23 +64,23 @@ INT_PTR CALLBACK TfrmMain::DlgProc_CaptureTabPage(HWND hDlg, UINT uMsg, WPARAM w case WM_CTLCOLORDLG: case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: - SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT)); + SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT)); return (INT_PTR)GetStockObject(WHITE_BRUSH); case WM_COMMAND: - if(HIWORD(wParam)==BN_CLICKED && LOWORD(wParam)==ID_btnExplore){ /// local file tab - OPENFILENAME ofn={sizeof(OPENFILENAME)}; + if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == ID_btnExplore) { /// local file tab + OPENFILENAME ofn = { sizeof(OPENFILENAME) }; TCHAR filename[MAX_PATH]; - GetDlgItemText(hDlg,ID_edtSize,filename,_countof(filename)); + GetDlgItemText(hDlg, ID_edtSize, filename, _countof(filename)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hDlg; ofn.lpstrFilter = _T("Images\0*.png;*.jpg;*.jpeg;*.bmp;*.gif;*.tif;*.tiff\0"); ofn.nFilterIndex = 1; ofn.lpstrFile = filename; ofn.nMaxFile = MAX_PATH; -// ofn.lpstrInitialDir = m_FDestFolder; + // ofn.lpstrInitialDir = m_FDestFolder; ofn.Flags = OFN_FILEMUSTEXIST | OFN_READONLY; - if(GetOpenFileName(&ofn)){ - SetDlgItemText(hDlg,ID_edtSize,filename); + if (GetOpenFileName(&ofn)) { + SetDlgItemText(hDlg, ID_edtSize, filename); } break; } @@ -100,72 +102,73 @@ TfrmMain::CHandleMapping TfrmMain::_HandleMapping; INT_PTR 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_HEADERBAR: - SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT)); - break; - default: - return 0; + switch (GetWindowLongPtr((HWND)lParam, GWL_ID)) { + case IDC_HEADERBAR: + SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT)); + break; + default: + return 0; } SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); return (INT_PTR)GetStockObject(WHITE_BRUSH); //GetSysColorBrush(COLOR_WINDOW); } CHandleMapping::iterator wnd; - if(msg==WM_INITDIALOG) { + if (msg == WM_INITDIALOG) { wnd = _HandleMapping.insert(CHandleMapping::value_type(hWnd, reinterpret_cast<TfrmMain*>(lParam))).first; wnd->second->m_hWnd = hWnd; wnd->second->wmInitdialog(wParam, lParam); return 0; } - wnd=_HandleMapping.find(hWnd); - if(wnd==_HandleMapping.end()) { //something screwed up dialog! + wnd = _HandleMapping.find(hWnd); + if (wnd == _HandleMapping.end()) { //something screwed up dialog! return 0; //do not use ::DefWindowProc(hWnd, msg, wParam, lParam); } - switch (msg){ - case WM_DROPFILES:{ /// Drag&Drop of local files + switch (msg) { + case WM_DROPFILES:{ /// Drag&Drop of local files TCHAR filename[MAX_PATH]; - if(!DragQueryFile((HDROP)wParam,0,filename,MAX_PATH)) *filename='\0'; + if (!DragQueryFile((HDROP)wParam, 0, filename, MAX_PATH)) *filename = '\0'; DragFinish((HDROP)wParam); - if(wnd->second->m_hwndTabPage) - ShowWindow(wnd->second->m_hwndTabPage,SW_HIDE); - TAB_INFO itab={TCIF_PARAM}; - wnd->second->m_opt_tabCapture=2; // activate file tab - TabCtrl_SetCurSel(wnd->second->m_hwndTab,wnd->second->m_opt_tabCapture); - TabCtrl_GetItem(wnd->second->m_hwndTab,wnd->second->m_opt_tabCapture,&itab); - wnd->second->m_hwndTabPage=itab.hwndTabPage; - ShowWindow(wnd->second->m_hwndTabPage,SW_SHOW); - SetDlgItemText(wnd->second->m_hwndTabPage,ID_edtSize,filename); - break;} - case WM_COMMAND: - wnd->second->wmCommand(wParam, lParam); - break; - case WM_CLOSE: - wnd->second->wmClose(wParam, lParam); - break; - case WM_DESTROY: - delete wnd->second; - break; - case WM_NOTIFY: - wnd->second->wmNotify(wParam, lParam); - break; - case WM_TIMER: - wnd->second->wmTimer(wParam, lParam); - break; - case UM_CLOSING: - wnd->second->UMClosing(wParam, lParam); - break; - case UM_EVENT: - wnd->second->UMevent(wParam, lParam); - break; + if (wnd->second->m_hwndTabPage) + ShowWindow(wnd->second->m_hwndTabPage, SW_HIDE); + TAB_INFO itab = { TCIF_PARAM }; + wnd->second->m_opt_tabCapture = 2; // activate file tab + TabCtrl_SetCurSel(wnd->second->m_hwndTab, wnd->second->m_opt_tabCapture); + TabCtrl_GetItem(wnd->second->m_hwndTab, wnd->second->m_opt_tabCapture, &itab); + wnd->second->m_hwndTabPage = itab.hwndTabPage; + ShowWindow(wnd->second->m_hwndTabPage, SW_SHOW); + SetDlgItemText(wnd->second->m_hwndTabPage, ID_edtSize, filename); + break; } + case WM_COMMAND: + wnd->second->wmCommand(wParam, lParam); + break; + case WM_CLOSE: + wnd->second->wmClose(wParam, lParam); + break; + case WM_DESTROY: + delete wnd->second; + break; + case WM_NOTIFY: + wnd->second->wmNotify(wParam, lParam); + break; + case WM_TIMER: + wnd->second->wmTimer(wParam, lParam); + break; + case UM_CLOSING: + wnd->second->UMClosing(wParam, lParam); + break; + case UM_EVENT: + wnd->second->UMevent(wParam, lParam); + break; } return 0; } //--------------------------------------------------------------------------- //WM_INITDIALOG: -void TfrmMain::wmInitdialog(WPARAM wParam, LPARAM lParam) { +void TfrmMain::wmInitdialog(WPARAM, LPARAM) +{ HWND hCtrl; /// Taskbar and Window icon SendMessage(m_hWnd, WM_SETICON, ICON_BIG, (LPARAM)GetIcon(ICO_MAIN)); @@ -182,13 +185,13 @@ void TfrmMain::wmInitdialog(WPARAM wParam, LPARAM lParam) { SendDlgItemMessage(m_hWnd, IDC_HEADERBAR, WM_SETICON, ICON_BIG, (LPARAM)GetIcon(ICO_MAIN)); /// 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)); + 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){ + if (!m_himlTab) { //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, 0, 1); ImageList_AddIcon(m_himlTab, GetIcon(ICO_TARGET)); @@ -198,123 +201,127 @@ void TfrmMain::wmInitdialog(WPARAM wParam, LPARAM lParam) { /// create the tab control. { - m_hwndTab = GetDlgItem(m_hWnd, IDC_CAPTURETAB); - TabCtrl_SetImageList(m_hwndTab, m_himlTab); - TabCtrl_SetItemExtra(m_hwndTab, sizeof(TAB_INFO) - sizeof(TCITEMHEADER)); - RECT rcTab; - TAB_INFO itab; - itab.hwndMain = m_hWnd; - itab.hwndTab = m_hwndTab; - itab.tcih.mask = TCIF_PARAM|TCIF_TEXT|TCIF_IMAGE; - - /// Add a tab for each of the three child dialog boxes. - itab.tcih.pszText = TranslateT("Window"); - itab.tcih.iImage = 0; - itab.hwndTabPage = CreateDialogParam(g_hSendSS,MAKEINTRESOURCE(IDD_UMain_CaptureWindow),m_hWnd,DlgProc_CaptureTabPage,IDD_UMain_CaptureWindow); - TabCtrl_InsertItem(m_hwndTab,0,&itab); - /// get tab boundaries (required after 1st tab) - GetClientRect(m_hwndTab,&rcTab); - MapWindowPoints(m_hwndTab,m_hWnd,(POINT*)&rcTab,2); - TabCtrl_AdjustRect(m_hwndTab,0,&rcTab); - rcTab.bottom-=rcTab.top; rcTab.right-=rcTab.left; - /// - SetWindowPos(itab.hwndTabPage,HWND_TOP,rcTab.left,rcTab.top,rcTab.right,rcTab.bottom,0); - CheckDlgButton(itab.hwndTabPage, ID_chkIndirectCapture, m_opt_chkIndirectCapture ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(itab.hwndTabPage, ID_chkClientArea, m_opt_chkClientArea ? BST_CHECKED : BST_UNCHECKED); - - itab.tcih.pszText = TranslateT("Desktop"); - itab.tcih.iImage = 1; - itab.hwndTabPage = CreateDialogParam(g_hSendSS,MAKEINTRESOURCE(IDD_UMain_CaptureDesktop),m_hWnd,DlgProc_CaptureTabPage,IDD_UMain_CaptureDesktop); - TabCtrl_InsertItem(m_hwndTab,1,&itab); - SetWindowPos(itab.hwndTabPage,HWND_TOP,rcTab.left,rcTab.top,rcTab.right,rcTab.bottom,0); - - 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 mon=0; mon<m_MonitorCount; ++mon) { /// @todo : fix format for non MSVC compilers - mir_sntprintf(tszTemp, _countof(tszTemp),_T("%Iu. %s%s"), - mon+1, TranslateT("Monitor"), - (m_Monitors[mon].dwFlags & MONITORINFOF_PRIMARY) ? TranslateT(" (primary)") : _T("") - ); - ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, tszTemp) , mon+1); + m_hwndTab = GetDlgItem(m_hWnd, IDC_CAPTURETAB); + TabCtrl_SetImageList(m_hwndTab, m_himlTab); + TabCtrl_SetItemExtra(m_hwndTab, sizeof(TAB_INFO) - sizeof(TCITEMHEADER)); + RECT rcTab; + TAB_INFO itab; + itab.hwndMain = m_hWnd; + itab.hwndTab = m_hwndTab; + itab.tcih.mask = TCIF_PARAM | TCIF_TEXT | TCIF_IMAGE; + + /// Add a tab for each of the three child dialog boxes. + itab.tcih.pszText = TranslateT("Window"); + itab.tcih.iImage = 0; + itab.hwndTabPage = CreateDialogParam(g_hSendSS, MAKEINTRESOURCE(IDD_UMain_CaptureWindow), m_hWnd, DlgProc_CaptureTabPage, IDD_UMain_CaptureWindow); + TabCtrl_InsertItem(m_hwndTab, 0, &itab); + /// get tab boundaries (required after 1st tab) + GetClientRect(m_hwndTab, &rcTab); + MapWindowPoints(m_hwndTab, m_hWnd, (POINT*)&rcTab, 2); + TabCtrl_AdjustRect(m_hwndTab, 0, &rcTab); + rcTab.bottom -= rcTab.top; rcTab.right -= rcTab.left; + /// + SetWindowPos(itab.hwndTabPage, HWND_TOP, rcTab.left, rcTab.top, rcTab.right, rcTab.bottom, 0); + CheckDlgButton(itab.hwndTabPage, ID_chkIndirectCapture, m_opt_chkIndirectCapture ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(itab.hwndTabPage, ID_chkClientArea, m_opt_chkClientArea ? BST_CHECKED : BST_UNCHECKED); + + itab.tcih.pszText = TranslateT("Desktop"); + itab.tcih.iImage = 1; + itab.hwndTabPage = CreateDialogParam(g_hSendSS, MAKEINTRESOURCE(IDD_UMain_CaptureDesktop), m_hWnd, DlgProc_CaptureTabPage, IDD_UMain_CaptureDesktop); + TabCtrl_InsertItem(m_hwndTab, 1, &itab); + SetWindowPos(itab.hwndTabPage, HWND_TOP, rcTab.left, rcTab.top, rcTab.right, rcTab.bottom, 0); + + 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 mon = 0; mon < m_MonitorCount; ++mon) { /// @todo : fix format for non MSVC compilers + mir_sntprintf(tszTemp, _countof(tszTemp), _T("%Iu. %s%s"), + mon + 1, TranslateT("Monitor"), + (m_Monitors[mon].dwFlags & MONITORINFOF_PRIMARY) ? TranslateT(" (primary)") : _T("") + ); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, tszTemp), mon + 1); + } + ComboBox_SelectItemData(hCtrl, m_opt_cboxDesktop); //use Workaround for MS bug ComboBox_SelectItemData } - 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); - - itab.tcih.pszText = TranslateT("File"); - itab.tcih.iImage = 2; - itab.hwndTabPage = CreateDialogParam(g_hSendSS,MAKEINTRESOURCE(IDD_UMain_CaptureFile),m_hWnd,DlgProc_CaptureTabPage,IDD_UMain_CaptureFile); - TabCtrl_InsertItem(m_hwndTab,2,&itab); - SetWindowPos(itab.hwndTabPage,HWND_TOP,rcTab.left,rcTab.top,rcTab.right,rcTab.bottom,0); - - /// select tab and set m_hwndTabPage - TabCtrl_SetCurSel(m_hwndTab, m_opt_tabCapture); - itab.tcih.mask = TCIF_PARAM; - TabCtrl_GetItem(m_hwndTab,m_opt_tabCapture,&itab); - m_hwndTabPage = itab.hwndTabPage; - ShowWindow(m_hwndTabPage,SW_SHOW); - - /// enable Drag&Drop for local file pane - typedef BOOL (WINAPI *ChangeWindowMessageFilterEx_t)(HWND hwnd,UINT message,DWORD action,PCHANGEFILTERSTRUCT pChangeFilterStruct); - ChangeWindowMessageFilterEx_t pChangeWindowMessageFilterEx; - pChangeWindowMessageFilterEx=(ChangeWindowMessageFilterEx_t)GetProcAddress(GetModuleHandleA("user32"),"ChangeWindowMessageFilterEx"); - if(pChangeWindowMessageFilterEx){ /// Win7+, UAC fix - pChangeWindowMessageFilterEx(m_hWnd,WM_DROPFILES,MSGFLT_ALLOW,NULL); - pChangeWindowMessageFilterEx(m_hWnd,WM_COPYDATA,MSGFLT_ALLOW,NULL); - pChangeWindowMessageFilterEx(m_hWnd,0x0049/*WM_COPYGLOBALDATA*/,MSGFLT_ALLOW,NULL); - } - DragAcceptFiles(m_hWnd,1); + PostMessage(m_hWnd, WM_COMMAND, MAKEWPARAM(ID_edtCaption, CBN_SELCHANGE), (LPARAM)hCtrl); + + itab.tcih.pszText = TranslateT("File"); + itab.tcih.iImage = 2; + itab.hwndTabPage = CreateDialogParam(g_hSendSS, MAKEINTRESOURCE(IDD_UMain_CaptureFile), m_hWnd, DlgProc_CaptureTabPage, IDD_UMain_CaptureFile); + TabCtrl_InsertItem(m_hwndTab, 2, &itab); + SetWindowPos(itab.hwndTabPage, HWND_TOP, rcTab.left, rcTab.top, rcTab.right, rcTab.bottom, 0); + + /// select tab and set m_hwndTabPage + TabCtrl_SetCurSel(m_hwndTab, m_opt_tabCapture); + itab.tcih.mask = TCIF_PARAM; + TabCtrl_GetItem(m_hwndTab, m_opt_tabCapture, &itab); + m_hwndTabPage = itab.hwndTabPage; + ShowWindow(m_hwndTabPage, SW_SHOW); + + /// enable Drag&Drop for local file pane + typedef BOOL(WINAPI *ChangeWindowMessageFilterEx_t)(HWND hwnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct); + ChangeWindowMessageFilterEx_t pChangeWindowMessageFilterEx; + pChangeWindowMessageFilterEx = (ChangeWindowMessageFilterEx_t)GetProcAddress(GetModuleHandleA("user32"), "ChangeWindowMessageFilterEx"); + if (pChangeWindowMessageFilterEx) { /// Win7+, UAC fix + pChangeWindowMessageFilterEx(m_hWnd, WM_DROPFILES, MSGFLT_ALLOW, NULL); + pChangeWindowMessageFilterEx(m_hWnd, WM_COPYDATA, MSGFLT_ALLOW, NULL); + pChangeWindowMessageFilterEx(m_hWnd, 0x0049/*WM_COPYGLOBALDATA*/, MSGFLT_ALLOW, NULL); + } + DragAcceptFiles(m_hWnd, 1); } /// 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 + 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, 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); - ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("E-mail")) ,SS_EMAIL); - if (g_myGlobals.PluginHTTPExist) { - ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("HTTP Server")) ,SS_HTTPSERVER); - }else if(m_opt_cboxSendBy == SS_HTTPSERVER) { + 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); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("E-mail")), SS_EMAIL); + if (g_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 (g_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; + } + } + else if (m_opt_cboxSendBy == SS_FILESEND || m_opt_cboxSendBy == SS_EMAIL || m_opt_cboxSendBy == SS_HTTPSERVER || m_opt_cboxSendBy == SS_FTPFILE) { m_opt_cboxSendBy = SS_IMAGESHACK; } - if (g_myGlobals.PluginFTPExist) { - ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("FTP File")) ,SS_FTPFILE); - }else if(m_opt_cboxSendBy == SS_FTPFILE) { + if (g_myGlobals.PluginDropboxExist) { + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("Dropbox")), SS_DROPBOX); + } + else if (m_opt_cboxSendBy == SS_DROPBOX) { m_opt_cboxSendBy = SS_IMAGESHACK; } - }else if(m_opt_cboxSendBy == SS_FILESEND || m_opt_cboxSendBy == SS_EMAIL || m_opt_cboxSendBy == SS_HTTPSERVER || m_opt_cboxSendBy == SS_FTPFILE) { - m_opt_cboxSendBy = SS_IMAGESHACK; - } - if (g_myGlobals.PluginDropboxExist) { - ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("Dropbox")), SS_DROPBOX); - }else if(m_opt_cboxSendBy == SS_DROPBOX) { - m_opt_cboxSendBy = SS_IMAGESHACK; - } - ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("ImageShack")), SS_IMAGESHACK); - ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Upload Pie (30m)")), SS_UPLOADPIE_30M); - ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Upload Pie (1d)")), SS_UPLOADPIE_1D); - ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Upload Pie (1w)")), SS_UPLOADPIE_1W); - ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("imgur")), SS_IMGUR); - ComboBox_SelectItemData (hCtrl, -1, m_opt_cboxSendBy); //use Workaround for MS bug ComboBox_SelectItemData + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("ImageShack")), SS_IMAGESHACK); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Upload Pie (30m)")), SS_UPLOADPIE_30M); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Upload Pie (1d)")), SS_UPLOADPIE_1D); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Upload Pie (1w)")), SS_UPLOADPIE_1W); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("imgur")), SS_IMGUR); + ComboBox_SelectItemData(hCtrl, m_opt_cboxSendBy); //use Workaround for MS bug ComboBox_SelectItemData } /// init footer options - CheckDlgButton(m_hWnd,ID_chkOpenAgain, m_opt_chkOpenAgain ? BST_CHECKED : BST_UNCHECKED); + 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); @@ -367,328 +374,342 @@ void TfrmMain::wmInitdialog(WPARAM wParam, LPARAM lParam) { } //WM_COMMAND: -void TfrmMain::wmCommand(WPARAM wParam, LPARAM lParam) { +void TfrmMain::wmCommand(WPARAM wParam, LPARAM lParam) +{ //--------------------------------------------------------------------------- int IDControl = LOWORD(wParam); switch (HIWORD(wParam)) { - case BN_CLICKED: //Button controls - switch(IDControl) { - case IDCANCEL: // ESC pressed - this->Close(); - break; - case ID_chkTimed: - m_opt_chkTimed = (BYTE)Button_GetCheck((HWND)lParam); - TfrmMain::chkTimedClick(); - break; - case ID_chkIndirectCapture: - m_opt_chkIndirectCapture = (BYTE)Button_GetCheck((HWND)lParam); - 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_imgTarget: - if(m_opt_tabCapture!=0) break; - m_hLastWin=NULL; - SetTimer(m_hWnd,ID_imgTarget,BUTTON_POLLDELAY,NULL); - break; - case ID_btnAbout: - TfrmMain::btnAboutClick(); - break; - case ID_btnExplore: - TfrmMain::btnExploreClick(); - break; - case ID_chkDesc:{ - m_opt_btnDesc=!m_opt_btnDesc; - HICON hIcon=GetIconBtn(m_opt_btnDesc?ICO_BTN_DESCON:ICO_BTN_DESC); - SendMessage((HWND)lParam,BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcon); - break;} - case ID_chkDeleteAfterSend:{ - m_opt_btnDeleteAfterSend=!m_opt_btnDeleteAfterSend; - HICON hIcon=GetIconBtn(m_opt_btnDeleteAfterSend?ICO_BTN_DELON:ICO_BTN_DEL); - SendMessage((HWND)lParam,BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcon); - if(m_cSend) m_cSend->m_bDeleteAfterSend=m_opt_btnDeleteAfterSend; - break;} - case ID_chkEditor:{ - m_opt_chkEditor=!m_opt_chkEditor; - HICON hIcon=GetIconBtn(m_opt_chkEditor?ICO_BTN_EDITON:ICO_BTN_EDIT); - SendMessage((HWND)lParam,BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcon); - break;} - case ID_chkOpenAgain: - m_opt_chkOpenAgain=Button_GetCheck((HWND)lParam); - break; - case ID_btnCapture: - TfrmMain::btnCaptureClick(); - break; - default: - break; - } + case BN_CLICKED: //Button controls + switch (IDControl) { + case IDCANCEL: // ESC pressed + this->Close(); 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 = NULL; - 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; - } + case ID_chkTimed: + m_opt_chkTimed = (BYTE)Button_GetCheck((HWND)lParam); + TfrmMain::chkTimedClick(); + break; + case ID_chkIndirectCapture: + m_opt_chkIndirectCapture = (BYTE)Button_GetCheck((HWND)lParam); + 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_imgTarget: + if (m_opt_tabCapture != 0) break; + m_hLastWin = NULL; + SetTimer(m_hWnd, ID_imgTarget, BUTTON_POLLDELAY, NULL); + break; + case ID_btnAbout: + TfrmMain::btnAboutClick(); + break; + case ID_btnExplore: + TfrmMain::btnExploreClick(); + break; + case ID_chkDesc:{ + m_opt_btnDesc = !m_opt_btnDesc; + HICON hIcon = GetIconBtn(m_opt_btnDesc ? ICO_BTN_DESCON : ICO_BTN_DESC); + SendMessage((HWND)lParam, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + break; } + case ID_chkDeleteAfterSend:{ + m_opt_btnDeleteAfterSend = !m_opt_btnDeleteAfterSend; + HICON hIcon = GetIconBtn(m_opt_btnDeleteAfterSend ? ICO_BTN_DELON : ICO_BTN_DEL); + SendMessage((HWND)lParam, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + if (m_cSend) m_cSend->m_bDeleteAfterSend = m_opt_btnDeleteAfterSend; + break; } + case ID_chkEditor:{ + m_opt_chkEditor = !m_opt_chkEditor; + HICON hIcon = GetIconBtn(m_opt_chkEditor ? ICO_BTN_EDITON : ICO_BTN_EDIT); + SendMessage((HWND)lParam, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + break; } + case ID_chkOpenAgain: + m_opt_chkOpenAgain = Button_GetCheck((HWND)lParam); 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; + 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 = NULL; + 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; } } //WM_CLOSE: -void TfrmMain::wmClose(WPARAM wParam, LPARAM lParam) { +void TfrmMain::wmClose(WPARAM, LPARAM) +{ DestroyWindow(m_hWnd); return; } //WM_TIMER: -const int g_iTargetBorder=7; -void TfrmMain::SetTargetWindow(HWND hwnd){ - if(!hwnd){ +const int g_iTargetBorder = 7; +void TfrmMain::SetTargetWindow(HWND hwnd) +{ + if (!hwnd) { POINT point; GetCursorPos(&point); - hwnd=WindowFromPoint(point); -// if(!((GetAsyncKeyState(VK_SHIFT)|GetAsyncKeyState(VK_MENU))&0x8000)) - for(HWND hTMP; (hTMP=GetParent(hwnd)); hwnd=hTMP); + hwnd = WindowFromPoint(point); + // if(!((GetAsyncKeyState(VK_SHIFT)|GetAsyncKeyState(VK_MENU))&0x8000)) + for (HWND hTMP; (hTMP = GetParent(hwnd)); hwnd = hTMP); } - m_hTargetWindow=hwnd; - int len=GetWindowTextLength(m_hTargetWindow)+1; + m_hTargetWindow = hwnd; + int len = GetWindowTextLength(m_hTargetWindow) + 1; TCHAR* lpTitle; - if(len>1){ - lpTitle=(TCHAR*)mir_alloc(len*sizeof(TCHAR)); - GetWindowText(m_hTargetWindow,lpTitle,len); - }else{//no WindowText present, use WindowClass - lpTitle=(TCHAR*)mir_alloc(64*sizeof(TCHAR)); - RealGetWindowClass(m_hTargetWindow,lpTitle,64); + if (len > 1) { + lpTitle = (TCHAR*)mir_alloc(len*sizeof(TCHAR)); + GetWindowText(m_hTargetWindow, lpTitle, len); + } + else {//no WindowText present, use WindowClass + lpTitle = (TCHAR*)mir_alloc(64 * sizeof(TCHAR)); + RealGetWindowClass(m_hTargetWindow, lpTitle, 64); } - SetDlgItemText(m_hwndTabPage,ID_edtCaption,lpTitle); + SetDlgItemText(m_hwndTabPage, ID_edtCaption, lpTitle); mir_free(lpTitle); - edtSizeUpdate(m_hTargetWindow,m_opt_chkClientArea,m_hwndTabPage,ID_edtSize); + edtSizeUpdate(m_hTargetWindow, m_opt_chkClientArea, m_hwndTabPage, ID_edtSize); } -void TfrmMain::wmTimer(WPARAM wParam, LPARAM lParam){ - if(wParam==ID_imgTarget){// Timer for Target selector + +void TfrmMain::wmTimer(WPARAM wParam, LPARAM) +{ + if (wParam == ID_imgTarget) {// Timer for Target selector static int primarymouse; - if(!m_hTargetHighlighter){ - primarymouse=GetSystemMetrics(SM_SWAPBUTTON)?VK_RBUTTON:VK_LBUTTON; - m_hTargetHighlighter=CreateWindowEx(WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW,(TCHAR*)g_clsTargetHighlighter,NULL,WS_POPUP,0,0,0,0,NULL,NULL,g_hSendSS,NULL); - if(!m_hTargetHighlighter) return; - SetLayeredWindowAttributes(m_hTargetHighlighter,0,123,LWA_ALPHA); - SetSystemCursor(CopyCursor(GetIcon(ICO_TARGET)),OCR_IBEAM);//text cursor - SetSystemCursor(CopyCursor(GetIcon(ICO_TARGET)),OCR_NORMAL); + if (!m_hTargetHighlighter) { + primarymouse = GetSystemMetrics(SM_SWAPBUTTON) ? VK_RBUTTON : VK_LBUTTON; + m_hTargetHighlighter = CreateWindowEx(WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW, (TCHAR*)g_clsTargetHighlighter, NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, g_hSendSS, NULL); + if (!m_hTargetHighlighter) return; + SetLayeredWindowAttributes(m_hTargetHighlighter, 0, 123, LWA_ALPHA); + SetSystemCursor(CopyCursor(GetIcon(ICO_TARGET)), OCR_IBEAM);//text cursor + SetSystemCursor(CopyCursor(GetIcon(ICO_TARGET)), OCR_NORMAL); SetActiveWindow(m_hTargetHighlighter); // activate highlighter to fix focus problems with UAC (unelevated GetAsyncKeyState() fails if an elevated app got focus) Hide(); } - if(!(GetAsyncKeyState(primarymouse)&0x8000)){ - KillTimer(m_hWnd,ID_imgTarget); - SystemParametersInfo(SPI_SETCURSORS,0,NULL,0); - DestroyWindow(m_hTargetHighlighter),m_hTargetHighlighter=NULL; + if (!(GetAsyncKeyState(primarymouse) & 0x8000)) { + KillTimer(m_hWnd, ID_imgTarget); + SystemParametersInfo(SPI_SETCURSORS, 0, NULL, 0); + DestroyWindow(m_hTargetHighlighter), m_hTargetHighlighter = NULL; SetTargetWindow(m_hLastWin); Show(); return; } POINT point; GetCursorPos(&point); - HWND hwnd=WindowFromPoint(point); - if(!((GetAsyncKeyState(VK_SHIFT)|GetAsyncKeyState(VK_MENU))&0x8000)) - for(HWND hTMP; (hTMP=GetAncestor(hwnd,GA_PARENT)) && IsChild(hTMP,hwnd); hwnd=hTMP); - else{ - ScreenToClient(hwnd,&point); - HWND hTMP; if((hTMP=RealChildWindowFromPoint(hwnd,point))) - hwnd=hTMP; + HWND hwnd = WindowFromPoint(point); + if (!((GetAsyncKeyState(VK_SHIFT) | GetAsyncKeyState(VK_MENU)) & 0x8000)) + for (HWND hTMP; (hTMP = GetAncestor(hwnd, GA_PARENT)) && IsChild(hTMP, hwnd); hwnd = hTMP); + else { + ScreenToClient(hwnd, &point); + HWND hTMP; if ((hTMP = RealChildWindowFromPoint(hwnd, point))) + hwnd = hTMP; } - if(hwnd!=m_hLastWin){ - m_hLastWin=hwnd; + if (hwnd != m_hLastWin) { + m_hLastWin = hwnd; RECT rect; - if(m_opt_chkClientArea){ - GetClientRect(hwnd,&rect); - ClientToScreen(hwnd,(POINT*)&rect); - rect.right=rect.left+rect.right; - rect.bottom=rect.top+rect.bottom; - }else - GetWindowRect(hwnd,&rect); - int width=rect.right-rect.left; - int height=rect.bottom-rect.top; - if(g_iTargetBorder){ - SetWindowPos(m_hTargetHighlighter,NULL,0,0,0,0,SWP_HIDEWINDOW|SWP_NOMOVE|SWP_NOSIZE); - if(width>g_iTargetBorder*2 && height>g_iTargetBorder*2) { - HRGN hRegnNew=CreateRectRgn(0,0,width,height); - HRGN hRgnHole=CreateRectRgn(g_iTargetBorder,g_iTargetBorder,width-g_iTargetBorder,height-g_iTargetBorder); - CombineRgn(hRegnNew,hRegnNew,hRgnHole,RGN_XOR); + if (m_opt_chkClientArea) { + GetClientRect(hwnd, &rect); + ClientToScreen(hwnd, (POINT*)&rect); + rect.right = rect.left + rect.right; + rect.bottom = rect.top + rect.bottom; + } + else + GetWindowRect(hwnd, &rect); + int width = rect.right - rect.left; + int height = rect.bottom - rect.top; + if (g_iTargetBorder) { + SetWindowPos(m_hTargetHighlighter, NULL, 0, 0, 0, 0, SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE); + if (width > g_iTargetBorder * 2 && height > g_iTargetBorder * 2) { + HRGN hRegnNew = CreateRectRgn(0, 0, width, height); + HRGN hRgnHole = CreateRectRgn(g_iTargetBorder, g_iTargetBorder, width - g_iTargetBorder, height - g_iTargetBorder); + CombineRgn(hRegnNew, hRegnNew, hRgnHole, RGN_XOR); DeleteObject(hRgnHole); - SetWindowRgn(m_hTargetHighlighter,hRegnNew,FALSE);//cleans up hRegnNew - }else SetWindowRgn(m_hTargetHighlighter,NULL,FALSE); + SetWindowRgn(m_hTargetHighlighter, hRegnNew, FALSE);//cleans up hRegnNew + } + else SetWindowRgn(m_hTargetHighlighter, NULL, FALSE); } - SetWindowPos(m_hTargetHighlighter,HWND_TOPMOST,rect.left,rect.top,width,height,SWP_SHOWWINDOW|SWP_NOACTIVATE); + SetWindowPos(m_hTargetHighlighter, HWND_TOPMOST, rect.left, rect.top, width, height, SWP_SHOWWINDOW | SWP_NOACTIVATE); } return; } - if(wParam==ID_chkTimed){// Timer for Screenshot - #ifdef _DEBUG - OutputDebugStringA("SS Bitmap Timer Start\r\n" ); - #endif - if(!m_bCapture) { //only start once + 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, m_opt_chkClientArea, m_opt_chkIndirectCapture); - break; - case 1: - m_Screenshot = CaptureMonitor((m_opt_cboxDesktop > 0) ? m_Monitors[m_opt_cboxDesktop-1].szDevice : NULL); - break; - case 2: /// edge case, existing local file - break; - #ifdef _DEBUG - default: - OutputDebugStringA("SS Bitmap Timer Stop (no tabCapture)\r\n" ); - #endif + case 0: + m_Screenshot = CaptureWindow(m_hTargetWindow, m_opt_chkClientArea, m_opt_chkIndirectCapture); + break; + case 1: + m_Screenshot = CaptureMonitor((m_opt_cboxDesktop > 0) ? m_Monitors[m_opt_cboxDesktop - 1].szDevice : NULL); + break; + case 2: /// edge case, existing local file + break; +#ifdef _DEBUG + default: + OutputDebugStringA("SS Bitmap Timer Stop (no tabCapture)\r\n"); +#endif } m_bCapture = false; - if (m_Screenshot || m_opt_tabCapture==2) { /// @note : test without "if" - KillTimer(m_hWnd,ID_chkTimed); - #ifdef _DEBUG - OutputDebugStringA("SS Bitmap Timer Stop (CaptureDone)\r\n" ); - #endif - SendMessage(m_hWnd,UM_EVENT, 0, (LPARAM)EVT_CaptureDone); + if (m_Screenshot || m_opt_tabCapture == 2) { /// @note : test without "if" + KillTimer(m_hWnd, ID_chkTimed); +#ifdef _DEBUG + OutputDebugStringA("SS Bitmap Timer Stop (CaptureDone)\r\n"); +#endif + SendMessage(m_hWnd, UM_EVENT, 0, (LPARAM)EVT_CaptureDone); } } } } //WM_NOTIFY: -void 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:{ - if(!m_hwndTabPage) break; - ShowWindow(m_hwndTabPage,SW_HIDE); - m_hwndTabPage=NULL; - break;} - case TCN_SELCHANGE:{ - TAB_INFO itab={TCIF_PARAM}; - m_opt_tabCapture=TabCtrl_GetCurSel(m_hwndTab); - TabCtrl_GetItem(m_hwndTab, m_opt_tabCapture, &itab); - m_hwndTabPage=itab.hwndTabPage; - ShowWindow(m_hwndTabPage, SW_SHOW); - break;} - default: - break; - } - break; +void TfrmMain::wmNotify(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:{ + if (!m_hwndTabPage) break; + ShowWindow(m_hwndTabPage, SW_HIDE); + m_hwndTabPage = NULL; + break; } + case TCN_SELCHANGE:{ + TAB_INFO itab = { TCIF_PARAM }; + m_opt_tabCapture = TabCtrl_GetCurSel(m_hwndTab); + TabCtrl_GetItem(m_hwndTab, m_opt_tabCapture, &itab); + m_hwndTabPage = itab.hwndTabPage; + ShowWindow(m_hwndTabPage, SW_SHOW); + break; } default: break; + } + break; + default: + break; } } //UM_CLOSING: -void TfrmMain::UMClosing(WPARAM wParam, LPARAM lParam) { +void TfrmMain::UMClosing(WPARAM wParam, LPARAM lParam) +{ HWND hWnd = (HWND)wParam; switch (lParam) { - case IDD_UAboutForm: - btnAboutOnCloseWindow(hWnd); - break; - case IDD_UEditForm: - ; - break; - default: - break; + case IDD_UAboutForm: + btnAboutOnCloseWindow(hWnd); + break; + case IDD_UEditForm: + ; + break; + default: + break; } } //UM_EVENT: -void TfrmMain::UMevent(WPARAM wParam, LPARAM lParam) { +void TfrmMain::UMevent(WPARAM, LPARAM lParam) +{ //HWND hWnd = (HWND)wParam; switch (lParam) { - case EVT_CaptureDone: - if (!m_Screenshot && m_opt_tabCapture!=2) { - TCHAR *err = TranslateT("Couldn't take a screenshot"); - MessageBox(NULL,err,ERROR_TITLE,MB_OK|MB_ICONWARNING); - Show(); - return; - } - FormClose(); - break; - case EVT_SendFileDone: - break; - case EVT_CheckOpenAgain: - if(m_opt_chkOpenAgain){ - if(m_Screenshot){ - FIP->FI_Unload(m_Screenshot); - m_Screenshot = NULL; - } - Show(); - }else{// Saving Options and close - SaveOptions(); - Close(); + case EVT_CaptureDone: + if (!m_Screenshot && m_opt_tabCapture != 2) { + TCHAR *err = TranslateT("Couldn't take a screenshot"); + MessageBox(NULL, err, ERROR_TITLE, MB_OK | MB_ICONWARNING); + Show(); + return; + } + FormClose(); + break; + case EVT_SendFileDone: + break; + case EVT_CheckOpenAgain: + if (m_opt_chkOpenAgain) { + if (m_Screenshot) { + FIP->FI_Unload(m_Screenshot); + m_Screenshot = NULL; } - break; - default: - break; + Show(); + } + else {// Saving Options and close + SaveOptions(); + Close(); + } + break; + default: + break; } } //--------------------------------------------------------------------------- // Standard konstruktor/destruktor -TfrmMain::TfrmMain() { +TfrmMain::TfrmMain() +{ /* m_opt_XXX */ - m_bOnExitSave = TRUE; - - m_hWnd = NULL; - m_hContact = NULL; - m_bFormAbout=false; - m_hTargetWindow =m_hLastWin=NULL; - m_hTargetHighlighter=NULL; - m_FDestFolder =m_pszFile=m_pszFileDesc=NULL; - m_Screenshot = NULL; + m_bOnExitSave = TRUE; + + m_hWnd = NULL; + m_hContact = NULL; + m_bFormAbout = false; + m_hTargetWindow = m_hLastWin = NULL; + m_hTargetHighlighter = NULL; + m_FDestFolder = m_pszFile = m_pszFileDesc = NULL; + m_Screenshot = NULL; /* m_AlphaColor */ - m_cSend = NULL; + m_cSend = NULL; - m_Monitors = NULL; - m_MonitorCount = MonitorInfoEnum(m_Monitors, m_VirtualScreen); + m_Monitors = NULL; + m_MonitorCount = MonitorInfoEnum(m_Monitors, m_VirtualScreen); /* m_opt_XXX */ LoadOptions(); - m_bCapture = false; + m_bCapture = false; /* m_hwndTab,m_hwndTabPage */ - m_himlTab = NULL; + m_himlTab = NULL; } -TfrmMain::~TfrmMain() { +TfrmMain::~TfrmMain() +{ _HandleMapping.erase(m_hWnd); mir_free(m_pszFile); mir_free(m_FDestFolder); @@ -696,46 +717,48 @@ TfrmMain::~TfrmMain() { mir_free(m_Monitors); if (m_Screenshot) FIP->FI_Unload(m_Screenshot); if (m_cSend) delete m_cSend; - if(m_hTargetHighlighter){ - DestroyWindow(m_hTargetHighlighter),m_hTargetHighlighter=NULL; - SystemParametersInfo(SPI_SETCURSORS,0,NULL,0); + if (m_hTargetHighlighter) { + DestroyWindow(m_hTargetHighlighter), m_hTargetHighlighter = NULL; + SystemParametersInfo(SPI_SETCURSORS, 0, NULL, 0); } } //--------------------------------------------------------------------------- // 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_chkIndirectCapture = db_get_b(NULL, SZ_SENDSS, "IndirectCapture", 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", 0); - m_opt_cboxSendBy = db_get_b(NULL, SZ_SENDSS, "SendBy", 0); - - m_opt_btnDesc = db_get_b(NULL, SZ_SENDSS, "AutoDescription", 1); - m_opt_btnDeleteAfterSend = db_get_b(NULL, SZ_SENDSS, "DelAfterSend", 1)!=0; - m_opt_chkEditor = db_get_b(NULL, SZ_SENDSS, "Preview", 0); - m_opt_chkOpenAgain = db_get_b(NULL, SZ_SENDSS, "OpenAgain", 0); +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_chkIndirectCapture = db_get_b(NULL, SZ_SENDSS, "IndirectCapture", 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", 0); + m_opt_cboxSendBy = db_get_b(NULL, SZ_SENDSS, "SendBy", 0); + + m_opt_btnDesc = db_get_b(NULL, SZ_SENDSS, "AutoDescription", 1); + m_opt_btnDeleteAfterSend = db_get_b(NULL, SZ_SENDSS, "DelAfterSend", 1) != 0; + m_opt_chkEditor = db_get_b(NULL, SZ_SENDSS, "Preview", 0); + m_opt_chkOpenAgain = db_get_b(NULL, SZ_SENDSS, "OpenAgain", 0); } -void TfrmMain::SaveOptions(void) { - if(m_bOnExitSave) { +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, "AutoSend", m_opt_chkEmulateClick); db_set_b(NULL, SZ_SENDSS, "JpegQuality", m_opt_edtQuality); db_set_b(NULL, SZ_SENDSS, "Capture", m_opt_tabCapture); @@ -756,105 +779,110 @@ void TfrmMain::SaveOptions(void) { } //--------------------------------------------------------------------------- -void TfrmMain::Init(TCHAR* DestFolder, MCONTACT Contact) { +void TfrmMain::Init(TCHAR* DestFolder, MCONTACT Contact) +{ m_FDestFolder = mir_tstrdup(DestFolder); m_hContact = Contact; // create window - m_hWnd = CreateDialogParam(g_hSendSS, MAKEINTRESOURCE(IDD_UMainForm),0,DlgTfrmMain,(LPARAM)this); + m_hWnd = CreateDialogParam(g_hSendSS, MAKEINTRESOURCE(IDD_UMainForm), 0, DlgTfrmMain, (LPARAM)this); //register object _HandleMapping.insert(CHandleMapping::value_type(m_hWnd, this)); //check Contact - if(m_cSend) + if (m_cSend) m_cSend->SetContact(Contact); } //--------------------------------------------------------------------------- -void TfrmMain::btnCaptureClick() { - if(m_opt_tabCapture==1) m_hTargetWindow=GetDesktopWindow(); - else if(m_opt_tabCapture==2){ +void TfrmMain::btnCaptureClick() +{ + if (m_opt_tabCapture == 1) m_hTargetWindow = GetDesktopWindow(); + else if (m_opt_tabCapture == 2) { TCHAR filename[MAX_PATH]; GetDlgItemText(m_hwndTabPage, ID_edtSize, filename, _countof(filename)); - FILE* fp=_wfopen(filename,_T("rb")); - if(!fp){ + FILE* fp = _wfopen(filename, _T("rb")); + if (!fp) { TCHAR *err = TranslateT("Select a file"); - MessageBox(m_hWnd,err,ERROR_TITLE,MB_OK|MB_ICONWARNING); + MessageBox(m_hWnd, err, ERROR_TITLE, MB_OK | MB_ICONWARNING); return; } fclose(fp); - mir_free(m_pszFile); m_pszFile=mir_tstrdup(filename); - }else if(!m_hTargetWindow) { + mir_free(m_pszFile); m_pszFile = mir_tstrdup(filename); + } + else if (!m_hTargetWindow) { TCHAR *err = TranslateT("Select a target window."); - MessageBox(m_hWnd,err,ERROR_TITLE,MB_OK|MB_ICONWARNING); + MessageBox(m_hWnd, err, ERROR_TITLE, MB_OK | MB_ICONWARNING); return; } TfrmMain::Hide(); - if(m_opt_chkTimed){ - SetTimer(m_hWnd, ID_chkTimed, m_opt_edtTimed ? m_opt_edtTimed*1000 : 500, NULL); /// calls EVT_CaptureDone + if (m_opt_chkTimed) { + SetTimer(m_hWnd, ID_chkTimed, m_opt_edtTimed ? m_opt_edtTimed * 1000 : 500, NULL); /// calls EVT_CaptureDone return; } - if(m_opt_tabCapture==1){ /// desktop needs always time to update from TfrmMain::Hide() + if (m_opt_tabCapture == 1) { /// desktop needs always time to update from TfrmMain::Hide() SetTimer(m_hWnd, ID_chkTimed, 500, NULL); /// calls EVT_CaptureDone return; } - if(m_opt_tabCapture!=2){ + if (m_opt_tabCapture != 2) { m_Screenshot = CaptureWindow(m_hTargetWindow, m_opt_chkClientArea, m_opt_chkIndirectCapture); } - SendMessage(m_hWnd,UM_EVENT, 0, (LPARAM)EVT_CaptureDone); + SendMessage(m_hWnd, UM_EVENT, 0, (LPARAM)EVT_CaptureDone); } //--------------------------------------------------------------------------- -void TfrmMain::chkTimedClick() { +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::cboxSendByChange() { +void TfrmMain::cboxSendByChange() +{ BOOL bState; HICON hIcon; BYTE itemFlag = SS_DLG_DESCRIPTION; //SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND | - if(m_cSend) + if (m_cSend) delete m_cSend; - switch(m_opt_cboxSendBy) { - case SS_FILESEND: //"File Transfer" - m_cSend = new CSendFile(m_hWnd, m_hContact, true); - break; - case SS_EMAIL: //"E-mail" - m_cSend = new CSendEmail(m_hWnd, m_hContact, true); - break; - case SS_HTTPSERVER: //"HTTP Server" - m_cSend = new CSendHTTPServer(m_hWnd, m_hContact, true); - break; - case SS_FTPFILE: //"FTP File" - m_cSend = new CSendFTPFile(m_hWnd, m_hContact, true); - break; - case SS_DROPBOX: //"Dropbox" - m_cSend = new CSendDropbox(m_hWnd, m_hContact, false); - break; - case SS_IMAGESHACK: //"ImageShack" - m_cSend = new CSendHost_ImageShack(m_hWnd, m_hContact, true); - break; - case SS_UPLOADPIE_30M: //"Upload Pie (30 minutes)" - m_cSend = new CSendHost_UploadPie(m_hWnd, m_hContact, true,1); - break; - case SS_UPLOADPIE_1D: //"Upload Pie (1 day)" - m_cSend = new CSendHost_UploadPie(m_hWnd, m_hContact, true,4); - break; - case SS_UPLOADPIE_1W: //"Upload Pie (1 week)" - m_cSend = new CSendHost_UploadPie(m_hWnd, m_hContact, true,5); - break; - case SS_IMGUR: - m_cSend = new CSendHost_Imgur(m_hWnd, m_hContact, true); - break; - default: //SS_JUSTSAVE - "Just save it " - m_cSend = NULL; - break; + switch (m_opt_cboxSendBy) { + case SS_FILESEND: //"File Transfer" + m_cSend = new CSendFile(m_hWnd, m_hContact, true); + break; + case SS_EMAIL: //"E-mail" + m_cSend = new CSendEmail(m_hWnd, m_hContact, true); + break; + case SS_HTTPSERVER: //"HTTP Server" + m_cSend = new CSendHTTPServer(m_hWnd, m_hContact, true); + break; + case SS_FTPFILE: //"FTP File" + m_cSend = new CSendFTPFile(m_hWnd, m_hContact, true); + break; + case SS_DROPBOX: //"Dropbox" + m_cSend = new CSendDropbox(m_hWnd, m_hContact, false); + break; + case SS_IMAGESHACK: //"ImageShack" + m_cSend = new CSendHost_ImageShack(m_hWnd, m_hContact, true); + break; + case SS_UPLOADPIE_30M: //"Upload Pie (30 minutes)" + m_cSend = new CSendHost_UploadPie(m_hWnd, m_hContact, true, 1); + break; + case SS_UPLOADPIE_1D: //"Upload Pie (1 day)" + m_cSend = new CSendHost_UploadPie(m_hWnd, m_hContact, true, 4); + break; + case SS_UPLOADPIE_1W: //"Upload Pie (1 week)" + m_cSend = new CSendHost_UploadPie(m_hWnd, m_hContact, true, 5); + break; + case SS_IMGUR: + m_cSend = new CSendHost_Imgur(m_hWnd, m_hContact, true); + break; + default: //SS_JUSTSAVE - "Just save it " + m_cSend = NULL; + break; } - if(m_cSend){ + if (m_cSend) { itemFlag = m_cSend->GetEnableItem(); m_cSend->m_bDeleteAfterSend = m_opt_btnDeleteAfterSend; } @@ -870,34 +898,38 @@ void TfrmMain::cboxSendByChange() { } //--------------------------------------------------------------------------- -void TfrmMain::btnAboutClick() { +void TfrmMain::btnAboutClick() +{ if (m_bFormAbout) return; - TfrmAbout *frmAbout=new TfrmAbout(m_hWnd); + TfrmAbout *frmAbout = new TfrmAbout(m_hWnd); frmAbout->Show(); m_bFormAbout = true; } // Edit window call this event before it closes -void TfrmMain::btnAboutOnCloseWindow(HWND hWnd) { +void TfrmMain::btnAboutOnCloseWindow(HWND) +{ m_bFormAbout = false; } //--------------------------------------------------------------------------- -void TfrmMain::btnExploreClick() { +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) { +void TfrmMain::edtSizeUpdate(HWND hWnd, BOOL ClientArea, HWND hTarget, UINT Ctrl) +{ // get window dimensions - RECT rect = {0}; - RECT cliRect = {0}; + RECT rect = { 0 }; + RECT cliRect = { 0 }; TCHAR B[33], H[16]; GetWindowRect(hWnd, &rect); if (ClientArea) { - POINT pt = {0}; + POINT pt = { 0 }; GetClientRect(hWnd, &cliRect); pt.x = cliRect.left; pt.y = cliRect.top; @@ -906,20 +938,21 @@ void TfrmMain::edtSizeUpdate(HWND hWnd, BOOL ClientArea, HWND hTarget, UINT Ctrl pt.y = pt.y - rect.top; //offset y for client area rect = cliRect; } -// _itot_s(rect.right - rect.left, B, 33, 10); + // _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_s(rect.bottom - rect.top, H, 16, 10); _itot(rect.bottom - rect.top, H, 10); mir_tstrncat(B, _T("x"), _countof(B) - mir_tstrlen(B)); mir_tstrncat(B, H, _countof(B) - mir_tstrlen(B)); SetDlgItemText(hTarget, Ctrl, B); } -void TfrmMain::edtSizeUpdate(RECT rect, HWND hTarget, UINT Ctrl) { +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_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_s(ABS(rect.bottom - rect.top), H, 16, 10); _itot(ABS(rect.bottom - rect.top), H, 10); mir_tstrncat(B, _T("x"), _countof(B) - mir_tstrlen(B)); mir_tstrncat(B, H, _countof(B) - mir_tstrlen(B)); @@ -927,7 +960,8 @@ void TfrmMain::edtSizeUpdate(RECT rect, HWND hTarget, UINT Ctrl) { } //--------------------------------------------------------------------------- -INT_PTR TfrmMain::SaveScreenshot(FIBITMAP* dib) { +INT_PTR TfrmMain::SaveScreenshot(FIBITMAP* dib) +{ //generate File name FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; TCHAR* ret; @@ -935,15 +969,15 @@ INT_PTR TfrmMain::SaveScreenshot(FIBITMAP* dib) { TCHAR* pszFilename = NULL; TCHAR* pszFileDesc = NULL; if (!dib) return 1; //error - unsigned FileNumber=db_get_dw(NULL,SZ_SENDSS,"FileNumber",0)+1; - if(FileNumber>99999) FileNumber=1; + unsigned FileNumber = db_get_dw(NULL, SZ_SENDSS, "FileNumber", 0) + 1; + if (FileNumber > 99999) FileNumber = 1; //Generate FileName mir_tstradd(path, m_FDestFolder); - if (path[mir_tstrlen(path)-1] != _T('\\')) mir_tstradd(path, _T("\\")); + if (path[mir_tstrlen(path) - 1] != _T('\\')) mir_tstradd(path, _T("\\")); mir_tstradd(path, _T("shot%.5u"));//on format change, adapt "len" below - size_t len=mir_tstrlen(path)+2; + size_t len = mir_tstrlen(path) + 2; pszFilename = (TCHAR*)mir_alloc(sizeof(TCHAR)*(len)); - mir_sntprintf(pszFilename,len,path,FileNumber); + mir_sntprintf(pszFilename, len, path, FileNumber); mir_free(path); //Generate a description according to the screenshot @@ -955,7 +989,7 @@ INT_PTR TfrmMain::SaveScreenshot(FIBITMAP* dib) { mir_tstradd(pszFileDesc, TranslateT("of \"")); GetDlgItemText(m_hwndTabPage, ID_edtCaption, winText, _countof(winText)); mir_tstradd(pszFileDesc, winText); - if(m_opt_tabCapture==1) + if (m_opt_tabCapture == 1) mir_tstradd(pszFileDesc, _T("\"")); else mir_tstradd(pszFileDesc, TranslateT("\" Window")); @@ -964,82 +998,82 @@ INT_PTR TfrmMain::SaveScreenshot(FIBITMAP* dib) { 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); + 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; + 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; } -// bool bDummy = !(FIP->FI_GetICCProfile(dib_new)->flags & FIICC_COLOR_IS_CMYK); + // bool bDummy = !(FIP->FI_GetICCProfile(dib_new)->flags & FIICC_COLOR_IS_CMYK); - FIBITMAP *dib32,*dib24; + FIBITMAP *dib32, *dib24; 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 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); - ret = SaveImage(fif,dib24, pszFilename, _T("jpg")); - FIP->FI_Unload(dib24); - 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); + ret = SaveImage(fif, dib24, pszFilename, _T("jpg")); + FIP->FI_Unload(dib24); + break; - case 2: //BMP + 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); - ret = SaveImage(FIF_BMP,dib24, pszFilename, _T("bmp")); - FIP->FI_Unload(dib24); - break; + dib32 = FIP->FI_Composite(dib_new, FALSE, &m_AlphaColor, NULL); + dib24 = FIP->FI_ConvertTo24Bits(dib32); + FIP->FI_Unload(dib32); + ret = SaveImage(FIF_BMP, dib24, pszFilename, _T("bmp")); + FIP->FI_Unload(dib24); + break; - case 3: //TIFF (miranda freeimage interface do not support save tiff, we udse GDI+) - { + case 3: //TIFF (miranda freeimage interface do not support save tiff, we udse GDI+) + { TCHAR* pszFile = NULL; mir_tstradd(pszFile, pszFilename); mir_tstradd(pszFile, _T(".tif")); - dib32 = FIP->FI_Composite(dib_new,FALSE,&m_AlphaColor,NULL); + dib32 = FIP->FI_Composite(dib_new, FALSE, &m_AlphaColor, NULL); dib24 = FIP->FI_ConvertTo24Bits(dib32); FIP->FI_Unload(dib32); HBITMAP hBmp = FIP->FI_CreateHBITMAPFromDIB(dib24); FIP->FI_Unload(dib24); SaveTIF(hBmp, pszFile); - ret=pszFile; + ret = pszFile; DeleteObject(hBmp); - } - break; + } + break; - case 4: //GIF - { + case 4: //GIF + { //dib24 = FIP->FI_ConvertTo8Bits(dib_new); //ret = SaveImage(FIF_GIF,dib24, pszFilename, _T("gif")); //FIP->FI_Unload(dib24); @@ -1048,49 +1082,50 @@ INT_PTR TfrmMain::SaveScreenshot(FIBITMAP* dib) { mir_tstradd(pszFile, _T(".gif")); HBITMAP hBmp = FIP->FI_CreateHBITMAPFromDIB(dib_new); SaveGIF(hBmp, pszFile); - ret=pszFile; + ret = pszFile; DeleteObject(hBmp); - } - break; + } + break; - default: - ret=NULL; + default: + ret = NULL; } -/* //load PNG and save file in user format (if differ) - //this get better result for transparent aereas - //TCHAR* pszFormat = (TCHAR*)ComboBox_GetItemData(hwndCombo, ComboBox_GetCurSel(hwndCombo)); - TCHAR pszFormat[6]; - ComboBox_GetText(hwndCombo, pszFormat, 6); - if(ret && (mir_tstrcmpi (pszFormat,_T("png")) != 0)) { + /* //load PNG and save file in user format (if differ) + //this get better result for transparent aereas + //TCHAR* pszFormat = (TCHAR*)ComboBox_GetItemData(hwndCombo, ComboBox_GetCurSel(hwndCombo)); + TCHAR pszFormat[6]; + ComboBox_GetText(hwndCombo, pszFormat, 6); + if(ret && (mir_tstrcmpi (pszFormat,_T("png")) != 0)) { - fif = FIP->FI_GetFIFFromFilenameU(ret); - dib_new = FIP->FI_LoadU(fif, ret,0); + fif = FIP->FI_GetFIFFromFilenameU(ret); + dib_new = FIP->FI_LoadU(fif, ret,0); if(dib_new) { - DeleteFile(ret); - mir_free(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; + DeleteFile(ret); + mir_free(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); mir_free(pszFilename); - if(ret){ - db_set_dw(NULL,SZ_SENDSS,"FileNumber",FileNumber); - mir_free(m_pszFile); m_pszFile=ret; + if (ret) { + db_set_dw(NULL, SZ_SENDSS, "FileNumber", FileNumber); + mir_free(m_pszFile); m_pszFile = ret; mir_free(m_pszFileDesc); - if(IsWindowEnabled(GetDlgItem(m_hWnd,ID_chkDesc)) && m_opt_btnDesc){ - m_pszFileDesc=pszFileDesc; - }else{ + if (IsWindowEnabled(GetDlgItem(m_hWnd, ID_chkDesc)) && m_opt_btnDesc) { + m_pszFileDesc = pszFileDesc; + } + else { mir_free(pszFileDesc); - m_pszFileDesc=mir_tstrdup(_T("")); + m_pszFileDesc = mir_tstrdup(_T("")); } - if(m_cSend) { + if (m_cSend) { m_cSend->SetFile(m_pszFile); m_cSend->SetDescription(m_pszFileDesc); } @@ -1101,90 +1136,70 @@ INT_PTR TfrmMain::SaveScreenshot(FIBITMAP* dib) { } //--------------------------------------------------------------------------- -void TfrmMain::FormClose() { - bool bCanDelete=m_opt_btnDeleteAfterSend; - if(m_opt_tabCapture==2){ /// existing file +void TfrmMain::FormClose() +{ + bool bCanDelete = m_opt_btnDeleteAfterSend; + if (m_opt_tabCapture == 2) { /// existing file TCHAR description[1024]; GetDlgItemText(m_hwndTabPage, ID_edtCaption, description, _countof(description)); - if(!IsWindowEnabled(GetDlgItem(m_hWnd,ID_chkDesc)) || !m_opt_btnDesc) - *description='\0'; - if(m_cSend) { + if (!IsWindowEnabled(GetDlgItem(m_hWnd, ID_chkDesc)) || !m_opt_btnDesc) + *description = '\0'; + if (m_cSend) { m_cSend->m_bDeleteAfterSend = false; /// well... guess it's better to not delete existing files for now... m_cSend->SetFile(m_pszFile); m_cSend->SetDescription(description); } - bCanDelete=false; - }else if(SaveScreenshot(m_Screenshot)){ /// Saving the screenshot + bCanDelete = false; + } + else if (SaveScreenshot(m_Screenshot)) { /// Saving the screenshot Show(); // Error from SaveScreenshot return; } - - bool send=true; - if(m_opt_chkEditor){ - SHELLEXECUTEINFO shex={sizeof(SHELLEXECUTEINFO)}; - shex.fMask=SEE_MASK_NOCLOSEPROCESS; - shex.lpVerb=_T("edit"); - shex.lpFile=m_pszFile; - shex.nShow=SW_SHOWNORMAL; + + bool send = true; + if (m_opt_chkEditor) { + SHELLEXECUTEINFO shex = { sizeof(SHELLEXECUTEINFO) }; + shex.fMask = SEE_MASK_NOCLOSEPROCESS; + shex.lpVerb = _T("edit"); + shex.lpFile = m_pszFile; + shex.nShow = SW_SHOWNORMAL; ShellExecuteEx(&shex); - if(shex.hProcess){ + if (shex.hProcess) { DWORD res; MSG msg; - do{ + do { // wait for editor exit or messages/input - res=MsgWaitForMultipleObjects(1,&shex.hProcess,0,INFINITE,QS_ALLINPUT); - while(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){ - if(msg.message==WM_QUIT){ - res=WAIT_OBJECT_0; - PostMessage(NULL,WM_QUIT,0,0); // forward for outer message loops + res = MsgWaitForMultipleObjects(1, &shex.hProcess, 0, INFINITE, QS_ALLINPUT); + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + if (msg.message == WM_QUIT) { + res = WAIT_OBJECT_0; + PostMessage(NULL, WM_QUIT, 0, 0); // forward for outer message loops break; } // process dialog messages (of unknown dialogs) HWND hwndDlgModeless = GetActiveWindow(); -// HWND hwndDlgModeless = msg.hwnd; -// for(HWND hTMP; (hTMP=GetAncestor(hwndDlgModeless,GA_PARENT)) && IsChild(hTMP,hwndDlgModeless); hwndDlgModeless=hTMP); - if(hwndDlgModeless != NULL && IsDialogMessage(hwndDlgModeless, &msg)) /* Wine fix. */ + // HWND hwndDlgModeless = msg.hwnd; + // for(HWND hTMP; (hTMP=GetAncestor(hwndDlgModeless,GA_PARENT)) && IsChild(hTMP,hwndDlgModeless); hwndDlgModeless=hTMP); + if (hwndDlgModeless != NULL && IsDialogMessage(hwndDlgModeless, &msg)) /* Wine fix. */ continue; // process messages TranslateMessage(&msg); DispatchMessage(&msg); } - }while(res==WAIT_OBJECT_0+1); + } while (res == WAIT_OBJECT_0 + 1); CloseHandle(shex.hProcess); } - if(MessageBox(m_hWnd,TranslateT("Send screenshot?"),_T("SendSS"),MB_YESNO|MB_ICONQUESTION|MB_SYSTEMMODAL)!=IDYES) - send=false; + if (MessageBox(m_hWnd, TranslateT("Send screenshot?"), _T("SendSS"), MB_YESNO | MB_ICONQUESTION | MB_SYSTEMMODAL) != IDYES) + send = false; } - if(send && m_cSend && m_pszFile){ - if(!m_cSend->Send()) m_cSend=NULL; // not sent now, class deletes itself later + if (send && m_cSend && m_pszFile) { + if (!m_cSend->Send()) // not sent now, class deletes itself later + m_cSend = NULL; cboxSendByChange(); - }else if(!send && bCanDelete){ - DeleteFile(m_pszFile); } - 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(); - } -}*/ + else if (!send && bCanDelete) + DeleteFile(m_pszFile); -//--------------------------------------------------------------------------- + SendMessage(m_hWnd, UM_EVENT, 0, (LPARAM)EVT_CheckOpenAgain); +} diff --git a/plugins/SendScreenshotPlus/src/Utils.cpp b/plugins/SendScreenshotPlus/src/Utils.cpp index a8d8fe0146..51a268105f 100644 --- a/plugins/SendScreenshotPlus/src/Utils.cpp +++ b/plugins/SendScreenshotPlus/src/Utils.cpp @@ -30,11 +30,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //--------------------------------------------------------------------------- //Workaround for MS bug ComboBox_SelectItemData -int ComboBox_SelectItemData(HWND hwndCtl, int indexStart, LPARAM data) { +int ComboBox_SelectItemData(HWND hwndCtl, LPARAM data) +{ int i = 0; - for ( i ; i < ComboBox_GetCount(hwndCtl); i++) { - if(data == ComboBox_GetItemData(hwndCtl, i)) { - ComboBox_SetCurSel (hwndCtl,i); + for (i; i < ComboBox_GetCount(hwndCtl); i++) { + if (data == ComboBox_GetItemData(hwndCtl, i)) { + ComboBox_SetCurSel(hwndCtl, i); return i; } } @@ -43,9 +44,10 @@ int ComboBox_SelectItemData(HWND hwndCtl, int indexStart, LPARAM data) { //--------------------------------------------------------------------------- // MonitorInfoEnum -size_t MonitorInfoEnum(MONITORINFOEX* & myMonitors, RECT & virtualScreen) { - MONITORS tmp = {0,0}; - if (EnumDisplayMonitors(NULL, NULL, MonitorInfoEnumProc, (LPARAM)&tmp)){ +size_t MonitorInfoEnum(MONITORINFOEX* & myMonitors, RECT & virtualScreen) +{ + MONITORS tmp = { 0, 0 }; + if (EnumDisplayMonitors(NULL, NULL, MonitorInfoEnumProc, (LPARAM)&tmp)) { myMonitors = tmp.info; memset(&virtualScreen, 0, sizeof(virtualScreen)); for (size_t i = 0; i < tmp.count; ++i) { @@ -60,178 +62,190 @@ size_t MonitorInfoEnum(MONITORINFOEX* & myMonitors, RECT & virtualScreen) { } // MonitorInfoEnumProc - CALLBACK for MonitorInfoEnum -BOOL CALLBACK MonitorInfoEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { +BOOL CALLBACK MonitorInfoEnumProc(HMONITOR hMonitor, HDC, LPRECT, LPARAM dwData) +{ MONITORS* monitors = (MONITORS*)dwData; ++monitors->count; monitors->info = (MONITORINFOEX*)mir_realloc(monitors->info, sizeof(MONITORINFOEX)*monitors->count); - monitors->info[monitors->count-1].cbSize = sizeof(MONITORINFOEX); - if(!GetMonitorInfo(hMonitor, (LPMONITORINFO)(monitors->info + monitors->count-1))) { + monitors->info[monitors->count - 1].cbSize = sizeof(MONITORINFOEX); + if (!GetMonitorInfo(hMonitor, (LPMONITORINFO)(monitors->info + monitors->count - 1))) { return FALSE; // stop enumeration if error } return TRUE; } -FIBITMAP* CreateDIBFromDC(HDC hDC,const RECT* rect,HWND hCapture=0); +FIBITMAP* CreateDIBFromDC(HDC hDC, const RECT* rect, HWND hCapture = 0); //--------------------------------------------------------------------------- // capture window as FIBITMAP - caller must FIP->FI_Unload(dib) -FIBITMAP* CaptureWindow(HWND hCapture, BOOL bClientArea, BOOL bIndirectCapture){ +FIBITMAP* CaptureWindow(HWND hCapture, BOOL bClientArea, BOOL bIndirectCapture) +{ FIBITMAP* dib; HWND hForegroundWin; RECT rect;//cropping rect - if(!hCapture || !IsWindow(hCapture)) + if (!hCapture || !IsWindow(hCapture)) return NULL; - hForegroundWin=GetForegroundWindow(); // old foreground window + hForegroundWin = GetForegroundWindow(); // old foreground window SetForegroundWindow(hCapture); // force target foreground BringWindowToTop(hCapture); // bring it to top as well /// redraw window to prevent runtime artifacts in picture UpdateWindow(hCapture); - HWND hParent=GetAncestor(hCapture,GA_PARENT); - if(hParent && !IsChild(hParent,hCapture)) - hParent=NULL; - if(bIndirectCapture){ - intptr_t wastopmost=GetWindowLongPtr(hCapture,GWL_EXSTYLE)&WS_EX_TOPMOST; - if(!wastopmost) - SetWindowPos(hCapture,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); - if(bClientArea){ - GetClientRect(hCapture,&rect); - ClientToScreen(hCapture,(POINT*)&rect); - rect.right+=rect.left; rect.bottom+=rect.top; - }else - GetWindowRect(hCapture,&rect); - dib=CaptureMonitor(NULL,&rect); - if(!wastopmost) - SetWindowPos(hCapture,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); - }else{ + HWND hParent = GetAncestor(hCapture, GA_PARENT); + if (hParent && !IsChild(hParent, hCapture)) + hParent = NULL; + if (bIndirectCapture) { + intptr_t wastopmost = GetWindowLongPtr(hCapture, GWL_EXSTYLE)&WS_EX_TOPMOST; + if (!wastopmost) + SetWindowPos(hCapture, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); + if (bClientArea) { + GetClientRect(hCapture, &rect); + ClientToScreen(hCapture, (POINT*)&rect); + rect.right += rect.left; rect.bottom += rect.top; + } + else + GetWindowRect(hCapture, &rect); + dib = CaptureMonitor(NULL, &rect); + if (!wastopmost) + SetWindowPos(hCapture, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); + } + else { HDC hDCsrc; - GetWindowRect(hCapture,&rect); - if(hParent) - hDCsrc=GetDC(hCapture);//hCapture is part of a window, capture that + GetWindowRect(hCapture, &rect); + if (hParent) + hDCsrc = GetDC(hCapture);//hCapture is part of a window, capture that else - hDCsrc=GetWindowDC(hCapture);//entire window w/ title bar - rect.right=ABS(rect.right-rect.left); - rect.bottom=ABS(rect.bottom-rect.top); - rect.left=rect.top=0; + hDCsrc = GetWindowDC(hCapture);//entire window w/ title bar + rect.right = ABS(rect.right - rect.left); + rect.bottom = ABS(rect.bottom - rect.top); + rect.left = rect.top = 0; /// capture window and get FIBITMAP - dib = CreateDIBFromDC(hDCsrc,&rect,hCapture); - ReleaseDC(hCapture,hDCsrc); - if(bClientArea){//we could capture directly, but doing so breaks GetWindowRgn() and also includes artifacts... - GetWindowRect(hCapture,&rect); - RECT rectCA; GetClientRect(hCapture,&rectCA); - ClientToScreen(hCapture,(POINT*)&rectCA); - rectCA.left=ABS(rectCA.left-rect.left); - rectCA.top=ABS(rectCA.top-rect.top); - rectCA.right+=rectCA.left; rectCA.bottom+=rectCA.top; + dib = CreateDIBFromDC(hDCsrc, &rect, hCapture); + ReleaseDC(hCapture, hDCsrc); + if (bClientArea) {//we could capture directly, but doing so breaks GetWindowRgn() and also includes artifacts... + GetWindowRect(hCapture, &rect); + RECT rectCA; GetClientRect(hCapture, &rectCA); + ClientToScreen(hCapture, (POINT*)&rectCA); + rectCA.left = ABS(rectCA.left - rect.left); + rectCA.top = ABS(rectCA.top - rect.top); + rectCA.right += rectCA.left; rectCA.bottom += rectCA.top; /// crop the window to ClientArea - FIBITMAP* dibClient = FIP->FI_Copy(dib,rectCA.left,rectCA.top,rectCA.right,rectCA.bottom); + FIBITMAP* dibClient = FIP->FI_Copy(dib, rectCA.left, rectCA.top, rectCA.right, rectCA.bottom); FIP->FI_Unload(dib); dib = dibClient; } } - if(hForegroundWin){//restore previous foreground window + if (hForegroundWin) {//restore previous foreground window SetForegroundWindow(hForegroundWin); BringWindowToTop(hForegroundWin); } return dib; } -FIBITMAP* CaptureMonitor(const TCHAR* szDevice,const RECT* cropRect/*=NULL*/){ +FIBITMAP* CaptureMonitor(const TCHAR* szDevice, const RECT* cropRect/*=NULL*/) +{ HDC hScrDC; RECT rect; FIBITMAP* dib; /// get screen resolution - if(!szDevice){ - hScrDC = CreateDC(_T("DISPLAY"),NULL,NULL,NULL); - rect.left=GetSystemMetrics(SM_XVIRTUALSCREEN); - rect.top=GetSystemMetrics(SM_YVIRTUALSCREEN); - rect.right=GetSystemMetrics(SM_XVIRTUALSCREEN)+GetSystemMetrics(SM_CXVIRTUALSCREEN); - rect.bottom=GetSystemMetrics(SM_YVIRTUALSCREEN)+GetSystemMetrics(SM_CYVIRTUALSCREEN); - }else{ - hScrDC = CreateDC(szDevice,NULL,NULL,NULL); - rect.left=rect.top=0; - rect.right=GetDeviceCaps(hScrDC,HORZRES); - rect.bottom=GetDeviceCaps(hScrDC,VERTRES); + if (!szDevice) { + hScrDC = CreateDC(_T("DISPLAY"), NULL, NULL, NULL); + rect.left = GetSystemMetrics(SM_XVIRTUALSCREEN); + rect.top = GetSystemMetrics(SM_YVIRTUALSCREEN); + rect.right = GetSystemMetrics(SM_XVIRTUALSCREEN) + GetSystemMetrics(SM_CXVIRTUALSCREEN); + rect.bottom = GetSystemMetrics(SM_YVIRTUALSCREEN) + GetSystemMetrics(SM_CYVIRTUALSCREEN); } - if(cropRect){ - if(cropRect->left > rect.left) rect.left=cropRect->left; - if(cropRect->top > rect.top) rect.top=cropRect->top; - if(cropRect->right < rect.right) rect.right=cropRect->right; - if(cropRect->bottom < rect.bottom) rect.bottom=cropRect->bottom; + else { + hScrDC = CreateDC(szDevice, NULL, NULL, NULL); + rect.left = rect.top = 0; + rect.right = GetDeviceCaps(hScrDC, HORZRES); + rect.bottom = GetDeviceCaps(hScrDC, VERTRES); + } + if (cropRect) { + if (cropRect->left > rect.left) rect.left = cropRect->left; + if (cropRect->top > rect.top) rect.top = cropRect->top; + if (cropRect->right < rect.right) rect.right = cropRect->right; + if (cropRect->bottom < rect.bottom) rect.bottom = cropRect->bottom; } - dib=CreateDIBFromDC(hScrDC,&rect); - ReleaseDC(NULL,hScrDC); + dib = CreateDIBFromDC(hScrDC, &rect); + ReleaseDC(NULL, hScrDC); return dib; } -FIBITMAP* CreateDIBFromDC(HDC hDC,const RECT* rect,HWND hCapture/*=NULL*/){ -///HDC GetDC (NULL) entire desktp -///HDC GetDC (HWND hWnd) client area of the specified window. (may include artifacts) -///HDC GetWindowDC (HWND hWnd) entire window. +FIBITMAP* CreateDIBFromDC(HDC hDC, const RECT* rect, HWND hCapture/*=NULL*/) +{ + ///HDC GetDC (NULL) entire desktp + ///HDC GetDC (HWND hWnd) client area of the specified window. (may include artifacts) + ///HDC GetWindowDC (HWND hWnd) entire window. FIBITMAP* dib;// return value HBITMAP hBitmap; // handles to device-dependent bitmaps HDC hScrDC, hMemDC; // screen DC and memory DC - long width=rect->right-rect->left; - long height=rect->bottom-rect->top; + long width = rect->right - rect->left; + long height = rect->bottom - rect->top; // create a DC for the screen and create // a memory DC compatible to screen DC - if(!(hScrDC=hDC)) hScrDC=GetDC(hCapture); + if (!(hScrDC = hDC)) hScrDC = GetDC(hCapture); hMemDC = CreateCompatibleDC(hScrDC); // create a bitmap compatible with the screen DC - hBitmap = CreateCompatibleBitmap(hScrDC,width,height);//width,height + hBitmap = CreateCompatibleBitmap(hScrDC, width, height);//width,height // select new bitmap into memory DC SelectObject(hMemDC, hBitmap); - if(hCapture && hDC){ - PrintWindow(hCapture,hMemDC,0); - }else{// bitblt screen DC to memory DC - BitBlt(hMemDC,0,0,width,height,hScrDC,rect->left,rect->top,CAPTUREBLT|SRCCOPY); + if (hCapture && hDC) { + PrintWindow(hCapture, hMemDC, 0); + } + else {// bitblt screen DC to memory DC + BitBlt(hMemDC, 0, 0, width, height, hScrDC, rect->left, rect->top, CAPTUREBLT | SRCCOPY); } dib = FIP->FI_CreateDIBFromHBITMAP(hBitmap); //alpha channel from window is always wrong and sometimes even for desktop (Win7, no aero) //coz GDI do not draw all in alpha mode. //we have to create our own new alpha channel. - bool bFixAlpha=true; - bool bInvert=false; - HBRUSH hBr=CreateSolidBrush(RGB(255,255,255));//Create a SolidBrush object for non transparent area - HBITMAP hMask=CreateBitmap(width,height,1,1,NULL);// Create monochrome (1 bit) B+W mask bitmap. - HDC hMaskDC=CreateCompatibleDC(0); - SelectBitmap(hMaskDC,hMask); - HRGN hRgn=CreateRectRgn(0,0,0,0); - if(hCapture && GetWindowRgn(hCapture,hRgn)==ERROR){ - if((GetWindowLongPtr(hCapture,GWL_EXSTYLE)&WS_EX_LAYERED)){ - BYTE bAlpha=0; - COLORREF crKey=0x00000000; - DWORD dwFlags=0; - if(GetLayeredWindowAttributes(hCapture,&crKey,&bAlpha,&dwFlags)) { + bool bFixAlpha = true; + bool bInvert = false; + HBRUSH hBr = CreateSolidBrush(RGB(255, 255, 255));//Create a SolidBrush object for non transparent area + HBITMAP hMask = CreateBitmap(width, height, 1, 1, NULL);// Create monochrome (1 bit) B+W mask bitmap. + HDC hMaskDC = CreateCompatibleDC(0); + SelectBitmap(hMaskDC, hMask); + HRGN hRgn = CreateRectRgn(0, 0, 0, 0); + if (hCapture && GetWindowRgn(hCapture, hRgn) == ERROR) { + if ((GetWindowLongPtr(hCapture, GWL_EXSTYLE)&WS_EX_LAYERED)) { + BYTE bAlpha = 0; + COLORREF crKey = 0x00000000; + DWORD dwFlags = 0; + if (GetLayeredWindowAttributes(hCapture, &crKey, &bAlpha, &dwFlags)) { /// per window transparency (like fading in a whole window) - if((dwFlags&LWA_COLORKEY)){ - SetBkColor(hMemDC,crKey); - BitBlt(hMaskDC,0,0,width,height,hMemDC,rect->left,rect->top,SRCCOPY); - bInvert=true; - }else if((dwFlags&LWA_ALPHA)){ - bFixAlpha=false; + if ((dwFlags&LWA_COLORKEY)) { + SetBkColor(hMemDC, crKey); + BitBlt(hMaskDC, 0, 0, width, height, hMemDC, rect->left, rect->top, SRCCOPY); + bInvert = true; } - }else{//per-pixel transparency (won't use the WM_PAINT) - bFixAlpha=false; + else if ((dwFlags&LWA_ALPHA)) { + bFixAlpha = false; + } + } + else {//per-pixel transparency (won't use the WM_PAINT) + bFixAlpha = false; } - }else{//not layered - fill the window region - SetRectRgn(hRgn,0,0,width,height); - FillRgn(hMaskDC,hRgn,hBr); } - }else{ - if(!hCapture) SetRectRgn(hRgn,0,0,width,height);//client area only, no transparency - FillRgn(hMaskDC,hRgn,hBr); + else {//not layered - fill the window region + SetRectRgn(hRgn, 0, 0, width, height); + FillRgn(hMaskDC, hRgn, hBr); + } + } + else { + if (!hCapture) SetRectRgn(hRgn, 0, 0, width, height);//client area only, no transparency + FillRgn(hMaskDC, hRgn, hBr); } DeleteObject(hRgn); - if(bFixAlpha){ + if (bFixAlpha) { FIBITMAP* dibMask = FIP->FI_CreateDIBFromHBITMAP(hMask); - if(bInvert) FIP->FI_Invert(dibMask); + if (bInvert) FIP->FI_Invert(dibMask); FIBITMAP* dib8 = FIP->FI_ConvertTo8Bits(dibMask); //copy the dib8 alpha mask to dib32 main bitmap - FIP->FI_SetChannel(dib,dib8,FICC_ALPHA); + FIP->FI_SetChannel(dib, dib8, FICC_ALPHA); FIP->FI_Unload(dibMask); FIP->FI_Unload(dib8); } @@ -241,65 +255,66 @@ FIBITMAP* CreateDIBFromDC(HDC hDC,const RECT* rect,HWND hCapture/*=NULL*/){ //clean up DeleteDC(hMemDC); DeleteObject(hBitmap); - if(!hDC) ReleaseDC(NULL, hScrDC); - - #ifdef _DEBUG - switch (FIP->FI_GetImageType(dib)){ - case FIT_UNKNOWN: - OutputDebugStringA("FIBITMAP Type: FIT_UNKNOWN\r\n" ); - break; - case FIT_BITMAP: - OutputDebugStringA("FIBITMAP Type: FIT_BITMAP\r\n" ); - break; - case FIT_UINT16: - OutputDebugStringA("FIBITMAP Type: FIT_UINT16\r\n" ); - break; - case FIT_INT16: - OutputDebugStringA("FIBITMAP Type: FIT_INT16\r\n" ); - break; - case FIT_UINT32: - OutputDebugStringA("FIBITMAP Type: FIT_UINT32\r\n" ); - break; - case FIT_INT32: - OutputDebugStringA("FIBITMAP Type: FIT_INT32\r\n" ); - break; - case FIT_FLOAT: - OutputDebugStringA("FIBITMAP Type: FIT_FLOAT\r\n" ); - break; - case FIT_DOUBLE: - OutputDebugStringA("FIBITMAP Type: FIT_DOUBLE\r\n" ); - break; - case FIT_COMPLEX: - OutputDebugStringA("FIBITMAP Type: FIT_COMPLEX\r\n" ); - break; - case FIT_RGB16: - OutputDebugStringA("FIBITMAP Type: FIT_RGB16\r\n" ); - break; - case FIT_RGBA16: - OutputDebugStringA("FIBITMAP Type: FIT_RGBA16\r\n" ); - break; - case FIT_RGBF: - OutputDebugStringA("FIBITMAP Type: FIT_RGBF\r\n" ); - break; - case FIT_RGBAF: - OutputDebugStringA("FIBITMAP Type: FIT_RGBAF\r\n" ); - break; - default: - OutputDebugStringA("FIBITMAP Type: non detectable image type (error)\r\n" ); - break; + if (!hDC) ReleaseDC(NULL, hScrDC); + +#ifdef _DEBUG + switch (FIP->FI_GetImageType(dib)) { + case FIT_UNKNOWN: + OutputDebugStringA("FIBITMAP Type: FIT_UNKNOWN\r\n"); + break; + case FIT_BITMAP: + OutputDebugStringA("FIBITMAP Type: FIT_BITMAP\r\n"); + break; + case FIT_UINT16: + OutputDebugStringA("FIBITMAP Type: FIT_UINT16\r\n"); + break; + case FIT_INT16: + OutputDebugStringA("FIBITMAP Type: FIT_INT16\r\n"); + break; + case FIT_UINT32: + OutputDebugStringA("FIBITMAP Type: FIT_UINT32\r\n"); + break; + case FIT_INT32: + OutputDebugStringA("FIBITMAP Type: FIT_INT32\r\n"); + break; + case FIT_FLOAT: + OutputDebugStringA("FIBITMAP Type: FIT_FLOAT\r\n"); + break; + case FIT_DOUBLE: + OutputDebugStringA("FIBITMAP Type: FIT_DOUBLE\r\n"); + break; + case FIT_COMPLEX: + OutputDebugStringA("FIBITMAP Type: FIT_COMPLEX\r\n"); + break; + case FIT_RGB16: + OutputDebugStringA("FIBITMAP Type: FIT_RGB16\r\n"); + break; + case FIT_RGBA16: + OutputDebugStringA("FIBITMAP Type: FIT_RGBA16\r\n"); + break; + case FIT_RGBF: + OutputDebugStringA("FIBITMAP Type: FIT_RGBF\r\n"); + break; + case FIT_RGBAF: + OutputDebugStringA("FIBITMAP Type: FIT_RGBAF\r\n"); + break; + default: + OutputDebugStringA("FIBITMAP Type: non detectable image type (error)\r\n"); + break; } BOOL inf = FIP->FI_IsTransparent(dib); OutputDebugStringA(inf ? "FIBITMAP Transparent: true\r\n" : "FIBITMAP Transparent: false\r\n"); - #endif +#endif return dib; } -TCHAR* SaveImage(FREE_IMAGE_FORMAT fif, FIBITMAP* dib, const TCHAR* pszFilename, const TCHAR* pszExt, int flag) { - int ret=0; +TCHAR* SaveImage(FREE_IMAGE_FORMAT fif, FIBITMAP* dib, const TCHAR* pszFilename, const TCHAR* pszExt, int flag) +{ + int ret = 0; TCHAR* pszFile = NULL; TCHAR* FileExt = GetFileExt(pszFilename); - if(!FileExt) { - if(!pszExt) return NULL; + if (!FileExt) { + if (!pszExt) return NULL; mir_tstradd(pszFile, pszFilename); mir_tstradd(pszFile, _T(".")); mir_tstradd(pszFile, pszExt); @@ -308,7 +323,7 @@ TCHAR* SaveImage(FREE_IMAGE_FORMAT fif, FIBITMAP* dib, const TCHAR* pszFilename, mir_tstradd(pszFile, pszFilename); } - if(fif==FIF_UNKNOWN) { + if (fif == FIF_UNKNOWN) { fif = FIP->FI_GetFIFFromFilenameU(pszFile); } @@ -317,56 +332,61 @@ TCHAR* SaveImage(FREE_IMAGE_FORMAT fif, FIBITMAP* dib, const TCHAR* pszFilename, mir_free(FileExt); - if(ret) return pszFile; + if (ret) return pszFile; mir_free(pszFile); return NULL; } //--------------------------------------------------------------------------- -TCHAR* GetFileNameW(const TCHAR* pszPath) { - const TCHAR* slash=_tcsrchr(pszPath,_T('\\')); - if(!slash) slash=_tcsrchr(pszPath,_T('/')); - if(slash) - return mir_t2u(slash+1); +TCHAR* GetFileNameW(const TCHAR* pszPath) +{ + const TCHAR* slash = _tcsrchr(pszPath, _T('\\')); + if (!slash) slash = _tcsrchr(pszPath, _T('/')); + if (slash) + return mir_t2u(slash + 1); else return mir_t2u(pszPath); } -TCHAR* GetFileExtW(const TCHAR* pszPath) { - const TCHAR* slash=_tcsrchr(pszPath,_T('.')); - if(slash) +TCHAR* GetFileExtW(const TCHAR* pszPath) +{ + const TCHAR* slash = _tcsrchr(pszPath, _T('.')); + if (slash) return mir_t2u(slash); return NULL; } -char* GetFileNameA(const TCHAR* pszPath) { - const TCHAR* slash=_tcsrchr(pszPath,_T('\\')); - if(!slash) slash=_tcsrchr(pszPath,_T('/')); - if(slash) - return mir_t2a(slash+1); +char* GetFileNameA(const TCHAR* pszPath) +{ + const TCHAR* slash = _tcsrchr(pszPath, _T('\\')); + if (!slash) slash = _tcsrchr(pszPath, _T('/')); + if (slash) + return mir_t2a(slash + 1); else return mir_t2a(pszPath); } -char* GetFileExtA(const TCHAR* pszPath) { - const TCHAR* slash=_tcsrchr(pszPath,_T('.')); - if(slash) +char* GetFileExtA(const TCHAR* pszPath) +{ + const TCHAR* slash = _tcsrchr(pszPath, _T('.')); + if (slash) return mir_t2a(slash); return NULL; } //--------------------------------------------------------------------------- -BOOL GetEncoderClsid(wchar_t *wchMimeType, CLSID& clsidEncoder) { - UINT uiNum=0; - UINT uiSize=0; - BOOL bOk=FALSE; - Gdiplus::GetImageEncodersSize(&uiNum,&uiSize); - if(uiSize>0){ - Gdiplus::ImageCodecInfo* pImageCodecInfo=(Gdiplus::ImageCodecInfo*)mir_alloc(uiSize); - if(pImageCodecInfo){ - Gdiplus::GetImageEncoders(uiNum,uiSize,pImageCodecInfo); - for( UINT i=0; i<uiNum; ++i){ - if(!mir_wstrcmp(pImageCodecInfo[i].MimeType,wchMimeType)){ - clsidEncoder=pImageCodecInfo[i].Clsid; - bOk=TRUE; +BOOL GetEncoderClsid(wchar_t *wchMimeType, CLSID& clsidEncoder) +{ + UINT uiNum = 0; + UINT uiSize = 0; + BOOL bOk = FALSE; + Gdiplus::GetImageEncodersSize(&uiNum, &uiSize); + if (uiSize > 0) { + Gdiplus::ImageCodecInfo* pImageCodecInfo = (Gdiplus::ImageCodecInfo*)mir_alloc(uiSize); + if (pImageCodecInfo) { + Gdiplus::GetImageEncoders(uiNum, uiSize, pImageCodecInfo); + for (UINT i = 0; i < uiNum; ++i) { + if (!mir_wstrcmp(pImageCodecInfo[i].MimeType, wchMimeType)) { + clsidEncoder = pImageCodecInfo[i].Clsid; + bOk = TRUE; } } mir_free(pImageCodecInfo); @@ -374,36 +394,18 @@ BOOL GetEncoderClsid(wchar_t *wchMimeType, CLSID& clsidEncoder) { } return bOk; } -/* -void SavePNG(HBITMAP hBmp, TCHAR* szFilename) { - Gdiplus::GdiplusStartupInput gdiplusStartupInput; - ULONG_PTR gdiplusToken; - Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); - - Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromHBITMAP(hBmp, (HPALETTE)GetStockObject(DEFAULT_PALETTE) ); - if( pBitmap ) { - // Get the CLSID of the PNG encoder. - CLSID clsidEncoder; - if( GetEncoderClsid(L"image/png", clsidEncoder)) { - LPWSTR pswFile = mir_t2u(szFilename); - pBitmap->Save((const WCHAR*)pswFile, &clsidEncoder, NULL); - mir_free(pswFile); - } - delete pBitmap; - } - Gdiplus::GdiplusShutdown(gdiplusToken); -}*/ -void SaveGIF(HBITMAP hBmp, TCHAR* szFilename) { +void SaveGIF(HBITMAP hBmp, TCHAR* szFilename) +{ Gdiplus::GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); - Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromHBITMAP(hBmp, (HPALETTE)GetStockObject(DEFAULT_PALETTE) ); - if( pBitmap ) { + Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromHBITMAP(hBmp, (HPALETTE)GetStockObject(DEFAULT_PALETTE)); + if (pBitmap) { // Get the CLSID of the GIF encoder. CLSID clsidEncoder; - if( GetEncoderClsid(L"image/gif", clsidEncoder)) { + if (GetEncoderClsid(L"image/gif", clsidEncoder)) { LPWSTR pswFile = mir_t2u(szFilename); pBitmap->Save((const WCHAR*)pswFile, &clsidEncoder, NULL); mir_free(pswFile); @@ -413,34 +415,35 @@ void SaveGIF(HBITMAP hBmp, TCHAR* szFilename) { Gdiplus::GdiplusShutdown(gdiplusToken); } -void SaveTIF(HBITMAP hBmp, TCHAR* szFilename) { -//http://www.codeproject.com/Messages/1406708/How-to-reduce-the-size-of-an-Image-using-GDIplus.aspx +void SaveTIF(HBITMAP hBmp, TCHAR* szFilename) +{ + //http://www.codeproject.com/Messages/1406708/How-to-reduce-the-size-of-an-Image-using-GDIplus.aspx ULONG_PTR gdiplusToken; Gdiplus::GdiplusStartupInput gdiplusStartupInput; Gdiplus::Status stat; Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); - Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromHBITMAP(hBmp, (HPALETTE)GetStockObject(DEFAULT_PALETTE) ); - if( pBitmap ) { + Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromHBITMAP(hBmp, (HPALETTE)GetStockObject(DEFAULT_PALETTE)); + if (pBitmap) { // Get the CLSID of the GIF encoder. CLSID EncCLSID; - if( GetEncoderClsid(L"image/tiff", EncCLSID)) { + if (GetEncoderClsid(L"image/tiff", EncCLSID)) { //--- Create a 2-parameter array, for Compression and for Color Bit depth Gdiplus::EncoderParameters* EncParams = (Gdiplus::EncoderParameters*) malloc(sizeof(Gdiplus::EncoderParameters) + 1 * sizeof(Gdiplus::EncoderParameter)); - // Gdiplus::EncoderParameters pEncoderParameters; + // Gdiplus::EncoderParameters pEncoderParameters; //--- Use LZW Compression instead of Group 4, since it works for color and G4 doesn't - ULONG ulCompression = Gdiplus::EncoderValueCompressionLZW ; - ULONG ulColorDepth = 24L ; - - EncParams->Count = 2 ; - EncParams->Parameter[0].Guid = Gdiplus::EncoderCompression ; - EncParams->Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong ; - EncParams->Parameter[0].NumberOfValues = 1 ; - EncParams->Parameter[0].Value = &ulCompression ; - EncParams->Parameter[1].Guid = Gdiplus::EncoderColorDepth ; - EncParams->Parameter[1].Type = Gdiplus::EncoderParameterValueTypeLong ; - EncParams->Parameter[1].NumberOfValues = 1 ; - EncParams->Parameter[1].Value = &ulColorDepth ; + ULONG ulCompression = Gdiplus::EncoderValueCompressionLZW; + ULONG ulColorDepth = 24L; + + EncParams->Count = 2; + EncParams->Parameter[0].Guid = Gdiplus::EncoderCompression; + EncParams->Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong; + EncParams->Parameter[0].NumberOfValues = 1; + EncParams->Parameter[0].Value = &ulCompression; + EncParams->Parameter[1].Guid = Gdiplus::EncoderColorDepth; + EncParams->Parameter[1].Type = Gdiplus::EncoderParameterValueTypeLong; + EncParams->Parameter[1].NumberOfValues = 1; + EncParams->Parameter[1].Value = &ulColorDepth; LPWSTR pswFile = mir_t2u(szFilename); stat = pBitmap->Save((const WCHAR*)pswFile, &EncCLSID, EncParams); diff --git a/plugins/SendScreenshotPlus/src/Utils.h b/plugins/SendScreenshotPlus/src/Utils.h index 89432753a7..0beeaabd18 100644 --- a/plugins/SendScreenshotPlus/src/Utils.h +++ b/plugins/SendScreenshotPlus/src/Utils.h @@ -44,7 +44,7 @@ extern HWND g_hCapture; extern HBITMAP g_hBitmap, g_hbmMask; //--------------------------------------------------------------------------- -int ComboBox_SelectItemData(HWND hwndCtl, int indexStart, LPARAM data); +int ComboBox_SelectItemData(HWND hwndCtl, LPARAM data); size_t MonitorInfoEnum(MONITORINFOEX* & myMonitors, RECT & virtualScreen); BOOL CALLBACK MonitorInfoEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData); diff --git a/plugins/SendScreenshotPlus/src/ctrl_button.cpp b/plugins/SendScreenshotPlus/src/ctrl_button.cpp index 3211931d70..06fdadea88 100644 --- a/plugins/SendScreenshotPlus/src/ctrl_button.cpp +++ b/plugins/SendScreenshotPlus/src/ctrl_button.cpp @@ -25,7 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define BUTTON_POLLID 100 #define BUTTON_POLLDELAY 50 -typedef struct TMBCtrl{ +typedef struct TMBCtrl +{ HWND hwnd; HANDLE hThemeButton; HANDLE hThemeToolbar; @@ -35,9 +36,9 @@ typedef struct TMBCtrl{ HBITMAP hBitmap; HFONT hFont; // font - DWORD dwStyle; - BYTE bFocus; - + DWORD dwStyle; + BYTE bFocus; + int stateId; // button state int defbutton; // default button int pbState; @@ -54,7 +55,8 @@ static HWND hwndToolTips = NULL; * param: ctl - BTNCTRL structure with the information about the theme to close * return: nothing **/ -static void __fastcall DestroyTheme(BTNCTRL *ctl) { +static void __fastcall DestroyTheme(BTNCTRL *ctl) +{ if (ctl->hThemeButton) { CloseThemeData(ctl->hThemeButton); ctl->hThemeButton = NULL; @@ -71,10 +73,11 @@ static void __fastcall DestroyTheme(BTNCTRL *ctl) { * param: ctl - BTNCTRL structure with the information about the theme to load * return: nothing **/ -static void __fastcall LoadTheme(BTNCTRL *ctl) { +static void __fastcall LoadTheme(BTNCTRL *ctl) +{ DestroyTheme(ctl); - ctl->hThemeButton = OpenThemeData(ctl->hwnd,L"BUTTON"); - ctl->hThemeToolbar = OpenThemeData(ctl->hwnd,L"TOOLBAR"); + ctl->hThemeButton = OpenThemeData(ctl->hwnd, L"BUTTON"); + ctl->hThemeToolbar = OpenThemeData(ctl->hwnd, L"TOOLBAR"); } /** @@ -83,13 +86,14 @@ static void __fastcall LoadTheme(BTNCTRL *ctl) { * param: state - state id for the normal theme button * return: stateID for the flat theme button **/ -static int __fastcall TBStateConvert2Flat(int state) { +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; + 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; } @@ -116,12 +120,12 @@ static void __fastcall PaintIcon(BTNCTRL *ctl, HDC hdcMem, LPWORD ccText, LPRECT 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, + 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); } @@ -129,16 +133,16 @@ static void __fastcall PaintIcon(BTNCTRL *ctl, HDC hdcMem, LPWORD ccText, LPRECT // 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.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, + 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); } @@ -161,10 +165,10 @@ static void __fastcall PaintThemeButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClien // 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; + ? (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); @@ -175,9 +179,9 @@ static void __fastcall PaintThemeButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClien // draw themed button background if (ctl->hThemeButton) { int state = IsWindowEnabled(ctl->hwnd) - ? (ctl->stateId == PBS_NORMAL && ctl->defbutton - ? PBS_DEFAULTED - : ctl->stateId) + ? (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))) @@ -186,7 +190,7 @@ static void __fastcall PaintThemeButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClien DrawThemeBackground(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, state, rcClient, rcClient); } } - + // calculate text rect { RECT sizeText; @@ -196,7 +200,7 @@ static void __fastcall PaintThemeButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClien if (ccText > 0) { hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont); - + GetThemeTextExtent( ctl->hThemeButton, hdcMem, @@ -207,10 +211,10 @@ static void __fastcall PaintThemeButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClien DST_PREFIXTEXT, NULL, &sizeText); - + if (ctl->cHot) { RECT rcHot; - + GetThemeTextExtent(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, @@ -220,7 +224,7 @@ static void __fastcall PaintThemeButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClien DST_PREFIXTEXT, NULL, &rcHot); - + sizeText.right -= (rcHot.right - rcHot.left); } SelectObject(hdcMem, hOldFont); @@ -236,7 +240,7 @@ static void __fastcall PaintThemeButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClien } PaintIcon(ctl, hdcMem, &ccText, rcClient, &rcText); // draw text - if (ccText > 0 && ctl->hThemeButton) { + 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); @@ -260,7 +264,7 @@ static void __fastcall PaintButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClient) // 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 { @@ -278,16 +282,16 @@ static void __fastcall PaintButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClient) 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); + 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); + 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; + 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) { @@ -308,7 +312,7 @@ static void __fastcall PaintButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClient) GetTextExtentPoint32(hdcMem, szText, ccText, &sizeText); if (ctl->cHot) { SIZE sizeHot; - + GetTextExtentPoint32A(hdcMem, "&", 1, &sizeHot); sizeText.cx -= sizeHot.cx; } @@ -325,20 +329,20 @@ static void __fastcall PaintButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClient) PaintIcon(ctl, hdcMem, &ccText, rcClient, &rcText); // draw text - if (ccText > 0) { + if (ccText > 0) { HFONT hOldFont; hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont); SetBkMode(hdcMem, TRANSPARENT); - SetTextColor(hdcMem, - IsWindowEnabled(ctl->hwnd) || !ctl->hThemeButton + SetTextColor(hdcMem, + IsWindowEnabled(ctl->hwnd) || !ctl->hThemeButton ? ctl->stateId == PBS_HOT - ? GetSysColor(COLOR_HOTLIGHT) - : GetSysColor(COLOR_BTNTEXT) - : GetSysColor(COLOR_GRAYTEXT)); + ? GetSysColor(COLOR_HOTLIGHT) + : GetSysColor(COLOR_BTNTEXT) + : GetSysColor(COLOR_GRAYTEXT)); - DrawState(hdcMem, NULL, NULL, (LPARAM)szText, 0, + 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); @@ -354,9 +358,10 @@ static void __fastcall PaintButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClient) * lParam - message specific parameter * return: message specific **/ -static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, LPARAM lParam) { +static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ LPBTNCTRL bct = (LPBTNCTRL)GetWindowLongPtr(hwndBtn, 0); - + switch (uMsg) { case WM_NCCREATE: { @@ -374,9 +379,11 @@ static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, L bct->arrow = GetIconBtn(ICO_BTN_DOWNARROW); LoadTheme(bct); SetWindowLongPtr(hwndBtn, 0, (LONG_PTR)bct); - if (cs->lpszName) SetWindowText(hwndBtn, cs->lpszName); - return TRUE; + if (cs->lpszName) + SetWindowText(hwndBtn, cs->lpszName); } + return TRUE; + case WM_DESTROY: if (bct) { mir_cslock lck(csTips); @@ -401,6 +408,7 @@ static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, L } SetWindowLongPtr(hwndBtn, 0, 0); break; + case WM_SETTEXT: bct->cHot = 0; if ((LPTSTR)lParam) { @@ -416,6 +424,7 @@ static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, L 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) { @@ -429,14 +438,17 @@ static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, L return 0; } break; - case WM_THEMECHANGED: + + 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: { @@ -446,7 +458,7 @@ static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, L HBITMAP hbmMem; HDC hOld; RECT rcClient; - + if (hdcPaint = BeginPaint(hwndBtn, &ps)) { GetClientRect(bct->hwnd, &rcClient); hdcMem = CreateCompatibleDC(hdcPaint); @@ -464,11 +476,12 @@ static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, L BitBlt(hdcPaint, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, hdcMem, 0, 0, SRCCOPY); SelectObject(hdcMem, hOld); DeleteObject(hbmMem); - DeleteDC(hdcMem); + DeleteDC(hdcMem); EndPaint(hwndBtn, &ps); } } return 0; + case BM_SETIMAGE: if (wParam == IMAGE_ICON) { bct->hIcon = (HICON)lParam; @@ -486,6 +499,7 @@ static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, L InvalidateRect(bct->hwnd, NULL, TRUE); } break; + case BM_SETCHECK: if (!(bct->dwStyle & MBS_PUSHBUTTON)) break; if (wParam == BST_CHECKED) { @@ -498,15 +512,18 @@ static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, L } 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 != 0); InvalidateRect(bct->hwnd, NULL, TRUE); break; + case BUTTONADDTOOLTIP: - if (wParam) { + if (wParam) { mir_cslock lck(csTips); if (!hwndToolTips) hwndToolTips = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL); @@ -522,9 +539,9 @@ static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, L if (SendMessage(hwndToolTips, TTM_GETTOOLINFOW, 0, (LPARAM)&ti)) { SendMessage(hwndToolTips, TTM_DELTOOLW, 0, (LPARAM)&ti); } - ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS; + ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS; ti.uId = (UINT_PTR)bct->hwnd; - ti.lpszText=(LPWSTR)wParam; + ti.lpszText = (LPWSTR)wParam; SendMessage(hwndToolTips, TTM_ADDTOOLW, 0, (LPARAM)&ti); } else { @@ -538,47 +555,53 @@ static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, L if (SendMessage(hwndToolTips, TTM_GETTOOLINFOA, 0, (LPARAM)&ti)) { SendMessage(hwndToolTips, TTM_DELTOOLA, 0, (LPARAM)&ti); } - ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS; + ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS; ti.uId = (UINT_PTR)bct->hwnd; - ti.lpszText=(LPSTR)wParam; + ti.lpszText = (LPSTR)wParam; SendMessage(hwndToolTips, TTM_ADDTOOLA, 0, (LPARAM)&ti); } } break; + case BUTTONTRANSLATE: - { - TCHAR szButton[MAX_PATH]; - GetWindowText(bct->hwnd, szButton, _countof(szButton)); - SetWindowText(bct->hwnd, TranslateTS(szButton)); - } + TCHAR szButton[MAX_PATH]; + GetWindowText(bct->hwnd, szButton, _countof(szButton)); + 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 BYTE bPressed = bct->stateId == PBS_PRESSED; @@ -595,6 +618,7 @@ static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, L InvalidateRect(bct->hwnd, NULL, TRUE); } break; + case WM_MOUSEMOVE: if (bct->stateId == PBS_NORMAL) { bct->stateId = PBS_HOT; @@ -603,6 +627,7 @@ static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, L // 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; @@ -621,27 +646,28 @@ static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, L } return DefWindowProc(hwndBtn, uMsg, wParam, lParam); } -static bool g_init=false; -void CtrlButtonUnloadModule() + +static bool g_init = false; + +void CtrlButtonUnloadModule() { - if(!g_init) return; - g_init=false; + if (!g_init) return; + g_init = false; UnregisterClass(UINFOBUTTONCLASS, g_hSendSS); } void CtrlButtonLoadModule()/// @fixme : compatibility with UInfoEx is everything but perfect... we get a huge problem if UInfoEx is unloaded... { - if(ServiceExists("UserInfo/vCard/Export")) return; + if (ServiceExists("UserInfo/vCard/Export")) return; WNDCLASSEX wc; - g_init=true; - + g_init = true; + memset(&wc, 0, 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; + 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); } - diff --git a/plugins/SendScreenshotPlus/src/dlg_msgbox.cpp b/plugins/SendScreenshotPlus/src/dlg_msgbox.cpp index 34d9f65c4f..6f1653590c 100644 --- a/plugins/SendScreenshotPlus/src/dlg_msgbox.cpp +++ b/plugins/SendScreenshotPlus/src/dlg_msgbox.cpp @@ -27,7 +27,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MODNAME SZ_SENDSS #define ICO_COMMON_MAIN 0xFFFF #define ICO_DLG_DETAILS 0xFFFF -HICON Skin_GetIcon_SendSS(unsigned short id, BOOL big=0) + +HICON Skin_GetIcon_SendSS(unsigned short id) { if(id==0xFFFF) return GetIcon(ICO_MAIN); @@ -81,7 +82,7 @@ static HICON MsgLoadIcon(LPMSGBOX pMsgBox) hIcon = pMsgBox->hiMsg; break; - // default windows icons + // default windows icons case MB_ICON_ERROR: case MB_ICON_QUESTION: case MB_ICON_WARNING: @@ -92,7 +93,7 @@ static HICON MsgLoadIcon(LPMSGBOX pMsgBox) } break; - // no icon + // no icon default: hIcon = NULL; } @@ -210,7 +211,7 @@ static INT_PTR CALLBACK MsgBoxProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM l // set infobar's logo icon SendDlgItemMessage(hDlg, ICO_DLGLOGO, STM_SETIMAGE, IMAGE_ICON, - (pMsgBox->hiLogo ? (LPARAM)pMsgBox->hiLogo : (LPARAM)IcoLib_GetIcon(ICO_DLG_DETAILS,TRUE))); + (pMsgBox->hiLogo ? (LPARAM)pMsgBox->hiLogo : (LPARAM)IcoLib_GetIcon(ICO_DLG_DETAILS))); // enable headerbar ShowWindow(GetDlgItem(hDlg, TXT_NAME), SW_SHOW); @@ -240,43 +241,43 @@ static INT_PTR CALLBACK MsgBoxProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM l if (HDC hDC = GetDC(hDlg)) { POINT mpt = { 0, 0 }; RECT ws = { 0, 0, 0, 0 }; - int txtWidth=0, txtHeight=0, needX, needY; + int txtWidth = 0, txtHeight = 0, needX, needY; RECT rcDlg; SIZE ts; LPTSTR h, rs; SelectObject(hDC, hNormalFont); // get message text width and height - if(pMsgBox->ptszMsg) for (rs=h=pMsgBox->ptszMsg; ; ++h) { - if (*h=='\n' || !*h) { - GetTextExtentPoint32(hDC, rs, h-rs, &ts); + if (pMsgBox->ptszMsg) for (rs = h = pMsgBox->ptszMsg;; ++h) { + if (*h == '\n' || !*h) { + GetTextExtentPoint32(hDC, rs, h - rs, &ts); if (ts.cx > txtWidth) txtWidth = ts.cx; txtHeight += ts.cy; if (!*h) break; - rs = h+1; + rs = h + 1; } } // increase width if info text requires more - if((pMsgBox->uType&MB_INFOBAR) && pMsgBox->ptszInfoText && *pMsgBox->ptszInfoText){ + if ((pMsgBox->uType&MB_INFOBAR) && pMsgBox->ptszInfoText && *pMsgBox->ptszInfoText) { int multiline = 0; - RECT rcico; GetClientRect(GetDlgItem(hDlg,ICO_DLGLOGO), &rcico); - rcico.right = rcico.right*100/66; // padding - for(rs=h=pMsgBox->ptszInfoText; ; ++h) { - if (*h=='\n' || !*h) { - GetTextExtentPoint32(hDC, rs, h-rs, &ts); + RECT rcico; GetClientRect(GetDlgItem(hDlg, ICO_DLGLOGO), &rcico); + rcico.right = rcico.right * 100 / 66; // padding + for (rs = h = pMsgBox->ptszInfoText;; ++h) { + if (*h == '\n' || !*h) { + GetTextExtentPoint32(hDC, rs, h - rs, &ts); ts.cx += rcico.right; if (ts.cx > txtWidth) txtWidth = ts.cx; if (!*h) break; - rs = h+1; + rs = h + 1; ++multiline; } } - if(!multiline) - SetWindowLongPtr(GetDlgItem(hDlg,TXT_NAME), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hDlg,TXT_NAME), GWL_STYLE)|SS_CENTERIMAGE); + if (!multiline) + SetWindowLongPtr(GetDlgItem(hDlg, TXT_NAME), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hDlg, TXT_NAME), GWL_STYLE) | SS_CENTERIMAGE); } ReleaseDC(hDlg, hDC); @@ -285,8 +286,8 @@ static INT_PTR CALLBACK MsgBoxProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM l GetWindowRect(GetDlgItem(hDlg, TXT_MESSAGE), &ws); needX = txtWidth - (ws.right - ws.left) - icoWidth; needY = max(0, txtHeight - (ws.bottom - ws.top) + 5); - rcDlg.left -= needX/2; rcDlg.right += needX/2; - rcDlg.top -= (needY-InfoBarHeight)/2; rcDlg.bottom += (needY-InfoBarHeight)/2; + rcDlg.left -= needX / 2; rcDlg.right += needX / 2; + rcDlg.top -= (needY - InfoBarHeight) / 2; rcDlg.bottom += (needY - InfoBarHeight) / 2; // resize dialog window MoveWindow(hDlg, rcDlg.left, rcDlg.top, rcDlg.right - rcDlg.left, rcDlg.bottom - rcDlg.top, FALSE); @@ -492,7 +493,7 @@ static INT_PTR CALLBACK MsgBoxProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM l * this set call function in wait stait and do not freece miranda main thread * the window is outside the desktop */ -static INT_PTR CALLBACK MsgBoxPop(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +static INT_PTR CALLBACK MsgBoxPop(HWND hDlg, UINT uMsg, WPARAM, LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: @@ -597,7 +598,8 @@ static INT_PTR CALLBACK MsgBoxPop(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lP * * @return TRUE, FALSE, IDOK, IDYES, IDALL, IDNO or IDCANCEL **/ -static LRESULT CALLBACK PopupProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) + +LRESULT CALLBACK PopupProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case UM_POPUPACTION: @@ -645,7 +647,7 @@ static LRESULT CALLBACK PopupProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lP * @return The function returns the ID of the clicked button (IDOK, IDCANCEL, ...) * or -1 on error. **/ -INT_PTR MsgBoxService(WPARAM wParam, LPARAM lParam) +INT_PTR MsgBoxService(WPARAM, LPARAM lParam) { LPMSGBOX pMsgBox = (LPMSGBOX)lParam; @@ -705,7 +707,7 @@ INT_PTR CALLBACK MsgErr(HWND hParent, LPCTSTR pszFormat, ...) mir_vsntprintf(tszMsg, _countof(tszMsg), TranslateTS(pszFormat), vl); va_end(vl); - MSGBOX mb = {0}; + MSGBOX mb = { 0 }; mb.cbSize = sizeof(MSGBOX); mb.hParent = hParent; mb.hiLogo = IcoLib_GetIcon(ICO_COMMON_MAIN); diff --git a/plugins/SendScreenshotPlus/src/mir_string.cpp b/plugins/SendScreenshotPlus/src/mir_string.cpp index a363f21415..3cf4a76138 100644 --- a/plugins/SendScreenshotPlus/src/mir_string.cpp +++ b/plugins/SendScreenshotPlus/src/mir_string.cpp @@ -30,36 +30,36 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //---------------------------------------------------------------------------
void mir_stradd(char* &pszDest, const char* pszSrc)
{
- if(!pszSrc)
+ if (!pszSrc)
return;
- if(!pszDest)
+ if (!pszDest)
pszDest = mir_strdup(pszSrc);
else {
- size_t lenDest = mir_strlen(pszDest);
- size_t lenSrc = mir_strlen(pszSrc);
+ size_t lenDest = mir_strlen(pszDest);
+ size_t lenSrc = mir_strlen(pszSrc);
size_t lenNew = lenDest + lenSrc + 1;
- pszDest = (char *) mir_realloc(pszDest, sizeof(char)* lenNew);
+ pszDest = (char *)mir_realloc(pszDest, sizeof(char)* lenNew);
mir_strcpy(pszDest + lenDest, pszSrc);
- pszDest[lenNew-1] = 0;
+ pszDest[lenNew - 1] = 0;
}
}
void mir_wstradd(wchar_t* &pszDest, const wchar_t* pszSrc)
{
- if(!pszSrc)
+ if (!pszSrc)
return;
- if(!pszDest)
+ if (!pszDest)
pszDest = mir_wstrdup(pszSrc);
else {
- size_t lenDest = mir_wstrlen(pszDest);
- size_t lenSrc = mir_wstrlen(pszSrc);
+ size_t lenDest = mir_wstrlen(pszDest);
+ size_t lenSrc = mir_wstrlen(pszSrc);
size_t lenNew = lenDest + lenSrc + 1;
- pszDest = (wchar_t *) mir_realloc(pszDest, sizeof(wchar_t)*lenNew);
+ pszDest = (wchar_t *)mir_realloc(pszDest, sizeof(wchar_t)*lenNew);
mir_wstrcpy(pszDest + lenDest, pszSrc);
- pszDest[lenNew-1] = 0;
+ pszDest[lenNew - 1] = 0;
}
}
diff --git a/plugins/SendScreenshotPlus/src/stdafx.h b/plugins/SendScreenshotPlus/src/stdafx.h index cec50a38c3..f5f13d210d 100644 --- a/plugins/SendScreenshotPlus/src/stdafx.h +++ b/plugins/SendScreenshotPlus/src/stdafx.h @@ -28,7 +28,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _GLOBAL_H_ #define _GLOBAL_H_ -#define _CRT_SECURE_NO_WARNINGS #define OEMRESOURCE #include <windows.h> |