Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Issue: After SetParent - Child Window Messages Processing Question

$
0
0

Hello,

I have a simple windows form app, written in (I have a version in c# and vb.net).

What I want:

  • I want to be able to use PostMessage / SendMessage to send messages to windows that I have used SetParent against.

What happens:

Parent Form

  • I start my application, which will be the parent
  • Parent Form: Has KeyDown / KeyPress events set to create a messagebox to say what character was pressed
  • Parent Form: Not set to MDIContainer or set to MDIContainer (same results)
  • Parent Form: Turned on KeyPreview = True

Secondary Application

  • I start my second application (another windows form) - there is a reasons it just not a simple MDI application
  • I have KeyPress and Keydown implemented to show messageboxes with the values used

Message Posting Application

  • I start my 3rd application which is used to postmessages / sendmessages

Steps I take to test:

  • Using the PID of the Secondary Application, I use PostMessage to send a message to it from my Message Posting Application
  • As expected, the KeyDown / KeyPress events fire and I get my messages boxes
  • So perfect :-)
  • Next, I call SetParent in my Parent application, changing the  Secondary Application to have a Parent of my Parent #1 application
  • I use the Message Posting Application to send a PostMessage to the PID of the Secondary Application, which now has a new parent, and nothing happens. The message boxes don't appear
  • I click ON the secondary app so it has focus, within the Parent app, press a key and bingo the message boxes come up
  • If I set the parent of the Secondary App back to the desktop, it pops out of the Parent Application, and when I use PostMessage / SendMessage it once against works as I need it to.

My Problem and Ask:

  • Why does the PostMessage now not work? I am guessing it is related to how message processing works between the wndows
  • To be clear, I did NOT set the WS_CHILDWINDOW attribute on the Secondary Application, I merely did a SetParent, but left everything else, windows style wise, the same
  • How do I get the Parent App (or how do I configure the windows properly) so that PostMessage Keeps working?
  • In my case, I will actually end up with 5 total "secondary apps" all bound to the primary app. Again I dont' want to use MDI and it's a long story :-) . So although as individual windows PostMessage works great, how do I get around when its a snapped in window to a Parent?
  • Do I "have" to set the style to WS_CHILDWINDOW?
  • Or do I need to setup key processing in the Parent, and always do PostMessage to that?
  • If so, how does the parent app know which window to push (if it even can) the message too?
  • I am guessing somehow the messagepump on the secondary apps is now changed / messed up (per say) and that is why I am failing

Thanks!!


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>