教程中国
PHOTOSHOP CS9.0中文版 MAYA 8.5 FOR WINDOWS Corel Painter v9.0 Flash MX2004 中文版 Illustrator cs2 中文版
VC++6.0含sp6 中英文版 VB6.0 +sp6 简体中文版 Borland Delphi 7汉化版 MSDN for vb6.0中文版 Visual Studio 2005简体
教程中国下属 文件存储共享专家BIBIDU.COM 提供大型软件,教材,源码,电影,音乐,图书等下载 更多精品请点此进入
  您目前所在位置: 教程中国 >> VB >> 编程实例 >> VB 使用API创建窗体 RSS订阅
VB 使用API创建窗体
VB 使用API创建窗体(2)
教程(视频,书籍)下载:  ASP.NET AutoCAD 数据库 C# ASP java photoshop 网页设计 delphi 3dmax Flash C++ VB 张孝祥 实例   更多请进入BIBIDU搜索
IT搜索引擎   
Public Const MB_ICONEXCLAMATION = &H30&

声明几个我们需要的变量、常量:

Public Const gClassName = "MyClassName"
Public Const gAppName = "My Window Caption"

Public gButOldProc As Long
Public gHwnd As Long, gButtonHwnd As Long, gEditHwnd As Long

入口函数:

Sub Main

代码如下:

Public Sub Main()

   Dim wMsg As Msg

   ''Call procedure to register window classname. If false, then exit.
   If RegisterWindowClass = False Then Exit Sub
    
      ''Create window
      If CreateWindows Then
         ''Loop will exit when WM_QUIT is sent to the window.
         Do While GetMessage(wMsg, 0&, 0&, 0&)
            ''TranslateMessage takes keyboard messages and converts
            ''them to WM_CHAR for easier processing.
            Call TranslateMessage(wMsg)
            ''Dispatchmessage calls the default window procedure
            ''to process the window message. (WndProc)
            Call DispatchMessage(wMsg)
         Loop
      End If

    Call UnregisterClass(gClassName$, App.hInstance)


End Sub

Public Function RegisterWindowClass() As Boolean

    Dim wc As WNDCLASS
    
    
    wc.style = CS_HREDRAW Or CS_VREDRAW
    wc.lpfnwndproc = GetAddress(AddressOf WndProc) ''Address in memory of default window procedure.
    wc.hInstance = App.hInstance
    wc.hIcon = LoadIcon(0&, IDI_APPLICATION) ''Default application icon
    wc.hCursor = LoadCursor(0&, IDC_ARROW) ''Default arrow
    wc.hbrBackground = COLOR_WINDOW ''Default a color for window.
    wc.lpszClassName = gClassName$

    RegisterWindowClass = RegisterClass(wc) <> 0
    
End Function
Public Function CreateWindows() As Boolean
  
    ''开始创建窗体

主窗体.
    gHwnd& = CreateWindowEx(0&, gClassName$, gAppName$, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 208, 150, 0&, 0&, App.hInstance, ByVal 0&)
    ''创建一个按钮
    gButtonHwnd& = CreateWindowEx(0&, "Button", "Click Here", WS_CHILD, 58, 90, 85, 25, gHwnd&, 0&, App.hInstance, 0&)
    ''创建一个(WS_EX_CLIENTEDGE、ES_MULTILINE风格的TextBox
    gEditHwnd& = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "This is the edit control." & vbCrLf & "As you can see, it's multiline.", WS_CHILD Or ES_MULTILINE, 0&, 0&, 200, 80, gHwnd&, 0&, App.hInstance, 0&)

"Button ","Edit"系统中已经注册过了所以这里直接用
    创建完别忘了显示出来否则是隐藏的

    Call ShowWindow(gHwnd&, SW_SHOWNORMAL)
    Call ShowWindow(gButtonHwnd&, SW_SHOWNORMAL)
    Call ShowWindow(gEditHwnd&, SW_SHOWNORMAL)

记下按钮处理过错的当前所在地址    

gButOldProc& = GetWindowLong(gButtonHwnd&, GWL_WNDPROC)
    
    
    ''Set default window procedure of button to ButtonWndProc. Different
    ''settings of windows is listed in the MSDN Library. We are using GWL_WNDPROC
    ''to set the address of the window procedure.

指向新的处理过程地址
    Call SetWindowLong(gButtonHwnd&, GWL_WNDPROC, GetAddress(AddressOf ButtonWndProc))

    CreateWindows = (gHwnd& <> 0)
    
End Function

'窗体运行的主函数,在注册这个窗体时已经指定的
Public Function WndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

    Dim strTemp As String

处理消息,这里指处理了WM_DESTROY消息

    Select Case uMsg&
       Case WM_DESTROY:
          ''Since DefWindowProc doesn't automatically call
          ''PostQuitMessage (WM_QUIT). We need to do it ourselves.

来源:www.upschool.com.cn
作者:szyicol
关键字:VB,API创建窗体
发表日期:2007-2-9 17:12:21

网页显示有限 阅读全文请下载本文完整版WORD文档

上一篇:VB 列出SQL SERVER数据库中所有表及字段信息   下一篇:


共3页 9 7 [1] [2] [38 :>

本文的相类似文章
  • VB 使用API创建窗体
  • VB 列出SQL SERVER数据库中所有表及字段信息
  • 利用VB6.0设计屏幕保护程序
  • VB屏蔽ALT-TAB, ALT-ESC, CTRL-ESC,Win,Win+Any
  • VB 更改LISTVIEW的背景色
  • VB 获得操作系统的语言类型
  • VB 打开“我的电脑”
  • VB读出一个进程中所有的模块名和模块路径
  • 用VB创建开始菜单快捷方式(无需其他DLL)
  • VB 将域名转换成IP地址
  • 网友评论 查看本文全部评论
    笔 名: *
    评 论:
    最多500字。当前字数:0
    联系方式:
    验证码:
    在学习中进步 在进步中成长 教程中国相随您的成长之路
    华腾联合科技股份有限公司版权所有
    广告联系:Rosibo@163.com