                                    LITE
                                    STEP
               +----------------+       _   +----------------+
               |  EasyCut V1    |   |  |_   |  EasyCut V1    |
+----0-++-0----+----------------+   |_  _|  +----------------+--------------+
| SOURCE..INFO |                                             |   By Ender   |
+----0-++-0----+                     DLL                     +----0-++-0----+

BTW: If you see source for EasyCut V0.4, It is really source for 0.1
I used 0.4 in the heading, but it was really V0.1

Lines marked as // Ender - ADD are as of version 0.1. if a number is specified
(eg, // Ender - V0.2) then that number is the version this line was added in.

Instead of just including the source, this file contains instructions on
modifying the shortcut source.
This assumes you are modifing a 'group supporting' source, as of 1st Feb '99

First, open shortcut.h and add this line after  'UINT uTimer;':
 char sz_bmpOn[256], sz_bmpOff[256], sz_bmpClick[256]; // Ender - ADD
 char sz_Group[10]; // Ender - V0.2
 
Save shortcut.h, close it, and open shortcut.c

Add these lines somewhere after 'void RemoveHints(HWND hwnd);':
  // Ender - ADD
   BOOL ReadLine (FILE *f, LPSTR szBuffer, DWORD dwLength);
   char* StripLine (LPSTR szBuffer);
   void SnapShot(HWND caller ,char* args);
   void AddHook(void);    // V1
   void DeleteHook(void);    // V1
   void NewShortcut(char* file, LPPOINT drop_point); // V1
   HBITMAP Ender_LoadLSImage (LPCSTR szImage, LPCSTR szFile, int snum); // V1
   LRESULT CALLBACK DesktopWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); // Ender - V1
   long DesktopOldWndProc; // Ender - V1
  // Ender - END ADD

Next scroll down near the middle of 'initModuleEx', and before
'shortcuts[numShortcuts].bmpOff = LoadLSImage(token5, NULL);' add these lines:
 // Ender - ADD
   strcpy(shortcuts[numShortcuts].sz_bmpOff, token5);
   strcpy(shortcuts[numShortcuts].sz_bmpOn, token6);
   strcpy(shortcuts[numShortcuts].sz_bmpClick, token7);
 // Ender - END ADD

Delete the three 'LoadLSImage' lines below this.

Next, a few lines later there should be a if statement: 'if(token8[0] == '#')'
After the line 'shortcuts[numShortcuts].uGroup = atoi(&token8[1]);' add:

strcpy(shortcuts[numShortcuts].sz_Group, token8); // Ender - ADD V0.2

Then find the line 'if (shortcuts[numShortcuts].bmpOff)' and paste (above it)
 // Ender - MOVED
                                        shortcuts[numShortcuts].bmpOff = Ender_LoadLSImage(token5, NULL, numShortcuts); // V1
                                        shortcuts[numShortcuts].bmpOn = Ender_LoadLSImage(token6, NULL, numShortcuts); // V1
                                        shortcuts[numShortcuts].bmpClick = Ender_LoadLSImage(token7, NULL, numShortcuts); // V1
 // Ender - END MOVED

The final change in 'initModuleEx' is to add these lines before 'return 0;':
 AddBangCommand("!Snapshot", SnapShot);   // Ender - ADD
 AddHook(); // Ender - ADD V1

Now go to the WndProc callback.       
Scroll down till you come to 'case WM_RBUTTONUP: // Open popup menu'
and replace all the code between the code and the code for WM_RBUTTONDOWN with:
 case WM_RBUTTONUP: // Switch to move mode
 {  
  SendMessage(hwnd, WM_SYSCOMMAND, SC_MOVE, 0); // Ender - REPLACED
  return 0;
 }
 case WM_RBUTTONDOWN: 
  return 0;                                     // Ender - REPLACED  

Now find 'case WM_SYSCOMMAND:' and delete and copy this in its place:
 case WM_MOVE:
  // Ender - ADD (removed WM_SYSCOMMAND)
 {
  int i = GetShortcutByWnd(hwnd);
  if (i == -1) return 0;

  shortcuts[i].x = LOWORD(lParam);
  shortcuts[i].y = HIWORD(lParam);
  return 0;
 }
 
Now scroll to the end of the file (although above any comments that may be
there), and add the rest of this file (this acually does the work):

// Ender - ADD
void SnapShot(HWND caller ,char* args) {
  FILE *f, *sr;
  char line[256];
  char source[256];
  char target[256];
  int i, prefix_length;
  i = prefix_length = 0;

  strcpy(source, szLitestepPath);
  strcat(source, "\\step.rc");
  sr = fopen(source, "r");

  strcpy(target, szLitestepPath);
  strcat(target, "\\shortcut.rc");
  f = fopen(target, "w");

  prefix_length = strlen ("*shortcut");

// This bit copys the existing step.rc, and replaces existing *shortcut's
// (Replaces/updates in the same position they were already in)

  while (ReadLine(sr, line, sizeof (line)))
   {
    if (!strnicmp (StripLine(line), "*shortcut", prefix_length))
     {
      if (i < numShortcuts)
       {
        fprintf(f,"*Shortcut \"%s\" %d %d %s %s %s %s %s %s \"%s\" %s\n", shortcuts[i].szName ,shortcuts[i].x, shortcuts[i].y, shortcuts[i].sz_bmpOff, shortcuts[i].sz_bmpOn, shortcuts[i].sz_bmpClick, shortcuts[i].sz_Group ,shortcuts[i].szSoundOnMouseOver, shortcuts[i].szSoundOnMouseClicked,shortcuts[i].szCommand, shortcuts[i].szParameters);
        i++;
       }
     } else {fprintf(f, "%s", line);}
   }

// This bit adds any new shortcuts to the end of the file
for (i=i; i<numShortcuts; i++)
 {fprintf(f,"*Shortcut \"%s\" %d %d %s %s %s %s %s %s \"%s\" %s\n", shortcuts[i].szName ,shortcuts[i].x, shortcuts[i].y, shortcuts[i].sz_bmpOff, shortcuts[i].sz_bmpOn, shortcuts[i].sz_bmpClick, shortcuts[i].sz_Group ,shortcuts[i].szSoundOnMouseOver, shortcuts[i].szSoundOnMouseClicked,shortcuts[i].szCommand, shortcuts[i].szParameters);}

  fclose(f);
fclose(sr);
strcpy(line, szLitestepPath);
strcat(line, "\\step.org");

CopyFile(source, line, 0);
CopyFile(target, source, 0);
DeleteFile(target);
}

BOOL ReadLine (FILE *f, LPSTR szBuffer, DWORD dwLength)
{
	while (f && !feof (f))
	{
		if (!fgets (szBuffer, dwLength, f))
		{
			break;
		}
        return TRUE;
	}

	return FALSE;
}

char* StripLine (LPSTR szBuffer)
{
 char strip[256];
 int length;
 length = strlen (szBuffer);
 strcpy(strip, szBuffer);

 while (length && isspace (strip[0]))
 {
  length--;
  strcpy (strip, strip + 1);
 }

 while (length && isspace (strip[length-1]))
 {
  strip[--length] = '\0';
 }

return strip;
}
// Ender - END ADD

void AddHook(void)  // Ender - Added V1
{
SetWindowLong(desktop, GWL_EXSTYLE, GetWindowLong(desktop, GWL_EXSTYLE) | WS_EX_ACCEPTFILES);
DesktopOldWndProc = GetWindowLong(desktop, GWL_WNDPROC);
SetWindowLong(desktop, GWL_WNDPROC, &DesktopWndProc);
}

void DeleteHook(void)  // Ender - Added V1
{SetWindowLong(desktop, GWL_WNDPROC, DesktopOldWndProc);}

