BBC BASIC for Windows
« Window handles »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:49pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Window handles  (Read 264 times)
KenDown
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 181
xx Window handles
« Thread started on: Nov 23rd, 2017, 2:08pm »

I recently wrote a program that needed to send out e-mails, so I used the method given in the Wiki. You define to$ and from$ and so on, send the string to something or other and your mail program opens up with the To and From fields filled out.

However there is a 256 character limit (or was it 512?) which means that there has to be another method of entering the message. I used one of the keyboard imitating routines from the Wiki and it all works splendidly. The program calls the mail prog, pauses until the input focus is no longer @hwnd% and then types to the handle given by GetForegroundWindow.

Yesterday I got a scream for help from one of the users: my program was malfunctioning and the message was ending up being typed into the "From" box.

It all worked fine at my end, so I hotfooted it over there and discovered that the wretched woman has changed her mail client to something horrible produced by Microsoft, which opens up a dialog box that you have to click and close before proceeding to the mail. That was what was messing things up.

So my question is, is there any way of associating a window handle with a particular program? Is there a call which will tell me that 123456789 is the dialog box and 234567891 is the main window?

Any help appreciated.
User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: Window handles
« Reply #1 on: Nov 24th, 2017, 4:19pm »

Hi Kendall,

Not strictly an answer to your question, which I don't know, but have you re-tried simply generating the body text as a single string and sending that using the method listed in the wiki? Since the advent of BB4W 6 you can have infinite length strings. I've just made one with a body of 633 characters, and it seems to generate the email fine. I don't recommend actually sending it - no idea who Joe Bloggs is, but he probably gets enough random junk...

Best wishes,

D
Code:
      to$="joe_bloggs@gmail.com"
      subject$="Test for emailing from BB4W"
      body$="This is a long message, comfortably above the size limit. To achieve that I'm going to type a load of rubbish, about how exciting everything is at work. "
      body$+=" This may not be strictly accurate, but it does take up space and use more than 256 characters, I should think - or at least it will once I've"
      body$+=" finished typing some more! For example, this is Friday evening, it's after 5pm, and I'm still here because I can't tear myself away from the place. "
      body$+="Well, OK, it's because I know the traffic will be awful, and I might as well stay here playing with BB4W trying this out, rather than "
      body$+="sitting in a traffic jam getting depressed at the news."

      PRINT body$
      PRINT LEN(body$)


      SYS "ShellExecute", 0, 0, "mailto:"+to$+ \
      \                         "?subject="+subject$+ \
      \                         "&body="+body$, 0, 0, 0
 
User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: Window handles
« Reply #2 on: Nov 24th, 2017, 4:48pm »

Trying to answer your original question, how about "GetClassName"? Given a window handle, it returns a string containing the class name. For example this:
Code:
      DIM buffer% 256
      SYS "GetClassName",@hwnd%,buffer%,256  TO t%
      IF t%=0 THEN PRINT"Failed" ELSE PRINT$$buffer% 

returns "BBCProg", which is presumably the custom class created by BB4W for its standard output window.

This page:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633574(v=vs.85).aspx#class_styles

(note this link seems broken, so you'll need to copy and paste, not just click)

lists the standard system classes, and if I read it right suggests the ID for a dialogue box is "#32770", which, hopefully not coincidentally, is what this code returns:
Code:
      INSTALL @lib$+"WINLIB2"
      dlg% = FN_newdialog("Hello world",100,100,400,200,8,256)
      PROC_showdialog(dlg%)
      DIM buffer% 256
      SYS "GetClassName",!dlg%,buffer%,256  TO t%
      IF t%=0 THEN PRINT"Failed" ELSE PRINT$$buffer%
      PROC_closedialog(dlg%) 


That will allow you to check that it isn't (or is) talking to a dialogue box, but I'm not sure that gets you much further forward. I suspect that the "from" box and the "message" box might have the same class (probably "edit"), so it would be hard to check your output was going into the right box, so I suspect my previous answer, of just using a long string sent as the body parameter, might be more robust.

best wishes,

D
User IP Logged

KenDown
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 181
xx Re: Window handles
« Reply #3 on: Nov 24th, 2017, 8:12pm »

I'll have to try it, but my understanding is that it is the mail program which won't accept the longer strings rather than being a limitation with BB4W.

As for the other, gee, I wish I was clever like you! I'll play around with that and see if I can get it working. I'll keep you posted.
User IP Logged

KenDown
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 181
xx Re: Window handles
« Reply #4 on: Nov 24th, 2017, 8:30pm »

Hmmm. GetForegroundWindow returns mailw%. While waiting for the mail client to open up the GetClassName,@hwnd% returns "BBC BASIC" as you state above, but as soon as the client opens and I try

SYS"GetClassName",!mailw%,buffer%,256TOt%

t%=0 and $$buffer% returns a null string.

Am I doing something wrong?
User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: Window handles
« Reply #5 on: Nov 26th, 2017, 3:39pm »

Hi Kendall,

MSDN says GetForegroundWindow returns a handle, so you probably don't need !mailw%, just mailw% itself. Does that work?

best wishes,

D
User IP Logged

KenDown
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 181
xx Re: Window handles
« Reply #6 on: Nov 26th, 2017, 5:18pm »

Sorry, I should have mentioned that I tried both with and without the !

You can see what I'm doing with this code fragment:

DIMbuffer%256
REPEAT
SYS"GetForegroundWindow"TOmailw%
UNTILmailw%<>@hwnd%
VDU7
SYS"GetClassName",mailw%,buffer%,256TOt%
PRINTt%
PRINT$$buffer%

Have a Notepad (or other) window ready on your desktop. Run the above program and then click in the Notepad window, which will set it as the foreground window, so the Notepad handle is not the same as @hwnd% and the program beeps, gets the class name and displays it (or doesn't display it, as the case may be).

Thanks for your help.
User IP Logged

KenDown
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 181
xx Re: Window handles
« Reply #7 on: Nov 26th, 2017, 5:20pm »

However you are correct that the ! is a mistake. If you click in the code window for BB4W instead of Notepad, with the ! the program hangs up and crashes, without the ! it reports BBCWin with t% set to 6 (on my setup).
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls