attempt to convert most of this mess into something which at least look like C code
authorChristoph von Wittich <christoph_vw@reactos.org>
Tue, 16 Jun 2009 21:12:47 +0000 (21:12 +0000)
committerChristoph von Wittich <christoph_vw@reactos.org>
Tue, 16 Jun 2009 21:12:47 +0000 (21:12 +0000)
svn path=/trunk/; revision=41427

reactos/base/applications/paint/dib.c
reactos/base/applications/paint/drawing.c
reactos/base/applications/paint/history.c
reactos/base/applications/paint/main.c
reactos/base/applications/paint/mouse.c
reactos/base/applications/paint/palette.c
reactos/base/applications/paint/selection.c
reactos/base/applications/paint/toolsettings.c
reactos/base/applications/paint/winproc.c

index aa63e0a..ae66dec 100644 (file)
@@ -46,10 +46,15 @@ int GetDIBHeight(HBITMAP hbm)
 void SaveDIBToFile(HBITMAP hbm, LPTSTR name, HDC hdc)
 {
     BITMAP bm;
-    GetObject(hbm, sizeof(BITMAP), &bm);
+    HANDLE hFile;
     BITMAPFILEHEADER bf;
     BITMAPINFOHEADER bi;
-    int imgDataSize = bm.bmWidthBytes*bm.bmHeight;
+    int imgDataSize;
+    int bytesWritten;
+
+    GetObject(hbm, sizeof(BITMAP), &bm);
+
+    imgDataSize = bm.bmWidthBytes*bm.bmHeight;
     bf.bfType = 0x4d42;
     bf.bfSize = imgDataSize+52;
     bf.bfReserved1 = 0;
@@ -68,12 +73,11 @@ void SaveDIBToFile(HBITMAP hbm, LPTSTR name, HDC hdc)
     bi.biClrImportant = 0;
     int *buffer = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, imgDataSize);
     GetDIBits(hdc, hbm, 0, bm.bmHeight, buffer, (LPBITMAPINFO)&bi, DIB_RGB_COLORS);
