演示窗口最大化与最小化功能的Demo应用

版权申诉
0 下载量 118 浏览量 更新于2024-10-03 收藏 11KB RAR 举报
资源摘要信息:"在本文中,我们将深入探讨如何通过使用C++编程语言中的MFC(Microsoft Foundation Classes)库来实现窗口的最大化和最小化操作。我们将重点介绍通过调用CWnd类的SendMessage函数发送消息来实现窗口状态改变的过程。" 知识点概述: 1. MFC(Microsoft Foundation Classes)库 MFC是一个用于简化Windows应用程序开发的C++库,它封装了Windows API,并提供了一套面向对象的编程接口。MFC库是微软Visual C++开发环境中的一部分,旨在简化Windows应用程序的编程工作。 2. CWnd类 CWnd是MFC库中一个非常核心的类,它代表一个窗口对象。CWnd类提供了大量与窗口操作相关的成员函数,这些函数封装了Windows API函数,使得窗口的操作更加方便和高效。 3. SendMessage函数 SendMessage是CWnd类中的一个成员函数,用于向窗口发送一个消息。这个函数会将消息直接发送到窗口的消息队列中,并且函数会等待消息处理完成后才返回。这意味着调用SendMessage函数的代码会阻塞,直到窗口处理完消息。 4. 最大化和最小化窗口消息 在Windows系统中,当用户点击窗口的控制按钮时,系统会向窗口发送相应的消息。例如,当用户点击最大化按钮时,系统会向窗口发送WM_SYSCOMMAND消息,并附带SC_MAXIMIZE参数。同样,最小化按钮会发送WM_SYSCOMMAND消息并附带SC_MINIMIZE参数。 5. 调用CWnd::SendMessage实现窗口化操作 要实现窗口的最大化或最小化操作,可以通过CWnd类的SendMessage函数来发送WM_SYSCOMMAND消息。具体来说,调用的时候需要提供窗口的句柄,WM_SYSCOMMAND消息标识,以及具体的操作标识(SC_MAXIMIZE或SC_MINIMIZE)。 详细实现步骤: 1. 获取窗口句柄 首先,需要获得当前操作的窗口句柄。窗口句柄是一个指向窗口的指针,可以使用多种方式获取,例如使用AfxGetMainWnd函数获取主窗口句柄,或者在创建窗口时保存返回的句柄。 2. 发送最大化消息 调用CWnd::SendMessage,传入窗口句柄,WM_SYSCOMMAND消息标识(0x112),以及SC_MAXIMIZE操作标识(0xf030),即可实现窗口的最大化。 示例代码: ```cpp hWnd->SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0); ``` 3. 发送最小化消息 调用CWnd::SendMessage,传入窗口句柄,WM_SYSCOMMAND消息标识(0x112),以及SC_MINIMIZE操作标识(0xf020),即可实现窗口的最小化。 示例代码: ```cpp hWnd->SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0); ``` 4. Demo程序的实现 在给定的文件中,可能包含了名为“Demo”的程序代码,该程序使用上述方法实现了窗口的快速最大化和最小化操作。Demo程序可能是一个演示性的Windows应用程序,展示了如何使用MFC和CWnd类来控制窗口状态。 5. 注意事项 在使用SendMessage函数时,需要确保正确处理返回值,尤其是在UI线程中发送消息时。错误的消息处理可能会导致程序出现卡顿或其他不可预知的行为。此外,应当注意消息的正确标识和参数的传递,以确保消息被正确地识别和执行。 总结: 通过以上知识点的学习,我们可以了解到如何使用MFC库中的CWnd类的SendMessage成员函数,来实现窗口的最大化和最小化操作。掌握这项技能对于开发Windows应用程序非常有用,尤其是在需要对窗口进行动态控制的场景中。在实际的软件开发过程中,合理地利用Windows消息机制可以提高程序的响应性和用户体验。
2023-06-02 上传

Failed to invoke the method sendMessage in the service com.itbz.shopping_common.service.MessageService. Tried 3 times of the providers [192.168.66.10:20880] (1/1) from the registry 192.168.66.159:2181 on the consumer 192.168.119.1 using the dubbo version 2.7.8. Last error is: Invoke remote method timeout. method: sendMessage, provider: dubbo://192.168.66.10:20880/com.itbz.shopping_common.service.MessageService?anyhost=true&application=shopping_user_customer_api&check=false&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&init=false&interface=com.itbz.shopping_common.service.MessageService&metadata-type=remote&methods=sendMessage&pid=2912&qos.enable=false®ister.ip=192.168.119.1&release=2.7.8&remote.application=shopping_message_service&side=consumer&sticky=false×tamp=1689070199503, cause: org.apache.dubbo.remoting.TimeoutException: Waiting server-side response timeout by scan timer. start time: 2023-07-11 18:12:40.651, end time: 2023-07-11 18:12:41.662, client elapsed: 1 ms, server elapsed: 1010 ms, timeout: 1000 ms, request: Request [id=2, version=2.0.2, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=sendMessage, parameterTypes=[class java.lang.String, class java.lang.String], arguments=[185909224615, 9527], attachments={path=com.itbz.shopping_common.service.MessageService, remote.application=shopping_user_customer_api, interface=com.itbz.shopping_common.service.MessageService, version=0.0.0}]], channel: /192.168.66.10:63073 -> /192.168.66.10:20880

2023-07-12 上传

优化这段代码: public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (handler instanceof HandlerMethod) { HandlerMethod handlerMethod = (HandlerMethod) handler; Method method = handlerMethod.getMethod(); RepeatSubmit annotation = method.getAnnotation(RepeatSubmit.class); if (annotation != null) { if (this.isRepeatSubmit(request, annotation)) { AjaxResult ajaxResult = AjaxResult.error(annotation.message()); ServletUtils.renderString(response, JSON.toJSONString(ajaxResult)); return false; } } } boolean flag = false; TokenService tokenService = SpringUtils.getBean(TokenService.class); LoginAppUser loginUser = tokenService.getLoginUser(request); if (loginUser != null && loginUser.getGuest() != null && loginUser.getGuest().getGuestNum() != null) { tokenService.verifyToken(loginUser); String guestNum = loginUser.getGuest().getGuestNum(); HttpSession httpSession = request.getSession(); RedisCache redisUtil = SpringUtils.getBean(RedisCache.class); Guest guest = redisUtil.getCacheMapValue(RedisConstants.GUEST_MAP, guestNum); SysGuest sysGuest = JSON.parseObject(JSON.toJSONString(guest), SysGuest.class); if (sysGuest == null) { flag = false; httpSession.removeAttribute(Constants.SERVER_TYPE_APP); } else { if (httpSession.getAttribute(Constants.SERVER_TYPE_APP) == null) { httpSession.setAttribute(Constants.SERVER_TYPE_APP , sysGuest); } return true; } } //获取网名 也就是/login String servletPath = request.getServletPath(); if(servletPath.contains("/app/card/isCard") || servletPath.contains("/app/bank/signingBankCard") || servletPath.contains("/app/bank/sendMessage") || servletPath.contains("/app/bank/sendSysMessage") || servletPath.contains("/app/bank/login") || servletPath.contains("/app/card/guestIdAndPhone") || servletPath.contains("/app/family/isDevice") || servletPath.contains("/websocket/") || servletPath.contains("/upload/") || servletPath.contains("/app/deviceSocket/toSocket")) { flag = true; } if (!flag) { noLogin(response); } return flag; }

2023-06-08 上传