How to design cleaner PostMessage chain in WinApi/MFC -


i have mfc gui app has multiple frames (sort of outlook'ish behavior main window, , message/appointment windows being created in new frames, or skype multi frame syncronization), , need postmessage malloc'ed data through window hierarchy.

say, string, _wcsdup it, postmessage(wm_newstring, ...), and, control somewhere deep down hierarchy processes it, or if there no subscribers, message get's cleaned.

what looking now, messages posted application thread, thread finds active frame or best fit frame, passes message it, frame passes message it's view, view passes message subview , on, if there no view process message, get's free'd.

the problem these chaining commands pretty tiring write, have duplicate message forwarding code in each cwnd class have. @ same time, resource cleanup pretty unpleasant, because if there no window catch message, has call free. therefore posting message main message pump without handling, hoping catch it, not valid approach. postmessage returns s_ok, no 1 sees message processable, , it's left dangling.

is there better, correct approach i'm looking for?

i never use postmessage describe. solution involves hand-shake:

// cnotifierblah postmesssage(hwnd, uwm_new_data, 0, 0); // lresult cdestinationwnd::onnewdata(wparam wparam, lparam lparam) {     cnewdata newdata = getnotifierblah().getnewdata(); // thread-safe getter! } 

pretty same observer pattern.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -