From: beginner on
In article <1194462072.070301.115240(a)k35g2000prh.googlegroups.com>,
Mike Williams <gagamomo(a)yahoo.co.uk> wrote:
>On 7 Nov, 12:51, not.t...(a)address.spam.no (beginner) wrote:
>
>Judging by your newsgroup name you are a beginner in VB. Has it
>occurred to you that perhaps the "little code" you have requested
>would in fact be a great deal of code and not the simple job that you
>appear to think it is?

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

MS Paint does not "open itself up to the
>outside world" as do some other applications (as far as I know it does
>not expose any methods) so everything you do would need to be done by
>sending it the appropriate key messages. But what keystrokes do you
>think you are going to send to MS Paint, even if we told you how to
>send them? You could send Ctrl O to open a file and you could send it
>the keystrokes representing the full path and name of the bmp file and
>then you could send it Alt O to open the file. But what are you going
>to do then? You can't send it Ctrl S to save because if you do that
>then MS Paint will simply save the file in its current state and at
>its current colour depth, so you are back where you started! Somehow
>you are going to have to get it to perform a "Save As", but that
>operation does not have a shortcut key (at least not in my version of
>MS Paint) and so you are going to need to add lots of extra code to
>find the File menu and then more code to move the mouse to that
>position and click it.

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

Then you're goping to have to find the "Save
>As" submenu item and click that and then . . . it goes on and on, all
>sorts of stuff, including dispensing with the message box that MS
>Paint would pop up warning you about loss of colour quality. So, as
>you should now be able to see, it is not a simple job using "a little
>code". Not a simple job at all. Now can you understand why you have
>not yet had any responses?

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

>
>Having said all that, I personally don't think that messing about with
>MS Paint is the best way to do this kind of thing. The Windows API has
>all sorts of functions for creating bitmaps of all different sizes and
>colour depths and it is possible to create a memory DC containing a
>bitmap of the desired colour depth and to write some code to load your
>original full colour (or whatever) bitmap and mess about with your
>original pixel colours in such a way that the resultant reduced colour
>depth colour bitmap is a reasonable representation of the original
>full colour image (or at least as reasonable as it is possible to get
>at the colour depth you require). But this kind of thing is hardly the
>stuff of beginners (as you appear to be).

I am very much at a beginner level but am very inclined to learning new
things. So I will look up.

If you're interested in
>trying that method then you might like to look at the VB Accelerator
>code at the following link:
>
>http://www.vbaccelerator.com/home/vb/code/vbMedia/Image_Processing/Colour_Depth_Reduction/article.asp
>
>Otherwise, I'm sure there are various freeware libraries that can
>perform these tasks for you and that can be controlled from your VB
>program. In fact I know that there are. I don't know the name of any
>of them offhand because I've never used them (although the name
>FreeImage has just popped into my head?), but I'm sure others here
>will post a link for you, if you have a bit of patience ;-)

I can consider that option also, but it would be good to learn small
new things incrementally.

>
>By the way, as far as I understand your original question you are
>after a way of converting a full colour 24 bit bmp into a 16 colour
>bmp file. Is that what you actually want to do?

Yes, that is one part of the problem. The second is that I want to
learn how to run another program from my VB stuff.

If so then are you
>aware that converting it instead to a jpeg can give you just as much a
>reduction in file size (or more, of you require) while maintaining a
>lot more of the original colour information in the file?

Yes, but the exact colours are not important; sharpness is. Lossless JPG
might be an alternative. Or RLE compression?


Or does your
>original full colour bitmap contain no more than 16 individual colours
>anyway, and you want to preserve all of them on a pixel by pixel
>basis?

I would prefer to keep them on a pixel by pixel basis because I am not
playing with countryside pictures. I have multiple curves of calculated
results. The exact colours of each curve are not important as long as
I can keep them different. Since I never plot more than 10 curves and
one square on one chart, I can and have chosen the colours such that
reducing them to 16 colours still keeps all the colours intact. Colour
reduction algorithm is unnecessary.

If so then have you thought about converting to some other
>format, such as a gif, which would give you a greater range of colours
>than a 16 colour bitmap and yet achieve similar file size reduction?
>There are all sorts of possibilities, but none of them are the "simple
>little bit of code" that you appear to think they may be :-)
>
>Incidentally, you haven't said which version of VB you are using.

I have VB 6 and VB 3 (and one thing in VB 4) in use. I even have the
VB 2 user's manual here on my shelf..

If
>it is the "real" VB (Visual Basic 6 or previous versions) then that's
>fine, but if it is the imposter (the thing with "net" attached to it
>somewhere) then you are in the wrong newsgroup and you'll need to post
>your question to a dotnet group. In fact, just to show that I don't
>really have anything against dotnet (!) you should be "home and dry"

No, I don't like the .net and the fraud of calling a non-VB language
"VB.net". VB 6 should be safe for a few more years.

>if you are using it because it gives you native access to the new GDI+
>stuff, which should make your current specific task very easy.
>
>Mike
>
>

Thanks.





























From: Mike Williams on
On 8 Nov, 15:53, not.t...(a)address.spam.no (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


From: mayayana on
>
> I took your advice and besides looking at the site you
> mentioned, started looking for "automation" of programs
> in Windows on Google but could not find good pages. I
> will appreciate if you could suggest me an Internet site
> where I can read about automation.
>

That's a tough one. It mainly applies to MS Office and
IE, though you might find other software as well. I don't
know of any specific sites or pages that deal with automation,
though. Mainly I was thinking that if you read up on the
concept it will give you a better idea of the landscape
when it comes to controlling external programs.

> I would like to learn VBScript when I have several hours
> of more or less continuous time, may be after Christmas.
> It is presumably very similar to VB 6 and VBA.
>
> IrfanView is not a small program. If it were, I would look
> at it in a different way. I would like to manage with
> minimal extra code, and preferably without using third
> party stuff - the second party being Microsoft.

The IrfanView EXE is only 434 KB, and it probably doesn't
even need to be installed. I understand the desire not to
wander into 3rd-party software, though.

>
> Thanks again. Mike did not succeed in frightening me, but
> thanks to him also. I don't believe things are as difficult
> as he makes it sound like.

Many things are fairly easy. (And it may be that few things
are as hard as Mike Williams makes them sound.:) But what
you want to do doesn't have a simple solution in VB. If you
wanted tosay, load a JPG and convert it to a BMP, that would
be simple to do with a PictureBox. You just happened to pick
something that's involved.


From: beginner on
In article <1194551656.257192.132100(a)v29g2000prd.googlegroups.com>,
Mike Williams <gagamomo(a)yahoo.co.uk> wrote:
>On 8 Nov, 15:53, not.t...(a)address.spam.no (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.

There is a difference between our outlook. I think you want an
idiot-proof code irrespective of its length and complications, and
preferably with API commands, while I want something short and simple
which works most of the time on three of my computers.

So this is what I wrote.

Filnamn = "A.BMP"
PaintCommand = "C:\WINNT\SYSTEM32\MSPAINT.EXE " & Filnamn
X = Shell(PaintCommand, 1)
' SendKeys "%FA{TAB}{DOWN}{UP}{UP}{TAB}{ENTER}Y%FX" can mess up if not in 24 bit
SendKeys "%FA{TAB}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{UP}{UP}{UP}{TAB}{ENTER}Y%FX"

I am not sure it will work on Vista or with different versions of
Paint, but this is primarily for me, so I can improve the code when
I find it does not solve my problem. You could perhaps tell me when
this code will not work. Today, it works fine on this computer
running Windows NT. I suspect, I will need to make some changes for
the other two computers running XP and Vista.

This thing replaces the existing A.BMP. If I wanted to store it in
another file, it could have been done with some more code.

>> 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.

In this case, there is a simple solution which is not universal which
does not work on all Windows versions, and is not idiot-proof, but
good enough.

>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.

I have learnt something, and also solved a little problem of (not)
creating too many 1 MB files with very little value in the actual
colours.

Thanks again to you and others who have tried to help. Any suggestions
on how to extend this are welcome. The objective now is only to learn
something new, for which I have limited time, but unlimited energy and
urge.
















From: Mike Williams on
On 19 Nov, 08:52, not.t...(a)address.spam.no (beginner) wrote:

> There is a difference between our outlook. I think
> you want an idiot-proof code irrespective of its
> length and complications, and preferably with
> API commands

You're wrong. Leaving aside the "idiot proof code" thing (which is
another subject in itself!) I want code that works using whatever
methods are available. If native VB methods are capable of doing a
specific job then I'm quite happy to use them, and in fact I would
prefer to do so. I use API commands, as you call them, only when
native VB methods are not up to the job.

> while I want something short and simple

So do I, if it works.

> which works most of the time on three
> of my computers.

But so far you've only shown that it works on ONE of your own
computers, not three of them! In any case, I want my code to work all
of the time, not just some of the time or even most of the time, and I
want it to work on other computers as well as just one of the few
specific machines that currently happens to belong to me.

> So this is what I wrote.
> Filnamn = "A.BMP"
> PaintCommand = "C:\WINNT\SYSTEM32\MSPAINT.EXE " & Filnamn
> X = Shell(PaintCommand, 1)
> SendKeys "%FA{TAB}{DOWN}{DOWN}{DOWN}{DOWN}
> {DOWN}{UP}{UP}{UP}{TAB}{ENTER}Y%FX"
>
> I am not sure it will work on Vista

It won't. And neither will it work on Win98 or WinXP, partly because
the path is wrong on those machines and partly because the basic idea
is flawed. You can easily get around the path problem in a number of
different ways, and in fact you can fix the path problem by taking
advantage of the fact the Paint is normally a properly registered
program and by omitting everything expect the "MSPaint.exe " part of
the path, but you still won't make it work, at least on most systems.
It might work on a few systems that happen to be set up similar to
your own NT machine, if you're lucky, but certainly not on most of
them.

> You could perhaps tell me when this code
> will not work.

Okay. I've just tried your code on my own Vista machine, running it in
the IDE, and I get a "Runtime error 70 - Permission Denied", as I
expected I would because SendKeys does not work in Vista when running
in the IDE. SendKeys works in Vista when the code is compiled though,
so I compiled the code to a standard native code exe and tried it
again. This time your VB Form appeared on the display and the mouse
pointer kept flashing on and off its "busy" icon while at the same
time various MS Paint windows were flickering away busily in the
background. Quite psychedelic, really.

Anyway, after about thirty seconds of this psychedelic display things
settled down a little bit, with no further MSPaint windows opening,
but with the "busy" cursor still busily animating itself on top of
your VB Form. I quickly got fed up of watching the little "busy"
cursor animating itself and so I closed your VB Form. At that point
there were 68 separate copies of MS Paint running, each with the same
picture loaded into them. Then I went back to my desktop and I
discovered that no other applications would open at all, and I could
not even open any of the folders that I have on my desktop. Nothing
would work. In order to get my computer working again I had to
manually close the 68 copies of MS Paint, one by one, which was very
annoying. At this point if your program had been something I had
downloaded I would have dumped it straight into the bin and checked my
system for viruses (or is that virii?), and if it had been something I
had purchased I would have been after you for my money back!

To make things even worse, there was no "16 colour" copy of the
original anywhere on my system, so as well as messing up my computer
and forcing me to manually close 68 separate windows to get it working
again it did not even carry out the task it was supposed to carry out!
If this was evening time I would have definitely reached for the
whisky bottle (and the Coke(R) of course!), but since it is mid morning
here I'll have to settle for a strong cup of coffee instead!

> This thing replaces the existing A.BMP.

Not on my machine it doesn't!

> In this case, there is a simple solution which
> is not universal which does not work on all
> Windows versions, and is not idiot-proof

Oh. Is that all that's wrong with it? Yikes!

> but good enough.

.. . . erm . . . good enough for what?

> I have learnt something, and also solved a
> little problem . . .

Well, you've learned somnething alright, but I can't see what problem
you've solved?

> Thanks again to you and others who have tried
> to help.

We've done more than "try" to help. We've given you "real" help and
pointed you to code that actually works and that does exactly the job
you require. That surely qualifies us for something more than a mere
'tried to help', doesn't it?

> The objective now is only to learn something
> new, for which I have limited time, but
> unlimited energy and urge.

I'm afraid that energy and urge in themselves are not a great deal of
use if you have no time in which to use those otherwise commendable
attributes. If I were you I would spend a little time looking at the
various things we have previously posted in this thread and using them
to help you to write your code in a way that will actually work.

Mike