🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #13686

Re: Send a mail with attachment

#13686
From: Ed Mulroy [TeamB]
Date: Sun, 28 Sep 2003 22:04
110 lines
4909 bytes
Something that bothers me about that code is what is it going
to do if the user has his finger on the shift key.  Unfortunately
I can't think of an easy way around that and holding your finger
on that key is not normal user behavior.

This has now gotten into personal preferences so I'll show mine
(feel free to criticize or make fun of them - I've been married for
years so am used to it <g>).

Try this instead:

  --------------
  void SendCString(const char* s)
    {
    const char CSpecialChar[] = "!@#$%^&*()_+{}|:<>?\"";

    for (unsigned int i = 0, slen = strlen(s); i < slen) ; ++i)
      {
      char c = s[i];
      short kscan = VkKeyScan(c);

      if (isupper(c) || strchr(CSpecialChar, c))
        {
        // send Shift key down
        keybd_event(VK_SHIFT, 1, 0, 0);
        // send char down
        keybd_event(kscan, 1, 0, 0);
        // send char up
        keybd_event(kscan, 1, KEYEVENTF_KEYUP, 0);
        // send Shift key up
        keybd_event(VK_SHIFT, 1, KEYEVENTF_KEYUP, 0);
        }
      else
        {
        // send char down
        keybd_event(kscan, 1, 0, 0);
        // send char up
        keybd_event(kscan, 1, KEYEVENTF_KEYUP, 0);
        }
      }
    }
  --------------

The strlen call and associated search for the end of the string is not
done in each iteration of the loop, just once at the beginning.

The value of 'i' is pre-incremented because the way it is used in the
loop is not in a post-incrementing manner.  (and yes, in his
examples Bjarne does post-increment instead of pre-increment
when post-increment is not needed and yes, Bjarne is wrong).
Let the compiler optimization work on what you did not think of.
One should write so that the generated code quality is only
dependent on the optimizer for those things he does not already
know about.

There is only one indexed fetch from the array in memory per
iteration of the loop instead of 3 or 4 times depending upon the
result of isupper.

The array indexing uses brackets, "s[i]", instead of the old
1980 C way of "*(s+i)'" so may be more easily understood.

There is only one call to VkKeyScan instead of two calls per loop
iteration and generated code for one call instead of for four calls.

.  Ed

> Rodolfo Frino wrote in message
> news:3f77017d@newsgroups.borland.com...
>
> ...With this function the code
> can be simplified as:
>
> void SendCString(const char* s)
> {
>     const char CSpecialChar[] = "!@#$%^&*()_+{}|:<>?\"";
>     for (unsigned int i=0; i < strlen(s) ; i++)
>     {
>         if (isupper(*(s+i)) || strchr(CSpecialChar, *(s+i)))
>         {
>             // send Shift key down
>             keybd_event(VK_SHIFT, 1, 0, 0);
>             // send char down
>             keybd_event(VkKeyScan(*(s+i)), 1, 0, 0);
>             // send char up
>             keybd_event(VkKeyScan(*(s+i)), 1, KEYEVENTF_KEYUP, 0);
>             // send Shift key up
>             keybd_event(VK_SHIFT, 1, KEYEVENTF_KEYUP, 0);
>         }
>         else
>         {
>             // send char down
>             keybd_event(VkKeyScan(*(s+i)), 1, 0, 0);
>             // send char up
>             keybd_event(VkKeyScan(*(s+i)), 1, KEYEVENTF_KEYUP, 0);
>         }
>     }
> }
>
>
> The property you refer to is a Label that I placed on the
> form at design-time. Well, I wanted to display the number
> of e-mails sent (MessageCount) on that Label, which must
> be on a Form, so I needed the form for that, and also to
> place a button to send the e-mail. Of course you could also
> do it without the Label and without the Button.
>
> I don't worry about the Labels/Buttons/etc. that are not declared
> anywhere, people will figure it out, and they will add them/drop
> them into their forms to run the example.
Technical Details
Message-ID: <3f775aeb@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!diablo.theplanet.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3f70794d@newsgroups.borland.com> <3f7545de@newsgroups.borland.com> <3f755135@newsgroups.borland.com> <3f77017d@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,23d9e1242f297072
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-09-28 15:09:07 PST
From: "Ed Mulroy [TeamB]" <dont_email_me@bitbuck.et>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f70794d@newsgroups.borland.com> <3f7545de@newsgroups.borland.com> <3f755135@newsgroups.borland.com> <3f77017d@newsgroups.borland.com>
Subject: Re: Send a mail with attachment
Date: Sun, 28 Sep 2003 18:04:15 -0400
Lines: 112
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 206.228.162.47
Message-ID: <3f775aeb@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1064786667 206.228.162.47 (28 Sep 2003 15:04:27 -0700)
X-Authenticated-User: edmulroy
Path: arc1-ca.pugleaf.net!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!diablo.theplanet.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail