Re: Help with SendKeys



On 8 Nov, 15:53, not.t...@xxxxxxxxxxxxxxx (beginner) wrote:

I somehow can't think it could be so complicated.

I think you'll find plenty of complications as you begin to unravel
this specific task in the way that you have suggested, but if you're
lucky none of them will be insurmountable.

How about ALT F A and then use TAB instead
of fumbling with the mouse?

Yes. That's a very good suggestion. But I'm not sure if Tab is the
best way to go about it because it is possible that different versions
of MS Paint have a different number of controls and possibly tab in a
different order (although that may not be the case of course). I think
looking for windows in some other way might be the answer. I never use
MS Paint myself and so in my previous response I was just going by the
shortcut keys that are displayed against the menu items themselves,
and "Save As" does not have a shortcut key displayed against it, at
least on my version of Paint. But on testing it appears that the
shortcut does actually exist. So, your own suggestion of using Alt F A
would appear to be fine as far as bringing up the Save As dialog is
concerned. I'm not sure how you would then persuade MS Paint to select
the 16 colour bitmap option in the "Save as Type" combo, but if you
can come up with a shortcut key for that then you would indeed save
yourself the trouble of "fumbling with the mouse" as you have called
it. At a guess I would say that the current default entry and the
order of the items as listed in the combo might be very different on
different versions of MS Paint or on different version of Windows, so
apart from the tabbing problems there may be other brdges to cross
there. But it's certainly worth looking at. And of course yu would
need to dismiss the "colour loss" warning box, but it isn't worht
looking at that until you've got at least part way there.

I thought you people had no problems with
showing simple solutions to difficult VB
problems..

Well we don't, in cases where a simple solution actually does exist.
But you need to realise that not all tasks have a "simple solution"
and some tasks require a fairly complex solution which a beginner (as
you describe yourself) might not be comfortable with. However, having
said that, your own responses so far indicate that you are not
actually a typical beginner and so you might be very happy moving onto
more complex solutions as you go along.

I am very much at a beginner level but am
very inclined to learning new things.

So it would appear. In that case perhaps it is time to post some code
for you to start you off on your own original suggestion of shelling
the MS Paint program and attempting to control it to perform your
specific task using Sendkeys. We can do that when you post back
telling us how far you have so far got yourself. You will then either
succeed in that task (and I hope you do) or you will learn something
new along the way that causes you to realise that it is not quite so
easy as it first appears. Either way, you will have learned something
valuable.

So I will look up.

Okay. Fine. Then post back telling us which bits you have tackled and
which bits you need help with, so that we're not covering things that
you have already covered yourself. The first thing to do of course is
to shell MS Paint. It is possible to use ShellExecute (a Windows API
function) passing it the filename of the bmp file you wish to open and
the system will then open up that file into the default handler for
bmps. However, some systems might have MSPaint set up as the default
handler and other systems might have some other application set up to
handle them, so perhaps it might be better to use the fairly
straightforward VB Shell method to open up MS Paint (you don't need
its full path, just the name will do). Then you can send your
keystrokes to it after first making sure it has the focus. Let us know
which parts you are okay with and which parts you want help with. As
far as sending keystrokes is concerned, that job can usually be
handles by the fairly straightforward VB Sendkeys function. However,
there are problems with Sendkeys in Vista in that you get a
"permission denied" error under all ciurcumstances on early versions
of Vista. That problem was fixed in later versions of vista, but only
as far as your VB compiled exe is concerned. When using SendKeys in
your VB code running in the IDE you still get the "permission denied"
error, which makes it a bit difficult to easily test your code.
However, there is alternative to SendKeys. You can use the low level
KeyBd_Event API instead, which works fine in all versions of Vista,
bith in the IDE and when compiled (as long as you're not attempting to
send keys to something that has a higher level of permissions than
your own program, which does not apply in this case).

Anyway, you appear to be happy solving things yourself and only asking
for help when you really need it, so perhaps you might like to start
off with the "Shell" and the set focus stuff and let us know if and
when you need help with Keybd_Events.

I must say it's refreshing for a change to talk to a "beginner" who
appears to be a cut above the average. Best of luck with your project.
And if you do end up getting bogged down in it and if it becomes
apparent that there are too many bridges to cross to control MSPaint
in such a way (as it may or may not do) then no harm will have been
done and at least you'll then know that the extra effort involved in
using an alternative method, or perhaps the acceptance of using a
"third party" control if you don't personally wish to delve too deeply
into the API stuff, will not be for nothing.

In summary, I still think you would be better off delving into the
various API methods of creating and handling bitmaps of different
colour depths, perhaps using the link that I posted (which gives you
all the code you need in a "ready built and easy to use" fashion)
because then you will not only be able to load and save bitmaps at
whatever colour depth you wish (performing whatever colour depth
conversions you wish) but it will also allow your code to draw stuff
into those bitmaps if you wish. And not a third party control in
sight! However, it appears that you are not the sort of person to be
told what to do (which is actually a very good thing and I'm sure
you're not going to remain a "beginner" for very long). Just start off
on your "control MS Paint" methjod and post again if and when you get
stuck or need some help.

Mike


.



Relevant Pages

  • RE: Open non MS applications
    ... SendKeys sends keystrokes to another program. ... Before I run it, I select a picture. ... goes to the Paint program (which doesn't have ... copy the new picture from Paint to the clipboard ...
    (microsoft.public.excel.programming)
  • Re: Subclassing dynamically created controls
    ... I have achieved being able to paint the background colour of the CEdit box ... painting of the control in MFC by making a derived class will fail at this ... so this is the colour that you want to paint the background of the ... I call pDC->SetBkColor which tells the GDI pointer for this control, ...
    (microsoft.public.vc.mfc)
  • RE: Subclassing dynamically created controls
    ... I have achieved being able to paint the background colour of the CEdit box ... painting of the control in MFC by making a derived class will fail at this ... so this is the colour that you want to paint the background of the ... I call pDC->SetBkColor which tells the GDI pointer for this control, ...
    (microsoft.public.vc.mfc)
  • Re: Weird problem when re-painting form while moving it outside of the screen!
    ... You can only paint what is actually visible on the screen. ... If you want to determine what portion of your control is visible, ... When the control gets the paint event, I use a memory bitmap ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Graphics.Clip region always infinite when painting
    ... directly on the graphics object obtained from PaintEventArgs ... When Paint is initially called, ... Since this is a control, ...
    (microsoft.public.dotnet.framework.drawing)