473,382 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Closing down a hierarchy of modal windows nicely

Im sorry, I dont know the correct description for a hierarchy of parent and
child forms.
I have a main form that opens a child form modally. This child form in turn
opens it's own child form modally.
I also have a separate thread running that monitors a card reader. If the
user removes the card then the thread calls back the main form to tell it
that the card was pulled. The main form should then close down any children
leaving the main form as the only one that's open.
How do i do this cleanly and with as little code as possible please? I'd
prefer not to have to add code to all the forms if possible.
I thought that if I closed the "child" form from the main form, that this
"child" would kill its own "children". This isnt happening. Neither the
"child" or its "children" are closing.
When i used to code in delphi, the owner would always be passed to a child
when the child was constructed, and the child would add itself to its owners
Controls list. I assume this isnt happening here
I also tried changing the constructor for every form so that each form would
add itself to it's owners OwnedForm list. This also didnt work and was very
messy.

thank you

Nov 21 '06 #1
23 2692
Hi,

When you call the Show method pass in a reference to the owning form (it
will set the Form.Owner property):

Form form = new Form();
form.Show(this);

I've used "this" because I'm assuming that the code above will be executing
within the context of a Form. e.g., an event handler. If not, you'll have
to pass in a reference to the main Form.

--
Dave Sexton

"Chukkalove" <so*****@microsoft.comwrote in message
news:ug**************@TK2MSFTNGP03.phx.gbl...
Im sorry, I dont know the correct description for a hierarchy of parent
and child forms.
I have a main form that opens a child form modally. This child form in
turn opens it's own child form modally.
I also have a separate thread running that monitors a card reader. If the
user removes the card then the thread calls back the main form to tell it
that the card was pulled. The main form should then close down any
children leaving the main form as the only one that's open.
How do i do this cleanly and with as little code as possible please? I'd
prefer not to have to add code to all the forms if possible.
I thought that if I closed the "child" form from the main form, that this
"child" would kill its own "children". This isnt happening. Neither the
"child" or its "children" are closing.
When i used to code in delphi, the owner would always be passed to a child
when the child was constructed, and the child would add itself to its
owners Controls list. I assume this isnt happening here
I also tried changing the constructor for every form so that each form
would add itself to it's owners OwnedForm list. This also didnt work and
was very messy.

thank you

Nov 21 '06 #2
Hi,

Sorry, but I didn't realize that you wrote, "modal".

Instead of calling Show(this) call ShowDialog(this).

To close all modal Forms in a chain, each Form must save a reference to the
sub-modal Form that it's showing. Then add the following code to each Form:

protected override void OnClosing(CancelEventArgs e)
{
if (subModalForm != null)
// close the modal Form being shown by this Form
subModalForm.Close();

base.OnClosing(e);
}

To start the chain-reaction and close all open modal dialogs, call Close()
on the first Form.

--
Dave Sexton

"Chukkalove" <so*****@microsoft.comwrote in message
news:ug**************@TK2MSFTNGP03.phx.gbl...
Im sorry, I dont know the correct description for a hierarchy of parent
and child forms.
I have a main form that opens a child form modally. This child form in
turn opens it's own child form modally.
I also have a separate thread running that monitors a card reader. If the
user removes the card then the thread calls back the main form to tell it
that the card was pulled. The main form should then close down any
children leaving the main form as the only one that's open.
How do i do this cleanly and with as little code as possible please? I'd
prefer not to have to add code to all the forms if possible.
I thought that if I closed the "child" form from the main form, that this
"child" would kill its own "children". This isnt happening. Neither the
"child" or its "children" are closing.
When i used to code in delphi, the owner would always be passed to a child
when the child was constructed, and the child would add itself to its
owners Controls list. I assume this isnt happening here
I also tried changing the constructor for every form so that each form
would add itself to it's owners OwnedForm list. This also didnt work and
was very messy.

thank you

Nov 21 '06 #3
Hi,

I don't think you need to have a reference to subModalForm and you
don't have to call close() on it. When you are using ShowDiaglog(this),
a close() on the first window will do; the children will be closed (and
all their events will be triggered). Or am i missing something?

On Nov 21, 9:07 pm, "Dave Sexton" <dave@jwa[remove.this]online.com>
wrote:
Hi,

Sorry, but I didn't realize that you wrote, "modal".

Instead of calling Show(this) call ShowDialog(this).

To close all modal Forms in a chain, each Form must save a reference to the
sub-modal Form that it's showing. Then add the following code to each Form:

protected override void OnClosing(CancelEventArgs e)
{
if (subModalForm != null)
// close the modal Form being shown by this Form
subModalForm.Close();

base.OnClosing(e);

}To start the chain-reaction and close all open modal dialogs, call Close()
on the first Form.

--
Dave Sexton

"Chukkalove" <some...@microsoft.comwrote in messagenews:ug**************@TK2MSFTNGP03.phx.gbl. ..
Im sorry, I dont know the correct description for a hierarchy of parent
and child forms.
I have a main form that opens a child form modally. This child form in
turn opens it's own child form modally.
I also have a separate thread running that monitors a card reader. If the
user removes the card then the thread calls back the main form to tell it
that the card was pulled. The main form should then close down any
children leaving the main form as the only one that's open.
How do i do this cleanly and with as little code as possible please? I'd
prefer not to have to add code to all the forms if possible.
I thought that if I closed the "child" form from the main form, that this
"child" would kill its own "children". This isnt happening. Neither the
"child" or its "children" are closing.
When i used to code in delphi, the owner would always be passed to a child
when the child was constructed, and the child would add itself to its
owners Controls list. I assume this isnt happening here
I also tried changing the constructor for every form so that each form
would add itself to it's owners OwnedForm list. This also didnt work and
was very messy.
thank you
Nov 21 '06 #4
Hi Marc,

That doesn't work for modal dialogs.

--
Dave Sexton

"Marc Vangrieken" <ma*************@gmail.comwrote in message
news:11**********************@h54g2000cwb.googlegr oups.com...
Hi,

I don't think you need to have a reference to subModalForm and you
don't have to call close() on it. When you are using ShowDiaglog(this),
a close() on the first window will do; the children will be closed (and
all their events will be triggered). Or am i missing something?

On Nov 21, 9:07 pm, "Dave Sexton" <dave@jwa[remove.this]online.com>
wrote:
>Hi,

Sorry, but I didn't realize that you wrote, "modal".

Instead of calling Show(this) call ShowDialog(this).

To close all modal Forms in a chain, each Form must save a reference to
the
sub-modal Form that it's showing. Then add the following code to each
Form:

protected override void OnClosing(CancelEventArgs e)
{
if (subModalForm != null)
// close the modal Form being shown by this Form
subModalForm.Close();

base.OnClosing(e);

}To start the chain-reaction and close all open modal dialogs, call
Close()
on the first Form.

--
Dave Sexton

"Chukkalove" <some...@microsoft.comwrote in
messagenews:ug**************@TK2MSFTNGP03.phx.gbl ...
Im sorry, I dont know the correct description for a hierarchy of parent
and child forms.
I have a main form that opens a child form modally. This child form in
turn opens it's own child form modally.
I also have a separate thread running that monitors a card reader. If
the
user removes the card then the thread calls back the main form to tell
it
that the card was pulled. The main form should then close down any
children leaving the main form as the only one that's open.
How do i do this cleanly and with as little code as possible please?
I'd
prefer not to have to add code to all the forms if possible.
I thought that if I closed the "child" form from the main form, that
this
"child" would kill its own "children". This isnt happening. Neither the
"child" or its "children" are closing.
When i used to code in delphi, the owner would always be passed to a
child
when the child was constructed, and the child would add itself to its
owners Controls list. I assume this isnt happening here
I also tried changing the constructor for every form so that each form
would add itself to it's owners OwnedForm list. This also didnt work
and
was very messy.
thank you

Nov 21 '06 #5
"Chukkalove" <so*****@microsoft.comwrote in message
news:ug**************@TK2MSFTNGP03.phx.gbl...
Im sorry, I dont know the correct description for a hierarchy of parent
and child forms.
I have a main form that opens a child form modally. This child form in
turn opens it's own child form modally.
I also have a separate thread running that monitors a card reader.
Out of curiosity does this poll the drive to see if the media has been
removed or is there some API call for this? See my reply to Dave for closing
the forms.

Michael
Nov 22 '06 #6
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:uy**************@TK2MSFTNGP02.phx.gbl...
Hi Marc,

That doesn't work for modal dialogs.
But you can do something like this:

public void ClosePopups()
{
Form form = FindTopOwner(this);
if(form == null) return;
do
{
form.Close();
form = form.Owner;
if(form == null || form == this) return;
} while(true);
}

private Form FindTopOwner(Form TopForm)
{
Form ownedForm = TopForm;
do
{
if(ownedForm.OwnedForms.Length 0)
{
ownedForm = ownedForm.OwnedForms[0];
}
else
{
if(ownedForm != TopForm) return ownedForm;
return null;
}
}while(true);
}

Michael
Nov 22 '06 #7
Hi Michael,

Well, the OP did specify, "How do i do this cleanly and with as little code
as possible please"; I think my solution falls into that category :)

--
Dave Sexton

"Michael C" <no****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:uy**************@TK2MSFTNGP02.phx.gbl...
>Hi Marc,

That doesn't work for modal dialogs.

But you can do something like this:

public void ClosePopups()
{
Form form = FindTopOwner(this);
if(form == null) return;
do
{
form.Close();
form = form.Owner;
if(form == null || form == this) return;
} while(true);
}

private Form FindTopOwner(Form TopForm)
{
Form ownedForm = TopForm;
do
{
if(ownedForm.OwnedForms.Length 0)
{
ownedForm = ownedForm.OwnedForms[0];
}
else
{
if(ownedForm != TopForm) return ownedForm;
return null;
}
}while(true);
}

Michael

Nov 22 '06 #8
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:e0**************@TK2MSFTNGP04.phx.gbl...
Hi Michael,

Well, the OP did specify, "How do i do this cleanly and with as little
code as possible please"; I think my solution falls into that category :)
Not really. The OP did specify that the solution should involve modifying
the popup forms as little as possible. Because you're really duplicating
what's built into windows there's also good potential to introduce bugs.

Michael
Nov 22 '06 #9
Hi Michael,
>Well, the OP did specify, "How do i do this cleanly and with as little
code as possible please"; I think my solution falls into that category :)

Not really. The OP did specify that the solution should involve modifying
the popup forms as little as possible. Because you're really duplicating
what's built into windows there's also good potential to introduce bugs.
I'm aware of what the OP wanted, but my solution is very simple and it
certainly isn't "duplicating what's built into windows". Also, it works, so
I'm not sure what type of potential bugs you're considering.

The fact that it requires touching each Form might be too complicated for
the OP, so I'm not going to make any assumptions as to whether the solution
is satisfactory (and I wasn't trying to imply that in my last post either,
if that's what you assumed - note the light-hearted smiley. : ) : )

--
Dave Sexton
Nov 22 '06 #10
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
I'm aware of what the OP wanted, but my solution is very simple
The simplicity wasn't the issue, more having to modify every form was what I
was commenting on.
and it certainly isn't "duplicating what's built into windows".
Somewhere in windows (or maybe the framework?) each window can store a
reference to an owner form. You are storing a reference to an owner form.
Also, it works, so I'm not sure what type of potential bugs you're
considering.
The same code needs to be duplicated in every form so there is good
potential for an error.
The fact that it requires touching each Form might be too complicated for
the OP, so I'm not going to make any assumptions as to whether the
solution is satisfactory (and I wasn't trying to imply that in my last
post either, if that's what you assumed - note the light-hearted smiley.
: ) : )
I wouldn't use the words "too complicated". I would say that a simpler, more
generic, solution exists so why not use it? My solution was really derived
from posts by Marc and you and is just a more generic version of what you
wrote anyway.

Michael
Nov 22 '06 #11
Hi Michael,

<snip>
>and it certainly isn't "duplicating what's built into windows".

Somewhere in windows (or maybe the framework?) each window can store a
reference to an owner form. You are storing a reference to an owner form.
The Form class has an Owner property. When the Form is a child to another
Form, the Owner property is set, but in the context of "Owner" code, the
simplest way to find that child Form, which needs to be closed, is to assign
the reference to a field when the child is constructed. There is no
"duplication".
>Also, it works, so I'm not sure what type of potential bugs you're
considering.

The same code needs to be duplicated in every form so there is good
potential for an error.
Given that we're talking about copying only four substantial lines of code,
I don't see any room for error. But if you're worried that the OP might
somehow forget to copy the code to one of the Forms, then inheritance could
fix that if the OP's willing.
>The fact that it requires touching each Form might be too complicated for
the OP, so I'm not going to make any assumptions as to whether the
solution is satisfactory (and I wasn't trying to imply that in my last
post either, if that's what you assumed - note the light-hearted smiley.
: ) : )

I wouldn't use the words "too complicated". I would say that a simpler,
more generic, solution exists so why not use it?
Did I imply that the OP shouldn't?

I think the OP should choose whichever is more appropriate. At this point,
why make any assumptions about requirements that we don't know?

And I don't think your code is simpler at all, BTW. I've glanced at it
twice and I have no idea what it's doing - I'm just assuming that it works
:)
My solution was really derived from posts by Marc and you and is just a
more generic version of what you wrote anyway.
Marc was completely off (no offense Marc :), and I don't see how our
solutions are even close.

My solution is based on the fact that a modal dialog will "buffer" the
FormClosed event until all other owned modals are closed first - that's how
modal Forms behave. So, my code closes the one and only known child modal
(via a field reference) when the Owner itself is being closed, and the
FormClosed events for each modal are raised in a chain-reaction from
top-most to first. It's quite simple, really.

--
Dave Sexton
Nov 22 '06 #12
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:uX**************@TK2MSFTNGP02.phx.gbl...
The Form class has an Owner property. When the Form is a child to another
Form, the Owner property is set, but in the context of "Owner" code, the
simplest way to find that child Form, which needs to be closed, is to
assign the reference to a field when the child is constructed. There is
no "duplication".
I'm not really sure how you consider that not a duplication. You are storing
in a variable that mirrors what the form stores already. The reference is in
2 places. That is a duplication.
Given that we're talking about copying only four substantial lines of
code, I don't see any room for error. But if you're worried that the OP
might somehow forget to copy the code to one of the Forms, then
inheritance could fix that if the OP's willing.
There's always room for error. :-)
Did I imply that the OP shouldn't?
Yes.
And I don't think your code is simpler at all, BTW. I've glanced at it
twice and I have no idea what it's doing - I'm just assuming that it works
:)
It is one-off code that can be placed in 1 place in the app. It is more
complex than yours but once it's done it doesn't need to be duplicated in
potentially hundreds of locations. If you're really concerned about the
complexity of mine, the number of lines could easily be reduced.
Marc was completely off (no offense Marc :), and I don't see how our
solutions are even close.
Yours closes each form in many locations, mine does the same thing from one
location. Yours uses a member variable where mine uses the owner property.
My solution is based on the fact that a modal dialog will "buffer" the
FormClosed event until all other owned modals are closed first - that's
how modal Forms behave. So, my code closes the one and only known child
modal (via a field reference) when the Owner itself is being closed, and
the FormClosed events for each modal are raised in a chain-reaction from
top-most to first. It's quite simple, really.
I know how yours works, I used it to write a more generic solution. :-)

Michael
Nov 22 '06 #13
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:uX**************@TK2MSFTNGP02.phx.gbl...
And I don't think your code is simpler at all, BTW. I've glanced at it
twice and I have no idea what it's doing - I'm just assuming that it works
:)
Here's a simplified version of mine. This required 4 lines of code in one
location in the app and does not require code in each form.

private void CloseChildForms(Form ParentForm)
{
foreach(Form form in ParentForm.OwnedForms)
{
CloseChildForms(form);
form.Close();
}
}

Michael
Nov 22 '06 #14
Hi Michael,
>The Form class has an Owner property. When the Form is a child to
another Form, the Owner property is set, but in the context of "Owner"
code, the simplest way to find that child Form, which needs to be closed,
is to assign the reference to a field when the child is constructed.
There is no "duplication".

I'm not really sure how you consider that not a duplication. You are
storing in a variable that mirrors what the form stores already. The
reference is in 2 places. That is a duplication.
Yes, the variable stores a reference to a child Form which can be found also
by iterating over a collection supplied by the Form itself. You're thinking
much more dynamically about this than I. There is no duplication in storing
a reference that you've already created, which is how I see it:

private Form theReference;
....
theReference = new Form();
theReference.ShowDialog(this);
....
theReference.Close();

No duplication here, from my POV, since the reference was created anyway.
If the OP indicates that each Form may have multiple children then your
solution will probably be better, but that definitely wasn't the case, so
having a "collection" of child Forms vs. a single, known reference are two
very different things - not "duplication".

<snip>
>Did I imply that the OP shouldn't?

Yes.
That's 100% your interpretation because that was not my intention at all.
>And I don't think your code is simpler at all, BTW. I've glanced at it
twice and I have no idea what it's doing - I'm just assuming that it
works :)

It is one-off code that can be placed in 1 place in the app. It is more
complex than yours but once it's done it doesn't need to be duplicated in
potentially hundreds of locations. If you're really concerned about the
complexity of mine, the number of lines could easily be reduced.
I was never really concerned at all with your code or its level of
complexity. I've always felt that the OP should choose the best solution,
which may very well have been yours.

But assuming hundreds of modal Forms isn't very realistic. The OP never
said how many modals there are. And since your assuming things, how about
if each of the modals all derive from a common ancestor? In that case my
solution would work quite nicely and probably would be more appropriate than
yours.

And I still don't think either of our solutions even deserve all this
attention :)
>Marc was completely off (no offense Marc :), and I don't see how our
solutions are even close.

Yours closes each form in many locations, mine does the same thing from
one location. Yours uses a member variable where mine uses the owner
property.
They're completely different :)
>My solution is based on the fact that a modal dialog will "buffer" the
FormClosed event until all other owned modals are closed first - that's
how modal Forms behave. So, my code closes the one and only known child
modal (via a field reference) when the Owner itself is being closed, and
the FormClosed events for each modal are raised in a chain-reaction from
top-most to first. It's quite simple, really.

I know how yours works, I used it to write a more generic solution. :-)
The revised code in your adjacent post is much clearer. I'm not sure how my
solution helped you to write it, but if it works - great :)

--
Dave Sexton
Nov 22 '06 #15
Hi Michael,

The recursion is much nicer. I assume that the OP will probably find this
code to be more suitable.

--
Dave Sexton

"Michael C" <no****@nospam.comwrote in message
news:Oa**************@TK2MSFTNGP03.phx.gbl...
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:uX**************@TK2MSFTNGP02.phx.gbl...
>And I don't think your code is simpler at all, BTW. I've glanced at it
twice and I have no idea what it's doing - I'm just assuming that it
works :)

Here's a simplified version of mine. This required 4 lines of code in one
location in the app and does not require code in each form.

private void CloseChildForms(Form ParentForm)
{
foreach(Form form in ParentForm.OwnedForms)
{
CloseChildForms(form);
form.Close();
}
}

Michael

Nov 22 '06 #16
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:uc**************@TK2MSFTNGP03.phx.gbl...
Yes, the variable stores a reference to a child Form which can be found
also by iterating over a collection supplied by the Form itself. You're
thinking much more dynamically about this than I. There is no duplication
in storing a reference that you've already created, which is how I see it:

private Form theReference;
...
theReference = new Form();
theReference.ShowDialog(this);
...
theReference.Close();
I disagree, there are 2 reference to the same thing, hence duplication.
That's 100% your interpretation because that was not my intention at all.
If you wrote "did I say" I would have said no but you wrote "imply" :-)
But assuming hundreds of modal Forms isn't very realistic. The OP never
said how many modals there are. And since your assuming things, how about
if each of the modals all derive from a common ancestor? In that case my
solution would work quite nicely and probably would be more appropriate
than yours.
That is possible and might make it easy to extend functionality in the
future.
And I still don't think either of our solutions even deserve all this
attention :)
Very true.
They're completely different :)
Depends really. Both close the modal forms in order. There's very little
code in each so probably 50% is the same. :-)
The revised code in your adjacent post is much clearer. I'm not sure how
my solution helped you to write it, but if it works - great :)
Looking at the new code I can't believe how convoluted the previous code was
:-)

Michael
Nov 22 '06 #17
Hi Michael,

I'm glad we agree on almost everything...
>That's 100% your interpretation because that was not my intention at all.

If you wrote "did I say" I would have said no but you wrote "imply" :-)
My intent was not to imply any such thing. The question was actually
rhetorical, but you answered it anyway :)

--
Dave Sexton
Nov 22 '06 #18

My solution was really derived from posts by Marc and you and is just a
more generic version of what you wrote anyway.Marc was completely off (no offense Marc :), and I don't see how our
solutions are even close.
Thanks for pointing this out Dave :-) I wrote a quick test with modal
forms yesterday, but i made a mistake by issuing a close() on the main
form. And then every modal form does close, as the application goes
down :-) :-)

Hi Michael,

<snip>
and it certainly isn't "duplicating what's built into windows".
Somewhere in windows (or maybe the framework?) each window can store a
reference to an owner form. You are storing a reference to an owner form.The Form class has an Owner property. When the Form is a child to another
Form, the Owner property is set, but in the context of "Owner" code, the
simplest way to find that child Form, which needs to be closed, is to assign
the reference to a field when the child is constructed. There is no
"duplication".
Also, it works, so I'm not sure what type of potential bugs you're
considering.
The same code needs to be duplicated in every form so there is good
potential for an error.Given that we're talking about copying only four substantial lines of code,
I don't see any room for error. But if you're worried that the OP might
somehow forget to copy the code to one of the Forms, then inheritance could
fix that if the OP's willing.
The fact that it requires touching each Form might be too complicated for
the OP, so I'm not going to make any assumptions as to whether the
solution is satisfactory (and I wasn't trying to imply that in my last
post either, if that's what you assumed - note the light-hearted smiley.
: ) : )
I wouldn't use the words "too complicated". I would say that a simpler,
more generic, solution exists so why not use it?Did I imply that the OP shouldn't?

I think the OP should choose whichever is more appropriate. At this point,
why make any assumptions about requirements that we don't know?

And I don't think your code is simpler at all, BTW. I've glanced at it
twice and I have no idea what it's doing - I'm just assuming that it works
:)
My solution was really derived from posts by Marc and you and is just a
more generic version of what you wrote anyway.Marc was completely off (no offense Marc :), and I don't see how our
solutions are even close.

My solution is based on the fact that a modal dialog will "buffer" the
FormClosed event until all other owned modals are closed first - that's how
modal Forms behave. So, my code closes the one and only known child modal
(via a field reference) when the Owner itself is being closed, and the
FormClosed events for each modal are raised in a chain-reaction from
top-most to first. It's quite simple, really.

--
Dave Sexton
Nov 22 '06 #19
Thank you for your help all.
I was opening all forms modally using similar to mynewform.ShowDialog(this).
When i tried to close the root form, the child hierarchy didnt close.
This morning my friend, who had been trying to help me last night, sent me
the following code which i placed in my root form.
I think that all child forms need to be shown using ShowDialog(this) rather
than ShowDialog() for it to work but Ive not tested.

This works great and also iterates through all depths

static public void DestroyOwned(Form Root)
{
for ( int d=Root.OwnedForms.GetLength(0) - 1; d >= 0; d--)
{
DestroyOwned(Root.OwnedForms[d]);
Root.OwnedForms[d].Close();
}
}

DestroyOwned(this);// call from the root form
Nov 22 '06 #20

"Michael C" <no****@nospam.comwrote in message
news:OZ**************@TK2MSFTNGP02.phx.gbl...
"Chukkalove" <so*****@microsoft.comwrote in message
news:ug**************@TK2MSFTNGP03.phx.gbl...
>Im sorry, I dont know the correct description for a hierarchy of parent
and child forms.
I have a main form that opens a child form modally. This child form in
turn opens it's own child form modally.
I also have a separate thread running that monitors a card reader.

Out of curiosity does this poll the drive to see if the media has been
removed or is there some API call for this? See my reply to Dave for
closing the forms.

Michael
I use WinSCard API and poll the driver for its status every few seconds for
the presence of a card
We're using ACR38 card readers using PC/SC drivers

[DllImport(DllName, EntryPoint="SCardGetStatusChangeA")]
public static extern int SCardGetStatusChange(
Int32 hContext,
Int32 TimeOut,
ref SCARD_READERSTATE readerstate,
Int32 ReaderCount);
Nov 22 '06 #21
Thanks Michael :)
Nov 22 '06 #22
"Chukkalove" <so*****@microsoft.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
I use WinSCard API and poll the driver for its status every few seconds
for the presence of a card
We're using ACR38 card readers using PC/SC drivers
Is this a windows CE only api?
>
[DllImport(DllName, EntryPoint="SCardGetStatusChangeA")]
public static extern int SCardGetStatusChange(
Int32 hContext,
Int32 TimeOut,
ref SCARD_READERSTATE readerstate,
Int32 ReaderCount);

Nov 26 '06 #23

"Michael C" <no****@nospam.comwrote in message
news:eh**************@TK2MSFTNGP06.phx.gbl...
"Chukkalove" <so*****@microsoft.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>I use WinSCard API and poll the driver for its status every few seconds
for the presence of a card
We're using ACR38 card readers using PC/SC drivers

Is this a windows CE only api?
No, its the official Windows smart card reader api for using with USB PC/SC
compatible smart card reader/writers.

You also need PC/SC compatible drivers provided by card writer hardware
manufacturers. Some of the functions within it are generic across any
reader, others require knowledge of specific card types and specifications
for reading/writing from card reader/writer manufacturers. What I mean by
that is that I had to obtain instructions and examples for writing
specifically to the ACR38.
I was hoping that it could be used transparently and the manufacturers
driver would handle differences in implementation but it didn't work like
that.
http://msdn.microsoft.com/msdnmag/is...e/default.aspx

Nov 27 '06 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andrew | last post by:
I get a Null Reference Exception if I close a modeless form (that is, a form displayed using Show()) when a selection is made from a ComboxBox. If the form is modal (displayed using ShowDialog())...
3
by: Andrew | last post by:
I get a Null Reference Exception if I close a non-modal dialog (that is, a form opened with Show()) when a selection is made from a ComboBox. The error message refers to Unsafe Native Methods, but...
2
by: Tom | last post by:
How is the best way to avoid validation when closing a window? For instance, I have a Windows Forms window which has a validation event for a text box. However, if one enters invalid data in then...
2
by: Henry J. | last post by:
Has anybody run into this index out range exception when opening and then closing a collectionEditor from within a PropertyGrid? I use PropertyGrid to edit configurations in my application. One...
4
by: rdemyan | last post by:
I'm using code from the following web page to open the API Browse Folder dialog http://www.mvps.org/access/api/api0002.htm It all works fine. But if the dialog box is open and the user closes...
3
by: Grumman | last post by:
For various reasons, I've found myself in the position of needing to automate the operation of a small VB6 application from an external process. After a bit of searching, I found watsup, and it has...
14
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using VS2005 and .net 2.0. I'm creating an application that has 3 forms. I want allow users to move forward and backward with the forms and retain the data users have entered. I thought...
3
by: Mike Hofer | last post by:
Okay, here's the situation: we want to be able to display ASPX pages in an UpdatePanel. The reasons for this are performance related. The site in development uses *lots* of modal popups from some...
2
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
I am (still) relatively new to Windows applications, most of my experience has been Web based, and I am confused about what exactly happens when the Main() method is called and how to manipulate...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.