'模块级变量
Dim Shared 全局变量 As Long '加个 shared 为全局变量
Dim Shared yMenu1 As HMENU '菜单
Dim Shared yMenu2 As HMENU '菜单
'--------------------------------------------------------------------------------
Sub Form1_Command1_BN_Clicked(hWndForm As hWnd, hWndControl As hWnd) '单击
Dim As Long i, a
Dim bb As String
'类方式 ==================================================================
List1.Clear ' 删除列表框中所有项目
For i = 1 To 10
bb = Str(Rnd)
Print bb '调试输出,只是看看 在DOS窗口显示,如果不要DOS,在工程属性里设置
a = List1.AddItem(bb) '将字符串添加到列表框控件
List1.ItemData(a) = i '设置与列表框中指定项目相关联的 32 位值。
Next
'函数方式 ===================================================================
'FF_ListBox_ResetContent HWND_FORM1_LIST1 '删除列表框中所有项目
'For i = 1 To 10
'bb = Str(Rnd)
'Print bb '调试输出,只是看看 在DOS窗口显示,如果不要DOS,在工程属性里设置
'a = FF_ListBox_AddString(HWND_FORM1_LIST1, bb) '将字符串添加到列表框控件
'FF_ListBox_SetItemData HWND_FORM1_LIST1, a, i '设置与列表框中指定项目相关联的 32 位值。
'Next
End Sub
Sub Form1_List1_LBN_SelChange(hWndForm As hWnd, hWndControl As hWnd) '选择了列表
Dim a As Long
'类方式 ==================================================================
a = Me.List1.ListIndex ' 返回一个列表框中的当前选定项的索引。多选时不能使用此函数。
If a <> - 1 Then
Me.Label1.Caption = Me.List1.List(a)
End If
'函数方式 ===================================================================
'a = FF_ListBox_GetCurSel(HWND_FORM1_LIST1) ' 返回一个列表框中的当前选定项的索引。多选时不能使用此函数。
'If a <> -1 Then
'FF_Control_SetText HWND_FORM1_LABEL1, FF_ListBox_GetText(HWND_FORM1_LIST1, a)
'End If
End Sub
Sub Form1_Command2_BN_Clicked(hWndForm As hWnd, hWndControl As hWnd) '单击
Form2.Show(hWndForm, False) ' 普通显示窗口
End Sub
Sub Form1_Command3_BN_Clicked(hWndForm As hWnd, hWndControl As hWnd) '单击
Form2.Show(hWndForm, True) '模态显示窗口
End Sub
Sub Form1_Command4_BN_Clicked(hWndForm As hWnd, hWndControl As hWnd) '单击
Me.Caption = "窗口更名"
End Sub
Sub Form1_Command5_BN_Clicked(hWndForm As hWnd, hWndControl As hWnd) '单击
全局变量 + = 1
'FF_Control_SetText HWND_FORM1_COMMAND5, Str(全局变量) '函数方式与类方式都可以用
Me.Command5.Caption = Str(全局变量)
End Sub
Sub Form1_Command6_BN_Clicked(hWndForm As hWnd, hWndControl As hWnd) '单击
AfxMsg "自动随窗口大小改变位置" & vbCrLf & "在控件属性【ResizeRule】里设置"
End Sub
Sub Form1_Command7_BN_Clicked(hWndForm As hWnd, hWndControl As hWnd) '单击
Dim P As Point
GetCursorPos @p '获取鼠标位置
TrackPopupMenu yMenu1, 0, p.x, p.y, 0, hWndForm, Null '在某位置说弹出菜单
End Sub
Sub Form1_WM_Create(hWndForm As hWnd, UserData As Integer) '完成创建窗口及所有的控件后,此时窗口还未显示。注:自定义消息里 WM_Create 此时还未创建控件和初始赋值。
yMenu1 = CreatePopupMenu() '这里演示的是代码创建菜单,当然还有 菜单控件可以使用。
yMenu2 = CreatePopupMenu()
AddMenu yMenu1, 10001, "复制选择内容", "COPY" '带图标
AppendMenu yMenu1, MF_SEPARATOR, 0, "" '分割线
AppendMenu yMenu1, MF_STRING, 10002, "选择当前内存区" '不需要图标
AddMenu yMenu1, 10004, "选择当前内存区", "" '不需要图标
AddMenu yMenu1, 10005, "选择当前模块", ""
AddMenu yMenu1, 10022, "保存选择到文件", ""
AppendMenu yMenu1, MF_POPUP, Cast(Integer, yMenu2), "子菜单"
AppendMenu yMenu2, MF_STRING, 10009, "我是子菜单"
List1.AddItem("1111")
List1.AddItem("222")
List1.AddItem("总打嗝")
List1.AddItem("1测试1")
list2.AddItem("")
list2.AddItem("")
list2.AddItem("")
End Sub
Sub Form1_WM_Size(hWndForm As hWnd, fwSizeType As Long, nWidth As Long, nHeight As Long) '窗口已经改变了大小
Command8.move nWidth - AfxScaleX(110), AfxScaleY(16)
'坐标以 左上角 为 0,0 开始,向右下角辐射为正值,单位为 像素
'AfxScaleX(x),AfxScaleY(y) 是为了支持高DPI,窗口都自动支持高DPI了的
End Sub
Sub Form1_Command8_BN_Clicked(hWndForm As hWnd, hWndControl As hWnd) '单击
'在工具菜单里,用 【对话框编辑】产生API 提示框 代码
Select Case MessageBox(hWndForm, "在主窗口大小事件里改变位置", "基础方法例题", _
MB_OK or MB_ICONINFORMATION or MB_DEFBUTTON1 or MB_APPLMODAL)
Case IDOK
End Select
End Sub
Sub Form1_Command9_BN_Clicked(hWndForm As hWnd, hWndControl As hWnd) '单击
list1.ItemHeight = AfxScaleY(15)
list1.Refresh()
End Sub
Function Form1_Picture1_WM_Paint(hWndForm As hWnd, hWndControl As hWnd) As LResult '重绘,系统通知控件需要重新绘画。
Dim nDC As hDC
Dim ps As PAINTSTRUCT
Dim As Long w, h, x, a
nDC = BeginPaint(hWndControl, @ps) '获取需要绘画DC,推荐此方法,绘图效率高
FF_Control_GetSize(hWndControl, w, h)
Dim pMemBmp As CMemBmp = CMemBmp(w, h) '创建内存DC,先画内存DC,加速画画速度,避免产生闪耀
'需要内存DC类,必须在 FF_AppStart 模块里加 #include Once "afx\CMemBmp.inc "
'自己画画
DrawFrame(pMemBmp.GetMemDC, 0, 0, w + 1, h + 1, & HFF80FF)
TextOut1(pMemBmp.GetMemDC, 10, 10, "漂亮的,个性的要自绘")
TextOut1(pMemBmp.GetMemDC, 10, 40, "自绘固定模式例题")
'自己画画完成
BitBlt ndc, 0, 0, w, h, pMemBmp.GetMemDC, 0, 0, SrcCopy '将内存DC,输出到控件