* only show message box on exit if the image has not been saved and is not blank

* set as wallpaper: now working, setting wallpaper style: not yet
* made number of undo-steps changeable through define-statement; increased to 10 (see original)
* zoom tool got its track bar (see original)

svn path=/trunk/; revision=43266
This commit is contained in:
Benedikt Freisen 2009-10-03 16:33:41 +00:00
parent 5b8c2418b7
commit 8ccb271064
8 changed files with 70 additions and 26 deletions

View file

@ -8,6 +8,9 @@
/* DEFINES **********************************************************/
#define HISTORYSIZE 11
/* HISTORYSIZE = number of possible undo-steps + 1 */
#define SIZEOF(a) (sizeof(a) / sizeof((a)[0]))
#define IDI_APPICON 500

View file

@ -9,6 +9,7 @@
/* INCLUDES *********************************************************/
#include <windows.h>
#include "definitions.h"
/* VARIABLES declared in main.c *************************************/
@ -19,10 +20,11 @@ extern BITMAPINFO bitmapinfo;
extern int imgXRes;
extern int imgYRes;
extern HBITMAP hBms[4];
extern HBITMAP hBms[HISTORYSIZE];
extern int currInd;
extern int undoSteps;
extern int redoSteps;
extern BOOL imageSaved;
extern short startX;
extern short startY;
@ -86,6 +88,8 @@ extern HWND hSizeboxLeftBottom;
extern HWND hSizeboxCenterBottom;
extern HWND hSizeboxRightBottom;
extern HWND hTrackbarZoom;
/* VARIABLES declared in mouse.c *************************************/
extern POINT pointStack[256];

View file

@ -29,14 +29,15 @@ void setImgXYRes(int x, int y)
void newReversible()
{
DeleteObject(hBms[(currInd+1)%4]);
hBms[(currInd+1)%4] = CopyImage( hBms[currInd], IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG);
currInd = (currInd+1)%4;
if (undoSteps<3) undoSteps++;
DeleteObject(hBms[(currInd+1)%HISTORYSIZE]);
hBms[(currInd+1)%HISTORYSIZE] = CopyImage( hBms[currInd], IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG);
currInd = (currInd+1)%HISTORYSIZE;
if (undoSteps<HISTORYSIZE-1) undoSteps++;
redoSteps = 0;
SelectObject(hDrawingDC, hBms[currInd]);
imgXRes = GetDIBWidth(hBms[currInd]);
imgYRes = GetDIBHeight(hBms[currInd]);
imageSaved = FALSE;
}
void undo()
@ -44,10 +45,10 @@ void undo()
if (undoSteps>0)
{
ShowWindow(hSelection, SW_HIDE);
currInd = (currInd+3)%4;
currInd = (currInd+HISTORYSIZE-1)%HISTORYSIZE;
SelectObject(hDrawingDC, hBms[currInd]);
undoSteps--;
if (redoSteps<3) redoSteps++;
if (redoSteps<HISTORYSIZE-1) redoSteps++;
setImgXYRes(GetDIBWidth(hBms[currInd]), GetDIBHeight(hBms[currInd]));
}
}
@ -57,10 +58,10 @@ void redo()
if (redoSteps>0)
{
ShowWindow(hSelection, SW_HIDE);
currInd = (currInd+1)%4;
currInd = (currInd+1)%HISTORYSIZE;
SelectObject(hDrawingDC, hBms[currInd]);
redoSteps--;
if (undoSteps<3) undoSteps++;
if (undoSteps<HISTORYSIZE-1) undoSteps++;
setImgXYRes(GetDIBWidth(hBms[currInd]), GetDIBHeight(hBms[currInd]));
}
}
@ -68,7 +69,7 @@ void redo()
void resetToU1()
{
DeleteObject(hBms[currInd]);
hBms[currInd] = CopyImage( hBms[(currInd+3)%4], IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG);
hBms[currInd] = CopyImage( hBms[(currInd+HISTORYSIZE-1)%HISTORYSIZE], IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG);
SelectObject(hDrawingDC, hBms[currInd]);
imgXRes = GetDIBWidth(hBms[currInd]);
imgYRes = GetDIBHeight(hBms[currInd]);
@ -82,10 +83,10 @@ void clearHistory()
void insertReversible(HBITMAP hbm)
{
DeleteObject(hBms[(currInd+1)%4]);
hBms[(currInd+1)%4] = hbm;
currInd = (currInd+1)%4;
if (undoSteps<3) undoSteps++;
DeleteObject(hBms[(currInd+1)%HISTORYSIZE]);
hBms[(currInd+1)%HISTORYSIZE] = hbm;
currInd = (currInd+1)%HISTORYSIZE;
if (undoSteps<HISTORYSIZE-1) undoSteps++;
redoSteps = 0;
SelectObject(hDrawingDC, hBms[currInd]);
setImgXYRes(GetDIBWidth(hBms[currInd]), GetDIBHeight(hBms[currInd]));
@ -98,10 +99,10 @@ void cropReversible(int width, int height, int xOffset, int yOffset)
HBRUSH oldBrush;
SelectObject(hDrawingDC, hBms[currInd]);
DeleteObject(hBms[(currInd+1)%4]);
hBms[(currInd+1)%4] = CreateDIBWithProperties(width, height);
currInd = (currInd+1)%4;
if (undoSteps<3) undoSteps++;
DeleteObject(hBms[(currInd+1)%HISTORYSIZE]);
hBms[(currInd+1)%HISTORYSIZE] = CreateDIBWithProperties(width, height);
currInd = (currInd+1)%HISTORYSIZE;
if (undoSteps<HISTORYSIZE-1) undoSteps++;
redoSteps = 0;
hdc = CreateCompatibleDC(hDrawingDC);

View file

@ -37,10 +37,11 @@ BITMAPINFO bitmapinfo;
int imgXRes = 400;
int imgYRes = 300;
HBITMAP hBms[4];
HBITMAP hBms[HISTORYSIZE];
int currInd = 0;
int undoSteps = 0;
int redoSteps = 0;
BOOL imageSaved = TRUE;
// global status variables
@ -117,6 +118,8 @@ HWND hSizeboxLeftBottom;
HWND hSizeboxCenterBottom;
HWND hSizeboxRightBottom;
HWND hTrackbarZoom;
int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument, int nFunsterStil)
{
HWND hwnd; /* This is the handle for our window */
@ -305,6 +308,9 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR l
/* 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);

View file

@ -13,9 +13,11 @@
/* FUNCTIONS ********************************************************/
void SetWallpaper(TCHAR *FileName, DWORD dwStyle, DWORD dwTile)
void SetWallpaper(TCHAR *FileName, DWORD dwStyle, DWORD dwTile) //FIXME: The pattern (tiled/stretched) is not set
{
HKEY hDesktop;
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID) FileName, SPIF_UPDATEINIFILE);
/*HKEY hDesktop;
TCHAR szStyle[3], szTile[3];
if ((dwStyle > 2) || (dwTile > 2))
@ -34,5 +36,5 @@ void SetWallpaper(TCHAR *FileName, DWORD dwStyle, DWORD dwTile)
RegSetValueEx(hDesktop, _T("TileWallpaper"), 0, REG_SZ, (LPBYTE) szTile, _tcslen(szTile) * sizeof(TCHAR));
RegCloseKey(hDesktop);
}
}*/
}

View file

@ -9,8 +9,10 @@
/* INCLUDES *********************************************************/
#include <windows.h>
#include <commctrl.h>
#include "globalvar.h"
#include "drawing.h"
#include "winproc.h"
/* FUNCTIONS ********************************************************/
@ -18,6 +20,11 @@ LRESULT CALLBACK SettingsWinProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM
{
switch (message)
{
case WM_VSCROLL:
{
ZoomTo(125<<SendMessage(hTrackbarZoom, TBM_GETPOS, 0, 0));
}
break;
case WM_PAINT:
{
HDC hdc = GetDC(hwnd);
@ -25,8 +32,11 @@ LRESULT CALLBACK SettingsWinProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM
int rectang2[4] = {0, 70, 42, 136};
DefWindowProc (hwnd, message, wParam, lParam);
DrawEdge(hdc, (LPRECT)&rectang, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
if (activeTool!=6)
DrawEdge(hdc, (LPRECT)&rectang, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
else
DrawEdge(hdc, (LPRECT)&rectang, BDR_SUNKENOUTER, BF_RECT);
if (activeTool>=13)
DrawEdge(hdc, (LPRECT)&rectang2, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
else

View file

@ -31,6 +31,10 @@ void selectTool(int tool)
activeTool = tool;
pointSP = 0; // resets the point-buffer of the polygon and bezier functions
SendMessage(hToolSettings, WM_PAINT, 0, 0);
if (tool==6)
ShowWindow(hTrackbarZoom, SW_SHOW);
else
ShowWindow(hTrackbarZoom, SW_HIDE);
}
void updateCanvasAndScrollbars()
@ -48,6 +52,14 @@ void ZoomTo(int newZoom)
{
zoom = newZoom;
updateCanvasAndScrollbars();
int tbPos = 0;
int tempZoom = newZoom;
while (tempZoom>125)
{
tbPos++;
tempZoom = tempZoom>>1;
}
SendMessage(hTrackbarZoom, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)tbPos);
}
HDC hdc;
@ -67,7 +79,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
showMiniature = FALSE;
break;
}
if (undoSteps>0)
if (!imageSaved)
{
TCHAR programname[20];
TCHAR saveprompttext[100];
@ -503,7 +515,10 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
break;
case IDM_FILESAVE:
if (isAFile)
{
SaveDIBToFile(hBms[currInd], filepathname, hDrawingDC);
imageSaved = TRUE;
}
else
SendMessage(hwnd, WM_COMMAND, IDM_FILESAVEAS, 0);
break;
@ -514,11 +529,12 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
TCHAR resstr[100];
SaveDIBToFile(hBms[currInd], sfn.lpstrFile, hDrawingDC);
CopyMemory(filename, sfn.lpstrFileTitle, sizeof(filename));
CopyMemory(filepathname, sfn.lpstrFileTitle, sizeof(filepathname));
CopyMemory(filepathname, sfn.lpstrFile, sizeof(filepathname));
LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
_stprintf(tempstr, resstr, filename);
SetWindowText(hMainWnd, tempstr);
isAFile = TRUE;
imageSaved = TRUE;
}
break;
case IDM_FILEASWALLPAPERPLANE:

View file

@ -7,4 +7,6 @@
* PROGRAMMERS: Benedikt Freisen
*/
void ZoomTo(int newZoom);
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);