Sending new text to title bar of window

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

I don't know anything about using the API but I know it's possible to send text to gadgets and windows by getting their handle and then using Sendmessage_ (or Postmessage_).

Does anyone know how to use this to send extra text to a window AFTER a window is defined and WITHOUT DESTROYING the title that is already there?



Fangles
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Get the Windows caption with

GetWindowText_(hWnd, lpString, nMaxCount)
> hWnd = Window-Handle
> lpString = text buffer
> nMaxCount = maximum number of chars to copy
hWnd = Window-Handle
> lpString = pointer to the new text


SetWindowText_(hWnd, "Hello World")
works fine for me.

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Hi Fang, the problem must be the Delay(x) command.

try this:

Code: Select all

Procedure ShowGadgets() 
  WindowEvent() : WindowEvent() : WindowEvent()
EndProcedure

and put ShowGadgets() AFTER you create your gadgets, but BEFORE you call Delay(x) the first time.
I had this problem and Mr.Skunk helped me with 2x WindowEvent() and it worked.
Since than I use 3x WindowEvent() (you never know...).
You can play a bit with 1x WindowEvent() than 2x WindowEvent() and so on...
You can see the difference.
Hope this helps



Have a nice day...
Franco
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.
It works Danilo but something strange too. I set a delay into the code so I could see several string appearing in the window, one at a time but...If I had gadgets in my list, they always were drawn after the windows activity, even though the GetWindowText_ and SetWindowText_ were AFTER them.
Hmm, the gadgets aren't redrawn for me -- just the window title changes.
I have Windows 2000 (SP2). The code I tested it with was:

Code: Select all

For a=1 To 5
  a$=Space(255)
  GetWindowText_(WindowID(),a$,999)
  a$=a$+Str(a)
  SetWindowText_(WindowID(),a$)
  Delay(500)
Next

Edited by - PB on 27 December 2001 17:17:35
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.
Hmm, the gadgets aren't redrawn for me ...
PB, have you put in my ShowGadgets() Procedure?
Under Win98 it works this way (didn't test it under WinXP...)



Have a nice day...
Franco
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.
PB, have you put in my ShowGadgets() Procedure?
No, I didn't use your procedure, I only used the code example that I posted,
and it all worked fine (just the title changes, the gadgets do nothing).
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Heya FangBeast !!

Can you show us your code plz ??

PB compiles the code in the order
you write it, so thats not the
problem.

cya,
...Danilo


(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by wayne1.

;simple example just for quick demo

Global flooble
Procedure SetText(handle.l)
While flooble <= 1000
SetWindowText_(handle, Str(flooble))
flooble=flooble+1
Wend
ProcedureReturn
EndProcedure

;--------------------------------------------------------------------------------------------------------------------------
; Setup variable for the gadget items, make it easier to edit in one place, always start from 0
;--------------------------------------------------------------------------------------------------------------------------
#ListIconGadget1 = 1 ; This is the listview box
#GadgetCollumn1 = 1 ; This is the second collumn in the listview box
#GadgetCollumn2 = 1 ; This is the second collumn in the listview box
;--------------------------------------------------------------------------------------------------------------------------
; Set the starting position across and down of the window to be created
;--------------------------------------------------------------------------------------------------------------------------
#WindowXPos = 50 ; Starting from the left of the screen
#WindowYPos = 50 ; Starting from the top of the screen
;--------------------------------------------------------------------------------------------------------------------------
; Set the width and height of the window to be opened
;--------------------------------------------------------------------------------------------------------------------------
#WindowWidth = 450 ; How wide the window is
#WindowHeight = 450 ; How high the window is
;--------------------------------------------------------------------------------------------------------------------------
; What is the window title going to be and all other window and title messages
;--------------------------------------------------------------------------------------------------------------------------
WindowTitle$ = "iFind"
ErrorWindowTitle$ = "Window Open Error"
ErrorWindowText$ = "Cannot open a window to draw objects on, ending program"
ErrorGadgetTitle$ = "Gadget drawing error"
ErrorGadgetText$ = "Cannot draw objects on window, ending program"
;--------------------------------------------------------------------------------------------------------------------------
; How many gadget numbers are we going to reserve here, not how many gadgets there are
;--------------------------------------------------------------------------------------------------------------------------
InitGadget(6) ; Gadget numbers 0 to 6 to reserve
;--------------------------------------------------------------------------------------------------------------------------
; Open a window now from the variables declared earlier
;--------------------------------------------------------------------------------------------------------------------------
hWnd = OpenWindow(0, #WindowXPos, #WindowYPos, #WindowWidth, #WindowHeight, #PB_Window_SystemMenu, WindowTitle$)

If hWnd = 0
MessageRequester(ErrorWindowTitle$, ErrorWindowText$, #PB_MessageRequester_Ok)
End
EndIf

;--------------------------------------------------------------------------------------------------------------------------
; Check to see if the gadget list can be created otherwise end
;--------------------------------------------------------------------------------------------------------------------------
If CreateGadgetList(WindowID()) = 0
MessageRequester(ErrorGadgetTitle$, ErrorGadgetText$, #PB_MessageRequester_Ok)
End
EndIf

;--------------------------------------------------------------------------------------------------------------------------
; Setup the gadgets to be drawn on screen
;--------------------------------------------------------------------------------------------------------------------------
ListIconGadget(#ListIconGadget1, 0, 0, #WindowWidth, #WindowHeight, "BlahBlah", 150)
AddGadgetColumn(#GadgetCollumn1, 0, "Yadda", 150)
AddGadgetColumn(#GadgetCollumn2, 1, "Flooble", 150)

CreateThread(@SetText(), hWnd)

;--------------------------------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------------------------------
; Check for any keys being pressed and branch accordingly or or execute below the case statement
;--------------------------------------------------------------------------------------------------------------------------
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case 1
EndSelect
EndIf
Until EventID = #PB_EventCloseWindow
;-------------------------------------------------------------------------------------------------------------------------



Edited by - wayne1 on 28 December 2001 04:47:47

Edited by - wayne1 on 28 December 2001 05:04:30
Post Reply