PowerBASIC Forums
  PowerBASIC for Windows
  CONTROL SEND versus SendDlgItemMessage (Page 1)

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone!
This topic is 2 pages long:   1  2 
next newest topic | next oldest topic
Author Topic:   CONTROL SEND versus SendDlgItemMessage
Egbert Zijlema
Member
posted July 25, 2001 04:57 AM     Click Here to See the Profile for Egbert Zijlema     Edit/Delete Message   Reply w/Quote
Hi Folks,

As far as I can see, all the DDT CONTROL statements are really STATEMENTS, no FUNCTIONS.
Sometimes (often, maybe?) a programmer needs a function instead. For instance: if you want to
know the number of elements in a listbox array, you can't use

CONTROL SEND hDlg, idCtrl, %LB_GETCOUNT, 0, 0

Am I right?
elements = SendDlgItemMessage hDlg, idCtrl, %LB_GETCOUNT, 0, 0
does the trick, of course, but similar DDT functions would be very nice.
Something for the wishlist?

------------------
Egbert.Zijlema@basicguru.com
www.basicguru.com/zijlema/

[This message has been edited by Egbert Zijlema (edited July 25, 2001).]

IP: Logged

Lance Edmonds
Member
posted July 25, 2001 05:03 AM     Click Here to See the Profile for Lance Edmonds     Edit/Delete Message   Reply w/Quote
Done!

CONTROL SEND can receive a value, just as the API function can return...


CONTROL SEND hDlg, idCtrl, %LB_GETCOUNT, 0, 0 TO Result&


------------------
Lance
PowerBASIC Support
support@powerbasic.com

IP: Logged

Semen Matusovski
Member
posted July 25, 2001 05:04 AM     Click Here to See the Profile for Semen Matusovski     Edit/Delete Message   Reply w/Quote
Full form (see PB.Hlp) is CONTROL SEND hDlg&, Id&, Msg&, wParam&, lParam& TO result&

------------------
E-MAIL: matus@perevozki.ru

IP: Logged

Egbert Zijlema
Member
posted July 25, 2001 06:34 AM     Click Here to See the Profile for Egbert Zijlema     Edit/Delete Message   Reply w/Quote
Thank you, Lance and Semen.

------------------
Egbert.Zijlema@basicguru.com
www.basicguru.com/zijlema/

IP: Logged

Bruce Wood
Member
posted December 13, 2002 01:11 PM     Click Here to See the Profile for Bruce Wood     Edit/Delete Message   Reply w/Quote
Lance or other knowledgeable parties.

Do I understand the meaning of these post?

1). Can I use all of the PB Control and Dialog statements to send and manipulate existing Windows that I did not make?

2). For an existing Window w/Children, Do I need to Enum.. to get the Windows handle?

3). What API or command do I use then to get the idCtrl after I have the Windows handle? (I fixed this Question)

4). If my final results are to send a Text message to a ComboBox or Edit box.
The command to send the message would be CONTROL SEND hDlg, idCtrl, %CB_?, 0, 0 ?

I must admit.

I find it very frustrating that there is no book that I can buy which gives me an example/tutorial on the proper use of the Windows API's.

Under PowerBasic of course.

Mr. Appelman's Book VB guide to Win32 API, is frankly very lacking, just definitions on the API's,

but very very few examples on how the API is used.

Thx for looking.

Bruce


------------------

[This message has been edited by Bruce Wood (edited December 13, 2002).]

IP: Logged

Tom Hanlin
Member
posted December 13, 2002 09:27 PM     Click Here to See the Profile for Tom Hanlin     Edit/Delete Message   Reply w/Quote
It is generally not good to mix PowerBASIC DDT commands with Windows
calls. Sometimes it's ok but, you need to know a lot about what you're
doing before trying this. I'll leave details to others, as this is not
an area I know very well.

------------------
Tom Hanlin
PowerBASIC Staff

IP: Logged

Pierre Bellisle
Member
posted December 13, 2002 09:50 PM     Click Here to See the Profile for Pierre Bellisle     Edit/Delete Message   Reply w/Quote
Bruce,
many things can be done, some look pretty hard (at least to me).
Hope you will have some fun with following code...
It's not DDT but...

