Fix some bugs in Paint.
authorDmitry Gorbachev <gorbachev@reactos.org>
Wed, 27 May 2009 12:03:18 +0000 (12:03 +0000)
committerDmitry Gorbachev <gorbachev@reactos.org>
Wed, 27 May 2009 12:03:18 +0000 (12:03 +0000)
svn path=/trunk/; revision=41141

reactos/base/applications/paint/dialogs.c
reactos/base/applications/paint/dib.c
reactos/base/applications/paint/dib.h
reactos/base/applications/paint/history.c
reactos/base/applications/paint/main.c
reactos/base/applications/paint/mouse.c
reactos/base/applications/paint/selection.c
reactos/base/applications/paint/toolsettings.c
reactos/base/applications/paint/winproc.c

index c81adc3..a5592dc 100644 (file)
@@ -59,6 +59,7 @@ LRESULT CALLBACK MRDlgWinProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lP
         default:
             return FALSE;
     }
+    return TRUE;
 }
 
 int mirrorRotateDlg()
@@ -93,6 +94,7 @@ LRESULT CALLBACK ATTDlgWinProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM l
         default:
             return FALSE;
     }
+    return TRUE;
 }
 
 int attributesDlg()
@@ -125,6 +127,7 @@ LRESULT CALLBACK CHSIZEDlgWinProc (HWND hwnd, UINT message, WPARAM wParam, LPARA
         default:
             return FALSE;
     }
+    return TRUE;
 }
 
 int changeSizeDlg()
index 6f44110..ba6f8f0 100644 (file)
@@ -43,7 +43,7 @@ int GetDIBHeight(HBITMAP hbm)
     return bm.bmHeight;
 }
 
-void SaveDIBToFile(HBITMAP hbm, char name[], HDC hdc)
+void SaveDIBToFile(HBITMAP hbm, LPSTR name, HDC hdc)
 {
     BITMAP bm;
     GetObject(hbm, sizeof(BITMAP), &bm);
@@ -77,7 +77,7 @@ void SaveDIBToFile(HBITMAP hbm, char name[], HDC hdc)
     HeapFree(GetProcessHeap(), 0, buffer);
 }
 
-HBITMAP LoadDIBFromFile(char name[])
+HBITMAP LoadDIBFromFile(LPSTR name)
 {
     HBITMAP bm;
     BITMAPFILEHEADER bfh;
@@ -88,7 +88,7 @@ HBITMAP LoadDIBFromFile(char name[])
     ReadFile(f, &bfh, 14, (LPDWORD)&bytesRead, NULL);
     if (bfh.bfType!=0x4d42)
     {
-        fclose(f);
+        CloseHandle(f);
         return NULL;
     }
     bi = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, bfh.bfOffBits-14);
index a940bde..9f1c077 100644 (file)
@@ -12,6 +12,6 @@ int GetDIBWidth(HBITMAP hbm);
 
 int GetDIBHeight(HBITMAP hbm);
 
-void SaveDIBToFile(HBITMAP hbm, char name[], HDC hdc);
+void SaveDIBToFile(HBITMAP hbm, LPSTR name, HDC hdc);
 
-HBITMAP LoadDIBFromFile(char name[]);
+HBITMAP LoadDIBFromFile(LPSTR name);
index 7d65474..70057b2 100644 (file)
@@ -15,6 +15,8 @@
 
 /* FUNCTIONS ********************************************************/
 
+extern void updateCanvasAndScrollbars(void);
+
 void setImgXYRes(int x, int y)
 {
     if ((imgXRes!=x)||(imgYRes!=y))
index 739e370..99c4b73 100644 (file)
@@ -194,11 +194,11 @@ int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpsz
     wclSelection.hbrBackground  = NULL;//GetSysColorBrush(COLOR_BTNFACE);
     RegisterClassEx (&wclSelection);
 
-    LoadString(hThisInstance, IDS_DEFAULTFILENAME, (LPTSTR)&filename, 256);
+    LoadString(hThisInstance, IDS_DEFAULTFILENAME, (LPTSTR)filename, sizeof(filename));
     char progtitle[1000];
     char resstr[100];
-    LoadString(hThisInstance, IDS_WINDOWTITLE, (LPTSTR)&resstr, 100);
-    sprintf(progtitle, resstr, &filename);
+    LoadString(hThisInstance, IDS_WINDOWTITLE, (LPTSTR)resstr, sizeof(resstr));
+    sprintf(progtitle, resstr, filename);
     
     
     // create main window
@@ -240,9 +240,9 @@ int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpsz
     for (i=0; i<16; i++)
     {
         int wrapnow = 0;
-        if (i%2==1) wrapnow = TBSTATE_WRAP;
-        LoadString(hThisInstance, IDS_TOOLTIP1+i, (LPTSTR)&tooltips[i], 30);
-        TBBUTTON tbbutton = {i, (HMENU)(ID_FREESEL+i), TBSTATE_ENABLED | wrapnow, TBSTYLE_CHECKGROUP, {0}, 0, &tooltips[i]};
+        if (i % 2 == 1) wrapnow = TBSTATE_WRAP;
+        LoadString(hThisInstance, IDS_TOOLTIP1 + i, (LPTSTR)tooltips[i], 30);
+        TBBUTTON tbbutton = { i, ID_FREESEL + i, TBSTATE_ENABLED | wrapnow, TBSTYLE_CHECKGROUP, {0}, 0, (INT_PTR)tooltips[i] };
         SendMessage(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&tbbutton);
     }
    // SendMessage(hToolbar, TB_SETROWS, MAKEWPARAM(8, FALSE), (LPARAM)NULL);
@@ -299,41 +299,41 @@ int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpsz
     choosecolor.lpfnHook        = NULL;
     choosecolor.lpTemplateName  = NULL;
 
-    int c;
+    char *c;
 
     // initializing the OPENFILENAME structure for use with GetOpenFileName and GetSaveFileName
     char ofnFilename[1000];
-    CopyMemory(&ofnFilename, &filename, 256);
+    CopyMemory(ofnFilename, filename, sizeof(filename));
     char ofnFiletitle[256];
     char ofnFilter[1000];
-    LoadString(hThisInstance, IDS_OPENFILTER, (LPTSTR)&ofnFilter, 1000);
-    for (c=0; c<1000; c++) if (ofnFilter[c]==(char)1) ofnFilter[c] = (char)0;
+    LoadString(hThisInstance, IDS_OPENFILTER, (LPTSTR)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     = (LPCTSTR)&ofnFilter;
-    ofn.lpstrFile       = (LPTSTR)&ofnFilename;
-    ofn.nMaxFile        = 1000;
-    ofn.lpstrFileTitle  = (LPTSTR)&ofnFiletitle;
-    ofn.nMaxFileTitle   = 256;
+    ofn.lpstrFilter     = (LPCTSTR)ofnFilter;
+    ofn.lpstrFile       = (LPTSTR)ofnFilename;
+    ofn.nMaxFile        = sizeof(ofnFilename);
+    ofn.lpstrFileTitle  = (LPTSTR)ofnFiletitle;
+    ofn.nMaxFileTitle   = sizeof(ofnFiletitle);
     ofn.Flags           = OFN_HIDEREADONLY;
 
     char sfnFilename[1000];
-    CopyMemory(&sfnFilename, &filename, 256);
+    CopyMemory(sfnFilename, filename, sizeof(filename));
     char sfnFiletitle[256];
     char sfnFilter[1000];
-    LoadString(hThisInstance, IDS_SAVEFILTER, (LPTSTR)&sfnFilter, 1000);
-    for (c=0; c<1000; c++) if (sfnFilter[c]==(char)1) sfnFilter[c] = (char)0;
+    LoadString(hThisInstance, IDS_SAVEFILTER, (LPTSTR)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     = (LPCTSTR)&sfnFilter;
-    sfn.lpstrFile       = (LPTSTR)&sfnFilename;
-    sfn.nMaxFile        = 1000;
-    sfn.lpstrFileTitle  = (LPTSTR)&sfnFiletitle;
-    sfn.nMaxFileTitle   = 256;
+    sfn.lpstrFilter     = (LPCTSTR)sfnFilter;
+    sfn.lpstrFile       = (LPTSTR)sfnFilename;
+    sfn.nMaxFile        = sizeof(sfnFilename);
+    sfn.lpstrFileTitle  = (LPTSTR)sfnFiletitle;
+    sfn.nMaxFileTitle   = sizeof(sfnFiletitle);
     sfn.Flags           = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
 
 
index 209cf3a..1614fb7 100644 (file)
@@ -9,6 +9,9 @@
 /* INCLUDES *********************************************************/
 
 #include "globalvar.h"
+#include "dib.h"
+#include "drawing.h"
+#include "history.h"
 
 /* FUNCTIONS ********************************************************/
 
index 9cb0245..d628a18 100644 (file)
@@ -10,6 +10,9 @@
 
 #include <windows.h>
 #include "globalvar.h"
+#include "drawing.h"
+#include "history.h"
+#include "mouse.h"
 
 /* FUNCTIONS ********************************************************/
 
index 4e686ea..5d0b546 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <windows.h>
 #include "globalvar.h"
+#include "drawing.h"
 
 /* FUNCTIONS ********************************************************/
 
index 4191029..f5a1241 100644 (file)
 #include "definitions.h"
 #include "globalvar.h"
 #include "dialogs.h"
+#include "dib.h"
+#include "drawing.h"
 #include "history.h"
+#include "mouse.h"
 
 /* FUNCTIONS ********************************************************/
 
@@ -59,11 +62,11 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
             {
                 char programname[20];
                 char saveprompttext[100];
-                LoadString(hProgInstance, IDS_PROGRAMNAME, (LPTSTR)&programname, 20);
-                LoadString(hProgInstance, IDS_SAVEPROMPTTEXT, (LPTSTR)&saveprompttext, 100);
+                LoadString(hProgInstance, IDS_PROGRAMNAME, (LPTSTR)programname, sizeof(programname));
+                LoadString(hProgInstance, IDS_SAVEPROMPTTEXT, (LPTSTR)saveprompttext, sizeof(saveprompttext));
                 char temptext[500];
                 sprintf(temptext, saveprompttext, filename);
-                switch (MessageBox(hwnd, (LPTSTR)&temptext, (LPTSTR)&programname, MB_YESNOCANCEL | MB_ICONQUESTION))
+                switch (MessageBox(hwnd, (LPTSTR)temptext, (LPTSTR)programname, MB_YESNOCANCEL | MB_ICONQUESTION))
                 {
                     case IDNO:
                         DestroyWindow(hwnd);
@@ -361,9 +364,9 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
                         HICON paintIcon = LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON));
                         char infotitle[100];
                         char infotext[200];
-                        LoadString(hProgInstance, IDS_INFOTITLE, (LPTSTR)&infotitle, 100);
-                        LoadString(hProgInstance, IDS_INFOTEXT, (LPTSTR)&infotext, 200);
-                        ShellAbout(hMainWnd, (LPTSTR)&infotitle, (LPTSTR)&infotext, paintIcon);
+                        LoadString(hProgInstance, IDS_INFOTITLE, (LPTSTR)infotitle, sizeof(infotitle));
+                        LoadString(hProgInstance, IDS_INFOTEXT, (LPTSTR)infotext, sizeof(infotext));
+                        ShellAbout(hMainWnd, (LPTSTR)infotitle, (LPTSTR)infotext, paintIcon);
                         DeleteObject(paintIcon);
                     }
                     break;
@@ -387,10 +390,10 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
                             updateCanvasAndScrollbars();
                             char tempstr[1000];
                             char resstr[100];
-                            CopyMemory(&filename, ofn.lpstrFileTitle, 256);
-                            CopyMemory(&filepathname, ofn.lpstrFileTitle, 1000);
-                            LoadString(hProgInstance, IDS_WINDOWTITLE, (LPTSTR)&resstr, 100);
-                            sprintf(tempstr, resstr, &filename);
+                            CopyMemory(filename, ofn.lpstrFileTitle, sizeof(filename));
+                            CopyMemory(filepathname, ofn.lpstrFileTitle, sizeof(filepathname));
+                            LoadString(hProgInstance, IDS_WINDOWTITLE, (LPTSTR)resstr, sizeof(resstr));
+                            sprintf(tempstr, resstr, filename);
                             SetWindowText(hMainWnd, tempstr);
                             clearHistory();
                             isAFile = TRUE;
@@ -399,7 +402,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
                     break;
                 case IDM_FILESAVE:
                     if (isAFile)
-                        SaveDIBToFile(hBms[currInd], &filepathname, hDrawingDC);
+                        SaveDIBToFile(hBms[currInd], filepathname, hDrawingDC);
                     else
                         SendMessage(hwnd, WM_COMMAND, IDM_FILESAVEAS, 0);
                     break;
@@ -409,10 +412,10 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
                         SaveDIBToFile(hBms[currInd], sfn.lpstrFile, hDrawingDC);
                         char tempstr[1000];
                         char resstr[100];
-                        CopyMemory(&filename, sfn.lpstrFileTitle, 256);
-                        CopyMemory(&filepathname, sfn.lpstrFileTitle, 1000);
-                        LoadString(hProgInstance, IDS_WINDOWTITLE, (LPTSTR)&resstr, 100);
-                        sprintf(tempstr, resstr, &filename);
+                        CopyMemory(filename, sfn.lpstrFileTitle, sizeof(filename));
+                        CopyMemory(filepathname, sfn.lpstrFileTitle, sizeof(filepathname));
+                        LoadString(hProgInstance, IDS_WINDOWTITLE, (LPTSTR)resstr, sizeof(resstr));
+                        sprintf(tempstr, resstr, filename);
                         SetWindowText(hMainWnd, tempstr);
                         isAFile = TRUE;
                     }
@@ -503,7 +506,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
                     break;
                 case IDM_IMAGEATTRIBUTES:
                     {
-                        int attrdata[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+                        //int attrdata[8] = {0, 0, 0, 0, 0, 0, 0, 0};
                         attributesDlg();
                         //cropReversible(640, 200);
                         //ZoomTo(zoom);