9CBS - expert patient - VC / MFC interface problems Reply | Recommend | Add | Thematic | Announcement | Management | Save | Close topic: How to respond to mouse double-click the message in the MDI client area of the window of: huyoo (Spacebar) level: the credibility of the value? : 100 Forum: VC / MFC interface problem points: 20 replies: 15 Posted: 2004-5-15 4:48:26
Everyone knows that in the customer area in Photoshop, you will pop up the file dialog box; press and hold the Ctrl and double-click the mouse. My purpose is to respond to the mouse in the client area of the MDI window. After reading "In-depth MDI Customer Window Programming" (in 9CBS), I overloaded the PretranslateMessage (MSG * PMSG) function. Make it enabled before the message is sent to the translateMessage () and the DispatchMessage () function before pre-interpreted the message. the reload function can be intercepted message WM_LBUTTTONDBLCLK MDI client window, I do so: 1. in BOOL CMainFrame :: PreCreateWindow (CREATESTRUCT & cs) {(! CMDIFrameWnd :: PreCreateWindow (cs)) if return FALSE; return TRUE;} in Add cs.Style | = CS_DBLCLKS; to prevent the MDI window to do not respond to the message. 2. Heavy duty PretranslateMessage (MSG * PMSG) function Add code as follows: BOOL CMAINFRAME :: PretranslateMessage (msg * PMSG) {// if (PMSG-> HWnd == m_hwndmdiclient && pmsg-> message == wm_lbuttondown) // PostMessage (WM_LBUTTONDOWN); // I here comment out the message that intercepts the mouse click, because the customer area responds to the message // without a response Double click on the mouse
if (pMsg-> hwnd == m_hWndMDIClient && pMsg-> message == WM_LBUTTONDBLCLK) PostMessage (WM_LBUTTONDBLCLK); return CMDIFrameWnd :: PreTranslateMessage (pMsg);} 3 WM_LBUTTONDOWN and WM_LBUTTONDBLCLK addition response message to CMainFrame:. void CMainFrame :: OnLButtonDown (UINT nFlags, CPoint point) {AfxMessageBox ( "customer area click the mouse!"); CMDIFrameWnd :: OnLButtonDblClk (nFlags, point);} void CMainFrame :: OnLButtonDblClk (UINT nFlags, CPoint point) {AfxMessageBox ( "customer Zone doubles the mouse! "); CmdiframeWnd :: ONLBUTTONDBLCLK (NFLAGS, POINT);} 4. Compile, pass! >>>>>>> Perform, turn off the newly built document, test results: # Click the left mouse button : No reaction # Double-click the left mouse left mouse: No reaction 5. Cancel the CMAINFRAME:: PRETRANSLATEMESSAGE (MSG * PMSG) Note to WM_LBUTTONDOWN, compile and execute, turn off the new document, test results: # Click the left mouse button : Popked dialog # Double-click the left mouse button: No response
I don't know what to do, please help me !!!!! sos !!! Thank you all !!! Huyoo @ 2004/5/15 ---------------- ----------------------------------- Reply to: Enoloo (Will Nothing) () Reputation: 102 2004- 5-15 8:15:59 Score: 0 if (pmsg-> hWnd == getActiveFrame () -> getActiveView () -> m_hwnd && pmsg-> message == wm_lbuttondblclk) Normal childframe is not receiving dbclick, his view receive. You can handle the DBClick of the view, then send a message to the app, notify the establishment of a new document.
// I have found it, I can't find it. Can the landlord give a connection, thank you ~ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------- Reply to: huyoo (space bar) () reputation: 100 2004-5-15 10:23:04 Score: 0 test ...
Childframe's View View is to receive DBClick, but I am not this, because a childframe is a new document, not a client area of the MDI window.
Wow, as ENOLOO said, in the second step, the result is in the fourth step: 4. Compile, >>>>>>>>, turn off the newly built documentation, test results:
When the closure button of the ChildFrame, MDICLIENTMSG.EXE will be closed, ask me not to send a report. $% ^ $ ^ & * (Save a number of complaints ...)
The effect I want is whether there is a childframe (sub-document window) in Mainframe, as long as a part of the MDICLIENT customer area, double-click the gray MDICLIENT client area, pop up the open file dialog box. ^ _ ~
// I have searched CodeProject and CodeGuru, no articles and examples of this area. (! _!) // China's website is not more to say. @ _ @
You say why it (Mdiclient Customer Area) can respond to the mouse click (no matter the left and right), it is refused to respond to the left mock click (regardless of the left and right keys)?
I look forward to the heroes to solve ing ...
Huyoo @ 2004/5/15/10: 10: 18
-------------------------------------------------- -
Reply to: huyoo (space bar) () reputation: 100 2004-5-15 10:46:40 score: 0 // cold !!!! // You may be "in-depth MDI Customer Window Program" (at 9CBS there are) a link bar // http:? //expert.9cbs.net/Expert/topic/3043/3043812.xml temp = .7111627 theme:? VC programming experience 1.1 (VC programming Skills 1.1) author: sgnaw ( Li Xiaoyao)
There is a "in-depth MDI customer window programming" and a "add bitmap in the MDI main frame window" to download it. I downloaded here (there are several links in China): http: // lingrer. Spymac.net/collection/vc200402.chm
& _ ^ ###############################################################
HuYoo @ 2004/5/15
-------------------------------------------------- - Reply to: huyoo (space bar) () Reputation: 100 2004-5-15 10:50:15 Score: 0 Supplement: "Deepening MDI Customer Window Programming" and "Add a bitmap in the MDI main frame window" The article is in the --vc / mfc interface class. & _ ^ ############################################################################### ####### huyoo @ 2004/5/15
-------------------------------------------------- - Reply to: a_qiao () () Reputation: 100 2004-05-17 16:22:00 Score: 0 I read the instructions about the mouse double-click the message, found that the msdn said this is the case, this CS_DBLCLKS style can receive WM_LBUTTONDBLCLK ^^^^^^^^^^^^^^^^^^ messages, which the system generates whenever the user presses, releases, and again presses the left mouse button within the system's double-click time limit . Double-Clicking The Left Mouse Button Actually Generates Four Messages: WM_LButtondown, WM_LButtonup, WM_LButtondblclk, and WM_LButtonup Again.
So I think that the reason for your problem should be that the MDI's client area window has no cs_dblclks attribute, so it does not double-click the message. The solution is to use the function getClasslong () and setClasslong () to add the cs_dblclks attribute. I have tried it, confirming my guess.
-------------------------------------------------- - Reply to: huyoo (space bar) () Reputation: 100 2004-05-21 14:43:00 Score: 0 You can put your program specific implementation to watch it? I am in cmainframe :: oncreate (.. DWORD ClientStyle;
ClientStyle = getclasslong (m_hwndmdiclient, gwl_style); clientStyle | = cs_dblclks; clientStyle = setClasslong (m_hwndmdphmdphmdlient, gwl_style, clientstyle);
There is no success since then until successfully changed to BOOL CMAINFRAME :: PrecreateWindow (CreateStruct & Cs) !!! / / =========================== ========================================
Then I add the following in OnCreateClient in: BOOL CMainFrame :: OnCreateClient (LPCREATESTRUCT lpcs, CCreateContext * pContext) {lpcs-> style | = CS_DBLCLKS; return CMDIFrameWnd :: OnCreateClient (lpcs, pContext);} will be no success, no Response ~~~~~
Please help!!!
Huyoo @ 2001/05/21
-------------------------------------------------- - Reply to: a_qiao () () Reputation: 100 2004-05-22 12:56:00 Score: 0 My implementation method is different from you, it is done with SubclassWindow, but the principle is the same. I carefully After reading your method, I feel that the problem may be in the following aspects; (1) When oncreate, maybe m_hwndmdiclient is not ready, so there is no success (2) If OnCreate, M_HWndmdiclient is not ready, in PrecreateWindow It may be not ready to be ready. (3) In OnCreateClient, Style is the style of the window, do not mix with the windows of style. The style of the window is the start of WS_, while the window class STYLE It is CS_ beginning. Conclusion: Use setClasslong () instead of using lpcs-> style | = cs_dblclks -------------------------------------------------------------------------------------------------- ----------------------------- Reply to: huyoo (space bar) () Reputation: 100 2004-05-23 05:07 : 00 Score: 0 Say according to A_QIAO (), I changed the code in CMAINFRAME :: OnCreateClient as follows: BOOL CMAINFRAME :: On CMAINFRAME :: OnCreateClient (lpcreateStruct LPCS, CCReateContext * PContext) {// lpcs-> style | = WS_CAPTION; / / Cs_dblclks; // lpcs-> lpszclass = _t ("mdiclient");
DWord ClientStyle; ClientStyle = :: getClasslong (m_hwndmdiclient, gwl_style); clientStyle | = CS_DBLCLKS;
:: setClasslong (m_hwndmdiclient, gwl_style, clientstyle); return cmdiframewnd :: oncreateclient (lpcs, pcontext);}
Debug pass, but still there is no reaction !!!!!!!!
If you really look like the answer above, you should succeed. However, 嘿 ...
I trace debugging a bit and found CMainFrame :: OnCreate (LPCREATESTRUCT lpCreateStruct) calls CMDIFrameWnd :: OnCreate (lpCreateStruct), in CMDIFrameWnd :: OnCreate (lpCreateStruct) has completed the PreCreateWindow and OnCreateClient, so that (1) and ( 2) Is wrong.
(3) It is not possible. Because since OnCreateClient occurs before CMAINFRAME :: OnCreate, M_HWndmdiclient is not ready in OnCreateClient, m_hwndmdiclient is not ready to be ready ~~~~~ ~~~~~~
######### huyoo @ 2001/05/23
-------------------------------------------------- - Reply to: huyoo (space bar) () reputation: 100 2004-05-23 05:21:00 Score: 0 Add a few points: ## I am using getclasslong and setclasslong, want to modify the MDI customer with getclasslong and setclasslong The class structure information of the area, used the GWL_Style parameter, made a mistake, should be gcl_style. ## In CMAINFRAME: ONCREATECLIENT, I seem to have no changes to the function's parameters, it may be a reason for not responding.
## There is a paragraph in CMAINFRAME :: onCreateClient:
// lpcs-> style | = ws_caption; // cs_dblclks; // lpcs-> lpszclass = _t ("mdiclient");
It turns out that I have such a sentence: lpcs-> style | = WS_VSCROLL, when debugging, discovery in an internal function, the main window function does not allow the MDI customer area with WS_VSCROLL and WS_HSCROLL (can be up and down, left and right scrolling windows) window style, Here is a little prompt ^ _ ^
However, I didn't change any changes or effects in the following this sentence. LPCS-> style | = WS_CAPTION;
-------------------------------------------------- - Reply to: huyoo (space bar) () Reputation: 100 2004-05-23 06:46:00 Score: 0 ::::::::::::::: ::::::::::::::::::::: ::::::::::::::::::
I used subclasses to solve:
1. Create a window class with ClassWizard to CWND, named CNewClientWnd.2. Add types of window CNewclientWnd created in CMAINFRAME to step, named M_WndNewClient. 3. Member function in CMAINFRAME Once onCreate, the call to the base class cmdiframewnd :: OnCreate () Add a call statement for subclasswindow (). / / ======================= ==================== // Sub-class window m_hwndmdiclient if (! M_wndnewclient.subclasswindow (m_hwndmdiclient)) {trace ("Failed to Subclass MDI Client WINDOW / N" ); Return -1; // fail to create} // ==================================== m_hwndmdiclient is a member variable of cmdiframeWnd that includes a handle of the MDI customer window. 4. Add CNEWCLIENTWND, ONLBUTTONDOWN (for contrast) and ONLBUTTONDBLCLK message response processing:
void CNewClientWnd :: OnLButtonDblClk (UINT nFlags, CPoint point) {AfxMessageBox ( "double-clicking the left button in the client area!"); CWnd :: OnLButtonDblClk (nFlags, point);} void CNewClientWnd :: OnLButtonDown (UINT nFlags, CPoint point) {// afxMessageBox ("Left button Press!"); CWnd :: ONLBUTTONDOWN (NFLAGS, POINT);}
5. Add in the CMainFrame class CreateClient process, the aim is a client area of the window can accept double-click: BOOL CMainFrame :: OnCreateClient (LPCREATESTRUCT lpcs, CCreateContext * pContext) {DWORD st; st = :: GetClassLong (m_wndNewClient.m_hWnd / * m_hWndMDIClient * /, Gcl_style); st | = cs_dblclks ;:: setClasslong (m_wndnewclient.m_hwnd / * m_hwndmdiclient * /, gcl_style, st);
Return CmdiframeWnd :: OnCreateClient (LPCS, PCONTEXT);} 6. Compiling through, execution, or no response.
Please let a_qiao () tell me how you do it, and I want to know, your program responds to the customer's mouse double-click event?
Thank you !! huyoo @ 2004/05/23 ---------------------------------------------------------------------------------------------------- ----------- Reply to: MackZ (in mutual) () reputation: 99 2004-05-23 10:49:00 Score: 0 According to "In-depth MDI Customer Window Program" and "in MDI Add a bitmap in the frame window, "introduction of the subclass of the article, the subclass of the customer area window. Note that the base class is not a CWND. -------------------------------------------------- - Reply to: kongyunzhongque (Skylark) () Reputation: 120 2004-05-23 16:48:00 Score: 0 Bool CNewclientWnd :: OneRaseBkgn (CDC * PDC) {:: setClasslong () {:: setclasslong () {:: setClasslong (), gclong (M_HWND, GCL_Style) | CS_DBLCLKS;
Through verification, it may be placed, but it is this idea ----------------------------------- ---------------- Reply to: _foo (void) // 莫 号 莫函函 :) () Reputation: 163 2004-05-23 17:19:00 Score: 0 year or two I have answered the relevant issues before, it seems that I have entered FAQ. I just found http://www.codeproject.com/dialog/mdiBACKGROUNDIMAGE.ASP
Basically, you can refer to this article.
Add a CS_DBLCLKS style to the MDICLIENT window and processes the message. The key is the problem obtained by the MDICLIENT window handle
In this paper, I tried the code HWND hMain = pMainFrame-> GetWindow (GW_CHILD) -> GetSafeHwnd (); pfnOldWndProc = (WNDPROC) GetWindowLong (hMain, GWL_WNDPROC); SetWindowLong (hMain, GWL_WNDPROC, (long) pfnNewWndProc); there is no problem As for the cmdiframewnd :: m_hwndmdiclient this member variable has not been used. ----------------------------------------- -------------- Reply to: huyoo (space bar) () Reputation: 100 2004-05-23 21:43:00 Score: 0 // ======== =============== Thank you for your answer !!!
I tested the two programs you said, I found: ## kongyunzhongque (Skylark) program is very good, responding !! I am so happy !! I have said to what he said, I tried another place: [Note ] I have tested below, after the test is finished, comment out, and then the next test.
In the CNewClientWnd class: 1.void CNewClientWnd :: PRESUBCLASSWINDOW () {}, feasible ~~~, respond !!!!!!!!! 2.int CNewClientWnd :: oncreate (lpcreateStruct) {}, fail , does not respond 3.BOOL CNewClientWnd :: PreCreateWindow (CREATESTRUCT & cs) {} in, fail to realize, does not respond 4.void CNewClientWnd :: OnPaint () {CPaintDC dc (this); // device context for painting :: SetClassLong (GetSafeHwnd (), Gcl_style, :: getClasslong (m_hwnd, gcl_style) | cs_dblclks); // do not call cwnd :: onpaint () for painting message} is also implemented, respond !!! ~~ 5.void cnewclientWnd :: ONSHOWINDOW BSHOW, NSTATUS) {}, there is no problem, there is no more test. Please try it yourself ... The best position is where, I personally think that since it is realized, in Void CNewclientWnd: : PRESUBCLASSWINDOW () {} should be the best.
In the CMainFrame class: I :: SetClassLong (GetSafeHwnd (), GCL_STYLE, :: GetClassLong (m_hWnd, GCL_STYLE) | CS_DBLCLKS); instead :: SetClassLong (m_wndNewClient.m_hWnd, GCL_STYLE, :: GetClassLong (m_wndNewClient.m_hWnd, GCl_Style) | CS_DBLCLKS); then add it to the following process. 1. Bool CMAINFRAME :: PrecreateWindow (CreateStruct & Cs) {} is unable to implement After the subclass window m_hwndmdiclient statement, the response double click !!!!!!! int CMAINFRAME :: OnCreateStruct lpcreateStruct) {if (cmdiframeWnd :: oncreate (lpcreateStructure) == -1) Return -1; / / ===================================================== 子 子If (! m_wndnewclient.subclasswindow (m_hwndmdiclient)) {trace ("failed to subsclass mdi client window / n"); return -1; // fail to create} // ============= =================================================================================================================== =========================================== ...}
3. Bool CMAINFRAME :: OnCreateClient (lpcs, pcontext) {} is not implemented, no response. 4.void cmainframe :: onpaint () {} is implemented, respond to double click !!!!!!! 5.bool cmainframe :: OneRaseBkGnd (CDC * PDC) {} is also implemented, responded double click !!!!!!! / / ======================= ======================================== // ## _foo (void) // 莫 号:
[Note] I am used in that (not subclassified) program. Use the following code:
HWnd hmdiclientarea = getWindow (gw_child) -> getsafehwnd (); :: setClasslong (HmdiClientarea, gcl_style, :: getClasslong (HmdiClientarea, gcl_style) | CS_DBLCLKS);
Was then added to the following procedure. 1.BOOL CMainFrame :: PreCreateWindow (CREATESTRUCT & cs) {} in, fail to realize, does not respond 2.int CMainFrame :: OnCreate (lpCreateStruct) {} in int CMainFrame :: OnCreate (LPCREATESTRUCT lpCreateStruct ) {if (CMDIFrameWnd :: OnCreate (lpCreateStruct) == -1) return -1; HWND hMDIClientArea = GetWindow (GW_CHILD) -> GetSafeHwnd (); :: SetClassLong (hMDIClientArea, GCL_STYLE, :: GetClassLong (hMDIClientArea, GCL_STYLE) | CS_DBLCLKS); ...} is achieved, respond to double click !!!!!!!
3. Bool CMAINFRAME :: OnCreateClient (lpcs, pcontext) {} is not implemented, no response. 4.void cmainframe :: onpaint () {} is implemented, respond to double click !!!!!!! 5.bool cmainframe :: OneRaseBkGnd (CDC * PDC) {} is also realized, responded double click !!!!!!!
/ / =========================================================================================================================================================================================== === // So: Whether it is subclass of CNEWCLIENTWND, or CMAINFRAME, in OnPaint () and OneRaseBkGnd (), you can realize a double click on M_HWndmdiClient to change the information operation, you can do double-click in your own In the event, only the class information of m_hwndmdiclient in CMAINFRAME on CMAINFRAME can be responed to the mouse double-click. At this point, my question is to be solved. There are some things need to sum up, explore, and everyone exchange! I I think that I haven't achieved in front, it is very likely that I have not taken the real customer handle (m_hwndmdiclient), like a getsafehwnd () function, I use it or not, I should pay attention to it; another big mistake is to put GCL_Style The style of the class is missed to GWL_Style (the style of removing the window), which has not been achieved for a long time. It is worth noting.
Further, the subclass of example, the following code: DWORD clientstyle; clientstyle = :: GetClassLong (m_hWndMDIClient, GCL_STYLE); clientstyle | = CS_DBLCLKS; clientstyle = :: SetClassLong (m_hWndMDIClient, GCL_STYLE, clientstyle); for use in the CMainFrame Oncreate (), and :: setClasslong (m_wndnewclient.m_hwnd, gcl_style, :: getClasslong (m_wndnewclient.m_hwnd, gcl_style) | CS_DBLCLKS); the effect is the same ~~~~~~~~~~~
I wish you all a good job, happy life, work well !!!!
Huyoo @ 2004/05/23 --------------------------------- ------------------ Reply to: huyoo (space bar) () reputation: 100 2004-05-23 21:47:00 Score: 0 ====== =============================================== :::::: Experts from this problem ::::::::: ==================================================================================================================================================================================================================================================== ========== First, thank you for your enthusiasm for me! Unlocking questions about making me a long time.
Then, I want to say, this is not a solution to my question, and VC learner and developer who wants to achieve the mouse in the client district in the client district.
There is also a great help, you can't work !! Let them take a lot of detours.
Finally, I am sorry: I thought this is a very simple question, so I only gave 20 points. I didn't think that this problem didn't get solved. When I solved it, I attracted so many masters, I really sorry, Can't give too much points !!
Today, I want to end this post, I hope there is a good way to comment!!
thank you all!!
Huyoo @ 2004/05/23 --------------------------------- ------------------
Copyright? 9cbs.net, Inc. All Rights Reserved