Start your PowerBASIC COM Browser and try this...


#Compile Exe
#Dim All
#Include "Win32Api.Inc"

Function PbMain
LOCAL hProc AS LONG
LOCAL hControl AS LONG
LOCAL SomeText AS ASCIIZ * 50

SomeText = "This can be done!"
hProc = FindWindow("", "PowerBASIC COM Browser")
hControl = GetDlgItem(hProc, 1027)
'ID 1027 was found using EnumChildWindows, many example on PB BBS.
SendMessage hControl, %WM_SETTEXT, 0 ,VarPtr(SomeText)

End Function

'Some usefull api functions...
'FindWindowEx, GetDlgCtrlID, GetDlgItemText, GetDlgItemInt, SendDlgItemMessage
'PostMessage, SendNotifyMessage, SetDlgItemInt, SetDlgItemText, FindWindowEx,
'GetDlgCtrlID, EnumWindows, EnumChildWindows


------------------
Pierre Bellisle

[This message has been edited by Pierre Bellisle (edited February 27, 2004).]

IP: Logged

Gösta H. Lovgren-2
Member
posted December 14, 2002 07:01 AM     Click Here to See the Profile for Gösta H. Lovgren-2     Edit/Delete Message   Reply w/Quote
quote:
Originally posted by Pierre Bellisle: Bruce, many things can be done,
some look pretty hard (at least to me). Hope you will have some fun with
following code... It's not DDT but...

Start your PowerBASIC COM Browser and try this...

 #Compile Exe #Dim All
#Include "c:\Win32Api.Inc"

Function PBMAIN Local hProc AS LONG Local hControl AS LONG Local SomeText AS
Asciiz * 50

SomeText = "This can be done!" hProc = FindWindow("", "PowerBASIC COM Browser")
hControl = GetDlgItem(hProc, 1027) 'ID 1027 was found using EnumChildWindows,
many example on PB BBS. SendMessage hControl, %WM_SETTEXT, 0,VarPtr(SomeText)

End Function

'Some usefull api functions... 'FindWindowEx, GetDlgCtrlID, GetDlgItemText,
GetDlgItemInt, SendDlgItemMessage 'PostMessage, SendNotifyMessage,
SetDlgItemInt, SetDlgItemText, FindWindowEx, 'GetDlgCtrlID, EnumWindows,
EnumChildWindows '


Hi Pierre,

I tried your code fragment and it compiled fine. Now can you tell me what it
actually does? I mean it compiled, ran and did nothing, as far as I can see.

What I think it does is look for a dialog with "PowerBASIC COM Browser" in it

(hProc = FindWindow("", "PowerBASIC COM Browser")) 
and return the
handle of that dialog. Is that right?

Then:

 hControl = GetDlgItem(hProc, 1027)
return the Id of the
control that "PowerBASIC COM Browser" appears in. Is that right?

And then:

 SendMessage hControl, %WM_SETTEXT, 0,VarPtr(SomeText)

replace "PowerBASIC COM Browser" with SomeText ("This can be done!"). Is that
right?

Okay, if that's true (and it's always a BIG IF with me, or as me Ma used to say
"It's a wee word wi' a big meaning."), then this will be cool to play with. I
fooled around a little with it but no results so far and before I go further and
start to make myself nuts (a not infrequent occurrence) I'd like to be more sure
I am on the right track.

Oh, and one more thing:

 hControl = GetDlgItem(hProc, 1027) 'ID 1027 was found using
EnumChildWindows, many example on PB BBS.

Is 1027 a special number of some sort that causes a particular code handle to
return. I don't understand the significance of it.

Also,

[code] 'Some usefull api functions... 'FindWindowEx, GetDlgCtrlID,
GetDlgItemText, GetDlgItemInt, SendDlgItemMessage 'PostMessage,
SendNotifyMessage, SetDlgItemInt, SetDlgItemText, FindWindowEx, 'GetDlgCtrlID,
EnumWindows, EnumChildWindows [code]

I'm certain they are "useful" but what do they do? They are not self explanatory
to me, though they are implicit to "NON-Newbies" I'm sure.

