/* Поток для загрузки музыки в плейлист */ DWORD WINAPI Thread(LPVOID lp) { HDROP hDrop = (HDROP)lp; CHAR szFileName[MAX_PATH]; TCHAR buff[MAX_PATH]; DWORD dwCount = DragQueryFileA(hDrop, 0xFFFFFFFF, szFileName, MAX_PATH); //Определение количества загружаемых песен for (INT i = 0; i < dwCount; i++) { DragQueryFileA(hDrop, i, szFileName, MAX_PATH); //Определение пути к файлу INT len = strlen(szFileName); CHAR buffFormat[4]; //Формат песни INT j = 0; //для прохода по буферу формата песни for (INT i = len - 4; i < len; i++) { buffFormat[j] = szFileName[i]; j++; } if (me_strcmp(".mp3", buffFormat)) { HSTREAM stream = BASS_StreamCreateFile(0, szFileName, 0, 0, 0); //Создание потока mbstowcs(buff, szFileName, MAX_PATH); //преобразование CHAR to TCHAR DlgPlayList::_this->addSongToPlayList(stream, buff); //Добавление песни в плейлист } } DragFinish(hDrop); return FALSE; }
static LRESULT WINAPI drop_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch (msg) { case WM_DROPFILES: { HDROP hDrop = (HDROP)wparam; char filename[MAX_PATH] = "dummy"; UINT num; num = DragQueryFileA(hDrop, 0xffffffff, NULL, 0); ok(num == 1, "expected 1, got %u\n", num); num = DragQueryFileA(hDrop, 0xffffffff, (char*)0xdeadbeef, 0xffffffff); ok(num == 1, "expected 1, got %u\n", num); num = DragQueryFileA(hDrop, 0, filename, sizeof(filename)); ok(num == strlen(DROPTEST_FILENAME), "got %u\n", num); ok(!strcmp(filename, DROPTEST_FILENAME), "got %s\n", filename); DragFinish(hDrop); return 0; } } return DefWindowProcA(hwnd, msg, wparam, lparam); }
/************************************************************************* * DragQueryFileW [SHELL32.@] */ UINT WINAPI DragQueryFileW( HDROP hDrop, UINT lFile, LPWSTR lpszwFile, UINT lLength) { LPWSTR lpwDrop; UINT i = 0; DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop); TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength); if(!lpDropFileStruct) goto end; lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles); if(lpDropFileStruct->fWide == FALSE) { LPSTR lpszFileA = NULL; if(lpszwFile) { lpszFileA = (LPSTR)HeapAlloc(GetProcessHeap(), 0, lLength); if(lpszFileA == NULL) { goto end; } } i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength); if(lpszFileA) { MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength); HeapFree(GetProcessHeap(), 0, lpszFileA); } goto end; } i = 0; while (i++ < lFile) { while (*lpwDrop++); /* skip filename */ if (!*lpwDrop) { i = (lFile == 0xFFFFFFFF) ? i : 0; goto end; } } i = wcslen(lpwDrop); if ( !lpszwFile) goto end; /* needed buffer size */ lstrcpynW (lpszwFile, lpwDrop, lLength); end: GlobalUnlock(hDrop); return i; }
HRESULT ipcGetFiles(THeaderIPC *pipch, IDataObject* pDataObject, MCONTACT hContact) { FORMATETC fet; fet.cfFormat = CF_HDROP; fet.ptd = NULL; fet.dwAspect = DVASPECT_CONTENT; fet.lindex = -1; fet.tymed = TYMED_HGLOBAL; STGMEDIUM stgm; HRESULT hr = pDataObject->GetData(&fet, &stgm); if (hr == S_OK) { // FIX, actually lock the global object and get a pointer HANDLE hDrop = GlobalLock(stgm.hGlobal); if (hDrop != 0) { // get the maximum number of files UINT iFile, iFileMax = DragQueryFileA((HDROP)stgm.hGlobal, -1, NULL, 0); for (iFile = 0; iFile < iFileMax; iFile++) { // get the size of the file path int cbSize = DragQueryFileA((HDROP)stgm.hGlobal, iFile, NULL, 0); // get the buffer TSlotIPC *pct = ipcAlloc(pipch, cbSize + 1); // including null term // allocated? if (pct == NULL) break; // store the hContact pct->hContact = hContact; // copy it to the buffer DragQueryFileA((HDROP)stgm.hGlobal, iFile, LPSTR(pct) + sizeof(TSlotIPC), pct->cbStrSection); } // store the number of files pipch->Slots = iFile; GlobalUnlock(stgm.hGlobal); } // if hDrop check // release the mediumn the lock may of failed ReleaseStgMedium(&stgm); } return hr; }
BOOL OnDropFiles( HDROP hDrop, ThumbInfo *pThumb ) { UINT nDroppedItemsCount = DragQueryFile( hDrop, 0xFFFFFFFF, NULL, 0); char **ppDroppedItems = ( char** )malloc( sizeof(char*)*( nDroppedItemsCount + 1)); if ( ppDroppedItems == NULL ) { return FALSE; } ppDroppedItems[ nDroppedItemsCount ] = NULL; char szFilename[MAX_PATH]; for (UINT iItem = 0; iItem < nDroppedItemsCount; ++iItem ) { DragQueryFileA( hDrop, iItem, szFilename, sizeof( szFilename )); ppDroppedItems[ iItem ] = _strdup( szFilename ); } UINT nFilesCount = CountDroppedFiles( ppDroppedItems, nDroppedItemsCount ); char **ppFiles = ( char** )malloc( sizeof( char *)* ( nFilesCount+1)); BOOL bSuccess = FALSE; if (ppFiles != NULL) { ppFiles[nFilesCount] = NULL; ProcessDroppedItems(ppDroppedItems, nDroppedItemsCount, ppFiles); bSuccess = (BOOL)CallService(MS_CLIST_CONTACTFILESDROPPED, (WPARAM)pThumb->hContact, (LPARAM)ppFiles); for (UINT iItem = 0; iItem < nFilesCount ; ++iItem ) free(ppFiles[iItem]); free(ppFiles); } // Cleanup for (UINT iItem = 0; ppDroppedItems[ iItem ]; ++iItem ) { free( ppDroppedItems[ iItem ] ); } free( ppDroppedItems ); return bSuccess; }
void CViewer2Dlg::OnDropFiles(HDROP hDropInfo) { HDROP hdrop = hDropInfo; char filePath[ MAX_PATH]; const UINT size = DragQueryFileA(hdrop, 0, filePath, MAX_PATH); if (size == 0) return;// handle error... m_pView->LoadModel(filePath); wstring wstr = common::str2wstr(filePath); CString str = wstr.c_str(); m_FileList.InsertItem(m_FileList.GetItemCount(), str); CDialogEx::OnDropFiles(hDropInfo); }
UINT DragQueryFileUTF8(HDROP hDrop, UINT idx, char *buf, UINT bufsz) { if (buf && bufsz && idx!=-1 AND_IS_NOT_WIN9X) { const UINT reqsz = DragQueryFileW(hDrop,idx,NULL,0); WIDETOMB_ALLOC(wbuf, reqsz+32); if (wbuf) { UINT rv=DragQueryFileW(hDrop,idx,wbuf,(int)(wbuf_size/sizeof(WCHAR))); if (rv) { if (!WideCharToMultiByte(CP_UTF8,0,wbuf,-1,buf,bufsz,NULL,NULL) && GetLastError()==ERROR_INSUFFICIENT_BUFFER) buf[bufsz-1]=0; } WIDETOMB_FREE(wbuf); return rv; } } return DragQueryFileA(hDrop,idx,buf,bufsz); }
int DragQueryFileUTF8(HDROP hDrop, int idx, char *buf, int bufsz) { if (buf && bufsz && idx!=-1 && GetVersion()< 0x80000000) { int reqsz = DragQueryFileW(hDrop,idx,NULL,0)+32; WIDETOMB_ALLOC(wbuf, reqsz); if (wbuf) { int rv=DragQueryFileW(hDrop,idx,wbuf,wbuf_size/sizeof(WCHAR)); if (rv) { if (!WideCharToMultiByte(CP_UTF8,0,wbuf,-1,buf,bufsz,NULL,NULL) && GetLastError()==ERROR_INSUFFICIENT_BUFFER) buf[bufsz-1]=0; } WIDETOMB_FREE(wbuf); return rv; } } return DragQueryFileA(hDrop,idx,buf,bufsz); }
/* MAKE_EXPORT DragQueryFileW_new=DragQueryFileW */ UINT WINAPI DragQueryFileW_new(HDROP hDrop, UINT iFile, LPWSTR lpszFileW, UINT cch) { UINT ret; ALLOC_A(lpszFile, cch * 2); ret = DragQueryFileA(hDrop, iFile, lpszFileA, cch); if (ret && lpszFileA && iFile != 0xffffffff) { DWORD lasterr = GetLastError(); ret = AtoW(lpszFile, cch); if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER) ret = cch; if (ret) ret--; SetLastError(lasterr); } return ret; }
void cViewer::MessageProc( UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DROPFILES: { HDROP hdrop = (HDROP)wParam; char filePath[ MAX_PATH]; const UINT size = DragQueryFileA(hdrop, 0, filePath, MAX_PATH); if (size == 0) return;// handle error... m_filePath = filePath; m_model->Create(filePath); } break; case WM_MOUSEWHEEL: { int fwKeys = GET_KEYSTATE_WPARAM(wParam); int zDelta = GET_WHEEL_DELTA_WPARAM(wParam); dbg::Print( "%d %d", fwKeys, zDelta); Vector3 dir = m_lookAtPos - m_camPos; dir.Normalize(); float zoomLen = 50; if (fwKeys & 0x4) zoomLen = 1; m_camPos += (zDelta<0)? dir*-zoomLen : dir*zoomLen; UpdateCamera(); } break; case WM_KEYDOWN: switch (wParam) { case VK_F5: // Refresh { if (m_filePath.empty()) return; m_model->Create(m_filePath); } break; case VK_BACK: // 회전 행렬 초기화. m_rotateTm.SetIdentity(); m_model->SetTM(m_rotateTm); break; case VK_TAB: { static bool flag = false; graphic::GetDevice()->SetRenderState(D3DRS_CULLMODE, flag); graphic::GetDevice()->SetRenderState(D3DRS_FILLMODE, flag? D3DFILL_SOLID : D3DFILL_WIREFRAME); flag = !flag; } break; } break; case WM_LBUTTONDOWN: { m_LButtonDown = true; m_curPos.x = LOWORD(lParam); m_curPos.y = HIWORD(lParam); } break; case WM_LBUTTONUP: m_LButtonDown = false; break; case WM_RBUTTONDOWN: { m_RButtonDown = true; m_curPos.x = LOWORD(lParam); m_curPos.y = HIWORD(lParam); } break; case WM_RBUTTONUP: m_RButtonDown = false; break; case WM_MOUSEMOVE: if (m_LButtonDown) { POINT pos = {LOWORD(lParam), HIWORD(lParam)}; const int x = pos.x - m_curPos.x; const int y = pos.y - m_curPos.y; m_curPos = pos; Matrix44 mat1; mat1.SetRotationY( -x * 0.01f ); Matrix44 mat2; mat2.SetRotationX( -y * 0.01f ); m_rotateTm *= (mat1 * mat2); } else if (m_RButtonDown) { POINT pos = {LOWORD(lParam), HIWORD(lParam)}; const int x = pos.x - m_curPos.x; const int y = pos.y - m_curPos.y; m_curPos = pos; { // rotate Y-Axis Quaternion q(Vector3(0,1,0), x * 0.005f); Matrix44 m = q.GetMatrix(); m_camPos *= m; } { // rotate X-Axis Quaternion q(Vector3(1,0,0), y * 0.005f); Matrix44 m = q.GetMatrix(); m_camPos *= m; } UpdateCamera(); } break; } }
/********************************************************************** * Functions *********************************************************************/ BOOL CALLBACK IH_DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_INITDIALOG: { g_HWND=hwndDlg; EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_INLINE), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_COPY), FALSE); } return TRUE; case WM_HELP: { char id[10]=""; sprintf(id, "%d", IDS_HELPINLINE); SetEnvironmentVariableA("HELPID", id); SetEnvironmentVariableA("HELPTITLE", "Inline Help"); DialogBox(hInst, MAKEINTRESOURCE(DLG_HELP), hwndDlg, DlgHelp); } return TRUE; case WM_BROWSE: { strcpy(g_szFileName, (const char*)wParam); //Retrieve the directory of the file. int i=strlen(g_szFileName)-1; int j=0; while(g_szFileName[i]!='\\') { i--; j++; } strncpy(g_szTargetDir, g_szFileName, strlen(g_szFileName)-j-1); //Retrieve stuff. EnableWindow(GetDlgItem(g_HWND, IDC_BTN_INLINE), FALSE); EnableWindow(GetDlgItem(g_HWND, IDC_BTN_COPY), FALSE); SendDlgItemMessageA(g_HWND, IDC_EDT_OEP, EM_SETREADONLY, 0, 0); //Enable change of OEP... DragAcceptFiles(g_HWND, FALSE); g_FileIsDll=IH_Debugger(g_szFileName, &g_TargetData, IH_DebugEnd_Callback, IH_ErrorMessageCallback); } return TRUE; case WM_DROPFILES: { //Get the dropped file name. DragQueryFileA((HDROP)wParam, 0, g_szFileName, 256); //Retrieve the directory of the file. int i=strlen(g_szFileName)-1; int j=0; while(g_szFileName[i]!='\\') { i--; j++; } strncpy(g_szTargetDir, g_szFileName, strlen(g_szFileName)-j-1); //Retrieve stuff. EnableWindow(GetDlgItem(g_HWND, IDC_BTN_INLINE), FALSE); EnableWindow(GetDlgItem(g_HWND, IDC_BTN_COPY), FALSE); SendDlgItemMessageA(g_HWND, IDC_EDT_OEP, EM_SETREADONLY, 0, 0); //Enable change of OEP... DragAcceptFiles(g_HWND, FALSE); g_FileIsDll=IH_Debugger(g_szFileName, &g_TargetData, IH_DebugEnd_Callback, IH_ErrorMessageCallback); } return TRUE; case WM_COMMAND: { switch(LOWORD(wParam)) { case IDC_BTN_INLINE: { NoFocus(); if(!(g_TargetData.EmptyEntry)) { MessageBoxA(hwndDlg, "You need to specify the place to start the inline...", "N00B!", MB_ICONERROR); return TRUE; } char patch_filename[256]=""; patch_filename[0]=0; OPENFILENAME ofstruct; memset(&ofstruct, 0, sizeof(ofstruct)); ofstruct.lStructSize=sizeof(ofstruct); ofstruct.hwndOwner=hwndDlg; ofstruct.hInstance=hInst; if(!g_FileIsDll) ofstruct.lpstrFilter="Executable files (*.exe)\0*.exe\0\0"; else ofstruct.lpstrFilter="Executable files (*.dll)\0*.dll\0\0"; ofstruct.lpstrFile=patch_filename; ofstruct.nMaxFile=256; ofstruct.lpstrInitialDir=g_szTargetDir; ofstruct.lpstrTitle="Save file"; if(!g_FileIsDll) ofstruct.lpstrDefExt="exe"; else ofstruct.lpstrDefExt="dll"; ofstruct.Flags=OFN_EXTENSIONDIFFERENT|OFN_HIDEREADONLY|OFN_NONETWORKBUTTON|OFN_OVERWRITEPROMPT; GetSaveFileName(&ofstruct); if(!patch_filename[0]) { MessageBoxA(hwndDlg, "You must select a file...", "Warning", MB_ICONWARNING); return TRUE; } CopyFileA(g_szFileName, patch_filename, FALSE); SetPE32Data(patch_filename, 0, UE_OEP, g_TargetData.EmptyEntry-g_TargetData.ImageBase); long newflags=(long)GetPE32Data(patch_filename, g_TargetData.EntrySectionNumber, UE_SECTIONFLAGS); SetPE32Data(patch_filename, g_TargetData.EntrySectionNumber, UE_SECTIONFLAGS, (newflags|0x80000000)); IH_GenerateAsmCode(g_codeText, g_TargetData); CopyToClipboard(g_codeText); MessageBoxA(hwndDlg, "1) Open the file you just saved with OllyDbg\n2) Open Multimate Assembler v1.5+\n3) Paste the code\n4) Modify the code to do something with the Security DLL\n5) Save the patched file with OllyDbg\n6) Enjoy!", "Instructions", MB_ICONINFORMATION); } return TRUE; case IDC_EDT_FREESPACE: { char free_temp[10]=""; GetDlgItemTextA(hwndDlg, IDC_EDT_FREESPACE, free_temp, 10); sscanf(FormatTextHex(free_temp), "%X", &(g_TargetData.EmptyEntry)); } return TRUE; case IDC_BTN_COPY: { NoFocus(); if(g_codeText[0]) { IH_GenerateAsmCode(g_codeText, g_TargetData); CopyToClipboard(g_codeText); MessageBoxA(hwndDlg, "Code copied to clipboard!", "Yay!", MB_ICONINFORMATION); } else MessageBoxA(hwndDlg, "There is no code to copy, please load a file first...", "Error!", MB_ICONERROR); } return TRUE; case IDC_BTN_PLUGINS: { NoFocus(); PLUGFUNC PluginFunction; HINSTANCE PLUGIN_INST; char total_found_s[5]=""; char plugin_name[100]=""; char plugin_dll[100]=""; char dll_to_load[256]=""; char temp_str[5]=""; int total_found=0; GetPrivateProfileStringA("Plugins", "total_found", "", total_found_s, 4, sg_szPluginIniFilePath); sscanf(total_found_s, "%d", &total_found); if(total_found) { HMENU myMenu=0; myMenu=CreatePopupMenu(); for(int i=1; i!=(total_found+1); i++) { sprintf(temp_str, "%d", i); GetPrivateProfileStringA(temp_str, "plugin_name", "", plugin_name, 100, sg_szPluginIniFilePath); AppendMenuA(myMenu, MF_STRING, i, plugin_name); } POINT cursorPos; GetCursorPos(&cursorPos); SetForegroundWindow(hwndDlg); UINT MenuItemClicked=TrackPopupMenu(myMenu, TPM_RETURNCMD|TPM_NONOTIFY, cursorPos.x, cursorPos.y, 0, hwndDlg, 0); SendMessage(hwndDlg, WM_NULL, 0, 0); if(!MenuItemClicked) return TRUE; sprintf(temp_str, "%d", (int)MenuItemClicked); GetPrivateProfileStringA(temp_str, "plugin_dll", "", plugin_dll, 100, sg_szPluginIniFilePath); sprintf(dll_to_load, "plugins\\%s", plugin_dll); PLUGIN_INST=LoadLibraryA(dll_to_load); if(!PLUGIN_INST) MessageBoxA(hwndDlg, "There was an error loading the plugin", plugin_dll, MB_ICONERROR); else { PluginFunction=(PLUGFUNC)GetProcAddress(PLUGIN_INST, "PluginFunction"); if(!PluginFunction) MessageBoxA(hwndDlg, "The export \"PluginFunction\" could not be found, please contact the plugin supplier", plugin_dll, MB_ICONERROR); else { if(!g_TargetData.ImageBase) g_TargetData.ImageBase=0x400000; ShowWindow(GetParent(hwndDlg), 0); PluginFunction(PLUGIN_INST, hwndDlg, g_TargetData.SecurityAddrRegister, sg_szAKTDirectory, g_TargetData.ImageBase); ShowWindow(GetParent(hwndDlg), 1); FreeLibrary(PLUGIN_INST); SetForegroundWindow(hwndDlg); } } } else { HMENU myMenu=0; myMenu=CreatePopupMenu(); AppendMenuA(myMenu, MF_STRING|MF_GRAYED, 1, "No plugins found :("); POINT cursorPos; GetCursorPos(&cursorPos); SetForegroundWindow(hwndDlg); TrackPopupMenu(myMenu, TPM_RETURNCMD|TPM_NONOTIFY, cursorPos.x, cursorPos.y, 0, hwndDlg, 0); } } return TRUE; case IDC_EDT_OEP: { char temp_oep[10]=""; GetDlgItemTextA(hwndDlg, IDC_EDT_OEP, temp_oep, 10); sscanf(temp_oep, "%X", &(g_TargetData.OEP)); } return TRUE; } } return TRUE; } return FALSE; }
STDMETHODIMP VBoxDnDDropTarget::Drop(IDataObject *pDataObject, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) { RT_NOREF(pt); AssertPtrReturn(pDataObject, E_INVALIDARG); AssertPtrReturn(pdwEffect, E_INVALIDARG); LogFlowFunc(("mFormatEtc.cfFormat=%RI16 (%s), pDataObject=0x%p, grfKeyState=0x%x, x=%ld, y=%ld\n", mFormatEtc.cfFormat, VBoxDnDDataObject::ClipboardFormatToString(mFormatEtc.cfFormat), pDataObject, grfKeyState, pt.x, pt.y)); HRESULT hr = S_OK; if (mFormatEtc.cfFormat) /* Did we get a supported format yet? */ { /* Make sure the data object's data format is still valid. */ hr = pDataObject->QueryGetData(&mFormatEtc); AssertMsg(SUCCEEDED(hr), ("Data format changed to invalid between DragEnter() and Drop(), cfFormat=%RI16 (%s), hr=%Rhrc\n", mFormatEtc.cfFormat, VBoxDnDDataObject::ClipboardFormatToString(mFormatEtc.cfFormat), hr)); } int rc = VINF_SUCCESS; if (SUCCEEDED(hr)) { STGMEDIUM stgMed; hr = pDataObject->GetData(&mFormatEtc, &stgMed); if (SUCCEEDED(hr)) { /* * First stage: Prepare the access to the storage medium. * For now we only support HGLOBAL stuff. */ PVOID pvData = NULL; /** @todo Put this in an own union? */ switch (mFormatEtc.tymed) { case TYMED_HGLOBAL: pvData = GlobalLock(stgMed.hGlobal); if (!pvData) { LogFlowFunc(("Locking HGLOBAL storage failed with %Rrc\n", RTErrConvertFromWin32(GetLastError()))); rc = VERR_INVALID_HANDLE; hr = E_INVALIDARG; /* Set special hr for OLE. */ } break; default: AssertMsgFailed(("Storage medium type %RI32 supported\n", mFormatEtc.tymed)); rc = VERR_NOT_SUPPORTED; hr = DV_E_TYMED; /* Set special hr for OLE. */ break; } if (RT_SUCCESS(rc)) { /* * Second stage: Do the actual copying of the data object's data, * based on the storage medium type. */ switch (mFormatEtc.cfFormat) { case CF_TEXT: /* Fall through is intentional. */ case CF_UNICODETEXT: { AssertPtr(pvData); size_t cbSize = GlobalSize(pvData); LogFlowFunc(("CF_TEXT/CF_UNICODETEXT 0x%p got %zu bytes\n", pvData, cbSize)); if (cbSize) { char *pszText = NULL; rc = mFormatEtc.cfFormat == CF_TEXT /* ANSI codepage -> UTF-8 */ ? RTStrCurrentCPToUtf8(&pszText, (char *)pvData) /* Unicode -> UTF-8 */ : RTUtf16ToUtf8((PCRTUTF16)pvData, &pszText); if (RT_SUCCESS(rc)) { AssertPtr(pszText); size_t cbText = strlen(pszText) + 1; /* Include termination. */ mpvData = RTMemDup((void *)pszText, cbText); mcbData = cbText; RTStrFree(pszText); pszText = NULL; } } break; } case CF_HDROP: { AssertPtr(pvData); /* Convert to a string list, separated by \r\n. */ DROPFILES *pDropFiles = (DROPFILES *)pvData; AssertPtr(pDropFiles); bool fUnicode = RT_BOOL(pDropFiles->fWide); /* Get the offset of the file list. */ Assert(pDropFiles->pFiles >= sizeof(DROPFILES)); /* Note: This is *not* pDropFiles->pFiles! DragQueryFile only * will work with the plain storage medium pointer! */ HDROP hDrop = (HDROP)(pvData); /* First, get the file count. */ /** @todo Does this work on Windows 2000 / NT4? */ char *pszFiles = NULL; uint32_t cchFiles = 0; UINT cFiles = DragQueryFile(hDrop, UINT32_MAX /* iFile */, NULL /* lpszFile */, 0 /* cchFile */); LogFlowFunc(("CF_HDROP got %RU16 file(s)\n", cFiles)); for (UINT i = 0; i < cFiles; i++) { UINT cch = DragQueryFile(hDrop, i /* File index */, NULL /* Query size first */, 0 /* cchFile */); Assert(cch); if (RT_FAILURE(rc)) break; char *pszFile = NULL; /* UTF-8 version. */ UINT cchFile = 0; if (fUnicode) { /* Allocate enough space (including terminator). */ WCHAR *pwszFile = (WCHAR *)RTMemAlloc((cch + 1) * sizeof(WCHAR)); if (pwszFile) { cchFile = DragQueryFileW(hDrop, i /* File index */, pwszFile, cch + 1 /* Include terminator */); AssertMsg(cchFile == cch, ("cchCopied (%RU16) does not match cchFile (%RU16)\n", cchFile, cch)); rc = RTUtf16ToUtf8(pwszFile, &pszFile); AssertRC(rc); RTMemFree(pwszFile); } else rc = VERR_NO_MEMORY; } else /* ANSI */ { /* Allocate enough space (including terminator). */ pszFile = (char *)RTMemAlloc((cch + 1) * sizeof(char)); if (pszFile) { cchFile = DragQueryFileA(hDrop, i /* File index */, pszFile, cchFile + 1 /* Include terminator */); AssertMsg(cchFile == cch, ("cchCopied (%RU16) does not match cchFile (%RU16)\n", cchFile, cch)); } else rc = VERR_NO_MEMORY; } if (RT_SUCCESS(rc)) { LogFlowFunc(("\tFile: %s (cchFile=%RU32)\n", pszFile, cchFile)); rc = RTStrAAppendExN(&pszFiles, 1 /* cPairs */, pszFile, cchFile); if (RT_SUCCESS(rc)) cchFiles += cchFile; } if (pszFile) RTStrFree(pszFile); if (RT_FAILURE(rc)) break; /* Add separation between filenames. * Note: Also do this for the last element of the list. */ rc = RTStrAAppendExN(&pszFiles, 1 /* cPairs */, "\r\n", 2 /* Bytes */); if (RT_SUCCESS(rc)) cchFiles += 2; /* Include \r\n */ } if (RT_SUCCESS(rc)) { cchFiles += 1; /* Add string termination. */ uint32_t cbFiles = cchFiles * sizeof(char); LogFlowFunc(("cFiles=%u, cchFiles=%RU32, cbFiles=%RU32, pszFiles=0x%p\n", cFiles, cchFiles, cbFiles, pszFiles)); /* Translate the list into URI elements. */ DnDURIList lstURI; rc = lstURI.AppendNativePathsFromList(pszFiles, cbFiles, DNDURILIST_FLAGS_ABSOLUTE_PATHS); if (RT_SUCCESS(rc)) { RTCString strRoot = lstURI.RootToString(); size_t cbRoot = strRoot.length() + 1; /* Include termination */ mpvData = RTMemAlloc(cbRoot); if (mpvData) { memcpy(mpvData, strRoot.c_str(), cbRoot); mcbData = cbRoot; } else rc = VERR_NO_MEMORY; } } LogFlowFunc(("Building CF_HDROP list rc=%Rrc, pszFiles=0x%p, cFiles=%RU16, cchFiles=%RU32\n", rc, pszFiles, cFiles, cchFiles)); if (pszFiles) RTStrFree(pszFiles); break; } default: /* Note: Should not happen due to the checks done in DragEnter(). */ AssertMsgFailed(("Format of type %RI16 (%s) not supported\n", mFormatEtc.cfFormat, VBoxDnDDataObject::ClipboardFormatToString(mFormatEtc.cfFormat))); hr = DV_E_CLIPFORMAT; /* Set special hr for OLE. */ break; } /* * Third stage: Unlock + release access to the storage medium again. */ switch (mFormatEtc.tymed) { case TYMED_HGLOBAL: GlobalUnlock(stgMed.hGlobal); break; default: AssertMsgFailed(("Really should not happen -- see init stage!\n")); break; } } /* Release storage medium again. */ ReleaseStgMedium(&stgMed); /* Signal waiters. */ mDroppedRc = rc; RTSemEventSignal(hEventDrop); } } if (RT_SUCCESS(rc)) { /* Note: pt is not used since we don't need to differentiate within our * proxy window. */ *pdwEffect = VBoxDnDDropTarget::GetDropEffect(grfKeyState, *pdwEffect); } else *pdwEffect = DROPEFFECT_NONE; if (mpWndParent) mpWndParent->hide(); LogFlowFunc(("Returning with hr=%Rhrc (%Rrc), mFormatEtc.cfFormat=%RI16 (%s), *pdwEffect=%RI32\n", hr, rc, mFormatEtc.cfFormat, VBoxDnDDataObject::ClipboardFormatToString(mFormatEtc.cfFormat), *pdwEffect)); return hr; }
INT_PTR CALLBACK prg2wav_dialog_proc(HWND hwndDlg, //handle to dialog box UINT uMsg, //message WPARAM wParam, //first message parameter LPARAM lParam // second message parameter ){ switch (uMsg) { case WM_INITDIALOG: CheckRadioButton(hwndDlg, IDC_FAST, IDC_SLOW, IDC_FAST); CheckRadioButton(hwndDlg, IDC_TO_TAP, IDC_TO_SOUND, IDC_TO_TAP); if (audiotap_startup_status.audiofile_init_status != LIBRARY_OK || audiotap_startup_status.tapdecoder_init_status != LIBRARY_OK) EnableWindow(GetDlgItem(hwndDlg, IDC_TO_WAV), FALSE); if (audiotap_startup_status.portaudio_init_status != LIBRARY_OK || audiotap_startup_status.tapdecoder_init_status != LIBRARY_OK) EnableWindow(GetDlgItem(hwndDlg, IDC_TO_SOUND), FALSE); SetDlgItemInt(hwndDlg, IDC_FREQ, 44100, FALSE); SetDlgItemInt(hwndDlg, IDC_VOL, 254, FALSE); SendMessageA(GetDlgItem(hwndDlg, IDC_MACHINE_TO), CB_ADDSTRING, 0, (LPARAM) "C64 PAL"); SendMessageA(GetDlgItem(hwndDlg, IDC_MACHINE_TO), CB_ADDSTRING, 0, (LPARAM) "C64 NTSC"); SendMessageA(GetDlgItem(hwndDlg, IDC_MACHINE_TO), CB_ADDSTRING, 0, (LPARAM) "VIC20 PAL"); SendMessageA(GetDlgItem(hwndDlg, IDC_MACHINE_TO), CB_ADDSTRING, 0, (LPARAM) "VIC20 NTSC"); SendMessageA(GetDlgItem(hwndDlg, IDC_MACHINE_TO), CB_ADDSTRING, 0, (LPARAM) "C16 PAL"); SendMessageA(GetDlgItem(hwndDlg, IDC_MACHINE_TO), CB_ADDSTRING, 0, (LPARAM) "C16 NTSC"); SendMessage(GetDlgItem(hwndDlg, IDC_MACHINE_TO), CB_SETCURSEL, 0, 0); SendMessageA(GetDlgItem(hwndDlg, IDC_WAVEFORM), CB_ADDSTRING, 0, (LPARAM) "Triangle"); SendMessageA(GetDlgItem(hwndDlg, IDC_WAVEFORM), CB_ADDSTRING, 0, (LPARAM) "Square"); SendMessageA(GetDlgItem(hwndDlg, IDC_WAVEFORM), CB_ADDSTRING, 0, (LPARAM) "Sine"); SendMessageA(GetDlgItem(hwndDlg, IDC_WAVEFORM), CB_SETCURSEL, 1, 0); SendMessageA(GetDlgItem(hwndDlg, IDC_THRESHOLD_SPIN), UDM_SETRANGE, 0, MAKELONG(1600, 102)); SendMessage(GetDlgItem(hwndDlg, IDC_THRESHOLD_SPIN), UDM_SETPOS, 0, 263); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_FAST: EnableWindow(GetDlgItem(hwndDlg, IDC_THRESHOLD), TRUE); return TRUE; case IDC_SLOW: EnableWindow(GetDlgItem(hwndDlg, IDC_THRESHOLD), FALSE); return TRUE; case IDC_TO_TAP: EnableWindow(GetDlgItem(hwndDlg, IDC_INVERTED), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_FREQ), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_VOL), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_WAVEFORM), FALSE); return TRUE; case IDC_TO_WAV: case IDC_TO_SOUND: EnableWindow(GetDlgItem(hwndDlg, IDC_INVERTED), TRUE); EnableWindow(GetDlgItem(hwndDlg, IDC_FREQ), TRUE); EnableWindow(GetDlgItem(hwndDlg, IDC_VOL), TRUE); EnableWindow(GetDlgItem(hwndDlg, IDC_WAVEFORM), TRUE); return TRUE; case IDOK: choose_file(hwndDlg); return TRUE; case IDCANCEL: EndDialog(hwndDlg, 0); return TRUE; default: return FALSE; } case WM_DROPFILES: { UINT numfiles = DragQueryFileA((HDROP)wParam, 0xFFFFFFFF, NULL, 0); UINT i; struct prg2wav_params params; struct simple_block_list_element **current_block = ¶ms.program; params.program = NULL; for (i = 0; i < numfiles; i++) { UINT filenamesize = DragQueryFile((HDROP)wParam, i, NULL, 0); LPSTR filename; FILE* fd; filenamesize++; /* for the null termination */ filename = (LPSTR)malloc(filenamesize); DragQueryFileA((HDROP)wParam, i, filename, filenamesize); if ((fd = fopen(filename, "rb")) != NULL){ struct simple_block_list_element **new_current_block = add_all_entries_from_file(current_block, fd); if (detect_type(fd) == prg) put_filename_in_entryname(filename, (*current_block)->block.info.name); fclose(fd); current_block = new_current_block; } free(filename); } DragFinish((HDROP)wParam); if (params.program != NULL) choose_destination_file_and_convert(hwndDlg, ¶ms); } return TRUE; #ifdef HAVE_HTMLHELP case WM_HELP: HtmlHelpA(hwndDlg, "docs\\wavprg.chm::/prg2wav_main.htm", HH_DISPLAY_TOPIC, 0); return TRUE; #endif default: return FALSE; } }
BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_INITDIALOG: { HWND p=GetParent(hwndDlg); if(p) { HICON ico=(HICON)SendMessageA(p, WM_GETICON, ICON_SMALL, 0); SendMessageA(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)ico); } EnableWindow(GetDlgItem(hwndDlg, IDC_EDT_TEMPLATE), 0); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_COPY_CODE), 0); if(!Initialize(hwndDlg)) { MessageBoxA(hwndDlg, "Something went wrong during the initialization of the plugin.\n\nMaybe the file you are loading is unsupported, please contact me\n(Mr. eXoDia) at [email protected], I can fix it...", "Error...", MB_ICONERROR); SendMessageA(hwndDlg, WM_CLOSE, 0, 0); } } return TRUE; case WM_CLOSE: { EndDialog(hwndDlg, 0); } return TRUE; case WM_DROPFILES: { DragQueryFileA((HDROP)wParam, NULL, ini_file, MAX_PATH); if(!strcmp(ini_file+(strlen(ini_file)-3), "akt")) ReadIniFile(hwndDlg, ini_file); else MessageBoxA(hwndDlg, "Please drop a valid file...", "Error!", MB_ICONERROR); } return TRUE; case WM_COMMAND: { switch(LOWORD(wParam)) { case IDC_CHK_PROJECTID: { projectid=IsDlgButtonChecked(hwndDlg, IDC_CHK_PROJECTID); char new_pub_text[100]=""; if(GetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_NEW, new_pub_text, 100)) SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_NEW, new_pub_text); } return TRUE; case IDC_EDT_TEMPLATE: { char templ[256]=""; char base[256]=""; char x[256]=""; char y[256]=""; char pvt[256]=""; int old_len=strlen(cur_pub_text); if(GetDlgItemTextA(hwndDlg, IDC_EDT_TEMPLATE, templ, 256)) { GenerateEcdsaParameters(templ, pvt, base, x, y); sprintf(pvt, "%s,%s,%s", base, x, y); sprintf(base, "%X", strlen(pvt)); } int len=strlen(pvt); if(len==old_len) { SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_NEW, pvt); SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_NEW_LEN, base); } else { SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_NEW, ""); SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_NEW_LEN, ""); } } return TRUE; case IDC_LIST_CERTS: { switch(HIWORD(wParam)) { case CBN_SELCHANGE: { int current_selected=SendDlgItemMessageA(hwndDlg, IDC_LIST_CERTS, CB_GETCURSEL, 0, 0); if(ini_file_loaded) { char temp_name[10]=""; GetPrivateProfileStringA(cert_names[current_selected], "pub", "", cur_pub_text, 256, ini_file); GetPrivateProfileStringA(cert_names[current_selected], "diff", "", cur_dif_text, 10, ini_file); GetPrivateProfileStringA(cert_names[current_selected], "md5", "", cur_md5_text, 10, ini_file); //v9.60 support GetPrivateProfileStringA(cert_names[current_selected], "seed1", "", cur_seed1_text, 10, ini_file); GetPrivateProfileStringA(cert_names[current_selected], "seed2", "", cur_seed2_text, 10, ini_file); GetPrivateProfileStringA(cert_names[current_selected], "projectid_diff", "", cur_projectid_diff_text, 10, ini_file); SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_OLD, cur_pub_text); sprintf(temp_name, "%X", strlen(cur_pub_text)); SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_OLD_LEN, temp_name); //sprintf(base_code, base_code_format+1, register_used, cert_function_addr, register_used, md5_replace_addr, cur_md5_text); //SetDlgItemTextA(hwndDlg, IDC_EDT_CODE, base_code); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_COPY_CODE), 0); SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_NEW, ""); } } return TRUE; } } return TRUE; case IDC_EDT_PUBVALS_NEW: { char new_pub[256]=""; char new_byte[10]=""; unsigned int rand_init=~GetTickCount(); BYTE bytes_gtc[4]= {0}; bytes_gtc[0]=rand_init>>24; bytes_gtc[1]=(rand_init<<8)>>24; bytes_gtc[2]=(rand_init<<12)>>24; bytes_gtc[3]=(rand_init<<16)>>24; BYTE final_byte=bytes_gtc[0]^bytes_gtc[1]^bytes_gtc[2]^bytes_gtc[3]; if(final_byte<0x20) final_byte+=0x20; else if(final_byte>0x7E) { final_byte-=0x81; if(final_byte<0x20) final_byte+=0x21; } //v9.60 support unsigned char xor_byte=0; if(cur_seed1_text[0] and cur_seed2_text[0]) { unsigned int seed1=0; sscanf(cur_seed1_text, "%X", &seed1); CT_a=seed1; unsigned int result=CT_NextRandomRange(256); memcpy(&xor_byte, &result, 1); } sprintf(new_byte, "%X", final_byte^xor_byte); int new_pub_len=GetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_NEW, new_pub, 256); if(new_pub_len) { char replaced_pub_string[1024]=""; unsigned int proj_diff=2; //v9.60 support if(cur_seed1_text[0] and cur_seed2_text[0]) { sscanf(cur_projectid_diff_text, "%X", &proj_diff); unsigned char cpy[256]=""; strcpy((char*)cpy, new_pub); unsigned int seed2=0; sscanf(cur_seed2_text, "%X", &seed2); unsigned char* rand=CT_GetCryptBytes(seed2, new_pub_len); for(int i=0,j=0; i<new_pub_len; i++) { cpy[i]^=rand[i]; j+=sprintf(replaced_pub_string+j, "\\x%.2X", cpy[i]); } } else strcpy(replaced_pub_string, new_pub); if(projectid) sprintf(repl_code, repl_code_format, first_dword_text, proj_diff, new_byte, cur_dif_text, replaced_pub_string, new_pub_len); else sprintf(repl_code, repl_code_format2, first_dword_text, cur_dif_text, replaced_pub_string, new_pub_len); if(md5_replace_addr) sprintf(base_code, base_code_format, register_used, cert_function_addr, repl_code, register_used, md5_replace_addr, cur_md5_text); else sprintf(base_code, base_code_format2, register_used, cert_function_addr, repl_code); //TODO: fix this SetDlgItemTextA(hwndDlg, IDC_EDT_CODE, base_code); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_COPY_CODE), 1); } else { SetDlgItemTextA(hwndDlg, IDC_EDT_CODE, ""); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_COPY_CODE), 0); } } return TRUE; case IDC_BTN_COPY_CODE: { CopyToClipboard(base_code); MessageBeep(MB_ICONINFORMATION); } return TRUE; case IDC_BTN_ABOUT: { MessageBoxA(hwndDlg, "This plugin is very simple... Just Drag&Drop a .akt file created by Armadillo Key Tool,\nselect the certificate you want to use and use the Generate button to create new\npublic vals.\n\nThe Base Code is supposed be copied after: \";PLACE YOU CODE AFTER THIS!!!\"\nThe Replace Code should be appended to your inline code...\n\nMr. eXoDia\[email protected]", "Armadillo ECDSA Public Parameter Replace Plugin v0.4", MB_ICONINFORMATION); } return TRUE; } } return TRUE; } return FALSE; }
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { case WM_DROPFILES: { /*RECT rect; POINT pt; GetWindowRect(hWnd,&rect); GetCursorPos(&pt); if(windowed) { rect.left -= window_inset.left; // todo: look into the function: ScreenToClient(hwnd,point) rect.top -= window_inset.top; } ComputeMouseVector(pt.x-rect.left,pt.y-rect.top); */ //MouseVector = float3(0,0,-1); HDROP hDrop = (HDROP)wParam; unsigned int n = DragQueryFileA(hDrop, 0xFFFFFFFF, NULL, 0); for(unsigned int i=0; i<n; i++) { char fname[1024]; if(DragQueryFileA(hDrop, i, fname, sizeof(fname))) { char *s = fname+strlen(fname); while (s>fname && *s != '.' ) s--; if(*s=='.') s++; dropfiles.Add(String(s) + " \"" + fname + "\""); } } DragFinish(hDrop); break; } case WM_SETFOCUS: focus=1; break; case WM_KILLFOCUS: focus=0; break; case WM_DESTROY: PostQuitMessage( 0 ); quitrequest=1; return 0; case WM_CLOSE: PostQuitMessage(0); quitrequest=1; return 0; case WM_CHAR: if(entertext) { doconsole(wParam); return 0; } if(ManipulatorKeyPress((int) wParam)) // manipulator is taking the key input!!! return 0; switch (wParam) { case 27: /* ESC key */ PostQuitMessage(0); quitrequest=1; break; case '`': case '\n': case '\r': entertext=1; comstring[0]='\0'; break; default: { extern void keyvent(const char *name,int k); keyvent("keydown",toupper((int)wParam)); break; } } return 0; case WM_KEYUP: { if(entertext || ManipulatorKeysGrab()) return 0; extern void keyvent(const char *name,int k); keyvent("keyup",toupper((int)wParam)); return 0; } case WM_LBUTTONDOWN: /* if we don't set the capture we won't get mouse move messages when the mouse moves outside the window. */ SetCapture(hWnd); ComputeMouseVector(LOWORD(lParam),HIWORD(lParam)); shiftdown = (wParam&MK_SHIFT)?1:0; ctrldown = (wParam&MK_CONTROL)?1:0; MouseLeft = 1; return 0; case WM_RBUTTONDOWN: SetCapture(hWnd); ComputeMouseVector(LOWORD(lParam),HIWORD(lParam)); shiftdown = (wParam&MK_SHIFT)?1:0; ctrldown = (wParam&MK_CONTROL)?1:0; MouseRight = 1; FuncInterp("rbuttondown"); return 0; case WM_LBUTTONUP: ComputeMouseVector(LOWORD(lParam),HIWORD(lParam)); shiftdown = (wParam&MK_SHIFT)?1:0; ctrldown = (wParam&MK_CONTROL)?1:0; MouseLeft=0; /* remember to release the capture when we are finished. */ if(!MouseRight) ReleaseCapture(); return 0; case WM_RBUTTONUP: ComputeMouseVector(LOWORD(lParam),HIWORD(lParam)); shiftdown = (wParam&MK_SHIFT)?1:0; ctrldown = (wParam&MK_CONTROL)?1:0; MouseRight=0; /* remember to release the capture when we are finished. */ if(!MouseLeft) ReleaseCapture(); return 0; case WM_MOUSEMOVE: ComputeMouseVector(LOWORD(lParam),HIWORD(lParam)); shiftdown = (wParam&MK_SHIFT)?1:0; ctrldown = (wParam&MK_CONTROL)?1:0; return 0; case WM_MOUSEWHEEL: shiftdown = (wParam&MK_SHIFT)?1:0; ctrldown = (wParam&MK_CONTROL)?1:0; mousewheel += GET_WHEEL_DELTA_WPARAM(wParam)/WHEEL_DELTA; return 0; case WM_SETCURSOR: // Turn off Windows cursor SetCursor( NULL ); g_pd3dDevice->ShowCursor( 0 ); return 1; case WM_SYSCHAR: switch(wParam) { case 27: /* ESC key */ PostQuitMessage(0); quitrequest=1; break; case '\n': case '\r': windowed = !windowed; resetdevice(NULL); break; } return 0; case WM_MOVE: if(windowed) { windowx = LOWORD(lParam); windowy = HIWORD(lParam); } return 1; case WM_SIZE: wm_size_width = LOWORD(lParam); wm_size_height = HIWORD(lParam); windowwidth = LOWORD(lParam); windowheight= HIWORD(lParam); return 1; case WM_EXITSIZEMOVE: if(windowed && (Width != (int)(windowwidth ) || Height!= (int)(windowheight))) { resetdevice(NULL); } return 1; } return DefWindowProc( hWnd, msg, wParam, lParam ); }
static ws_uint_t drag_query_file(HDROP hdrop, ws_uint_t index, ws_char_a_t* buffer, ws_uint_t cchBuffer) { return DragQueryFileA(hdrop, index, buffer, cchBuffer); }
long EngineWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { char szAboutTitle[] = "[ About ]"; char szAboutText[] = "%s \r\n\r\n ReversingLabs - http://www.reversinglabs.com \r\n\r\n Minimum engine version needed:\r\n- TitanEngine %i.%i.%i by RevLabs\r\n\r\nUnpacker coded by %s"; typedef void(TITCALL * fStartUnpacking)(char* szInputFile, bool RealignFile, bool CopyOverlay); fStartUnpacking myStartUnpacking = (fStartUnpacking)EngineStartUnpackingCallBack; char GlobalBuffer[1024] = {}; char AboutBuffer[1024] = {}; bool bRealignFile = false; bool bCopyOverlay = false; if(uMsg == WM_INITDIALOG) { SendMessageA(hwndDlg, WM_SETTEXT, NULL, (LPARAM)&szWindowUnpackerTitle); HICON hIconLarge = (HICON)LoadImage(engineHandle, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 32, 32, LR_DEFAULTSIZE); SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIconLarge); HICON hIconSmall = (HICON)LoadImage(engineHandle, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, LR_DEFAULTSIZE); SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIconSmall); SetDlgItemTextA(hwndDlg, IDD_UNPACKERTITLE, szWindowUnpackerLongTitle); SetDlgItemTextA(hwndDlg, IDC_FILENAME, "filename.exe"); CheckDlgButton(hwndDlg, IDC_REALING, 1); EngineWindowHandle = hwndDlg; } else if(uMsg == WM_DROPFILES) { DragQueryFileA((HDROP)wParam, NULL, GlobalBuffer, sizeof(GlobalBuffer)); SetDlgItemTextA(hwndDlg, IDC_FILENAME, GlobalBuffer); } else if(uMsg == WM_CLOSE) { EndDialog(hwndDlg, NULL); } else if(uMsg == WM_COMMAND) { if(wParam == IDC_UNPACK) { GetDlgItemTextA(hwndDlg, IDC_FILENAME, GlobalBuffer, sizeof(GlobalBuffer)); if(!IsFileBeingDebugged() && EngineFileExists(GlobalBuffer)) { EngineBoxHandle = GetDlgItem(hwndDlg, IDC_LISTBOX); SendMessageA(EngineBoxHandle, LB_RESETCONTENT, NULL, NULL); if(IsDlgButtonChecked(EngineWindowHandle, IDC_REALING)) { bRealignFile = true; } if(IsDlgButtonChecked(EngineWindowHandle, IDC_COPYOVERLAY)) { bCopyOverlay = true; } myStartUnpacking(GlobalBuffer, bRealignFile, bCopyOverlay); } } else if(wParam == IDC_BROWSE) { if(EngineGetFileDialog(GlobalBuffer)) { SetDlgItemTextA(hwndDlg, IDC_FILENAME, GlobalBuffer); } } else if(wParam == IDC_ABOUT) { wsprintfA(AboutBuffer, szAboutText, szWindowUnpackerName, TE_VER_MAJOR, TE_VER_MIDDLE, TE_VER_MINOR, szWindowUnpackerAuthor); MessageBoxA(hwndDlg, AboutBuffer, szAboutTitle, MB_ICONASTERISK); } else if(wParam == IDC_EXIT) { EndDialog(hwndDlg, NULL); } } return 0; }
BOOL CALLBACK EV_DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_INITDIALOG: { EV_shared=hwndDlg; EV_list_hwnd=GetDlgItem(hwndDlg, IDC_LIST); } return TRUE; case WM_CLOSE: { EndDialog(hwndDlg, 0); } return TRUE; case WM_BROWSE: { SendMessageA(EV_list_hwnd, LB_RESETCONTENT, 0, 0); strcpy(EV_szFileName, (const char*)wParam); strcpy(EV_program_dir, EV_szFileName); int i=strlen(EV_program_dir); while(EV_program_dir[i]!='\\') i--; EV_program_dir[i]=0; CreateThread(0, 0, EV_DebugThread, 0, 0, 0); } return TRUE; case WM_DROPFILES: { SendMessageA(EV_list_hwnd, LB_RESETCONTENT, 0, 0); DragQueryFileA((HDROP)wParam, 0, EV_szFileName, MAX_PATH); strcpy(EV_program_dir, EV_szFileName); int i=strlen(EV_program_dir); while(EV_program_dir[i]!='\\') i--; EV_program_dir[i]=0; CreateThread(0, 0, EV_DebugThread, 0, 0, 0); } return TRUE; case WM_CONTEXTMENU: { if(GetDlgCtrlID((HWND)wParam)==IDC_LIST) { LeftClick(); LeftClick(); } } return TRUE; case WM_HELP: { char id[10]=""; sprintf(id, "%d", IDS_HELPEVLOG); SetEnvironmentVariableA("HELPID", id); SetEnvironmentVariableA("HELPTITLE", "EVLog Help"); DialogBox(hInst, MAKEINTRESOURCE(DLG_HELP), hwndDlg, DlgHelp); } return TRUE; case WM_COMMAND: { switch(LOWORD(wParam)) { case IDC_LIST: { switch(HIWORD(wParam)) { case LBN_DBLCLK: { int cursel=SendMessageA(EV_list_hwnd, LB_GETCURSEL, 0, 0); int count=SendMessageA(EV_list_hwnd, LB_GETCOUNT, 0, 0); if(!count) return TRUE; char line_text[1024]=""; char var_name[512]=""; char var_value[512]=""; SendMessageA(EV_list_hwnd, LB_GETTEXT, cursel, (LPARAM)line_text); int len=strlen(line_text); for(int i=0,j=0,k=0,l=0; i<len; i++) { if(line_text[i]=='=') { i++; j=1; } if(!j) k+=sprintf(var_name+k, "%c", line_text[i]); else l+=sprintf(var_value+l, "%c", line_text[i]); } HMENU myMenu=0; myMenu=CreatePopupMenu(); AppendMenu(myMenu, MF_STRING, 1, "Copy Variable &Name"); if(strcmp(var_value, "(0)")) AppendMenu(myMenu, MF_STRING, 2, "Copy Variable &Value"); AppendMenu(myMenu, MF_STRING, 3, "Copy &Line"); POINT cursorPos; GetCursorPos(&cursorPos); SetForegroundWindow(hwndDlg); UINT MenuItemClicked=TrackPopupMenu(myMenu, TPM_RETURNCMD|TPM_NONOTIFY, cursorPos.x, cursorPos.y, 0, hwndDlg, 0); SendMessage(hwndDlg, WM_NULL, 0, 0); switch(MenuItemClicked) { case 1: CopyToClipboard(var_name); break; case 2: CopyToClipboard(var_value); break; case 3: CopyToClipboard(line_text); break; } } return TRUE; } } return TRUE; case IDC_BTN_DUMP: { char massive_string[32768]="", single_string[255]="Coded by Mr. eXoDia // T.P.o.D.T 2012\r\n\r\n"; int total=SendDlgItemMessage(hwndDlg, IDC_LIST, LB_GETCOUNT, 0, 0); for(int i=0; i!=total; i++) { SendDlgItemMessage(hwndDlg, IDC_LIST, LB_GETTEXT, (WPARAM)i, (LPARAM)single_string); sprintf(massive_string, "%s%s\r\n", massive_string, single_string); } char log_filename[MAX_PATH]=""; log_filename[0]=0; OPENFILENAME ofstruct; memset(&ofstruct, 0, sizeof(ofstruct)); ofstruct.lStructSize=sizeof(ofstruct); ofstruct.hwndOwner=hwndDlg; ofstruct.hInstance=hInst; ofstruct.lpstrFilter="Log files (*.log)\0*.log\0\0"; ofstruct.lpstrFile=log_filename; ofstruct.nMaxFile=MAX_PATH; ofstruct.lpstrInitialDir=EV_program_dir; ofstruct.lpstrTitle="Save file"; ofstruct.lpstrDefExt="log"; ofstruct.Flags=OFN_EXTENSIONDIFFERENT|OFN_HIDEREADONLY|OFN_NONETWORKBUTTON|OFN_OVERWRITEPROMPT; GetSaveFileName(&ofstruct); if(!log_filename[0]) return TRUE; HANDLE hFile=CreateFileA(log_filename, GENERIC_ALL, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if(hFile==INVALID_HANDLE_VALUE) { MessageBoxA(hwndDlg, "Could not create the file, maybe it's in use...", "Error!", MB_ICONERROR); return TRUE; } DWORD written=0; if(!WriteFile(hFile, massive_string, strlen(massive_string), &written, 0)) { CloseHandle(hFile); MessageBoxA(hwndDlg, "Could not write to the file, maybe it's in use...", "Error!", MB_ICONERROR); return TRUE; } CloseHandle(hFile); } return TRUE; } } return TRUE; } return FALSE; }
//***************************************************************************** // クラス設計 LRESULT CALLBACK WindowProcedure( HWND handle_window, UINT message, WPARAM w_paramater, LPARAM l_paramater) { switch (message) { case WM_CREATE: { // windowを真ん中 wow::WindowCenter(handle_window); // ドラッグドロップを有効にする DragAcceptFiles(handle_window, TRUE); break; } case WM_DESTROY: { // システムに終了を要求 PostQuitMessage(0); break; } case WM_CLOSE: { // 指定されたウィンドウを破棄 DestroyWindow(handle_window); break; } case WM_DROPFILES: { // ドラッグした位置を取得 POINT mouse_position; GetCursorPos(&mouse_position); ScreenToClient( handle_window, // ウィンドウのハンドル &mouse_position); // スクリーン座標 // ドラッグしたファイル名を取得 HDROP drop = (HDROP)w_paramater; char file_name[256]; DragQueryFileA(drop, 0, file_name, 256); DragFinish(drop); break; } case WM_LBUTTONDOWN: { break; } case WM_KEYDOWN: { switch (w_paramater) { case VK_ESCAPE: DestroyWindow(handle_window); break; } break; } } // デフォルトの処理を返す return DefWindowProc(handle_window, message, w_paramater, l_paramater); }
BOOL CALLBACK VF_DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_INITDIALOG: { g_shared_hwnd=hwndDlg; EnableWin(IDC_BTN_CALCFROMRAW, 0); CheckDlgButton(hwndDlg, IDC_CHK_LOG, log_version); } return TRUE; case WM_CLOSE: { EndDialog(hwndDlg, 0); } return TRUE; case WM_HELP: { char id[10]=""; sprintf(id, "%d", IDS_HELPVERSION); SetEnvironmentVariableA("HELPID", id); SetEnvironmentVariableA("HELPTITLE", "Version Help"); DialogBox(hInst, MAKEINTRESOURCE(DLG_HELP), hwndDlg, DlgHelp); } return TRUE; case WM_BROWSE: { strcpy(g_szFileName, (const char*)wParam); CreateThread(0, 0, VF_DebugThread, 0, 0, 0); } return TRUE; case WM_DROPFILES: { DragQueryFileA((HDROP)wParam, 0, g_szFileName, 256); CreateThread(0, 0, VF_DebugThread, 0, 0, 0); } return TRUE; case WM_COMMAND: { switch(LOWORD(wParam)) { case IDC_CHK_LOG: { NoFocus(); log_version=!!IsDlgButtonChecked(hwndDlg, LOWORD(wParam)); } return TRUE; case IDC_BTN_CALCFROMRAW: { NoFocus(); ResetContent(false); ARMA_OPTIONS op= {0}; EXTRA_OPTIONS eo= {0}; if(g_extra_options) { FillArmaExtraOptionsStruct(g_extra_options, &eo); FillArmaOptionsStruct(g_raw_options, g_version, &op, &eo, g_minimal); } else FillArmaOptionsStruct(g_raw_options, g_version, &op, 0, g_minimal); PrintArmaOptionsStruct(&op, 0, g_raw_options, g_extra_options); } return TRUE; case IDC_EDT_RAWOPTIONS: { char str[11]=""; if(GetDlgItemTextA(hwndDlg, IDC_EDT_RAWOPTIONS, str, 10)) { EnableWin(IDC_BTN_CALCFROMRAW, 1); sscanf(str, "%X", &g_raw_options); } } return TRUE; case IDC_EDT_EXTRAOPTIONS: { char str[11]=""; if(GetDlgItemTextA(hwndDlg, IDC_EDT_EXTRAOPTIONS, str, 10)) { EnableWin(IDC_BTN_CALCFROMRAW, 1); sscanf(str, "%X", &g_extra_options); } } return TRUE; } } return TRUE; } return FALSE; }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; CHAR * strTemp; HDROP hDropInfo; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); SetBkColor(hdc, RGB(0, 0, 0)); FillRect(hdc, &rectScreen, GetStockBrush(BLACK_BRUSH)); SetTextColor(hdc, RGB(255, 255, 255)); DrawTextA(hdc, strFileName, strlen(strFileName), &rectTopLeft, DT_RIGHT | DT_SINGLELINE); if (strFilePath) DrawTextA(hdc, strFilePath, strlen(strFilePath), &rectTopRight, DT_LEFT | DT_EDITCONTROL | DT_WORDBREAK | DT_PATH_ELLIPSIS); switch (conStep) { case CONVERT_STEP_READY_COMPLETE: strTemp = strReadyCompleted; break; case CONVERT_STEP_READY: strTemp = strReady; break; //Step 1 processing case CONVERT_STEP_1: strTemp = strProcessing1; break; case CONVERT_STEP_INVALID_FILE: strTemp = strErrorInvalidFile; break; case CONVERT_STEP_MANIFEST_INCLUDED: strTemp = strErrorManifestIncluded; break; case CONVERT_STEP_NOPERM: strTemp = strErrorNoPerm; break; //Step 2 processing case CONVERT_STEP_2: strTemp = strProcessing2; break; case CONVERT_STEP_APP_RESOURCE_FAIL: strTemp = strErrorAppResourceMissing; break; //Step 3 processing case CONVERT_STEP_3: strTemp = strProcessing3; break; case CONVERT_STEP_UNABLE_MOVE_FILE: strTemp = strErrorUnableMoveFile; break; case CONVERT_STEP_UNABLE_COPY_FILE: strTemp = strErrorUnableCopyFile; break; //Step 4 processing case CONVERT_STEP_4: strTemp = strProcessing4; break; case CONVERT_STEP_UNABLE_WRITE_FILE: strTemp = strErrorUnableWriteFile; break; case CONVERT_STEP_UNABLE_ADD_RES: strTemp = strErrorUnableAddRes; break; case CONVERT_STEP_UNABLE_SAVE_RES: strTemp = strErrorUnableSaveRes; break; default: strTemp = strDefault; break; } DrawTextA(hdc, strTemp, strlen(strTemp), &rectBottom, DT_CENTER | DT_VCENTER | DT_SINGLELINE); EndPaint(hWnd, &ps); break; case WM_DESTROY: if (strFilePath) free(strFilePath); PostQuitMessage(0); break; case WM_DROPFILES: hDropInfo = (HDROP)wParam; if (hThreadHandle) { DWORD dwWaitResult = WaitForSingleObject(hThreadHandle, 0); switch (dwWaitResult) { case STATUS_WAIT_0: case STATUS_ABANDONED_WAIT_0: CloseHandle(hThreadHandle); hThreadHandle = 0; break; default: userTryMultiFiles: MessageBoxA(hWnd, mbMsg, mbCaption, MB_OK | MB_ICONWARNING); goto doNotProcessNewFile; } } UINT numFiles = DragQueryFileA(hDropInfo, -1, NULL, 0); if (numFiles > 1) { goto userTryMultiFiles; } EnterCriticalSection(&m_cs); UINT buffsize = MAX_SIZE; CHAR * buf = malloc(MAX_SIZE); workerInfo* worker = malloc(sizeof(workerInfo)); if (strFilePath) { free(strFilePath); strFilePath = NULL; } DragQueryFileA(hDropInfo, 0, buf, buffsize); worker->fileStr = buf; worker->hWnd = hWnd; hThreadHandle = CreateThread(NULL, 0, WorkerThread, worker, 0, (LPDWORD)&hThread); LeaveCriticalSection(&m_cs); doNotProcessNewFile: //This is required to be at bottom for less coding. DragFinish(hDropInfo); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }