Page 1 of 1

Posted: Thu Aug 08, 2002 10:45 pm
by BackupUser
Restored from previous forum. Originally posted by Art Sentinel.

Hi, I am just finishing up another tutorial, but suddenly I have smashed into a brick wall. :) [ouch]

It seems that either I am doing something very dumb, or else PB is not handling the pointer I set to an array in the manner I expected. You see, an API function is wanting a pointer to an array of a specific number of elements. (Simple?) However the API call is apparently not accessing that array? Hmm..

Here is my current code (VERY messy right now, I know..)

.

.

;Declare variables
#wID = 66


;Open window
If OpenWindow(0, 150, 150, 300, 300, #PB_Window_SystemMenu, "Read Status Bar API Test")
hWnd = WindowID()

Else
MessageRequester("Ouch", "Damn brick walls! :wink:", 0)

EndIf


;Set up status bar
test$ = "WORK?"
InitCommonControls_()
StatushWnd = CreateStatusWindow_(#WS_VISIBLE | #WS_CHILD, @test$, hWnd, #wID)


;Set up gadgets
If CreateGadgetList(hWnd)
TextGadget(007, 2, 50, 100, 20, "", #PB_Text_Center | #PB_Text_Border)

Else
MessageRequester("", "", 0)

EndIf


;Call SendMessage API
szText$ = Space(12)
SetText$ = "Yahoo!!"

Dim SetParts.w(3)
SetParts(0) = 60
SetParts(1) = 120
SetParts(2) = 180

SendMessage_(StatushWnd, #SB_SETPARTS, 3, @SetParts)
SendMessage_(StatushWnd, #SB_SETTEXT, 0, @SetText$)
SendMessage_(StatushWnd, #SB_GETTEXT, 0, @szText$)
SetGadgetText(007, szText$)


;Main loop
Repeat

Select WaitWindowEvent()

Case #WM_ClOSE
Quit = 1

EndSelect

Until Quit = 1


;Finish up
End

.

.

#SB_SETPARTS is not working the way I expected. The trouble seems to be localized there. Did I make some foolish logic error (or typo)? Or is there something about using pointers to arrays in PB I am not yet familar with? Please help me if you can. Thank you!

Take care.


- Art Sentinel
http://www.artsentinel.net

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

Top Ten Reasons Not To Procrastinate:


Coming Soon...

Posted: Thu Aug 08, 2002 10:57 pm
by BackupUser
Restored from previous forum. Originally posted by freak.

Yes, they are possible. Look at this small test:

Code: Select all

Dim array.l(10)
PokeL(@array(10), 10)
Debug array(10)
You always need to specify the entry of the Array, you want the adress of.
In your case, as you want the pointer to the whole one, just use the pointer
to the first entry.
In you case that is: @SetParts(0)

So the line

Code: Select all

SendMessage_(StatushWnd, #SB_SETPARTS, 3, @SetParts)
should be

Code: Select all

SendMessage_(StatushWnd, #SB_SETPARTS, 3, @SetParts(0))
After that change, everything works just fine.

That's it, hope it helps...

Timo


--
If it stinks, it's chemistry. If it moves, it's biology.
If it does not work, It's computer science.

Posted: Thu Aug 08, 2002 11:03 pm
by BackupUser
Restored from previous forum. Originally posted by freak.

Just a short question:

Is this just a test, or are you working on StatusBar routines for PB?
Well, maybe you haven't noticed, that there is a StatusBar Library in PB.
(So you don't need commands like CreateStatusWindow_() )

Just a thought...

Timo

--
If it stinks, it's chemistry. If it moves, it's biology.
If it does not work, It's computer science.

Posted: Fri Aug 09, 2002 12:09 am
by BackupUser
Restored from previous forum. Originally posted by Art Sentinel.

Thank you for helping, freak. Unfortunately I tried the same method earlier and it still did not work. Did you get it working for you? (You said, "After that change, everything works just fine.")

The status bar should be displaying the three parts I specified--with right edges located at 60, 120, and 180. However it is not doing that. In case you did not already experiment with the array pointer, if you specify another element, (4) for example, it will display the contents of the second part? (Set text for the second part first.) This is odd. It is almost as if the array was supposed to be a multidimensional array, but I do not see that specified in the API docs.

Does anyone have any idea? :)

.

Yes, freak, I am aware of the built in PB statusbar commands. This is for testing purposes, and to offer a greater level of understanding and control. It is not such an advanced technique at all (and just about as easy as using the built in commands); I just have this single hurdle to cross before I gain control of my application again. :wink:

Take Care.


- Art Sentinel
http://www.artsentinel.net


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

Top Ten Reasons Not To Procrastinate:


Coming Soon...

Posted: Fri Aug 09, 2002 12:28 am
by BackupUser
Restored from previous forum. Originally posted by freak.

The pointer part is right, the way i told you. It was just that I didn't realise, what the code should do.

Now, I found another mistake in you code:

Your Array is of WORD type, but it should be LONG.

I don't know, where you get the Information from, but in the Platform SDK, it says "Pointer to an integer array", and by integer, they mean LONG.

So you should change 'Dim SetParts.w(3)' to 'Dim SetParts.l(3)', and than, it does, what you just told me.

Timo

--
If it stinks, it's chemistry. If it moves, it's biology.
If it does not work, It's computer science.

Posted: Fri Aug 09, 2002 12:33 am
by BackupUser
Restored from previous forum. Originally posted by Pupil.
Does anyone have any idea? :)
The WIN API doc says 'integer array' -are you sure this means word type? Try changing the array to long type...:)

Posted: Fri Aug 09, 2002 1:48 am
by BackupUser
Restored from previous forum. Originally posted by Art Sentinel.

Integer means Long.. of course. [sigh]

Hey! I knew that. Really I did! :wink: Haha..

Actually what happened was somewhere between using CreateWindow_() to demonstrate status window control in the API, and finding more efficient uses of the #SB_XXX constants, I changed the .l to .w for a separate (unrelated test). Then I forgot to change it back.

Thank you freak and Pupil for pointing out my error. I sincerely appreciate your help. Did you ever notice the hardest problem to find a solution for oftentimes has the most simple answer? :) I'm glad it was user error on my part and not a short coming in PureBasic.

I will post the next tutorial tomorrow.

Take care, my helpful and quick-eyed friends!


- Art Sentinel
http://www.artsentinel.net


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

Top Ten Reasons Not To Procrastinate:


Coming Soon...