Cwnd window creation process

Source: Internet
Author: User
Bool cwnd: Create (lpctstr lpszclassname, lpctstr lpszwindowname, DWORD dwstyle, const rect & rect, cwnd * pparentwnd, uint NID, ccreatecontext * pcontext) {// can't use for desktop or pop-up windows (use createex instead) assert (pparentwnd! = NULL); Assert (dwstyle & ws_popup) = 0); // call createex internally to create return createex (0, lpszclassname, lpszwindowname, dwstyle | ws_child, rect. left, rect. top, rect. right-rect. left, rect. bottom-rect. top, pparentwnd-> getsafehwnd (), (hmenu) (uint_ptr) NID, (lpvoid) pcontext);} bool cwnd: createex, DWORD dwstyle, int X, int y, int nwidth, int Nhe Ight, hwnd hwndparent, hmenu nidorhmenu, lpvoid lpparam) {assert (lpszclassname = NULL | afxisvalidstring (plaintext) | afxisvalidatom (lpszclassname )); ensure_arg (lpszwindowname = NULL | afxisvalidstring (lpszwindowname); // allow modification of several common create parameters // set the window style createstruct Cs; CS. dwexstyle = dwexstyle; CS. lpszclass = lpszclassname; CS. lpszname = lpszwindowname; CS. style = Dwstyle; CS. X = x; CS. y = y; CS. cx = nwidth; CS. cy = nheight; CS. hwndparent = hwndparent; CS. hmenu = nidorhmenu; CS. hinstance = AfxGetInstanceHandle (); CS. lpcreateparams = lpparam; If (! Precreatewindow (CS) // registers the window class. precreatewindow is a virtual function and can be reloaded. Modify the window style {postncdestroy (); Return false;} afxhookwindowcreate (this ); // use the hook to register the window function and set the window function corresponding to the class to afxwndproc // create the window hwnd =: afxctxcreatejavaswex (CS. dwexstyle, CS. lpszclass, CS. lpszname, CS. style, CS. x, CS. y, CS. CX, CS. cy, CS. hwndparent, CS. hmenu, CS. hinstance, CS. lpcreateparams );//...} lresult afxwndproc (hwnd, uint nmsg, wparam, lpara M lparam) {// special message which identifies the window as using afxwndprocif (nmsg = wm_queryafxwndproc) return 1; // all other messages route through message mapcwnd * pwnd = cwnd :: fromhandlepermanent (hwnd); Assert (pwnd! = NULL); Assert (pwnd = NULL | pwnd-> m_hwnd = hwnd); If (pwnd = NULL | pwnd-> m_hwnd! = Hwnd) Return: defwindowproc (hwnd, nmsg, wparam, lparam); Return afxcallwndproc (pwnd, hwnd, nmsg, wparam, lparam ); // call the corresponding window handler} lresult afxapi afxcallwndproc (cwnd * pwnd, hwnd, uint nmsg, wparam = 0, lparam = 0 ){//... lresult = pwnd-> windowproc (nmsg, wparam, lparam); // call the corresponding window processing function //...} lresult cwnd: windowproc (uint message, wparam, lparam) {// onwndmsg does MOS T of the work, counter t for defwindowproc calllresult lresult = 0; If (! Onwndmsg (message, wparam, lparam, & lresult) // call the onwndmsg class to process messages. lresult = defwindowproc (message, wparam, lparam); Return lresult;} bool cwnd :: onwndmsg (uint message, wparam, lparam, lresult * presult) {lresult = 0; Union messagemapfunctions MMF; MMF. PFN = 0; cinternalgloballock winmsglock; // special case for commandsif (Message = wm_command) // process command messages in oncommand {If (oncommand (wpara M, lparam) {lresult = 1; goto lreturntrue;} return false;} // special case for notifiesif (Message = wm_policy) // process the notification message {nmhdr * pnmhdr = (nmhdr *) lparam; If (pnmhdr-> hwndfrom! = NULL & onnotify (wparam, lparam, & lresult) goto lreturntrue; return false ;}//... afxfindmessageentry // process common messages in afxfindmessageentry, find the message ing table, and trace back in a straight line //...} cwnd: onnotify or cwnd: oncommand {//... // reflect notification to Child Window control // reflection the message back to the sending subwindow, giving the subwindow a processing opportunity if (reflectlastmsg (hwndctrl, presult) return true; // eaten by child. If the subwindow has processed the message, the message is returned directly. You do not need to find afx_policy notify; notify. presult = presult; policy. pnmhdr = pnmhdr; return on1_msg (uint) NID, makelong (ncode, wm_1_y), verify ify, null );}

To sum up, dispatchmessage distributes messages to afxwndproc. afxwndproc actually calls window functions of various window classes internally, and then either goes back to the Message ing table to process messages, either go to oncommand or oncommand y to process the message. They provide an opportunity to reflect the message back to the subwindow. In fact, they also look for the message ing table for processing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.