-    HANDLE f = CreateFile(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
-    int bytesWritten;
-    WriteFile(f, &bf, 14, (LPDWORD)&bytesWritten, NULL);
-    WriteFile(f, &bi, 40, (LPDWORD)&bytesWritten, NULL);
-    WriteFile(f, buffer, imgDataSize, (LPDWORD)&bytesWritten, NULL);
-    CloseHandle(f);
+    hFile = CreateFile(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
+    WriteFile(hFile, &bf, 14, (LPDWORD)&bytesWritten, NULL);
+    WriteFile(hFile, &bi, 40, (LPDWORD)&bytesWritten, NULL);
+    WriteFile(hFile, buffer, imgDataSize, (LPDWORD)&bytesWritten, NULL);
+    CloseHandle(hFile);
     HeapFree(GetProcessHeap(), 0, buffer);
 }
 
index d8e6031..b7a787c 100644 (file)
@@ -22,12 +22,13 @@ void Line(HDC hdc, short x1, short y1, short x2, short y2, int color, int thickn
 
 void Rect(HDC hdc, short x1, short y1, short x2, short y2, int fg, int bg, int thickness, BOOL filled)
 {
-    HPEN oldPen = SelectObject(hdc, CreatePen(PS_SOLID, thickness, fg));
+    HBRUSH oldBrush;
     LOGBRUSH logbrush;
+    HPEN oldPen = SelectObject(hdc, CreatePen(PS_SOLID, thickness, fg));
     if (filled) logbrush.lbStyle = BS_SOLID; else logbrush.lbStyle = BS_HOLLOW;
     logbrush.lbColor = bg;
     logbrush.lbHatch = 0;
-    HBRUSH oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
+    oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
     Rectangle(hdc, x1, y1, x2, y2);
     DeleteObject(SelectObject(hdc, oldBrush));
     DeleteObject(SelectObject(hdc, oldPen));
@@ -35,12 +36,13 @@ void Rect(HDC hdc, short x1, short y1, short x2, short y2, int fg, int bg, int t
 
 void Ellp(HDC hdc, short x1, short y1, short x2, short y2, int fg, int bg, int thickness, BOOL filled)
 {
-    HPEN oldPen = SelectObject(hdc, CreatePen(PS_SOLID, thickness, fg));
+    HBRUSH oldBrush;
     LOGBRUSH logbrush;
+    HPEN oldPen = SelectObject(hdc, CreatePen(PS_SOLID, thickness, fg));
     if (filled) logbrush.lbStyle = BS_SOLID; else logbrush.lbStyle = BS_HOLLOW;
     logbrush.lbColor = bg;
     logbrush.lbHatch = 0;
-    HBRUSH oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
+    oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
     Ellipse(hdc, x1, y1, x2, y2);
     DeleteObject(SelectObject(hdc, oldBrush));
     DeleteObject(SelectObject(hdc, oldPen));
@@ -48,12 +50,13 @@ void Ellp(HDC hdc, short x1, short y1, short x2, short y2, int fg, int bg, int t
 
 void RRect(HDC hdc, short x1, short y1, short x2, short y2, int fg, int bg, int thickness, BOOL filled)
 {
-    HPEN oldPen = SelectObject(hdc, CreatePen(PS_SOLID, thickness, fg));
     LOGBRUSH logbrush;
+    HBRUSH oldBrush;
+    HPEN oldPen = SelectObject(hdc, CreatePen(PS_SOLID, thickness, fg));
     if (filled) logbrush.lbStyle = BS_SOLID; else logbrush.lbStyle = BS_HOLLOW;
     logbrush.lbColor = bg;
     logbrush.lbHatch = 0;
-    HBRUSH oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
+    oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
     RoundRect(hdc, x1, y1, x2, y2, 16, 16);
     DeleteObject(SelectObject(hdc, oldBrush));
     DeleteObject(SelectObject(hdc, oldPen));
@@ -68,9 +71,10 @@ void Fill(HDC hdc, int x, int y, int color)
 
 void Erase(HDC hdc, short x1, short y1, short x2, short y2, int color, int radius)
 {
-    HPEN oldPen = SelectObject(hdc, CreatePen(PS_SOLID, 1, color));
-    HBRUSH oldBrush = SelectObject(hdc, CreateSolidBrush(color));
     short a;
+    HPEN oldPen;
+    HBRUSH oldBrush = SelectObject(hdc, CreateSolidBrush(color));
+    oldPen = SelectObject(hdc, CreatePen(PS_SOLID, 1, color));
     for (a=0; a<=100; a++)
         Rectangle(hdc, (x1*(100-a)+x2*a)/100-radius+1, (y1*(100-a)+y2*a)/100-radius+1, (x1*(100-a)+x2*a)/100+radius+1, (y1*(100-a)+y2*a)/100+radius+1);
     DeleteObject(SelectObject(hdc, oldBrush));
@@ -165,12 +169,13 @@ void Brush(HDC hdc, short x1, short y1, short x2, short y2, int color, int style
 
 void RectSel(HDC hdc, short x1, short y1, short x2, short y2)
 {
-    HPEN oldPen = SelectObject(hdc, CreatePen(PS_DOT, 1, 0x00000000));
+    HBRUSH oldBrush;
     LOGBRUSH logbrush;
+    HPEN oldPen = SelectObject(hdc, CreatePen(PS_DOT, 1, 0x00000000));
     logbrush.lbStyle = BS_HOLLOW;
     logbrush.lbColor = 0;
     logbrush.lbHatch = 0;
-    HBRUSH oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
+    oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
     Rectangle(hdc, x1, y1, x2, y2);
     DeleteObject(SelectObject(hdc, oldBrush));
     DeleteObject(SelectObject(hdc, oldPen));
@@ -178,12 +183,13 @@ void RectSel(HDC hdc, short x1, short y1, short x2, short y2)
 
 void SelectionFrame(HDC hdc, int x1, int y1, int x2, int y2)
 {
-    HPEN oldPen = SelectObject(hdc, CreatePen(PS_DOT, 1, 0x00000000));
+    HBRUSH oldBrush;
     LOGBRUSH logbrush;
+    HPEN oldPen = SelectObject(hdc, CreatePen(PS_DOT, 1, 0x00000000));
     logbrush.lbStyle = BS_HOLLOW;
     logbrush.lbColor = 0;
     logbrush.lbHatch = 0;
-    HBRUSH oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
+    oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
     Rectangle(hdc, x1, y1, x2, y2);
     DeleteObject(SelectObject(hdc, oldBrush));
     DeleteObject(SelectObject(hdc, oldPen));
index a8a8664..b0eb560 100644 (file)
@@ -93,6 +93,10 @@ void insertReversible(HBITMAP hbm)
 
 void cropReversible(int x, int y)//FIXME: This function is broken
 {
+    HBITMAP oldBitmap;
+    HPEN oldPen;
+    HBRUSH oldBrush;
+
     SelectObject(hDrawingDC, hBms[currInd]);
     DeleteObject(hBms[(currInd+1)%4]);
     hBms[(currInd+1)%4] = CreateDIBWithProperties(x, y);
@@ -100,9 +104,9 @@ void cropReversible(int x, int y)//FIXME: This function is broken
     if (undoSteps<3) undoSteps++;
     redoSteps = 0;
     
-    HBITMAP oldBitmap = SelectObject(hSelDC, hBms[currInd]);
-    HPEN oldPen = SelectObject(hSelDC, CreatePen(PS_SOLID, 1, bgColor));
-    HBRUSH oldBrush = SelectObject(hSelDC, CreateSolidBrush(bgColor));
+    oldBitmap = SelectObject(hSelDC, hBms[currInd]);
+    oldPen = SelectObject(hSelDC, CreatePen(PS_SOLID, 1, bgColor));
+    oldBrush = SelectObject(hSelDC, CreateSolidBrush(bgColor));
     Rectangle(hSelDC, 0, 0, x, y);
     DeleteObject(SelectObject(hSelDC, oldBrush));
     DeleteObject(SelectObject(hSelDC, oldPen));
index 3fed5eb..91d41d5 100644 (file)
@@ -104,15 +104,39 @@ BOOL isAFile = FALSE;
 
 int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument, int nFunsterStil)
 {
-    hProgInstance = hThisInstance;
     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];
+    int custColors[16] =
+        {0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+        0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff};
 
-    // Necessary
+    hProgInstance = hThisInstance;
+
+    /* Necessary */
     InitCommonControls();
 
-    //initializing and registering the window class used for the main window
-    WNDCLASSEX wincl;
+    /* initializing and registering the window class used for the main window */
     wincl.hInstance         = hThisInstance;
     wincl.lpszClassName     = _T("WindowsApp");
     wincl.lpfnWndProc       = WindowProcedure;
@@ -127,9 +151,7 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR l
     wincl.hbrBackground     = GetSysColorBrush(COLOR_BTNFACE);
     RegisterClassEx (&wincl);
 
-    // initializing and registering the window class used for the scroll box
-
-    WNDCLASSEX wclScroll;
+    /* initializing and registering the window class used for the scroll box */
     wclScroll.hInstance     = hThisInstance;
     wclScroll.lpszClassName = _T("Scrollbox");
     wclScroll.lpfnWndProc   = WindowProcedure;
@@ -144,9 +166,7 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR l
     wclScroll.hbrBackground = GetSysColorBrush(COLOR_APPWORKSPACE);
     RegisterClassEx (&wclScroll);
 
-    // initializing and registering the window class used for the palette window
-
-    WNDCLASSEX wclPal;
+    /* initializing and registering the window class used for the palette window */
     wclPal.hInstance        = hThisInstance;
     wclPal.lpszClassName    = _T("Palette");
     wclPal.lpfnWndProc      = PalWinProc;
@@ -161,9 +181,7 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR l
     wclPal.hbrBackground    = GetSysColorBrush(COLOR_BTNFACE);
     RegisterClassEx (&wclPal);
 
-    // initializing and registering the window class for the settings window
-
-    WNDCLASSEX wclSettings;
+    /* initializing and registering the window class for the settings window */
     wclSettings.hInstance       = hThisInstance;
     wclSettings.lpszClassName   = _T("ToolSettings");
     wclSettings.lpfnWndProc     = SettingsWinProc;
@@ -178,9 +196,7 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR l
     wclSettings.hbrBackground   = GetSysColorBrush(COLOR_BTNFACE);
     RegisterClassEx (&wclSettings);
 
-    // initializing and registering the window class for the selection frame
-
-    WNDCLASSEX wclSelection;
+    /* initializing and registering the window class for the selection frame */
     wclSelection.hInstance      = hThisInstance;
     wclSelection.lpszClassName  = _T("Selection");
     wclSelection.lpfnWndProc    = SelectionWinProc;
@@ -196,24 +212,21 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR l
     RegisterClassEx (&wclSelection);
 
     LoadString(hThisInstance, IDS_DEFAULTFILENAME, filename, SIZEOF(filename));
-    TCHAR progtitle[1000];
-    TCHAR resstr[100];
     LoadString(hThisInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
     _stprintf(progtitle, resstr, filename);
     
     
-    // create main window
+    /* create main window */
     hwnd = CreateWindowEx (0, _T("WindowsApp"), progtitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 544, 375, HWND_DESKTOP, NULL, hThisInstance, NULL);
 
     hMainWnd = hwnd;
 
-    // loading and setting the window menu from resource
-    HMENU menu;
+    /* loading and setting the window menu from resource */
     menu = LoadMenu(hThisInstance, MAKEINTRESOURCE(ID_MENU));
     SetMenu(hwnd, menu);
-    HANDLE haccel = LoadAccelerators(hThisInstance, MAKEINTRESOURCE(800));
+    haccel = LoadAccelerators(hThisInstance, MAKEINTRESOURCE(800));
 
-    // preloading the draw transparent/nontransparent icons for later use
+    /* 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);
 
@@ -225,19 +238,17 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR l
 
     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
+    /* 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
-    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);
-    HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 16, 0);
+    /* 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);
-    HBITMAP tempBm = LoadImage(hThisInstance, MAKEINTRESOURCE(IDB_TOOLBARICONS), IMAGE_BITMAP, 256, 16, 0);
+    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);
-    int i;
-    TCHAR tooltips[16][30];
     for (i=0; i<16; i++)
     {
         int wrapnow = 0;
@@ -246,35 +257,35 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR l
         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);
+   /* SendMessage(hToolbar, TB_SETROWS, MAKEWPARAM(8, FALSE), (LPARAM)NULL); */
     SendMessage(hToolbar, TB_CHECKBUTTON, ID_PEN, MAKELONG(TRUE, 0));
     SendMessage(hToolbar, TB_SETMAXTEXTROWS, 0, 0);
 
     SendMessage(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(25, 25));
-   // SendMessage(hToolbar, TB_AUTOSIZE, 0, 0);
+   /* SendMessage(hToolbar, TB_AUTOSIZE, 0, 0); */
 
 
 
 
-    // creating the tool settings child window
+    /* creating the tool settings child window */
     hToolSettings = CreateWindowEx(0, _T("ToolSettings"), _T(""), WS_CHILD | WS_VISIBLE, 7, 210, 42, 140, hwnd, NULL, hThisInstance, NULL);
 
-    // creating the palette child window
+    /* 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
+    /* 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
+    /* 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)
+    /* 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
+    /* 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));
@@ -286,10 +297,7 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR l
     SelectObject(hDrawingDC, hBms[0]);
     Rectangle(hDrawingDC, 0-1, 0-1, imgXRes+1, imgYRes+1);
 
-    // initializing the CHOOSECOLOR structure for use with ChooseColor
-    int custColors[16] =
-        {0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
-        0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff};
+    /* initializing the CHOOSECOLOR structure for use with ChooseColor */
     choosecolor.lStructSize     = sizeof(CHOOSECOLOR);
     choosecolor.hwndOwner       = hwnd;
     choosecolor.hInstance       = NULL;
@@ -300,13 +308,8 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR l
     choosecolor.lpfnHook        = NULL;
     choosecolor.lpTemplateName  = NULL;
 
-    TCHAR *c;
-
-    // initializing the OPENFILENAME structure for use with GetOpenFileName and GetSaveFileName
-    TCHAR ofnFilename[1000];
+    /* initializing the OPENFILENAME structure for use with GetOpenFileName and GetSaveFileName */
     CopyMemory(ofnFilename, filename, sizeof(filename));
-    TCHAR ofnFiletitle[256];
-    TCHAR ofnFilter[1000];
     LoadString(hThisInstance, IDS_OPENFILTER, ofnFilter, SIZEOF(ofnFilter));
     for (c = ofnFilter; *c; c++) if (*c == '\1') *c = '\0';
     ZeroMemory(&ofn, sizeof(OPENFILENAME));
@@ -320,10 +323,7 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR l
     ofn.nMaxFileTitle   = SIZEOF(ofnFiletitle);
     ofn.Flags           = OFN_HIDEREADONLY;
 
-    TCHAR sfnFilename[1000];
     CopyMemory(sfnFilename, filename, sizeof(filename));
-    TCHAR sfnFiletitle[256];
-    TCHAR sfnFilter[1000];
     LoadString(hThisInstance, IDS_SAVEFILTER, sfnFilter, SIZEOF(sfnFilter));
     for (c = sfnFilter; *c; c++) if (*c == '\1') *c = '\0';
     ZeroMemory(&sfn, sizeof(OPENFILENAME));
@@ -338,7 +338,7 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR l
     sfn.Flags           = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
 
 
-    // by moving the window, the things in WM_SIZE are done
+    /* 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 */
index 1614fb7..61aef29 100644 (file)
@@ -59,9 +59,11 @@ void whilePainting(HDC hdc, short x, short y, int fg, int bg)
     {
         case 2:
             {
+                short tempX;
+                short tempY;
                 resetToU1();
-                short tempX = max(0, min(x, imgXRes));
-                short tempY = max(0, min(y, imgYRes));
+                tempX = max(0, min(x, imgXRes));
+                tempY = max(0, min(y, imgYRes));
                 rectSel_dest[0] = rectSel_src[0] = min(startX, tempX);
                 rectSel_dest[1] = rectSel_src[1] = min(startY, tempY);
                 rectSel_dest[2] = rectSel_src[2] = max(startX, tempX)-min(startX, tempX);
index 897235a..b6d0b6f 100644 (file)
@@ -19,14 +19,16 @@ LRESULT CALLBACK PalWinProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lPar
     {
         case WM_PAINT:
             {
-                DefWindowProc (hwnd, message, wParam, lParam);
-                HDC hdc = GetDC(hwnd);
-                HPEN oldPen;
-                HBRUSH oldBrush;
                 int i;
                 long rectang[4] = {0, 0, 31, 32};
                 int a;
                 int b;
+                HDC hdc = GetDC(hwnd);
+                HPEN oldPen;
+                HBRUSH oldBrush;
+
+                DefWindowProc (hwnd, message, wParam, lParam);
+
                 for (b=2; b<30; b++) for (a=2; a<29; a++) if ((a+b)%2==1) SetPixel(hdc, a, b, GetSysColor(COLOR_BTNHILIGHT));
                 DrawEdge(hdc, (LPRECT)&rectang, EDGE_RAISED, BF_TOPLEFT);
                 DrawEdge(hdc, (LPRECT)&rectang, BDR_SUNKENOUTER, BF_TOPLEFT|BF_BOTTOMRIGHT);
index d628a18..6d605a1 100644 (file)
@@ -28,8 +28,8 @@ LRESULT CALLBACK SelectionWinProc (HWND hwnd, UINT message, WPARAM wParam, LPARA
             {
                 if (!moving)
                 {
-                    DefWindowProc (hwnd, message, wParam, lParam);
                     HDC hdc=GetDC(hwnd);
+                    DefWindowProc (hwnd, message, wParam, lParam);
                     SelectionFrame(hdc, 1, 1, rectSel_dest[2]*zoom/1000+5, rectSel_dest[3]*zoom/1000+5);
                     ReleaseDC(hwnd, hdc);
                 }
index 5d0b546..b5141eb 100644 (file)
@@ -20,13 +20,13 @@ LRESULT CALLBACK SettingsWinProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM
     {
         case WM_PAINT:
             {
-                DefWindowProc (hwnd, message, wParam, lParam);
-                
                 HDC hdc = GetDC(hwnd);
-                
                 int rectang[4] = {0, 0, 42, 66};
-                DrawEdge(hdc, (LPRECT)&rectang, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
                 int rectang2[4] = {0, 70, 42, 136};
+
+                DefWindowProc (hwnd, message, wParam, lParam);
+                
+                DrawEdge(hdc, (LPRECT)&rectang, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
                 if (activeTool>=13)
                     DrawEdge(hdc, (LPRECT)&rectang2, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
                 else
@@ -64,11 +64,11 @@ LRESULT CALLBACK SettingsWinProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM
                         break;
                     case 8:
                         {
+                            int i;
                             HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
                             SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
                             Rectangle(hdc, brushStyle%3*13+2, brushStyle/3*15+2, brushStyle%3*13+15, brushStyle/3*15+17);
                             DeleteObject(SelectObject(hdc, oldPen));
-                            int i;
                             for (i=0; i<12; i++)
                             if (i==brushStyle)
                                 Brush(hdc, i%3*13+7, i/3*15+8, i%3*13+7, i/3*15+8, GetSysColor(COLOR_HIGHLIGHTTEXT), i);
index 35ecab8..290bdd7 100644 (file)
@@ -64,9 +64,9 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
             {
                 TCHAR programname[20];
                 TCHAR saveprompttext[100];
+                TCHAR temptext[500];
                 LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
                 LoadString(hProgInstance, IDS_SAVEPROMPTTEXT, saveprompttext, SIZEOF(saveprompttext));
-                TCHAR temptext[500];
                 _stprintf(temptext, saveprompttext, filename);
                 switch (MessageBox(hwnd, temptext, programname, MB_YESNOCANCEL | MB_ICONQUESTION))
                 {
@@ -157,11 +157,12 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
             if ((hwnd==hImageArea)||(hwnd==hScrollbox))
             {
                 long clientRectScrollbox[4];
-                GetClientRect(hScrollbox, (LPRECT)&clientRectScrollbox);
                 long clientRectImageArea[4];
+                SCROLLINFO horzScroll;
+                SCROLLINFO vertScroll;
+                GetClientRect(hScrollbox, (LPRECT)&clientRectScrollbox);
                 GetClientRect(hImageArea, (LPRECT)&clientRectImageArea);
                 MoveWindow(hScrlClient, 0, 0, max(clientRectImageArea[2]+6, clientRectScrollbox[2]), max(clientRectImageArea[3]+6, clientRectScrollbox[3]), TRUE);
-                SCROLLINFO horzScroll;
                 horzScroll.cbSize       = sizeof(SCROLLINFO);
                 horzScroll.fMask        = SIF_PAGE | SIF_RANGE;
                 horzScroll.nMax         = 10000;
@@ -171,7 +172,6 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
                 horzScroll.nTrackPos    = 0;
                 SetScrollInfo(hScrollbox, SB_HORZ, &horzScroll, TRUE);
                 GetClientRect(hScrollbox, (LPRECT)clientRectScrollbox);
-                SCROLLINFO vertScroll;
                 vertScroll.cbSize       = sizeof(SCROLLINFO);
                 vertScroll.fMask        = SIF_PAGE | SIF_RANGE;
                 vertScroll.nMax         = 10000;
@@ -388,10 +388,10 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
                         HBITMAP bmNew = (HBITMAP)LoadDIBFromFile(ofn.lpstrFile);
                         if (bmNew!=NULL)
                         {
-                            insertReversible(bmNew);
-                            updateCanvasAndScrollbars();
                             TCHAR tempstr[1000];
                             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));
@@ -411,9 +411,9 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
                 case IDM_FILESAVEAS:
                     if (GetSaveFileName(&sfn)!=0)
                     {
-                        SaveDIBToFile(hBms[currInd], sfn.lpstrFile, hDrawingDC);
                         TCHAR tempstr[1000];
                         TCHAR resstr[100];
+                        SaveDIBToFile(hBms[currInd], sfn.lpstrFile, hDrawingDC);
                         CopyMemory(filename, sfn.lpstrFileTitle, sizeof(filename));
                         CopyMemory(filepathname, sfn.lpstrFileTitle, sizeof(filepathname));
                         LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
@@ -484,9 +484,10 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
                     break;
                 case IDM_IMAGEINVERTCOLORS:
                     {
+                        RECT tempRect;
                         newReversible();
-                        int tempRect[4] = {0, 0, imgXRes, imgYRes};
-                        InvertRect(hDrawingDC, (LPRECT)tempRect);
+                        SetRect(&tempRect, 0, 0, imgXRes, imgYRes);
+                        InvertRect(hDrawingDC, &tempRect);
                         SendMessage(hImageArea, WM_PAINT, 0, 0);
                     }
                     break;