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