[This message has been edited by Gösta H. Lovgren-2 (edited December 14, 2002).]

IP: Logged

Lance Edmonds
Member
posted December 14, 2002 07:26 AM     Click Here to See the Profile for Lance Edmonds     Edit/Delete Message   Reply w/Quote
quote:
What I think it does is look for a dialog with "PowerBASIC COM Browser" in it...

Your analysis is pretty much spot on.

quote:
 hControl = GetDlgItem(hProc, 1027) 'ID 1027 was found using
EnumChildWindows, many example on PB BBS.

Is 1027 a special number of some sort that causes a particular code handle to
return. I don't understand the significance of it.

1027 is the ID number of a control on the target dialog. Essentially, the programmer assigns an ID number to a control when it is being created, and Windows generates a unique window handle to identify the control itself. The GetDlgItem() ASPI function is useful to find out the windows-assigned handle to a control whose ID number is known.

You can use the complementary GetDlgCtrlID() function to determine the (programmer-assigned) ID from a control whose window handle is known.

Therefore, if you know the handle of the window, you can find the ID if you only know the control handle; and you can find out the window handle if you only know the ID.


[code]
I'm certain they are "useful" but what do they do? They are not self explanatory
to me, though they are implicit to "NON-Newbies" I'm sure.[/quote]
First step would be to read about them in Win32.HLP... http://www.powerbasic.com/files/pub/mstools/win32.zip (8Mb)

However, without an understanding of the principles of message-based programming, then you might still struggle with the explanations.

Therefore I HIGHLY recommend that you invest in yourself and get a good Windows programming theory book, such as Petzold's "Programming Windows". See http://www.powerbasic.com/support/forums/Forum2/HTML/000031.html for a list of recommended titles.

Books on Windows programming are rarely a bad investment if you are serious about learning Windows programming (especially if you want to learn about GUI programming). If you understand how Windows works, you'll find it much easier to write "proper" windows applications.

I hope this helps!

------------------
Lance
PowerBASIC Support
support@powerbasic.com

IP: Logged

Gösta H. Lovgren-2
Member
posted December 14, 2002 09:23 AM     Click Here to See the Profile for Gösta H. Lovgren-2     Edit/Delete Message   Reply w/Quote
quote:
Originally posted by Lance Edmonds: [QUOTE]What I think it does is
look for a dialog with "PowerBASIC COM Browser" in it...

Your analysis is pretty much spot on.
[/QUOTE] [/QUOTE]

Thank you. Now I am
encouraged to fool around with some programs I have written to do some changing,
perhaps dynamically as data changes.

quote:
 hControl = GetDlgItem(hProc, 1027) 
'ID 1027 was found using
EnumChildWindows, many example on PB BBS.
Is 1027 a special number of
some sort that causes a particular code handle to return. I don't understand the
significance of it.

quote:

1027 is the ID number of a control on the target dialog. Essentially, the
programmer assigns an ID number to a control when it is being created, and
Windows generates a unique window handle to identify the control itself. The
GetDlgItem() ASPI function is useful to find out the windows-assigned handle to
a control whose ID number is known.


Sorry, but that didn't answer my question. I'm well aware of what a ControlId
is. What I didn't know is if the number "1027" had an explicit meaning. Based on
your answer, I will presume it's merely a number Pierre picked
(programmer-assigned).

quote:
You can use the complementary GetDlgCtrlID() function to determine the
(programmer-assigned) ID from a control whose window handle is known.

I'm not sure I understand. Wouldn't the programmer ALREADY know the ControlID?
Or, (thinking as I write) is the handle returned a Windows internal handle
("Hproc" in the example). In other words, I may assign the LONG value of 125
("Id_Txt_Box1= 125" in my code) as a ControlId for a TextBox (for example) but
internally Windows will use a value of its own choosing (as it were). And what
GetDlgItem(hProc, 125) will return in hProc is the actual handle Windows uses.


quote:
Therefore, if you know the handle of the window, you can find the ID if
you only know the control handle; and you can find out the window handle if you
only know the ID.

I would understand it clearly if the last sentence read: "and you can find out
the window handle if you only know the [b]CONTROL
ID>" May I presume the
added "CONTROL"?

quote:
[code] I'm certain they are "useful" but what do they do? They are not
self explanatory to me, though they are implicit to "NON-Newbies" I'm
sure.
First step would be to read about them in Win32.HLP...
http://www
.powerbasic.com/files/pub/mstools/win32.zip
(8Mb)

However, without an understanding of the principles of message-based
programming, then you might still struggle with the explanations.

Therefore I HIGHLY recommend that you invest in yourself and get a good Windows
programming theory book, such as Petzold's "Programming Windows". See
http:// <A HREF="http://www.powerbasic.com/support/forums/Forum2/HTML/000031.html" TARGET=_blank>www.powerbasic.com/support/forums/Forum2/HTML/000031.html[/URL]</A> for a list of
recommended titles.

Books on Windows programming are rarely a bad investment if you are serious
about learning Windows programming (especially if you want to learn about GUI
programming). If you understand how Windows works, you'll find it much easier
to write "proper" windows applications.

I hope this helps!

[/B][/QUOTE]

I have to tell you this last section is of NO help at all. I don't want to sound
at all ungrateful for your generous help (on many occasions) but I HAVE read
(much of)Petzold, as well as a couple (expensive) others, and do use WinHlp.
And many things are still not clear to me.

It demonstrates to me you (and many others here) don't really comprehend the
depth of ignorance some of us Newbies have. In my case, for example, I don't
have ANY formal training (college courses, etc. or even high school) nor do I
have C experience. Many of the replies here presume that level experience and so
leave me (still) lost.

What WOULD be REALLY helpful is to have a separate forum where Newbies could go
and have examples and explanations posted with well commented complete code.
Pierre's example above is a good one. However it would have been much more
helpful had an actual working sample been included us Newbies could load into
our editors and run and seen the effects of FindWindow & GetDlgItem.

Then we could go and experiment and incorporate on our own, and just maybe, for
the less slow among us, gain more understanding of Windows programming.

Lance, I honestly believe you cannot understand how intimidating posting on this
forum (where probably the best and most competent programmers IN THE WORLD hang
out and post) can be for a Newby to ask a "foolish" question (and please, no
posts "There is no such thing as a foolish question.... Only ...") and how
frustrating and offputting a reply like "Read Petzold .." or "Search the Forum"
can be.

I don't think I am the only one who is in love with PB but is having trouble.
I'm sure I'm not the only one. We REALLY need our own forum.

------------------
Thx............Gösta
Gosta@SwedesDock.com
http://www.SwedesDock.com
http://www.PondersBible.com

[This message has been edited by Gösta H. Lovgren-2 (edited December 14, 2002).]

IP: Logged

Bruce Wood
Member
posted December 14, 2002 01:11 PM     Click Here to See the Profile for Bruce Wood     Edit/Delete Message   Reply w/Quote

Pierre:

Many thanks,

I compiled your code and it put's the words "This can be done!" in the Interface Prefix Box.

Your code was very nicely done, to show what can be done.

This is part that kills you.

'ID 1027 was found using EnumChildWindows, many example on PB BBS

EnumChildWindows is not a trivial piece of code. I noticed you left that part out.

Because it is just that, not trivial.

Getting that Id is critical to sending the message.

What constitutes a handle and what constitutes an ID?

How does a programmer get the Handle and/or ID?

It just seems that programming for Windows starts by being complicated from the very beginning.

Simple Idea: Place some text into an Edit or ComboBox on the current screen. (Lucky for me, I know they are called that)

Let's see.... what book would have this information?

Well a book by Microsoft of course - "The complete guide to Win32 API Programming"....NOT

Now let's look up "Sending Messages" or "Placing text on the screen"

If you find something...Dollars to Donuts says it will be either esoteric mumbo jumbo - or nothing like what you really want.

Probably no example or a very nasty looking C+ code structure. And it will be just a fragment of what you need to do the job.

After struggling and maybe finding what you think is the proper API.

You find out that this API requires input information that must be extracted from 5 other API calls and that you don't know what they are.

Oh, and sending a message to a ListBox,Combo and or Edit use difference code.

Yes, I am a programmer, 30 yrs , assembler, (I won't even go into trying to programming Windows in Assembler),

Getting the proper information to program Windows should not be so difficult.

Needing 4 or 5 books to maybe find the information you want. That is unreal.

Ok, I'm a little older than most here maybe, but I want to still want to learn how to do this.

It is so much quicker and easier to be given a working example or shone how to do something.

PowerBasic:

It would be a god send, to have a section that contains example coding, showing how it perform a large number of the most common or complex Window API calls.

This forum has some of the best PB programmers around and maybe some of the best programmer period.

They graciously contribute code and their time here, perhaps they would place some of there common code functions into this section.

We "progressing" programmer would learn quicker and would not have to re-invent the wheel.

Where is the complete "Guide to PowerBasic and Win32 API interfacing /with rip roaring examples"

I'd buy that BOOK yesterday!

Gösta H. Lovgren-2, I couldn't agree with you more.


------------------

IP: Logged

Gösta H. Lovgren-2
Member
posted December 14, 2002 04:51 PM     Click Here to See the Profile for Gösta H. Lovgren-2     Edit/Delete Message   Reply w/Quote
quote:
Originally posted by Bruce Wood:

Pierre:

Many thanks,

I compiled your code and it put's the words "This can be done!"
in the Interface Prefix Box.

Your code was very nicely done, to show what can be done.


It is nice code. I just tried the code again (using the PB
Editor instead of JellyFish) but nothing happens. It compiles
okay. Where is the "Interface Prefix Box"?

quote:

...<snip>

Ok, I'm a little older than most here maybe, but I want to still
want to learn how to do this.


I wouldn't wanna bet on who is older, but I've been retired
nearly 18 years. And been programming almost twice that long.
Kinda hard for me to understand how dumb I really am {grin}.


quote:

...<snip>
We "progressing" programmer would learn quicker and would not
have to re-invent the wheel.

Where is the complete "Guide to PowerBasic and Win32 API
interfacing /with rip roaring examples"

I'd buy that BOOK yesterday!



You'd have to get in a pretty long line, especially if you made
that "with rip roaring WELL COMMENTED examples".

quote:

Gösta H. Lovgren-2, I couldn't agree with you more.

If the truth were know, I'll plenty others who would agree too.

------------------
Thx............Gösta
Gosta@SwedesDock.com
http://www.SwedesDock.com
http://www.PondersBible.com

IP: Logged

JOSE ROCA
Member
posted December 14, 2002 05:10 PM     Click Here to See the Profile for JOSE ROCA     Edit/Delete Message   Reply w/Quote
Have you started the PowerBASIC COM Browser? If you don't start it nothing can happen...

------------------

IP: Logged

Pierre Bellisle
Member
posted December 14, 2002 06:11 PM     Click Here to See the Profile for Pierre Bellisle     Edit/Delete Message   Reply w/Quote
OK,
I was lazy, let's try another one, more complete...

Still have to run "PowerBASIC COM Browser" program first.
(In PB ide, Tool, PowerBASIC COM Browser)

This one have the famous EnumWindows and
EnumChildWindows function wrapped in it.
I've tryed to add comments to the best of my knowledge.

I don't know for other, but for me it was a very long
and hard study before I can come up with this kind of code...
Thanks to PB gurus, for me, no-can-do without them...

Windows is a very complex beast,
understanding it is a never ending thrill...

Hope this help.
Ciao.

Some comment added and code updtate 2002/12/15

Code moved to source code at http://www.powerbasic.com/support/forums/Forum7/HTML/001681.html

Topic: EnumWindows and EnumChildWindows


[This message has been edited by Pierre Bellisle (edited December 15, 2002).]

IP: Logged

Bruce Wood
Member
posted December 15, 2002 01:13 AM     Click Here to See the Profile for Bruce Wood     Edit/Delete Message   Reply w/Quote

Pierre:

Wow, now that's more like it.

I will enjoy consuming this code.

Thank you very much!


I will not doubt for more questions.

Bruce

------------------

IP: Logged


This topic is 2 pages long:   1  2 

All times are EasternTime (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | PowerBASIC BASIC Compilers

Copyright © 1999-2007 PowerBASIC, Inc. All Rights Reserved.


Ultimate Bulletin Board 5.45c