Code to transform paste buffer strings

Copying text from an IE5 browser window and pasting to Office2K, InterDev or FrontPage or gives:

<TITLE>Join <%=SITENAME%></TITLE>

instead of:

<TITLE>Join <%=SITENAME%></TITLE>

Surely there's a trival solution to over-ride this behavior...is 200 points enough for an executable?

thankx
--steve...

juststeveAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
KangaRooConnect With a Mentor Commented:
Do you have access to a C++ compiler, or should I mail the executable? Here is the code.
When executed the program reads the clipboard, modifies the text replacing &lt with < and &gt; with >
The modified text is placed back on the clipboard and the program terminates. You can assign it to a hotkey from windows.
//=============================================================
#include <windows.h>

int main()
{
   // Check if text is available
   if(!IsClipboardFormatAvailable(CF_TEXT))
      return 1;
   // if so, Get it
   if(!OpenClipboard(0))
      return 2;
   HANDLE hData = GetClipboardData(CF_TEXT);
   if(!hData)
   {
      CloseClipboard();
      return 2;
   }
   char* buffer = (char*)GlobalLock(hData);

   HGLOBAL hglb = GlobalAlloc(GMEM_SHARE, strlen(buffer) + 1);
   if(!hglb)
   {
      CloseClipboard();
      GlobalUnlock(hData);
      return 2;
   }

   char* outbuffer = (char*)GlobalLock(hglb);
   char* out = outbuffer;

   // parse and modify
   int cursor = 0;
   while(buffer[cursor])
   {
      if(buffer[cursor] == '&' && buffer[cursor + 2] == 't' && buffer[cursor + 3] == ';')
      {
         switch(buffer[cursor+1])
         {
            case 'l' : *out++ = '<'; cursor += 4; break;
            case 'g' : *out++ = '>'; cursor += 4; break;
            default  : *out++ = buffer[cursor++]; break;
         }
      }
      else *out++ = buffer[cursor++];
   }
   *out = '\0';

   // release handles
   GlobalUnlock(hData);
   GlobalUnlock(hglb);

   // put modified data back on the clipboard
   EmptyClipboard();
   SetClipboardData(CF_TEXT, hglb);

   CloseClipboard();
}
0
 
chensuCommented:
What exactly do you want? C++ code?
0
 
juststeveAuthor Commented:
an executable.

I don't care if it vb-based or what. I just figured the platform best suited for this would be c++

Possible something like this could be accessed via registry keys? But I'll be moving to win2k soon and expect the same issure going on there.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
chensuCommented:
Do you want the executable to simply convert the string for you? Or do you want the executable to toggle the IE5 behavior?
0
 
Jan LouwerensSoftware EngineerCommented:
what happens if you do a View Source on the page, and then copy and paste from there?
0
 
juststeveAuthor Commented:
Copying from View Source has the same effect my currect solution of pasting to a notepad window and re-copying -unworkable to expect to be able to find the exact source I'm looking to copy.

As to toggle or not... the best solution I can imagine is an application that's associated with the key combination: Ctrl-SpaceBar. When pressed the conversion es effected on whatever's in the paste buffer.

Does this whole issue arise as the result of the clipboard 'enhancements' in Office2K?
0
 
KangaRooCommented:
It appears that only < and > are replaced by &lt; and &gt; respectively. VBA or macro to replace these tokenstrings might be the simplest solution.

IE5 + Word 97 doesn't behave this way, so I can't reproduce it.
0
 
KangaRooCommented:
You could try the following code:

Sub Macro1()
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "&lt;"
        .Replacement.Text = "<"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "&gt;"
        .Replacement.Text = ">"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
0
 
juststeveAuthor Commented:
But VBA apps can't execute inside FrontPage or InterDev, can they?
0
 
KangaRooCommented:
I don't know, I'm using Office 97 and don't have Frontpage or InterDev. If I'd thought it was the solution to your problem I'd have submitted it as answer :) I think it'll work for Word tough (did it?).
0
 
juststeveAuthor Commented:
My mistake for not making it clear that I need this for developement work (FP and InterDev) so i haven't run it against Word.

thankx anyway.
--steve...
0
 
KangaRooCommented:
Can you give me your e-mail so that I can mail you the executable?
0
 
juststeveAuthor Commented:
steve@juststeve.com

we need to add one more conversion:

find &amp; replace with &

many thankx
--steve...

0
All Courses

From novice to tech pro — start learning today.