LRESULT CALLBACK DesktopWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) // Ender - Added V1
{
 switch (message)
 {
  case WM_DROPFILES:
  {
   int numDropped;
   char szFname[256];
   LPPOINT drop_point;
               
   numDropped = DragQueryFile((HDROP) wParam, 0xFFFFFFFF, NULL, 0);
   if (numDropped > 1)
   {
    MessageBox(0, "Please only drag one shortcut (to the desktop) at a time", "Error adding shortcut!", MB_OK|MB_TOPMOST);
    return 0;
   }

   DragQueryFile((HDROP) wParam, 0, (char *)&szFname, sizeof(szFname));
   if (szFname && szFname[0])
   {   
    DragQueryPoint((HDROP) wParam, drop_point);
    NewShortcut(szFname, drop_point);
   }
   DragFinish((HDROP) wParam);
   return 0;
  }


   default: CallWindowProc(DesktopOldWndProc, hwnd, message, wParam, lParam);
 }
}

void NewShortcut(char* file, LPPOINT drop_point)
{
char bitmap[256], sysdir[256], windir[256];
BITMAP bmInfo;
shortcuts = realloc(shortcuts, (numShortcuts+1)*sizeof(shortcutType));
memset(&shortcuts[numShortcuts], 0, sizeof(shortcutType));

GetWindowsDirectory(windir, 256);
GetSystemDirectory(sysdir, 256);

strcpy(shortcuts[numShortcuts].szName, file);
strcpy(shortcuts[numShortcuts].szCommand, file);

shortcuts[numShortcuts].x = drop_point->x;
shortcuts[numShortcuts].y = drop_point->y;

strcpy(shortcuts[numShortcuts].sz_bmpOff, ".winicon");
strcpy(shortcuts[numShortcuts].sz_bmpOn, ".winicon");
strcpy(shortcuts[numShortcuts].sz_bmpClick, ".winicon");

shortcuts[numShortcuts].bmpOff = Ender_LoadLSImage(shortcuts[numShortcuts].sz_bmpOff, NULL, numShortcuts);
shortcuts[numShortcuts].bmpOn = Ender_LoadLSImage(shortcuts[numShortcuts].sz_bmpOn, NULL, numShortcuts);
shortcuts[numShortcuts].bmpClick = Ender_LoadLSImage(shortcuts[numShortcuts].sz_bmpClick, NULL, numShortcuts);

shortcuts[numShortcuts].bVisible = TRUE;
shortcuts[numShortcuts].uGroup = 0;

if (shortcuts[numShortcuts].bmpOff)
{
 int res = GetObject(shortcuts[numShortcuts].bmpOff, sizeof(bmInfo), &bmInfo);
 if (res > 0)
 {
  shortcuts[numShortcuts].offSize.cx = bmInfo.bmWidth;
  shortcuts[numShortcuts].offSize.cy = bmInfo.bmHeight;
 } else {
  shortcuts[numShortcuts].offSize.cx = 64;
  shortcuts[numShortcuts].offSize.cy = 64;
 }
}

shortcuts[numShortcuts].uTimer = 0;

CreateShortcut(numShortcuts);
numShortcuts++;
}

HBITMAP Ender_LoadLSImage (LPCSTR szImage, LPCSTR szFile, int snum)
{
	static char szImagesFolder[MAX_PATH] = { '\0' };
	char szImageBuf[MAX_PATH];
	char szImageFinal[MAX_PATH];

	static BOOL bCheckedImagesFolder = FALSE;
	HINSTANCE	hInstance;
	HBITMAP 	hBitmap;
	HWND		hWnd;

	strcpy(szImageBuf, szImage);

        // WAS - Themeinuse stuff from lsapi. Cant be bothered replicating :)
        //       (Ender, 28/2/1999)
	
	if (!bCheckedImagesFolder)
	{
		GetRCString("PixmapPath", szImagesFolder, "c:\\litestep2\\images\\", sizeof(szImagesFolder));
	}
	
	if (!strcmpi (szImageBuf, ".none"))
	{
		return NULL;
	}
	
	hWnd = GetLitestepWnd ();
	if (!hWnd)
	{
		return NULL;
	}
	
	hInstance = (HINSTANCE) GetWindowLong (hWnd, GWL_HINSTANCE);
	if (!hInstance)
	{
		return NULL;
	}
// Bitmap merging by Thedd
//  Thedd - pic1.bmp|pic2.bmp merges the images. Works recursively,
//  so pic1.bmp|.extract=whatever.dll,3|pic2.bmp also works etc...
//  pic1.bmp is put "on top of" pic2.bmp in pic1.bmp|pic2.bmp. 
//  Images should be of the same size, or wierd things will happen.
     if (strrchr (szImageBuf, '|'))
     {
          HDC tmpDC2, tmpDC1, hMemDC;
          HBITMAP tmpbitmap1, tmpbitmap2, finalBMP, hOldBitmap;
          int xs,ys,xs2,ys2;

          char szBuffer1[MAX_PATH+10] = "\0", szBuffer2[1024] = "\0";      
          char *pipepos = NULL;

          pipepos = strchr(szImageBuf, '|');
          pipepos++;
          strcpy(szBuffer2, pipepos);
          strncpy(szBuffer1, szImageBuf, strlen(szImageBuf)-strlen(szBuffer2)-1);
          
          tmpbitmap1 = Ender_LoadLSImage(szBuffer1, szFile, snum);
          tmpbitmap2 = Ender_LoadLSImage(szBuffer2, szFile, snum);

          if(tmpbitmap2 == NULL) return tmpbitmap1;

          GetLSBitmapSize(tmpbitmap2, &xs, &ys);
          GetLSBitmapSize(tmpbitmap1, &xs2, &ys2);
          tmpDC2=CreateCompatibleDC(NULL);
          tmpDC1=CreateCompatibleDC(NULL);
          SelectObject(tmpDC1, tmpbitmap1);
          SelectObject(tmpDC2, tmpbitmap2);
     
          TransparentBltLS(tmpDC2, (xs-xs2)/2, (ys-ys2)/2, xs2, ys2, tmpDC1, 0, 0, RGB(255,0,255));

          hMemDC = CreateCompatibleDC(tmpDC2);
          finalBMP=CreateCompatibleBitmap(tmpDC2, xs, ys);

	      hOldBitmap = SelectObject(hMemDC, finalBMP);
          BitBlt(hMemDC, 0, 0, ys, xs, tmpDC2, 0, 0, SRCCOPY);

          finalBMP = SelectObject(hMemDC, hOldBitmap);

          DeleteDC(tmpDC1);
          DeleteDC(tmpDC2);
          DeleteDC(hMemDC);
          DeleteObject(tmpbitmap1);
          DeleteObject(tmpbitmap2);
          DeleteObject(hOldBitmap);

          return finalBMP;
     }
// End bitmap merging by Thedd
        if (!strnicmp (szImageBuf, ".winicon", strlen(".winicon")))
	{
        // Returns the ASSOCIATED icon for this file/type
                HICON        hIcon;
                SHFILEINFO   shf;
                CHAR         dir[255];
                SHGetFileInfo(shortcuts[snum].szCommand, NULL, &shf, sizeof(shf), SHGFI_ICON);
                if (shf.hIcon != NULL)
                 hIcon = shf.hIcon;
                else {
                 _searchenv(shortcuts[snum].szCommand, "PATH", dir);
                 if (strlen(dir) != 0) {
                  SHGetFileInfo(dir, NULL, &shf, sizeof(shf), SHGFI_ICON);
                  hIcon = shf.hIcon;}
                }

		if (hIcon)
		{
			hBitmap = BitmapFromIcon (hIcon);
			DestroyIcon (hIcon);
			
			return hBitmap;
		}
	}
	else	// For now, we only support .BMP files
	{
		char szFullPath[MAX_PATH];
		strcpy (szFullPath, szImagesFolder);
		VarExpansion(szImageFinal, szImageBuf);
//		MessageBox(0, szFile, szImageFinal, MB_OK|MB_TOPMOST);

		strcat (szFullPath, szImageFinal);

		hBitmap = (HBITMAP) LoadImage
			(
			hInstance,
			szFullPath,
			IMAGE_BITMAP,
			0,
			0,
			LR_DEFAULTCOLOR | LR_LOADFROMFILE
			);
		
		if (!hBitmap)
		{
			hBitmap = (HBITMAP) LoadImage
				(
				hInstance,
				szImageFinal,
				IMAGE_BITMAP,
				0,
				0,
				LR_DEFAULTCOLOR | LR_LOADFROMFILE
				);
		}
		return hBitmap;
	}
	
	return NULL;
}
