BBC BASIC for Windows
General >> General Board >> Accessing the Window's API
http://bb4w.conforums.com/index.cgi?board=general&action=display&num=1284924284

Accessing the Window's API
Post by Matt on Sep 19th, 2010, 7:24pm

Although I'm not new to BBC Basic (I've been dabbling in it for the past 25 years), nor an I that new to BB4W (~3 years) I am just dicovering that there is more to it than just the 'basic' programming. Accessing the Window's API can open a lot of doors. However, I have no idea how to go about learning about it. The MSDN site has some interesting items, but they are written for the expert and are gobbledegook to me. Any suggestions about learing from square one? (I no very little about VB or C++, either.)

Matt
Re: Accessing the Window's API
Post by admin on Sep 19th, 2010, 9:25pm

on Sep 19th, 2010, 7:24pm, Matt wrote:
Accessing the Window's API can open a lot of doors. However, I have no idea how to go about learning about it.

One idea might be to compare BBC BASIC code for accessing the Windows API (you can find plenty in the Help manual, in the example programs and on the BB4W Wiki) with how those same API functions are documented in MSDN and elsewhere. Hopefully you might then be able to see how the C syntax relates to the BASIC syntax, and gradually learn how to convert one to the other.

Another useful resource is Malcolm Marten's Beginners' Windows tutorials which you will find on the group here:

http://groups.yahoo.com/group/bb4w/files/WindowsAPI/Beginners_Windows.htm

http://groups.yahoo.com/group/bb4w/files/WindowsAPI/Beginners_windows_part2.htm

Richard.

Re: Accessing the Window's API
Post by Matt on Sep 20th, 2010, 05:13am

Thanks Richard,

I'll read the articles. The first suggestion, though, for me, is not as easy as it sounds. I've tried this and I just don't seem to be able to understand how to transfer one command into another correctly. But I guess that's just my inexperience. Hopefully, the articles will help.

Matt
Re: Accessing the Window's API
Post by admin on Sep 20th, 2010, 09:31am

on Sep 20th, 2010, 05:13am, Matt wrote:
I've tried this and I just don't seem to be able to understand how to transfer one command into another correctly.

Maybe you could give an example? Here's a call to the very useful MessageBox API, first in C (as you might find it elsewhere) and then in BBC BASIC:

C code:

Code:
      MessageBox (hwnd, "Something didn't work",
            "BB4W", MB_OK | MB_ICONEXCLAMATION) ; 

BBC BASIC code:

Code:
      SYS "MessageBox", @hwnd%, "Something didn't work", \
      \            "BB4W", MB_OK OR MB_ICONEXCLAMATION 

Salient differences are that in C the function parameters are contained in parentheses, and the statement is terminated by a semicolon. In BBC BASIC there isn't an explicit statement terminator, so you have to use continuation characters to split the line.

Also, the 'or' operator in C is | and in BBC BASIC it is OR.

I would like to think that the similarities between the two pieces of code are quite striking. You don't need to be able to program in C, but you do need a passing knowledge of C syntax and what symbols are used for various operations.

Richard.
Re: Accessing the Window's API
Post by Matt on Sep 21st, 2010, 8:14pm

Ok,

I just found something interesting - the Month Calendar Control.

Part of the main program I'm writing uses a calendar to allow the user to set a date. I had to design a dialog sheet to do this, but I really wanted the style used by windows. I suddenly found it. However, I can't work out how to go about using the controls. Could you help, and could you show me how to do it so it will help me to use other controls? Please!

Matt
Re: Accessing the Window's API
Post by admin on Sep 21st, 2010, 9:12pm

on Sep 21st, 2010, 8:14pm, Matt wrote:
I just found something interesting - the Month Calendar Control....
However, I can't work out how to go about using the controls.

I presume you've read the relevant Wiki article:

http://bb4w.wikispaces.com/Using+the+Date+and+Time+Picker

What is it that you need to know that the article doesn't cover?

Richard.

Re: Accessing the Window's API
Post by Matt on Sep 23rd, 2010, 06:30am

Thanks Richard.

This article is very useful and I've managed to implement it into a property sheet. I've also, due to experimenting, found that style 2 creates a check box to deselect the date if needs be. However, I can't seem to find a way of defalting it to deselect. Whatever number I put in there it comes up as selected. How can I choose the default setting of the check box, and how can I change it by program rather than user.

Matt
Re: Accessing the Window's API
Post by admin on Sep 23rd, 2010, 08:33am

on Sep 23rd, 2010, 06:30am, Matt wrote:
How can I choose the default setting of the check box, and how can I change it by program rather than user.

MSDN is your friend! All is revealed on this page:

http://msdn.microsoft.com/en-us/library/bb761728.aspx

The salient text is: "The state of the check box can be set with the DTM_SETSYSTEMTIME message or queried with the DTM_GETSYSTEMTIME message".

It doesn't seem to be possible to initialise the control to the 'unchecked' state but if you send the appropriate message immediately after the control is created the effect should be indistinguishable.

Richard.
Re: Accessing the Window's API
Post by Matt on Sep 24th, 2010, 06:20am

Thanks Richard,

I've played around with this and I seem to be getting the hang of some of it - albeit slowly. I can deselect, change the date and the format. So I think I can use this, thanks. One thing I don't like about the date format is, when using the full date format (i.e. dd mmmm yyyy) the month, when short (say May) has massive gaps between the day and the year. And there doesn't seem to be a way of having the date format as dd mmm yyyy (i.e. three letter months). Hey Ho. Not a big problem.

Thanks all the same.

Matt
Re: Accessing the Window's API
Post by admin on Sep 24th, 2010, 08:37am

on Sep 24th, 2010, 06:20am, Matt wrote:
And there doesn't seem to be a way of having the date format as dd mmm yyyy (i.e. three letter months).

Huh? It works fine for me, so long as I use the correct format: "dd MMM yyyy" (lowercase mm is minutes, not months!).

It is rare for MSDN to be incorrect, so if you find something doesn't work you should suspect your own code rather than blaming an imagined shortcoming in Windows.

Richard.
Re: Accessing the Window's API
Post by Matt on Sep 28th, 2010, 09:47am

I'm sorry Richard, but I can't figure out how to change the time to "dd MMM yyyy". All I gan get is "dd/MM/yyyy" or "dd MMMM yyyy" by changing the style% in

ICC_DATE_CLASSES = &100
DIM iccx{Size%, ICC%}
iccx.Size% = 8
iccx.ICC% = ICC_DATE_CLASSES
SYS "InitCommonControlsEx", iccx{}
hdtp% = FN_createwindow("SysDateTimePick32", "", x%, y%, cx%, cy%, 0, style%, 0)


Matt
Re: Accessing the Window's API
Post by admin on Sep 28th, 2010, 6:07pm

on Sep 28th, 2010, 09:47am, Matt wrote:
I'm sorry Richard, but I can't figure out how to change the time to "dd MMM yyyy".

I'm surprised you weren't able to find it on MSDN:

http://msdn.microsoft.com/en-us/library/bb761771.aspx

Starting at the main Date and Time Picker page you've only got to scroll about half way down, where it says "Sets the display of a date and time picker (DTP) control based on a given format string":

http://msdn.microsoft.com/en-us/library/bb761727.aspx

Perhaps you need to hone your search technique.

Richard.
Re: Accessing the Window's API
Post by Matt on Sep 28th, 2010, 8:48pm

Thanks, Richard.

It's not search technique that's the problem with me, it's understanding of the system. I'm slowly picking it up, but 'slowly' is the operative word. I did look at this API message, but I didn't understand it enough to realise it was the one I was after. My appologies for being so slow, and thanks again.

Matt
Re: Accessing the Window's API
Post by Matt on Oct 3rd, 2010, 5:18pm

Hi,

I'm trying to teach myself understanding the API. But I can't find the constant value for DTM_GETDATETIMEPICKERINFO. I've tried everywhere on the net and with the API Viewer, but nothing.

Any idea?

Matt
Re: Accessing the Window's API
Post by admin on Oct 3rd, 2010, 9:28pm

on Oct 3rd, 2010, 5:18pm, Matt wrote:
I can't find the constant value for DTM_GETDATETIMEPICKERINFO

The reason you're having trouble finding it is that it's a Vista (and later) only message. Therefore it's not something you can use in a program which needs to run on, for example, Windows XP.

If you don't mind your program being specific to Windows Vista and Windows 7, the value is as follows:

Code:
DTM_GETDATETIMEPICKERINFO = &100E 

Richard.
Re: Accessing the Window's API
Post by Matt on Oct 4th, 2010, 06:17am

Ah, that would explain my problem. Thanks.

One of the things I was trying to do with this was to find out if the DateTime checkbox that I've got on a Propsheet is checked or not. I can't seem to find another constant that would allow me to do this. Am I, again, just missing something obvious?

Matt
Re: Accessing the Window's API
Post by admin on Oct 4th, 2010, 11:01am

on Oct 4th, 2010, 06:17am, Matt wrote:
One of the things I was trying to do with this was to find out if the DateTime checkbox that I've got on a Propsheet is checked or not. Am I, again, just missing something obvious?

I don't know whether it is "obvious", but it is there! If you look at the docs for the DTM_GETSYSTEMTIME message you will find this:

Returns GDT_VALID if the time information was successfully placed in lpSysTime. Returns GDT_NONE if the control was set to the DTS_SHOWNONE style and the control check box was not selected:

http://msdn.microsoft.com/en-us/library/bb761769.aspx

So to determine whether the checkbox was selected or not, simply query the date/time in the normal way and test the value returned from SendMessage. If the checkbox was selected you will get GDT_VALID (0) , if it wasn't you will get GDT_NONE (1).

Richard.
Re: Accessing the Window's API
Post by Matt on Oct 4th, 2010, 7:52pm

Thanks Richard.

Just tried it and it works fine. Although it seems to me that the result is the wrong way round as zero is normally considered as false, but that's splitting hairs.

Thanks again.

Matt
Re: Accessing the Window's API
Post by admin on Oct 4th, 2010, 9:41pm

on Oct 4th, 2010, 7:52pm, Matt wrote:
it seems to me that the result is the wrong way round

It makes perfect sense if you consider the returned value to be an error code. GDT_VALID (0) indicates success (the checkbox was selected, so a valid date/time was returned) and GDT_NONE (1) indicates failure (the checkbox was not selected, so there is no date/time to return). The other value that can be returned is GDT_ERROR (-1) which indicates that some other error occurred.

Richard.

Re: Accessing the Window's API
Post by Matt on Oct 5th, 2010, 04:52am

I stand corrected. Now you explain it, it does make sence. Thanks.
Re: Accessing the Window's API
Post by Matt on Oct 9th, 2010, 8:32pm

Hi,

I've managed to get access to a line's info on a List View by single clicking and getting the index, then clicking another button to get the record. But I can't figure out how to access it by double clicking using a List View control. Is there one, or will I just have to use a seperate button?

Matt
Re: Accessing the Window's API
Post by admin on Oct 10th, 2010, 09:24am

on Oct 9th, 2010, 8:32pm, Matt wrote:
But I can't figure out how to access it by double clicking using a List View control. Is there one, or will I just have to use a seperate button?

If you've ever used the Search BASIC Programs add-in utility you'll know that double-clicking in a List View is supported (in that utility you double-click on a program name to display it in a new instantiation of the IDE).

Unfortunately the double-click notification is sent in the form of a WM_NOTIFY message and the only reliable way to intercept that in BB4W is using assembler code (although WM_NOTIFY is one of the messages you can intercept using *SYS 1, the data it carries is volatile and typically no longer valid by the time you get to see it).

This contrasts with a regular List Box control, which passes the double-click notification as a WM_COMMAND message that you can reliably intercept using ON SYS (and, no, I have no idea why they work differently).

So if you want to handle the double-click notification from a List View it's a case of incorporating some assembler code, even if you don't know how it works! If so let me know and I'll write it up in a Wiki article.

Richard.

Re: Accessing the Window's API
Post by Matt on Oct 10th, 2010, 6:42pm

Hi Richard,

I'm using the assember and other parts from the program 'DIRdetails.bbc' (Can't remember where I got it.) These are the main parts.

WHEN WM_NOTIFY :
IF sortcount%>-1 THEN
IF click%(1) = sortcol% THEN
direction% *= -1
C% = sortcount%+1
CALL indexsort%((direction%+1)/2), sort$(0,0), sort$(1,0)
sortcol% = click%(1)
ELSE
direction% = 1
sortcol% = click%(1)
PROC_SORT
ENDIF
relist% = TRUE
ENDIF


FOR pass% = 8 TO 10 STEP 2
P% = code
[OPT pass%
.oldwndproc
dd 0
:
.hdn_itemclick
mov eax,[eax+12]
mov [esp+16],eax
mov dword [esp+8],WM_COMMAND
mov dword [esp+12],WM_NOTIFY
jmp [oldwndproc]
:
.wm_notify
mov eax,[esp+16]
cmp dword [eax+8],HDN_ITEMCLICKA
jz hdn_itemclick
jmp [oldwndproc]
:
.newwndproc
cmp dword [esp+8],WM_NOTIFY
jz wm_notify
jmp [oldwndproc]
]
NEXT pass%


But this only seems to check for clicking on the column header. To check for the item I'm using,

SYS "SendMessage", hlist%, LVM_GETNEXTITEM, -1, LVNI_SELECTED TO index%

This gives a constant running value, so I can't even time a double click.

Are these the types of codings that you are referring to?

Matt
Re: Accessing the Window's API
Post by admin on Oct 10th, 2010, 9:38pm

on Oct 10th, 2010, 6:42pm, Matt wrote:
I'm using the assember and other parts from the program 'DIRdetails.bbc'.... But this only seems to check for clicking on the column header.

Since you're already using assembler code to handle the HDN_ITEMCLICKA notification you can add to that code to handle the NM_DBLCLK notification as well. The HDN_ITEMCLICKA gets converted by the assembler code to a WM_COMMAND message (which can easily be processed using ON SYS) so it would make sense to do just the same for the NM_DBLCLK notification.

As only one notification is intercepted by the existing code it isn't necessary to indicate which notification it was. Obviously once you're handling both HDN_ITEMCLICKA and NM_DBLCLK notifications you'll have to pass more information to your ON SYS handler; You could for example pass the notification code as the @lparam% parameter (currently unused), although it might be more consistent with the way List Boxes and other simple controls work to pass it in the high 16-bits of @wparam%.

Richard.
Re: Accessing the Window's API
Post by Michael Hutton on Oct 12th, 2010, 12:11pm

Although not entirely relevant you may find this article useful when intercepting windows messages in assembler, especially those pesky WM_NOTIFY messages.

http://bb4w.wikispaces.com/Colour+text+in+a+List+View

It is, I admit, rather effusive and probably more confusing than helpful as I wrote it a while back but it may help. I would be interested in your comments!

Michael Hutton