重拾VB6(22):Mouse Pointer, Keyboard Events, Interrupting Background Processing

大学生创业训练设计包含申报/中期/结题模板、ESP32 智能农场项目 ESP32 智能农场项目 立即下载

来自MSDN-2001-OCT: Visual Tools and Languages/Visual Studio 6.0 Documentation/Visual Basic Documentation/Using Visual Basic/Programmer’s Guide/Part 2: What Can You Do With Visual Basic/Responding to Mouse and Keyboard Events/

1. Customizing the Mouse Pointer

(1)You can use the MousePointer and MouseIcon properties to display a custom icon, cursor, or any one of a variety of predefined mouse pointers.

(2)With the MousePointer property you can select any one of sixteen predefined pointers.

When you set the MousePointer property for a control, the pointer appears when the mouse is over the corresponding control. When you set the MousePointer property for a form, the selected pointer appears both when the mouse is over blank areas of the form and when the mouse is over controls with the MousePointer property set to 0-Default.

(3)To use a custom icon or cursor, you set both the MousePointer and MouseIcon properties.

a) Select a form or control and set the MousePointer property to 99-Custom.

b) Load an .ico file into the MouseIcon property. For example, for a form:

Form1.MouseIcon = LoadPicture("c:/Program _
Files/Microsoft Visual _
Basic/Icons/Computer/Disk04.ico")

(4)Cursors are .cur files and, like icons, are essentially bitmaps. 

Cursors also contain hot spot information. The hot spot is a pixel which tracks the location of the cursor — the x and y coordinates. Typically, the hot spot is located at the center of the cursor. Icons, when loaded into Visual Basic through the MouseIcon property, are converted to the cursor format and the hot spot is set to the center pixel.

The two differ in that the hot spot location of a .cur file can be changed, whereas that of an .ico file cannot.

Cursor files can be edited in Image Editor, which is available in the Windows SDK.

Visual Basic does not support animated cursor (.ani) files.

2. Responding to Keyboard Events

(1) The KeyPress, KeyUp, and KeyDown events

(2) Only the object that has the focus can receive a keyboard event.

A form has the focus only if it is active and no control on that form has the focus. This happens only on blank forms and forms on which all controls have been disabled. However, if you set the KeyPreview property on a form to True, the form receives all keyboard events for every control on the form before the control recognizes them.

(3) The KeyDown and KeyUp events provide the lowest level of keyboard response. Use these events to detect a condition that the KeyPress event is unable to detect.

Before using the KeyUp and KeyDown events, make sure that the KeyPress event isn't sufficient. This event detects keys that correspond to all the standard ASCII characters: letters, digits, and punctuation on a standard keyboard, as well as the ENTER, TAB, and BACKSPACE keys. It's generally easier to write code for the KeyPress event.

You also should consider using shortcut and access keys. You can assign shortcut keys without writing additional code.

(4) Note that some controls (command buttons, option buttons, and check boxes) do not receive arrow-key events: Instead, arrow keys cause movement to another control.

3. Key codes

(1)

Private Sub Text1_KeyPress (KeyAscii As Integer)
   KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

(2) When the user types uppercase "A," the KeyDown event gets the ASCII code for "A." The KeyDown event gets the same code when the user types lowercase "a." To determine whether the character pressed is uppercase or lowercase, these events use the shift argument. In contrast, the KeyPress event treats the uppercase and lowercase forms of a letter as two separate ASCII characters.

(3) Key codes for letter keys are the same as the ASCII codes of the uppercase character of the letter. So the keycode for both "A" and "a" is the value returned by Asc("A").

4. Writing Form-Level Keyboard Handlers

(1) If you have defined a shortcut key for a menu control, the Click event for that menu control occurs automatically when the user types that key, and no key event occurs.

(2) Similarly, if there is a command button on the form with the Default property set to True, the ENTER key causes the Click event for that command button to occur instead of a key event. If there is a command button with the Cancel property set to True, the ESC key causes the Click event for that command button to occur instead of a key event.

(3) Notice that the TAB key moves the focus from control to control and does not cause a key event unless every control on the form is disabled or has TabStop set to False.

(4) When the KeyPreview property of the form is set to True, the form recognizes the keyboard events before the controls, but the events still occur for the controls. To prevent this, you can set the keyascii or keycode arguments in the form key-event procedures to 0.

Private Sub Form_KeyPress (KeyAscii As Integer)
Dim NextTabIndex As Integer, i As Integer
   If KeyAscii = 13 Then
      If Screen.ActiveControl.TabIndex = _
      Count - 1 Then
         NextTabIndex = 0
      Else
         NextTabIndex = Screen.ActiveControl._
         TabIndex + 1
      End If
      For i = 0 To Count - 1
         If Me.Controls(i).TabIndex = _
         NextTabIndex Then
            Me.Controls(i).SetFocus
            Exit For
         End If
      Next i
      KeyAscii = 0
   End If
End Sub

5. Interrupting Background Processing 

(1) Windows is a preemptively multitasking operating system, which means that idle processor time is efficiently shared among background tasks. Priority is always given to the application that the user is working with, however. This ensures that the mouse and keyboard always respond immediately.

During long background tasks, your application cannot respond to user input. Therefore, you should provide the user with a way to interrupt or cancel the background processing by writing code for either the mouse or keyboard events.

(2) One way to allow users to interrupt a task is to display a Cancel button and allow its Click event to be processed. You can do this by placing the code for your background task in a timer event, using the following guidelines.

  • a) Use static variables for information that must persist between occurrences of the Timer event procedure.
  • b) When the Timer event gets control, allow it to run slightly longer than the time you specified for the Interval property. This ensures that your background task will use every bit of processor time the system can give it. The next Timer event will simply wait in the message queue until the last one is done.
  • c) Use a fairly large value — five to ten seconds — for the timer's Interval property, as this makes for more efficient processing. Preemptive multitasking prevents other applications from being blocked, and users are generally tolerant of a slight delay in canceling a long task.
  • d) Use the Enabled property of the Timer as a flag to prevent the background task from being initiated when it is already running.

(3) Although Timer events are the best tool for background processing, particularly for very long tasks, the DoEvents function provides a convenient way to allow a task to be canceled.

DoEvents switches control to the operating-environment kernel. Control returns to your application as soon as all other applications in the environment have had a chance to respond to pending events. This doesn't cause the current application to give up the focus, but it does enable background events to be processed.

You may want to prevent an event procedure that gives up control with DoEvents from being called again before DoEvents returns. Otherwise, the procedure might end up being called endlessly, until system resources are exhausted. You can prevent this from happening either by temporarily disabling the control or by setting a static "flag" variable, as in the earlier example.

(4) Avoiding DoEvents When Using Global Data

ASP.NET毕业设计含文档和代码ASP.NET网上人才招聘系统(源代码+论文) 立即下载

相关推荐

云桌面20260902

云桌面20260902

VB6浮雕效果源代码

 Private Sub Command1_Click()    Dim r2, g2, b2 As Integer    Dim r1, g1, b1 As Integer    Dim c1 As Long    Dim c2 As Long    Dim x0 As Integer    Dim y0 As Integer    Screen.MousePointer = 11     m

keenweiwei的专栏 1833

如何实现高校科技成果快速转化?.docx

如何实现高校科技成果快速转化?

vb6.MousePointer

常数 值 描述 vbDefault 0 缺省值 vbArrow 1 箭头 vbCrosshair2十字线 vbIbeam 3 I 型标 vbIconPointer 4 图标 vbSi...

龙哥(webnum)说的,每天进步一点点,总有一天会实现梦想! 585

vb MousePointer(鼠标形状)

MousePointer属性用来显示鼠标箭头的形状的。 可在C:/WINDOWS/Cursors 找到这些形状。  常数                       值      描述       vbDefault               0       缺省值       vbArrow                 1       箭头       vbCrosshair            2      十字线       vbIbeam                 3      I  

姬豪杰的专栏 1万+

OpenCV-5.0.0编译时所需要下载的文件

OpenCV-5.0.0编译时所需要下载的文件

基于监督学习的多模态MRI脑肿瘤分割利用监督体素的纹理特征(Matlab代码实现)

内容概要:本文系统研究了基于监督学习的多模态MRI脑肿瘤分割方法,重点聚焦于利用监督体素的纹理特征实现肿瘤区域的精确识别。文章首先阐述了监督学习的基本原理及多模态MRI在医学影像分析中的独特优势,进而深入探讨了灰度共生矩阵(GLCM)、局部二值模式(LBP)和小波变换等多种纹理特征提取技术。在此基础上,构建了基于传统特征工程的分类器模型以及融合深度学习的混合模型,并通过在公开数据集上的实验验证其分割性能,采用Dice系数、敏感度、特异度等指标进行全面评估。研究还剖析了当前面临的关键挑战,如高质量标注数据稀缺、模型泛化能力受限、可解释性不足以及肿瘤边界模糊等问题,进一步提出了结合半监督学习、多任务学习、模型可解释性增强及多模态信息深度融合等未来发展方向,为提升脑肿瘤自动分割的精度与临床实用性提供了系统的理论依据和技术路径。; 适合人群:具备医学图像处理或机器学习基础知识,从事生物医学工程、人工智能辅助诊断、计算机视觉等相关领域的科研人员及研究生。; 使用场景及目标:①掌握多模态MRI脑肿瘤分割中的关键技术流程与核心算法;②深入理解监督体素与纹理特征在医学图像分割中的具体应用价值;③为研发高精度、强可解释性的自动化脑肿瘤分割系统提供方法参考与技术支持。; 阅读建议:建议结合提供的Matlab代码实现同步学习,重点关注纹理特征提取与模型构建部分,动手复现实验过程以深化理解,同时重视数据预处理与结果评估环节,全面提升科研实践与创新能力。

产业园区如何借助数字化平台优化技术资源对接?.docx

科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。

LEACH与HEED的比较分析研究(Matlab代码实现)

内容概要:本文围绕LEACH与HEED两种无线传感器网络(WSN)中的经典路由协议展开深入的比较分析研究,系统探讨了二者在能耗均衡性、网络寿命、簇头选举机制、数据传输效率等关键性能指标上的差异。通过Matlab构建仿真模型,对比分析不同网络规模、节点密度及初始能量配置下的协议表现,揭示各自的优势与局限性,为相关领域的研究人员提供技术选型依据和算法优化方向。研究特别强调了在仿真过程中参数设置的科学性与实验结果可重复性的重要性。; 适合人群:具备无线传感器网络基本理论知识,熟悉Matlab编程环境,正在从事物联网、通信工程、嵌入式系统等相关领域研究的科研人员及高校研究生。; 使用场景及目标:①深入理解LEACH与HEED协议的核心工作机制及其适用条件;②通过仿真实验定量对比不同路由算法的性能优劣;③为WSN路由协议的进一步优化或新型协议的设计提供可靠的参考基准和验证平台。; 阅读建议:建议读者结合文中提供的Matlab代码进行逐行调试与运行,深刻领会协议的实现细节,并主动调整网络参数(如节点数量、能量阈值、轮数等)观察其对网络性能的影响,从而有效提升自身的实践动手能力和科研创新能力。

政府科技管理部门如何提升科技服务的智能化水平?.docx

科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。

科技服务机构如何提升服务专业性与效率?.docx

科技服务机构如何提升服务专业性与效率?

边缘计算与嵌入式AI应用实战 TFLite Micro STM32 推理骨架、int8 量化脚本(可运行)

边缘计算与嵌入式AI应用实战 TFLite Micro STM32 推理骨架、int8 量化脚本(可运行)

政府科技管理部门如何实现科技服务资源统筹?.docx

政府科技管理部门如何实现科技服务资源统筹?

科技中介机构如何提升服务的专业性与效率?.docx

科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。

科技中介如何通过数智平台提升服务效率与专业性?.docx

科技中介如何通过数智平台提升服务效率与专业性?

Java 微服务架构实战Seata 事务、Sentinel 规则、ShardingSphere、CI/CD

Java 微服务架构实战Seata 事务、Sentinel 规则、ShardingSphere、CI/CD

科技成果转化效率低如何解决?.docx

科技成果转化效率低如何解决?

上一篇: 重拾VB6(21): OLE Drag and Drop
下一篇: 重拾VB6(23):Fonts, Print, Format, and Selected Text
slowgrace
博客等级 码龄18年 4613粉丝 205原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值