|
-
Nov 8th, 2002, 10:33 PM
#1
Thread Starter
Fanatic Member
Will CreateWindowEx's window self-destroyed if thread is quitted?
I s'ppose yes, but my problem ain't this only.
I've a module, in the Sub Main, I created a window using
CreateWindowEx, then I'll go into a infinite loop to Translate this
window's messages.
But now I just want to SetTimer to ask Window to call back
this message Translator procedure, which I dont have to go into
a loop and can go on with my codes. So it's kinda like Multi-
Threading.
This might not be a problem, but until I want to make it a DLL,
which there'll be a sub(SubCreate) which'll create a window and
then exit sub. In this sub of course I'll also SetTimer to call
back the msg Translator. Otherwise SubCreate will've to loop
4ever to Translate msg and can't exit.(Bear in mind this's a class
object, if this sub can't exit that'll sort of spoil the concept of class)
So, ok, now I SetTimer in SubCreate and exit, will the
window I created be destroyed since I exit the sub? Because
I've tried it in a module which after exitting Sub Main the window
destroys itself.
So, I was thinking, will the window destroys itself after exitting a
sub which created it or after the thread is quitted?(In this case,
the thread is my DLL)
Thanks a lot. Pls reply I'll explain more of my problem if u still dont
understand.
ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
Programming is fun, but only if you're not on a tight deadline 
So I consider all those working engineers sad people
VB FTP class
3 page PHP crash course
Crash Course on DX9 Managed with VB.NET covering basics till terrain creation
-
Nov 8th, 2002, 10:52 PM
#2
I'm not 100% sure I have fully understood your question but here goes: The window will not be destroyed when the sub that has created it ends. If so you wouldn't be able to create a window since you have to do it in some procedure....
However you should always explicitly destroy all the windows you have created.
In your post you don't mention what kind of window you create but I guess that isn't importent. However you say you use SetTimer which requires a callback procedure. This can cause an other problems with an ActiveX DLL. Since callback procedures must reside in a regular module in VB.
The code that resides in modules will be shared by all instances of your objects. So even though the class code will be recreated for each object they all share the same module code. You will need to add code so you know which instance the callback is dealing with.
-
Nov 8th, 2002, 11:12 PM
#3
Thread Starter
Fanatic Member
Yea Joacim, u understand almost my problem 
Yes about that callback function problem u mentioned I've
thought 'bout that long b4 and already have a solution for that.
For every instances of the class module which requires to callback,
I'll create a unique event ID using the CreateEvent api.
Everytime I need to callback I just have to issue the SetEvent
and the callback function will just've 2 WaitForMultipleObjects.
OK, now I know that the window(a form) will be destroyed only if
the thread exits.
Now I'm putting this in a class module. So if the user initiates my
class by Set ClsWnd = New ClassWindow then calling a
sub of ClsWnd which creates the window and then exit sub.
Will this class's thread quits and only reinvoked when I call it's
procedure?
Or the class's thread will remain from when I Set it as New until
I Set it as Nothing?
ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
Programming is fun, but only if you're not on a tight deadline 
So I consider all those working engineers sad people
VB FTP class
3 page PHP crash course
Crash Course on DX9 Managed with VB.NET covering basics till terrain creation
-
Nov 9th, 2002, 12:59 AM
#4
That depends on where the ClsWnd object is declared. If it's declared in the same procedure that's creates the object (using the New keyword) it will go out of scope when that procedure is ended (the procedure that declared the object). However if it's declared as Private or Public it will persist until it's set to Nothing or if it's declared in a Form until that Form is destroyed.
However in any case you should use the Class_Terminate event to destroy the window you have created.
Cheers,
-
Nov 9th, 2002, 09:23 AM
#5
Thread Starter
Fanatic Member
Thx Joacim, u've enlighten me 
OK, now got another problem, After creating the window, I want
to programmatically close it. I've use various methods like
PostMessage,SendMessage including DefWindowProc with the
message WM_DESTROY or WM_CLOSE. But it never close until
another msg or event occurs, i.e I move my mouse over the form.
Really donno where's da prob...
ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
Programming is fun, but only if you're not on a tight deadline 
So I consider all those working engineers sad people
VB FTP class
3 page PHP crash course
Crash Course on DX9 Managed with VB.NET covering basics till terrain creation
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|