2009-05-12 14:15:48 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: PAINT for ReactOS
|
|
|
|
* LICENSE: LGPL
|
2009-10-21 15:44:31 +00:00
|
|
|
* FILE: base/applications/paint/main.c
|
2009-05-12 14:15:48 +00:00
|
|
|
* PURPOSE: Initializing everything
|
|
|
|
* PROGRAMMERS: Benedikt Freisen
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *********************************************************/
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <windowsx.h>
|
|
|
|
#include <commctrl.h>
|
|
|
|
#include <stdio.h>
|
2009-05-27 17:56:50 +00:00
|
|
|
#include <tchar.h>
|
2009-05-12 14:15:48 +00:00
|
|
|
#include "definitions.h"
|
|
|
|
|
|
|
|
#include "drawing.h"
|
|
|
|
#include "dib.h"
|
|
|
|
|
|
|
|
#include "globalvar.h"
|
|
|
|
#include "history.h"
|
|
|
|
#include "mouse.h"
|
|
|
|
|
|
|
|
#include "winproc.h"
|
|
|
|
#include "palette.h"
|
|
|
|
#include "toolsettings.h"
|
|
|
|
#include "selection.h"
|
2009-07-02 17:02:37 +00:00
|
|
|
#include "sizebox.h"
|
2009-05-12 14:15:48 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS ********************************************************/
|
|
|
|
|
|
|
|
HDC hDrawingDC;
|
|
|
|
HDC hSelDC;
|
|
|
|
int *bmAddress;
|
|
|
|
BITMAPINFO bitmapinfo;
|
|
|
|
int imgXRes = 400;
|
|
|
|
int imgYRes = 300;
|
|
|
|
|
2009-10-03 16:33:41 +00:00
|
|
|
HBITMAP hBms[HISTORYSIZE];
|
2009-05-12 14:15:48 +00:00
|
|
|
int currInd = 0;
|
|
|
|
int undoSteps = 0;
|
|
|
|
int redoSteps = 0;
|
2009-10-03 16:33:41 +00:00
|
|
|
BOOL imageSaved = TRUE;
|
2009-05-12 14:15:48 +00:00
|
|
|
|
|
|
|
short startX;
|
|
|
|
short startY;
|
|
|
|
short lastX;
|
|
|
|
short lastY;
|
|
|
|
int lineWidth = 1;
|
|
|
|
int shapeStyle = 0;
|
|
|
|
int brushStyle = 0;
|
2010-05-27 12:21:50 +00:00
|
|
|
int activeTool = TOOL_PEN;
|
2009-05-12 14:15:48 +00:00
|
|
|
int airBrushWidth = 5;
|
|
|
|
int rubberRadius = 4;
|
|
|
|
int transpBg = 0;
|
|
|
|
int zoom = 1000;
|
|
|
|
int rectSel_src[4];
|
|
|
|
int rectSel_dest[4];
|
|
|
|
HWND hSelection;
|
|
|
|
HWND hImageArea;
|
|
|
|
HBITMAP hSelBm;
|
2010-01-16 23:21:45 +00:00
|
|
|
HBITMAP hSelMask;
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-10-21 15:44:31 +00:00
|
|
|
/* initial palette colors; may be changed by the user during execution */
|
|
|
|
int palColors[28] = { 0x000000, 0x464646, 0x787878, 0x300099, 0x241ced, 0x0078ff, 0x0ec2ff,
|
2009-05-12 14:15:48 +00:00
|
|
|
0x00f2ff, 0x1de6a8, 0x4cb122, 0xefb700, 0xf36d4d, 0x99362f, 0x98316f,
|
|
|
|
0xffffff, 0xdcdcdc, 0xb4b4b4, 0x3c5a9c, 0xb1a3ff, 0x7aaae5, 0x9ce4f5,
|
2009-10-21 15:44:31 +00:00
|
|
|
0xbdf9ff, 0xbcf9d3, 0x61bb9d, 0xead999, 0xd19a70, 0x8e6d54, 0xd5a5b5
|
|
|
|
};
|
|
|
|
|
|
|
|
/* foreground and background colors with initial value */
|
2009-05-12 14:15:48 +00:00
|
|
|
int fgColor = 0x00000000;
|
|
|
|
int bgColor = 0x00ffffff;
|
2009-10-21 15:44:31 +00:00
|
|
|
|
2009-05-12 14:15:48 +00:00
|
|
|
HWND hStatusBar;
|
|
|
|
HWND hScrollbox;
|
|
|
|
HWND hMainWnd;
|
|
|
|
HWND hPalWin;
|
2009-12-27 21:15:08 +00:00
|
|
|
HWND hToolBoxContainer;
|
2009-05-12 14:15:48 +00:00
|
|
|
HWND hToolSettings;
|
2009-10-21 15:44:31 +00:00
|
|
|
HWND hTrackbarZoom;
|
2009-05-12 14:15:48 +00:00
|
|
|
CHOOSECOLOR choosecolor;
|
|
|
|
OPENFILENAME ofn;
|
|
|
|
OPENFILENAME sfn;
|
|
|
|
HICON hNontranspIcon;
|
|
|
|
HICON hTranspIcon;
|
|
|
|
|
|
|
|
HCURSOR hCurFill;
|
|
|
|
HCURSOR hCurColor;
|
|
|
|
HCURSOR hCurZoom;
|
|
|
|
HCURSOR hCurPen;
|
|
|
|
HCURSOR hCurAirbrush;
|
|
|
|
|
|
|
|
HWND hScrlClient;
|
|
|
|
|
|
|
|
HWND hToolBtn[16];
|
|
|
|
|
|
|
|
HINSTANCE hProgInstance;
|
|
|
|
|
2009-05-27 17:56:50 +00:00
|
|
|
TCHAR filename[256];
|
|
|
|
TCHAR filepathname[1000];
|
2009-05-12 14:15:48 +00:00
|
|
|
BOOL isAFile = FALSE;
|
2009-10-18 18:36:46 +00:00
|
|
|
int fileSize;
|
|
|
|
int fileHPPM = 2834;
|
|
|
|
int fileVPPM = 2834;
|
|
|
|
SYSTEMTIME fileTime;
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-07-01 19:24:17 +00:00
|
|
|
BOOL showGrid = FALSE;
|
|
|
|
BOOL showMiniature = FALSE;
|
|
|
|
|
|
|
|
HWND hwndMiniature;
|
|
|
|
|
2009-07-02 17:02:37 +00:00
|
|
|
HWND hSizeboxLeftTop;
|
|
|
|
HWND hSizeboxCenterTop;
|
|
|
|
HWND hSizeboxRightTop;
|
|
|
|
HWND hSizeboxLeftCenter;
|
|
|
|
HWND hSizeboxRightCenter;
|
|
|
|
HWND hSizeboxLeftBottom;
|
|
|
|
HWND hSizeboxCenterBottom;
|
|
|
|
HWND hSizeboxRightBottom;
|
|
|
|
|
2009-10-21 15:44:31 +00:00
|
|
|
/* entry point */
|
2009-10-03 16:33:41 +00:00
|
|
|
|
2009-10-21 15:44:31 +00:00
|
|
|
int WINAPI
|
|
|
|
_tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument, int nFunsterStil)
|
2009-05-12 14:15:48 +00:00
|
|
|
{
|
|
|
|
HWND hwnd; /* This is the handle for our window */
|
|
|
|
MSG messages; /* Here messages to the application are saved */
|
2009-10-21 15:44:31 +00:00
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
WNDCLASSEX wclScroll;
|
|
|
|
WNDCLASSEX wincl;
|
|
|
|
WNDCLASSEX wclPal;
|
|
|
|
WNDCLASSEX wclSettings;
|
|
|
|
WNDCLASSEX wclSelection;
|
2009-10-21 15:44:31 +00:00
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
TCHAR progtitle[1000];
|
|
|
|
TCHAR resstr[100];
|
|
|
|
HMENU menu;
|
|
|
|
HWND hToolbar;
|
|
|
|
HIMAGELIST hImageList;
|
|
|
|
HANDLE haccel;
|
|
|
|
HBITMAP tempBm;
|
|
|
|
int i;
|
|
|
|
TCHAR tooltips[16][30];
|
2010-04-29 19:56:18 +00:00
|
|
|
HDC hDC;
|
2009-10-21 15:44:31 +00:00
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
TCHAR *c;
|
|
|
|
TCHAR sfnFilename[1000];
|
|
|
|
TCHAR sfnFiletitle[256];
|
|
|
|
TCHAR sfnFilter[1000];
|
|
|
|
TCHAR ofnFilename[1000];
|
|
|
|
TCHAR ofnFiletitle[256];
|
|
|
|
TCHAR ofnFilter[1000];
|
2009-07-01 21:31:13 +00:00
|
|
|
TCHAR miniaturetitle[100];
|
2010-04-29 19:56:18 +00:00
|
|
|
static int custColors[16] = { 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
|
2009-10-21 15:44:31 +00:00
|
|
|
0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff
|
|
|
|
};
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
hProgInstance = hThisInstance;
|
|
|
|
|
|
|
|
/* Necessary */
|
2009-05-12 14:15:48 +00:00
|
|
|
InitCommonControls();
|
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* initializing and registering the window class used for the main window */
|
2009-05-12 14:15:48 +00:00
|
|
|
wincl.hInstance = hThisInstance;
|
2009-05-27 17:56:50 +00:00
|
|
|
wincl.lpszClassName = _T("WindowsApp");
|
2009-05-12 14:15:48 +00:00
|
|
|
wincl.lpfnWndProc = WindowProcedure;
|
|
|
|
wincl.style = CS_DBLCLKS;
|
2009-10-21 15:44:31 +00:00
|
|
|
wincl.cbSize = sizeof(WNDCLASSEX);
|
|
|
|
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
|
|
|
wincl.hIconSm = LoadIcon(hThisInstance, MAKEINTRESOURCE(500));
|
|
|
|
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
|
2009-05-12 14:15:48 +00:00
|
|
|
wincl.lpszMenuName = NULL;
|
|
|
|
wincl.cbClsExtra = 0;
|
|
|
|
wincl.cbWndExtra = 0;
|
|
|
|
wincl.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
|
|
|
|
RegisterClassEx (&wincl);
|
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* initializing and registering the window class used for the scroll box */
|
2009-05-12 14:15:48 +00:00
|
|
|
wclScroll.hInstance = hThisInstance;
|
2009-05-27 17:56:50 +00:00
|
|
|
wclScroll.lpszClassName = _T("Scrollbox");
|
2009-05-12 14:15:48 +00:00
|
|
|
wclScroll.lpfnWndProc = WindowProcedure;
|
|
|
|
wclScroll.style = 0;
|
2009-10-21 15:44:31 +00:00
|
|
|
wclScroll.cbSize = sizeof(WNDCLASSEX);
|
2009-05-12 14:15:48 +00:00
|
|
|
wclScroll.hIcon = NULL;
|
|
|
|
wclScroll.hIconSm = NULL;
|
2009-10-21 15:44:31 +00:00
|
|
|
wclScroll.hCursor = LoadCursor(NULL, IDC_ARROW);
|
2009-05-12 14:15:48 +00:00
|
|
|
wclScroll.lpszMenuName = NULL;
|
|
|
|
wclScroll.cbClsExtra = 0;
|
|
|
|
wclScroll.cbWndExtra = 0;
|
|
|
|
wclScroll.hbrBackground = GetSysColorBrush(COLOR_APPWORKSPACE);
|
|
|
|
RegisterClassEx (&wclScroll);
|
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* initializing and registering the window class used for the palette window */
|
2009-05-12 14:15:48 +00:00
|
|
|
wclPal.hInstance = hThisInstance;
|
2009-05-27 17:56:50 +00:00
|
|
|
wclPal.lpszClassName = _T("Palette");
|
2009-05-12 14:15:48 +00:00
|
|
|
wclPal.lpfnWndProc = PalWinProc;
|
|
|
|
wclPal.style = CS_DBLCLKS;
|
2009-10-21 15:44:31 +00:00
|
|
|
wclPal.cbSize = sizeof(WNDCLASSEX);
|
2009-05-12 14:15:48 +00:00
|
|
|
wclPal.hIcon = NULL;
|
|
|
|
wclPal.hIconSm = NULL;
|
2009-10-21 15:44:31 +00:00
|
|
|
wclPal.hCursor = LoadCursor(NULL, IDC_ARROW);
|
2009-05-12 14:15:48 +00:00
|
|
|
wclPal.lpszMenuName = NULL;
|
|
|
|
wclPal.cbClsExtra = 0;
|
|
|
|
wclPal.cbWndExtra = 0;
|
|
|
|
wclPal.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
|
|
|
|
RegisterClassEx (&wclPal);
|
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* initializing and registering the window class for the settings window */
|
2009-05-12 14:15:48 +00:00
|
|
|
wclSettings.hInstance = hThisInstance;
|
2009-05-27 17:56:50 +00:00
|
|
|
wclSettings.lpszClassName = _T("ToolSettings");
|
2009-05-12 14:15:48 +00:00
|
|
|
wclSettings.lpfnWndProc = SettingsWinProc;
|
|
|
|
wclSettings.style = CS_DBLCLKS;
|
2009-10-21 15:44:31 +00:00
|
|
|
wclSettings.cbSize = sizeof(WNDCLASSEX);
|
2009-05-12 14:15:48 +00:00
|
|
|
wclSettings.hIcon = NULL;
|
|
|
|
wclSettings.hIconSm = NULL;
|
2009-10-21 15:44:31 +00:00
|
|
|
wclSettings.hCursor = LoadCursor(NULL, IDC_ARROW);
|
2009-05-12 14:15:48 +00:00
|
|
|
wclSettings.lpszMenuName = NULL;
|
|
|
|
wclSettings.cbClsExtra = 0;
|
|
|
|
wclSettings.cbWndExtra = 0;
|
|
|
|
wclSettings.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
|
|
|
|
RegisterClassEx (&wclSettings);
|
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* initializing and registering the window class for the selection frame */
|
2009-05-12 14:15:48 +00:00
|
|
|
wclSelection.hInstance = hThisInstance;
|
2009-05-27 17:56:50 +00:00
|
|
|
wclSelection.lpszClassName = _T("Selection");
|
2009-05-12 14:15:48 +00:00
|
|
|
wclSelection.lpfnWndProc = SelectionWinProc;
|
|
|
|
wclSelection.style = CS_DBLCLKS;
|
2009-10-21 15:44:31 +00:00
|
|
|
wclSelection.cbSize = sizeof(WNDCLASSEX);
|
2009-05-12 14:15:48 +00:00
|
|
|
wclSelection.hIcon = NULL;
|
|
|
|
wclSelection.hIconSm = NULL;
|
2009-10-21 15:44:31 +00:00
|
|
|
wclSelection.hCursor = LoadCursor(NULL, IDC_SIZEALL);
|
2009-05-12 14:15:48 +00:00
|
|
|
wclSelection.lpszMenuName = NULL;
|
|
|
|
wclSelection.cbClsExtra = 0;
|
|
|
|
wclSelection.cbWndExtra = 0;
|
2009-10-21 15:44:31 +00:00
|
|
|
wclSelection.hbrBackground = NULL;
|
2009-05-12 14:15:48 +00:00
|
|
|
RegisterClassEx (&wclSelection);
|
|
|
|
|
2009-07-02 17:02:37 +00:00
|
|
|
/* initializing and registering the window class for the size boxes */
|
|
|
|
wclSettings.hInstance = hThisInstance;
|
|
|
|
wclSettings.lpszClassName = _T("Sizebox");
|
|
|
|
wclSettings.lpfnWndProc = SizeboxWinProc;
|
|
|
|
wclSettings.style = CS_DBLCLKS;
|
2009-10-21 15:44:31 +00:00
|
|
|
wclSettings.cbSize = sizeof(WNDCLASSEX);
|
2009-07-02 17:02:37 +00:00
|
|
|
wclSettings.hIcon = NULL;
|
|
|
|
wclSettings.hIconSm = NULL;
|
2009-10-21 15:44:31 +00:00
|
|
|
wclSettings.hCursor = LoadCursor(NULL, IDC_ARROW);
|
2009-07-02 17:02:37 +00:00
|
|
|
wclSettings.lpszMenuName = NULL;
|
|
|
|
wclSettings.cbClsExtra = 0;
|
|
|
|
wclSettings.cbWndExtra = 0;
|
|
|
|
wclSettings.hbrBackground = GetSysColorBrush(COLOR_HIGHLIGHT);
|
|
|
|
RegisterClassEx (&wclSettings);
|
|
|
|
|
2009-05-27 17:56:50 +00:00
|
|
|
LoadString(hThisInstance, IDS_DEFAULTFILENAME, filename, SIZEOF(filename));
|
|
|
|
LoadString(hThisInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
|
|
|
|
_stprintf(progtitle, resstr, filename);
|
2009-07-01 19:24:17 +00:00
|
|
|
LoadString(hThisInstance, IDS_MINIATURETITLE, miniaturetitle, SIZEOF(miniaturetitle));
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* create main window */
|
2009-10-21 15:44:31 +00:00
|
|
|
hwnd =
|
|
|
|
CreateWindowEx(0, _T("WindowsApp"), progtitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 544,
|
|
|
|
375, HWND_DESKTOP, NULL, hThisInstance, NULL);
|
2009-05-12 14:15:48 +00:00
|
|
|
hMainWnd = hwnd;
|
2009-10-21 15:44:31 +00:00
|
|
|
|
|
|
|
hwndMiniature =
|
|
|
|
CreateWindowEx(WS_EX_PALETTEWINDOW, _T("WindowsApp"), miniaturetitle,
|
|
|
|
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME, 180, 200, 120, 100, hwnd,
|
|
|
|
NULL, hThisInstance, NULL);
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* loading and setting the window menu from resource */
|
2009-05-12 14:15:48 +00:00
|
|
|
menu = LoadMenu(hThisInstance, MAKEINTRESOURCE(ID_MENU));
|
|
|
|
SetMenu(hwnd, menu);
|
2009-06-16 21:12:47 +00:00
|
|
|
haccel = LoadAccelerators(hThisInstance, MAKEINTRESOURCE(800));
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* preloading the draw transparent/nontransparent icons for later use */
|
2009-10-21 15:44:31 +00:00
|
|
|
hNontranspIcon =
|
|
|
|
LoadImage(hThisInstance, MAKEINTRESOURCE(IDI_NONTRANSPARENT), IMAGE_ICON, 40, 30, LR_DEFAULTCOLOR);
|
|
|
|
hTranspIcon =
|
|
|
|
LoadImage(hThisInstance, MAKEINTRESOURCE(IDI_TRANSPARENT), IMAGE_ICON, 40, 30, LR_DEFAULTCOLOR);
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-10-21 15:44:31 +00:00
|
|
|
hCurFill = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_FILL));
|
|
|
|
hCurColor = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_COLOR));
|
|
|
|
hCurZoom = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_ZOOM));
|
|
|
|
hCurPen = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_PEN));
|
|
|
|
hCurAirbrush = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_AIRBRUSH));
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-10-21 15:44:31 +00:00
|
|
|
CreateWindowEx(0, _T("STATIC"), _T(""), WS_CHILD | WS_VISIBLE | SS_ETCHEDHORZ, 0, 0, 5000, 2, hwnd, NULL,
|
|
|
|
hThisInstance, NULL);
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-12-27 21:15:08 +00:00
|
|
|
hToolBoxContainer =
|
|
|
|
CreateWindowEx(0, _T("WindowsApp"), _T(""), WS_CHILD | WS_VISIBLE, 2, 2, 52, 350, hwnd, NULL,
|
|
|
|
hThisInstance, NULL);
|
2009-06-16 21:12:47 +00:00
|
|
|
/* creating the 16 bitmap radio buttons and setting the bitmap */
|
2009-05-12 14:15:48 +00:00
|
|
|
|
|
|
|
|
2009-10-21 15:44:31 +00:00
|
|
|
/*
|
|
|
|
* FIXME: Unintentionally there is a line above the tool bar.
|
|
|
|
* To prevent cropping of the buttons height has been increased from 200 to 205
|
|
|
|
*/
|
|
|
|
hToolbar =
|
|
|
|
CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
|
|
|
|
WS_CHILD | WS_VISIBLE | CCS_NOPARENTALIGN | CCS_VERT | CCS_NORESIZE | TBSTYLE_TOOLTIPS,
|
2009-12-27 21:15:08 +00:00
|
|
|
1, 1, 50, 205, hToolBoxContainer, NULL, hThisInstance, NULL);
|
2009-06-16 21:12:47 +00:00
|
|
|
hImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 16, 0);
|
2009-10-21 15:44:31 +00:00
|
|
|
SendMessage(hToolbar, TB_SETIMAGELIST, 0, (LPARAM) hImageList);
|
2009-06-16 21:12:47 +00:00
|
|
|
tempBm = LoadImage(hThisInstance, MAKEINTRESOURCE(IDB_TOOLBARICONS), IMAGE_BITMAP, 256, 16, 0);
|
2009-05-12 14:15:48 +00:00
|
|
|
ImageList_AddMasked(hImageList, tempBm, 0xff00ff);
|
|
|
|
DeleteObject(tempBm);
|
|
|
|
SendMessage(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
|
2009-10-21 15:44:31 +00:00
|
|
|
|
|
|
|
for(i = 0; i < 16; i++)
|
2009-05-12 14:15:48 +00:00
|
|
|
{
|
2009-06-17 11:52:39 +00:00
|
|
|
TBBUTTON tbbutton;
|
2009-05-12 14:15:48 +00:00
|
|
|
int wrapnow = 0;
|
2009-06-17 11:52:39 +00:00
|
|
|
|
2009-10-21 15:44:31 +00:00
|
|
|
if (i % 2 == 1)
|
|
|
|
wrapnow = TBSTATE_WRAP;
|
|
|
|
|
2009-05-27 17:56:50 +00:00
|
|
|
LoadString(hThisInstance, IDS_TOOLTIP1 + i, tooltips[i], 30);
|
2009-06-17 11:52:39 +00:00
|
|
|
ZeroMemory(&tbbutton, sizeof(TBBUTTON));
|
2009-10-21 15:44:31 +00:00
|
|
|
tbbutton.iString = (INT_PTR) tooltips[i];
|
|
|
|
tbbutton.fsStyle = TBSTYLE_CHECKGROUP;
|
|
|
|
tbbutton.fsState = TBSTATE_ENABLED | wrapnow;
|
2009-06-17 11:52:39 +00:00
|
|
|
tbbutton.idCommand = ID_FREESEL + i;
|
2009-10-21 15:44:31 +00:00
|
|
|
tbbutton.iBitmap = i;
|
|
|
|
SendMessage(hToolbar, TB_ADDBUTTONS, 1, (LPARAM) &tbbutton);
|
2009-05-12 14:15:48 +00:00
|
|
|
}
|
2009-10-21 15:44:31 +00:00
|
|
|
|
2009-05-12 14:15:48 +00:00
|
|
|
SendMessage(hToolbar, TB_CHECKBUTTON, ID_PEN, MAKELONG(TRUE, 0));
|
|
|
|
SendMessage(hToolbar, TB_SETMAXTEXTROWS, 0, 0);
|
|
|
|
SendMessage(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(25, 25));
|
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* creating the tool settings child window */
|
2009-10-21 15:44:31 +00:00
|
|
|
hToolSettings =
|
2009-12-27 21:15:08 +00:00
|
|
|
CreateWindowEx(0, _T("ToolSettings"), _T(""), WS_CHILD | WS_VISIBLE, 5, 208, 42, 140,
|
|
|
|
hToolBoxContainer, NULL, hThisInstance, NULL);
|
2009-10-21 15:44:31 +00:00
|
|
|
hTrackbarZoom =
|
|
|
|
CreateWindowEx(0, TRACKBAR_CLASS, _T(""), WS_CHILD | TBS_VERT | TBS_AUTOTICKS, 1, 1, 40, 64,
|
|
|
|
hToolSettings, NULL, hThisInstance, NULL);
|
|
|
|
SendMessage(hTrackbarZoom, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 6));
|
|
|
|
SendMessage(hTrackbarZoom, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) 3);
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* creating the palette child window */
|
2009-10-21 15:44:31 +00:00
|
|
|
hPalWin =
|
|
|
|
CreateWindowEx(0, _T("Palette"), _T(""), WS_CHILD | WS_VISIBLE, 56, 9, 255, 32, hwnd, NULL,
|
|
|
|
hThisInstance, NULL);
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* creating the scroll box */
|
2009-10-21 15:44:31 +00:00
|
|
|
hScrollbox =
|
|
|
|
CreateWindowEx(WS_EX_CLIENTEDGE, _T("Scrollbox"), _T(""),
|
|
|
|
WS_CHILD | WS_GROUP | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE, 56, 49, 472, 248, hwnd,
|
|
|
|
NULL, hThisInstance, NULL);
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* creating the status bar */
|
2009-10-21 15:44:31 +00:00
|
|
|
hStatusBar =
|
|
|
|
CreateWindowEx(0, STATUSCLASSNAME, _T(""), SBARS_SIZEGRIP | WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd,
|
|
|
|
NULL, hThisInstance, NULL);
|
2009-05-12 14:15:48 +00:00
|
|
|
SendMessage(hStatusBar, SB_SETMINHEIGHT, 21, 0);
|
|
|
|
|
2009-10-21 15:44:31 +00:00
|
|
|
hScrlClient =
|
|
|
|
CreateWindowEx(0, _T("Scrollbox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 500, 500, hScrollbox, NULL,
|
|
|
|
hThisInstance, NULL);
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* create selection window (initially hidden) */
|
2009-10-21 15:44:31 +00:00
|
|
|
hSelection =
|
|
|
|
CreateWindowEx(WS_EX_TRANSPARENT, _T("Selection"), _T(""), WS_CHILD | BS_OWNERDRAW, 350, 0, 100, 100,
|
|
|
|
hScrlClient, NULL, hThisInstance, NULL);
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* creating the window inside the scroll box, on which the image in hDrawingDC's bitmap is drawn */
|
2009-10-21 15:44:31 +00:00
|
|
|
hImageArea =
|
|
|
|
CreateWindowEx(0, _T("Scrollbox"), _T(""), WS_CHILD | WS_VISIBLE, 3, 3, imgXRes, imgYRes, hScrlClient,
|
|
|
|
NULL, hThisInstance, NULL);
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2010-04-29 19:56:18 +00:00
|
|
|
hDC = GetDC(hImageArea);
|
|
|
|
hDrawingDC = CreateCompatibleDC(hDC);
|
|
|
|
hSelDC = CreateCompatibleDC(hDC);
|
|
|
|
ReleaseDC(hImageArea, hDC);
|
2009-05-12 14:15:48 +00:00
|
|
|
SelectObject(hDrawingDC, CreatePen(PS_SOLID, 0, fgColor));
|
|
|
|
SelectObject(hDrawingDC, CreateSolidBrush(bgColor));
|
|
|
|
|
|
|
|
hBms[0] = CreateDIBWithProperties(imgXRes, imgYRes);
|
|
|
|
SelectObject(hDrawingDC, hBms[0]);
|
2009-10-21 15:44:31 +00:00
|
|
|
Rectangle(hDrawingDC, 0 - 1, 0 - 1, imgXRes + 1, imgYRes + 1);
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-10-18 18:36:46 +00:00
|
|
|
if (lpszArgument[0] != 0)
|
|
|
|
{
|
|
|
|
HBITMAP bmNew = NULL;
|
|
|
|
LoadDIBFromFile(&bmNew, lpszArgument, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
|
2009-10-21 15:44:31 +00:00
|
|
|
if (bmNew != NULL)
|
2009-10-18 18:36:46 +00:00
|
|
|
{
|
|
|
|
TCHAR tempstr[1000];
|
|
|
|
TCHAR resstr[100];
|
|
|
|
TCHAR *temp;
|
2009-10-19 17:46:29 +00:00
|
|
|
insertReversible(bmNew);
|
2009-10-21 15:44:31 +00:00
|
|
|
GetFullPathName(lpszArgument, SIZEOF(filepathname), filepathname, &temp);
|
2009-10-18 18:36:46 +00:00
|
|
|
_tcscpy(filename, temp);
|
|
|
|
LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
|
|
|
|
_stprintf(tempstr, resstr, filename);
|
|
|
|
SetWindowText(hMainWnd, tempstr);
|
|
|
|
clearHistory();
|
|
|
|
isAFile = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* initializing the CHOOSECOLOR structure for use with ChooseColor */
|
2009-10-21 15:44:31 +00:00
|
|
|
choosecolor.lStructSize = sizeof(CHOOSECOLOR);
|
|
|
|
choosecolor.hwndOwner = hwnd;
|
|
|
|
choosecolor.hInstance = NULL;
|
|
|
|
choosecolor.rgbResult = 0x00ffffff;
|
|
|
|
choosecolor.lpCustColors = (COLORREF*) &custColors;
|
|
|
|
choosecolor.Flags = 0;
|
|
|
|
choosecolor.lCustData = 0;
|
|
|
|
choosecolor.lpfnHook = NULL;
|
|
|
|
choosecolor.lpTemplateName = NULL;
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* initializing the OPENFILENAME structure for use with GetOpenFileName and GetSaveFileName */
|
2009-05-27 12:03:18 +00:00
|
|
|
CopyMemory(ofnFilename, filename, sizeof(filename));
|
2009-05-27 17:56:50 +00:00
|
|
|
LoadString(hThisInstance, IDS_OPENFILTER, ofnFilter, SIZEOF(ofnFilter));
|
2009-10-21 15:44:31 +00:00
|
|
|
for(c = ofnFilter; *c; c++)
|
|
|
|
if (*c == '\1')
|
|
|
|
*c = '\0';
|
2009-05-12 14:15:48 +00:00
|
|
|
ZeroMemory(&ofn, sizeof(OPENFILENAME));
|
2009-10-21 15:44:31 +00:00
|
|
|
ofn.lStructSize = sizeof(OPENFILENAME);
|
|
|
|
ofn.hwndOwner = hwnd;
|
|
|
|
ofn.hInstance = hThisInstance;
|
|
|
|
ofn.lpstrFilter = ofnFilter;
|
|
|
|
ofn.lpstrFile = ofnFilename;
|
|
|
|
ofn.nMaxFile = SIZEOF(ofnFilename);
|
|
|
|
ofn.lpstrFileTitle = ofnFiletitle;
|
|
|
|
ofn.nMaxFileTitle = SIZEOF(ofnFiletitle);
|
|
|
|
ofn.Flags = OFN_HIDEREADONLY;
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-05-27 12:03:18 +00:00
|
|
|
CopyMemory(sfnFilename, filename, sizeof(filename));
|
2009-05-27 17:56:50 +00:00
|
|
|
LoadString(hThisInstance, IDS_SAVEFILTER, sfnFilter, SIZEOF(sfnFilter));
|
2009-10-21 15:44:31 +00:00
|
|
|
for(c = sfnFilter; *c; c++)
|
|
|
|
if (*c == '\1')
|
|
|
|
*c = '\0';
|
2009-05-12 14:15:48 +00:00
|
|
|
ZeroMemory(&sfn, sizeof(OPENFILENAME));
|
2009-10-21 15:44:31 +00:00
|
|
|
sfn.lStructSize = sizeof(OPENFILENAME);
|
|
|
|
sfn.hwndOwner = hwnd;
|
|
|
|
sfn.hInstance = hThisInstance;
|
|
|
|
sfn.lpstrFilter = sfnFilter;
|
|
|
|
sfn.lpstrFile = sfnFilename;
|
|
|
|
sfn.nMaxFile = SIZEOF(sfnFilename);
|
|
|
|
sfn.lpstrFileTitle = sfnFiletitle;
|
|
|
|
sfn.nMaxFileTitle = SIZEOF(sfnFiletitle);
|
|
|
|
sfn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
|
|
|
|
|
|
|
|
/* creating the size boxes */
|
|
|
|
hSizeboxLeftTop =
|
|
|
|
CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
|
|
|
|
hThisInstance, NULL);
|
|
|
|
hSizeboxCenterTop =
|
|
|
|
CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
|
|
|
|
hThisInstance, NULL);
|
|
|
|
hSizeboxRightTop =
|
|
|
|
CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
|
|
|
|
hThisInstance, NULL);
|
|
|
|
hSizeboxLeftCenter =
|
|
|
|
CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
|
|
|
|
hThisInstance, NULL);
|
|
|
|
hSizeboxRightCenter =
|
|
|
|
CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
|
|
|
|
hThisInstance, NULL);
|
|
|
|
hSizeboxLeftBottom =
|
|
|
|
CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
|
|
|
|
hThisInstance, NULL);
|
|
|
|
hSizeboxCenterBottom =
|
|
|
|
CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
|
|
|
|
hThisInstance, NULL);
|
|
|
|
hSizeboxRightBottom =
|
|
|
|
CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
|
|
|
|
hThisInstance, NULL);
|
|
|
|
/* placing the size boxes around the image */
|
2009-07-02 17:02:37 +00:00
|
|
|
SendMessage(hImageArea, WM_SIZE, 0, 0);
|
2009-05-12 14:15:48 +00:00
|
|
|
|
2009-06-16 21:12:47 +00:00
|
|
|
/* by moving the window, the things in WM_SIZE are done */
|
2009-05-12 14:15:48 +00:00
|
|
|
MoveWindow(hwnd, 100, 100, 600, 450, TRUE);
|
|
|
|
|
|
|
|
/* Make the window visible on the screen */
|
|
|
|
ShowWindow (hwnd, nFunsterStil);
|
|
|
|
|
|
|
|
/* Run the message loop. It will run until GetMessage() returns 0 */
|
2009-10-21 15:44:31 +00:00
|
|
|
while (GetMessage(&messages, NULL, 0, 0))
|
2009-05-12 14:15:48 +00:00
|
|
|
{
|
|
|
|
TranslateAccelerator(hwnd, haccel, &messages);
|
|
|
|
|
|
|
|
/* Translate virtual-key messages into character messages */
|
|
|
|
TranslateMessage(&messages);
|
|
|
|
/* Send message to WindowProcedure */
|
|
|
|
DispatchMessage(&messages);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The program return-value is 0 - The value that PostQuitMessage() gave */
|
|
|
|
return messages.wParam;
|
|
|
|
}
|