1. RE: API curiosity

Wolf,

Curious I could not reproduce the problem using this Win32Lib example.
-------------------
include win32lib.ew

atom normal,working,void
normal=allocate_string("Normal Title")
working=allocate_string("Working Title")

constant
   Win=create(Window,peek_string(normal),0,Default,Default,200,100,0),
   Btn1=create(PushButton,"normal",Win,20,20,50,30,0),
   Btn2=create(PushButton,"working",Win,100,20,50,30,0)

procedure onClick_Btn1()
   atom hwnd
   hwnd = getHandle(Win)
   void=w32Func(xSetWindowText,{hwnd,normal})
end procedure
onClick[Btn1] = routine_id( "onClick_Btn1" )

procedure onClick_Btn2()
   atom hwnd
   hwnd = getHandle(Win)
   void=w32Func(xSetWindowText,{hwnd,working})
end procedure
onClick[Btn2] = routine_id( "onClick_Btn2" )

procedure onClose_Win()
   free(normal)
   free(working)
end procedure
onClose[Win] = routine_id( "onClose_Win" )

WinMain(Win,Normal)
-------------------

Perhaps you could send me your example?
-- Brian

Wolf wrote:
> I found this so strange... thought I'd mention it.
> In writing a little proggy using only API, I declared two atoms for the 
> window's titles as follows:
> atom normal, working
> normal=allocate_string("Normal Title")
> working=allocate_string("Working Title")
> 
> The pointer to 'normal' was obviously used in CreateWindowEx(), to set 
> the window's title.
> 
> ... and in my 'event handler', I had the following simple code:
>         void=c_func(xSetWindowText,{hwnd,working})
>         do_some_stuff()
>         void=c_func(xSetWindowText,{hwnd,normal})
> 
> I was quite surprised that this wouldn't work, because once the title 
> had been changed by the first xSetWindowText(),
> the memory pointed to by 'normal' no longer contained the 'literal' 
> string "Normal Title".
> So much for re-useability...
> ... just guessing by the gibberish contained in the title bar, it may 
> even be a pointer ?
> If this is the case, how many other seemingly simple API functions do 
> weird things like this ?
> 
>

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu