mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 15:26:02 +00:00
[MSPAINT]
Apply patches from CORE-7551 (Drag and Drop between Paint and the shell) and CORE-7561 (insert from file) svn path=/trunk/; revision=61860
This commit is contained in:
parent
422315f946
commit
fe9e1e9388
5 changed files with 99 additions and 39 deletions
|
@ -95,6 +95,17 @@ SaveDIBToFile(HBITMAP hBitmap, LPTSTR FileName, HDC hDC, LPSYSTEMTIME time, int
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
HeapFree(GetProcessHeap(), 0, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShowFileLoadError(LPTSTR name)
|
||||||
|
{
|
||||||
|
TCHAR programname[20];
|
||||||
|
TCHAR loaderrortext[100];
|
||||||
|
TCHAR temptext[500];
|
||||||
|
LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
|
||||||
|
LoadString(hProgInstance, IDS_LOADERRORTEXT, loaderrortext, SIZEOF(loaderrortext));
|
||||||
|
_stprintf(temptext, loaderrortext, name);
|
||||||
|
MessageBox(hMainWnd, temptext, programname, MB_OK | MB_ICONEXCLAMATION);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LoadDIBFromFile(HBITMAP * hBitmap, LPTSTR name, LPSYSTEMTIME time, int *size, int *hRes, int *vRes)
|
LoadDIBFromFile(HBITMAP * hBitmap, LPTSTR name, LPSYSTEMTIME time, int *size, int *hRes, int *vRes)
|
||||||
{
|
{
|
||||||
|
@ -105,18 +116,25 @@ LoadDIBFromFile(HBITMAP * hBitmap, LPTSTR name, LPSYSTEMTIME time, int *size, in
|
||||||
HANDLE hFile;
|
HANDLE hFile;
|
||||||
|
|
||||||
if (!hBitmap)
|
if (!hBitmap)
|
||||||
|
{
|
||||||
|
ShowFileLoadError(name);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
hFile =
|
hFile =
|
||||||
CreateFile(name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
CreateFile(name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||||
if (hFile == INVALID_HANDLE_VALUE)
|
if (hFile == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
ShowFileLoadError(name);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* read header and check for 'BM' magic */
|
/* read header and check for 'BM' magic */
|
||||||
ReadFile(hFile, &bfh, sizeof(BITMAPFILEHEADER), &dwBytesRead, NULL);
|
ReadFile(hFile, &bfh, sizeof(BITMAPFILEHEADER), &dwBytesRead, NULL);
|
||||||
if (bfh.bfType != 0x4d42)
|
if (bfh.bfType != 0x4d42)
|
||||||
{
|
{
|
||||||
CloseHandle(hFile);
|
CloseHandle(hFile);
|
||||||
|
ShowFileLoadError(name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +151,7 @@ LoadDIBFromFile(HBITMAP * hBitmap, LPTSTR name, LPSYSTEMTIME time, int *size, in
|
||||||
if (!bi)
|
if (!bi)
|
||||||
{
|
{
|
||||||
CloseHandle(hFile);
|
CloseHandle(hFile);
|
||||||
|
ShowFileLoadError(name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,3 +16,5 @@ void SaveDIBToFile(HBITMAP hBitmap, LPTSTR FileName, HDC hDC, LPSYSTEMTIME time,
|
||||||
int vRes);
|
int vRes);
|
||||||
|
|
||||||
void LoadDIBFromFile(HBITMAP *hBitmap, LPTSTR name, LPSYSTEMTIME time, int *size, int *hRes, int *vRes);
|
void LoadDIBFromFile(HBITMAP *hBitmap, LPTSTR name, LPSYSTEMTIME time, int *size, int *hRes, int *vRes);
|
||||||
|
|
||||||
|
void ShowFileLoadError(LPTSTR name);
|
||||||
|
|
|
@ -409,6 +409,10 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument
|
||||||
clearHistory();
|
clearHistory();
|
||||||
isAFile = TRUE;
|
isAFile = TRUE;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initializing the CHOOSECOLOR structure for use with ChooseColor */
|
/* initializing the CHOOSECOLOR structure for use with ChooseColor */
|
||||||
|
@ -489,6 +493,9 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument
|
||||||
/* Make the window visible on the screen */
|
/* Make the window visible on the screen */
|
||||||
ShowWindow (hwnd, nFunsterStil);
|
ShowWindow (hwnd, nFunsterStil);
|
||||||
|
|
||||||
|
/* inform the system, that the main window accepts dropped files */
|
||||||
|
DragAcceptFiles(hwnd, TRUE);
|
||||||
|
|
||||||
/* Run the message loop. It will run until GetMessage() returns 0 */
|
/* Run the message loop. It will run until GetMessage() returns 0 */
|
||||||
while (GetMessage(&messages, NULL, 0, 0))
|
while (GetMessage(&messages, NULL, 0, 0))
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <commctrl.h>
|
#include <commctrl.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <shellapi.h>
|
||||||
|
|
||||||
#include "definitions.h"
|
#include "definitions.h"
|
||||||
#include "drawing.h"
|
#include "drawing.h"
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
|
||||||
#include <shellapi.h>
|
|
||||||
|
|
||||||
#include "dialogs.h"
|
#include "dialogs.h"
|
||||||
#include "registry.h"
|
#include "registry.h"
|
||||||
|
|
||||||
|
@ -162,6 +160,43 @@ saveImage(BOOL overwrite)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UpdateApplicationProperties(HBITMAP bitmap, LPTSTR newfilename, LPTSTR newfilepathname)
|
||||||
|
{
|
||||||
|
TCHAR tempstr[1000];
|
||||||
|
TCHAR resstr[100];
|
||||||
|
insertReversible(bitmap);
|
||||||
|
updateCanvasAndScrollbars();
|
||||||
|
CopyMemory(filename, newfilename, sizeof(filename));
|
||||||
|
CopyMemory(filepathname, newfilepathname, sizeof(filepathname));
|
||||||
|
LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
|
||||||
|
_stprintf(tempstr, resstr, filename);
|
||||||
|
SetWindowText(hMainWnd, tempstr);
|
||||||
|
clearHistory();
|
||||||
|
isAFile = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
InsertSelectionFromHBITMAP(HBITMAP bitmap, HWND window)
|
||||||
|
{
|
||||||
|
HWND hToolbar = FindWindowEx(hToolBoxContainer, NULL, TOOLBARCLASSNAME, NULL);
|
||||||
|
SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELONG(TRUE, 0));
|
||||||
|
SendMessage(window, WM_COMMAND, ID_RECTSEL, 0);
|
||||||
|
|
||||||
|
DeleteObject(SelectObject(hSelDC, hSelBm = CopyImage(bitmap,
|
||||||
|
IMAGE_BITMAP, 0, 0,
|
||||||
|
LR_COPYRETURNORG)));
|
||||||
|
newReversible();
|
||||||
|
rectSel_src[0] = rectSel_src[1] = rectSel_src[2] = rectSel_src[3] = 0;
|
||||||
|
rectSel_dest[0] = rectSel_dest[1] = 0;
|
||||||
|
rectSel_dest[2] = GetDIBWidth(hSelBm);
|
||||||
|
rectSel_dest[3] = GetDIBHeight(hSelBm);
|
||||||
|
BitBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3],
|
||||||
|
hSelDC, 0, 0, SRCCOPY);
|
||||||
|
placeSelWin();
|
||||||
|
ShowWindow(hSelection, SW_SHOW);
|
||||||
|
}
|
||||||
|
|
||||||
BOOL drawing;
|
BOOL drawing;
|
||||||
|
|
||||||
LRESULT CALLBACK
|
LRESULT CALLBACK
|
||||||
|
@ -169,6 +204,25 @@ WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
switch (message) /* handle the messages */
|
switch (message) /* handle the messages */
|
||||||
{
|
{
|
||||||
|
case WM_DROPFILES:
|
||||||
|
{
|
||||||
|
HDROP drophandle;
|
||||||
|
TCHAR droppedfile[MAX_PATH];
|
||||||
|
drophandle = (HDROP)wParam;
|
||||||
|
DragQueryFile(drophandle, 0, droppedfile, sizeof(droppedfile));
|
||||||
|
DragFinish(drophandle);
|
||||||
|
HBITMAP bmNew = NULL;
|
||||||
|
LoadDIBFromFile(&bmNew, droppedfile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
|
||||||
|
if (bmNew != NULL)
|
||||||
|
{
|
||||||
|
TCHAR *pathend;
|
||||||
|
pathend = _tcsrchr(droppedfile, '\\');
|
||||||
|
pathend++;
|
||||||
|
UpdateApplicationProperties(bmNew, pathend, pathend);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
ptStack = NULL;
|
ptStack = NULL;
|
||||||
ptSP = 0;
|
ptSP = 0;
|
||||||
|
@ -785,27 +839,7 @@ WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
|
LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
|
||||||
if (bmNew != NULL)
|
if (bmNew != NULL)
|
||||||
{
|
{
|
||||||
TCHAR tempstr[1000];
|
UpdateApplicationProperties(bmNew, ofn.lpstrFileTitle, ofn.lpstrFileTitle);
|
||||||
TCHAR resstr[100];
|
|
||||||
insertReversible(bmNew);
|
|
||||||
updateCanvasAndScrollbars();
|
|
||||||
CopyMemory(filename, ofn.lpstrFileTitle, sizeof(filename));
|
|
||||||
CopyMemory(filepathname, ofn.lpstrFileTitle, sizeof(filepathname));
|
|
||||||
LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
|
|
||||||
_stprintf(tempstr, resstr, filename);
|
|
||||||
SetWindowText(hMainWnd, tempstr);
|
|
||||||
clearHistory();
|
|
||||||
isAFile = TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TCHAR programname[20];
|
|
||||||
TCHAR loaderrortext[100];
|
|
||||||
TCHAR temptext[500];
|
|
||||||
LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
|
|
||||||
LoadString(hProgInstance, IDS_LOADERRORTEXT, loaderrortext, SIZEOF(loaderrortext));
|
|
||||||
_stprintf(temptext, loaderrortext, ofn.lpstrFile);
|
|
||||||
MessageBox(hwnd, temptext, programname, MB_OK | MB_ICONEXCLAMATION);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -848,22 +882,7 @@ WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
OpenClipboard(hMainWnd);
|
OpenClipboard(hMainWnd);
|
||||||
if (GetClipboardData(CF_BITMAP) != NULL)
|
if (GetClipboardData(CF_BITMAP) != NULL)
|
||||||
{
|
{
|
||||||
HWND hToolbar = FindWindowEx(hToolBoxContainer, NULL, TOOLBARCLASSNAME, NULL);
|
InsertSelectionFromHBITMAP(GetClipboardData(CF_BITMAP), hwnd);
|
||||||
SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELONG(TRUE, 0));
|
|
||||||
SendMessage(hwnd, WM_COMMAND, ID_RECTSEL, 0);
|
|
||||||
|
|
||||||
DeleteObject(SelectObject(hSelDC, hSelBm = CopyImage(GetClipboardData(CF_BITMAP),
|
|
||||||
IMAGE_BITMAP, 0, 0,
|
|
||||||
LR_COPYRETURNORG)));
|
|
||||||
newReversible();
|
|
||||||
rectSel_src[0] = rectSel_src[1] = rectSel_src[2] = rectSel_src[3] = 0;
|
|
||||||
rectSel_dest[0] = rectSel_dest[1] = 0;
|
|
||||||
rectSel_dest[2] = GetDIBWidth(hSelBm);
|
|
||||||
rectSel_dest[3] = GetDIBHeight(hSelBm);
|
|
||||||
BitBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3],
|
|
||||||
hSelDC, 0, 0, SRCCOPY);
|
|
||||||
placeSelWin();
|
|
||||||
ShowWindow(hSelection, SW_SHOW);
|
|
||||||
}
|
}
|
||||||
CloseClipboard();
|
CloseClipboard();
|
||||||
break;
|
break;
|
||||||
|
@ -899,6 +918,18 @@ WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
if (GetSaveFileName(&ofn) != 0)
|
if (GetSaveFileName(&ofn) != 0)
|
||||||
SaveDIBToFile(hSelBm, ofn.lpstrFile, hDrawingDC, NULL, NULL, fileHPPM, fileVPPM);
|
SaveDIBToFile(hSelBm, ofn.lpstrFile, hDrawingDC, NULL, NULL, fileHPPM, fileVPPM);
|
||||||
break;
|
break;
|
||||||
|
case IDM_EDITPASTEFROM:
|
||||||
|
if (GetOpenFileName(&ofn) != 0)
|
||||||
|
{
|
||||||
|
HBITMAP bmNew = NULL;
|
||||||
|
LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
|
||||||
|
if (bmNew != NULL)
|
||||||
|
{
|
||||||
|
InsertSelectionFromHBITMAP(bmNew, hwnd);
|
||||||
|
DeleteObject(bmNew);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case IDM_COLORSEDITPALETTE:
|
case IDM_COLORSEDITPALETTE:
|
||||||
if (ChooseColor(&choosecolor))
|
if (ChooseColor(&choosecolor))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue