VB6中的HWND与VB.NET的Handle有区别吗?

hwshws123 2004-12-11 11:40:22
VB6中的HWND与VB.NET的Handle有区别吗?
...全文
127 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
allanli 2004-12-12
  • 打赏
  • 举报
回复
有什么区别就要看他们代表的是什么了(都是指针的值,看指向什么对象的地址)
Private Declare Function capCreateCaptureWindow Lib "avicap32.dll" _ Alias "capCreateCaptureWindowA" ( _ ByVal lpszWindowName As String, _ ByVal dwStyle As Long, _ ByVal x As Long, _ ByVal y As Long, _ ByVal nWidth As Long, _ ByVal nHeight As Long, _ ByVal hWndParent As Long, _ ByVal nID As Long) As Long Private Const WS_CHILD = &H40000000 Private Const WS_VISIBLE = &H10000000 Private Const WM_USER = &H400 Private Const WM_CAP_START = &H400 Private Const WM_CAP_EDIT_COPY = (WM_CAP_START + 30) Private Const WM_CAP_DRIVER_CONNECT = (WM_CAP_START + 10) Private Const WM_CAP_SET_PREVIEWRATE = (WM_CAP_START + 52) Private Const WM_CAP_SET_OVERLAY = (WM_CAP_START + 51) Private Const WM_CAP_SET_PREVIEW = (WM_CAP_START + 50) Private Const WM_CAP_DRIVER_DISCONNECT = (WM_CAP_START + 11) Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" ( _ ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Preview_Handle As Long Public Function CreateCaptureWindow( _ hWndParent As Long, _ Optional x As Long = 0, _ Optional y As Long = 0, _ Optional nWidth As Long = 320, _ Optional nHeight As Long = 240, _ Optional ncameraid As Long = 0) As Long Preview_Handle = capCreateCaptureWindow("Video", _ WS_CHILD + WS_VISIBLE, x, y, _ nWidth, nHeight, hWndParent, 1) SendMessage Preview_Handle, WM_CAP_DRIVER_CONNECT, ncameraid, 0 SendMessage Preview_Handle, WM_CAP_SET_PREVIEWRATE, 30, 0 SendMessage Preview_Handle, WM_CAP_SET_OVERLAY, 1, 0 SendMessage Preview_Handle, WM_CAP_SET_PREVIEW, 1, 0 CreateCaptureWindow = Preview_Handle End Function Public Function CapturePicture(ncapturehandle As Long) As StdPicture Clipboard.Clear SendMessage ncapturehandle, WM_CAP_EDIT_COPY, 0, 0 Set CapturePicture = Clipboard.GetData End Function Public Sub Disconnect(ncapturehandle As Long, _ Optional ncameraid = 0) SendMessage ncapturehandle, WM_CAP_DRIVER_DISCONNECT, _ ncameraid, 0 End Sub Dim video_handle As Long Private Sub form_load() Me.Top = 840 Me.Left = 11240 Me.Width = 4800 Me.Height = 4380 On Error Resume Next video_handle = CreateCaptureWindow(Form1.hWnd) End Sub Private Sub Command1_Click() 员工信息.Enabled = True On Error Resume Next If Dir$("D:\kkk.jpg") <> "" Then Kill "D:\kkk.jpg" End If Dim x As StdPicture Set x = CapturePicture(video_handle) SavePicture x, "D:\kkk.jpg" Disconnect (video_handle) video_handle = 0 Unload Form1 员工信息.SetFocus If Dir$("D:\kkk.jpg") = "" Then MsgBox "请先采集照片!" Command1.SetFocus Else Set 员工信息.Image1.Picture = LoadPicture("D:\kkk.jpg") Text1.Text = "" Clipboard.Clear End If Unload Me End Sub
可用来在VB,VC驱动摄像头,进行静帧捕捉的DLL动态链接库(必须要有摄像头生成StillCap0000.bmp):将MyDll文件解压后把MyDll.dll与MyDll.lib一起拷入工程DEBUG目录(为保险起见DEBUG的外层目录也拷贝一份吧),另有一个VC++6的测试工程test_Dll,已经考入相应DLL和LIB文件,可直接编译运行,VB只拷贝MyDll.dll与MyDll.lib VB2008 调用方法,在公共模块声名: Public Declare Function CreateWnd Lib "MyDll" () As Double Public Declare Function ClearGraphs Lib "MyDll" () As Double Public Declare Function OnpStillCapture Lib "MyDll" (ByVal hwnd As Long) As Double Public Declare Function InitStillGraph Lib "MyDll" (ByVal hwnd As Long) As Double Public Declare Function CloseWnd Lib "MyDll" () As Double 在窗体上放置2个PictureBox控件,名字为:pic1,pic2 放置三个按键:名字为Btn1,Btn2,Btn3 Btn1为打开视频,调用代码: Private Sub Btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn1.Click InitStillGraph(pic1.Handle) '打开摄像头预览视频 end sub Btn2为截取视频保存为BMP,文件保存在应用程序路径下,调用代码: Private Sub Btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn2.Click OnpStillCapture(pic2.Handle) '截取预览视频一帧图像 end sub Btn3为截取视频保存为清除内存,调用代码: Private Sub Btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn3.Click ClearGraphs() '退出前,完成内存清扫工 end sub VC调用方法: 在对话框上放置两个图像框,类型为位图,三个按键B1,B2,B3 定义全局函数引用: typedef HWND(* CreateWnd)(void);// typedef HRESULT(* InitStillGraph)(HWND hwnd); typedef void (* OnpStillCapture)(HWND hwnd); typedef int (* ClearGraphs)(); HINSTANCE glibsample; //如果定义成HANDLE类型,则出错 CreateWnd createwnd; InitStillGraph initStillGraph;//定义引用函数 OnpStillCapture onpStillCapture;//定义引用函数 ClearGraphs clearGraphs;//定义引用函数 用类向导为两个位图框建立控件(类型为Contorl)变量,m_p1,m_2 : 在窗口OnInitDialog()函数调整图像框大小: // TODO: Add your specialized code here and/or call the base class m_p1.MoveWindow(0,0,200,200,true); m_p2.MoveWindow(210,0,200,200,true); glibsample=LoadLibrary("MyDll.dll"); //加载dll 在B1消息函数: void 你的类::OnB1() { initStillGraph=(InitStillGraph)GetProcAddress(glibsample,"InitStillGraph"); (*initStillGraph)(m_p1.m_hWnd);//预览图像 } 在B2消息函数: void 你的类::O
1 , docudel.zip
This example shows how to clear the document history on the start menu.
2 , BatteryAPIdemo.zip
This example demonstrates how to "To get information about the battery status with out having to use the SysInfo.ocx from MS"
3 , DisableXexam.zip
This example easily demonstrates how to remove the "X" from your forms.
4 , manc-sleep.zip
This example demonstrates how to pause for a specified duration in seconds using the 'Sleep' win32 API function.
5 , camp-api.zip
An example of editing the "win.ini" file to execute programs when Windows loads.
6 , win32api.exe
This will install the Win32API.txt on your system. This file holds all API declarations for Windows. Must 下载.
7 , transparentblt.zip
This demonstrates how to display an image transparently on the form. An excellent example.
8 , MessageBoxDemo.zip
Manipulate Message Boxes using API. These include a self-closing message box, and a form-centered message box.
9 , menucol.zip
This shows how to add "columns" to your menus. An excellent example.
10 , changeborder.zip
Have you ever wanted to change the border style during runtime? Now you can using SetWindowLong. This example demonstrates greatly how you can accomplish this.
11 , capmousedemo.zip
This example demonstrates how to Set capture on the mouse to detect when it enters and leaves a specific portion of your form.
12 , apilines.zip
This example demonstrates how to draw lines using API.
13 , killapp.zip
This is a bas file to close any window with just it's caption.
14 , combohgt.zip
This demonstrates how to change the height of a combobox's drop-down height using API.
15 , bat-os.zip
This demonstrates how to retrieve information about Battery Powered machines.
16 , display.zip
This will open the Screen Resolution Dialog so you can manipulate it.
17 , ciasystray.zip
This shows you how to add your icon to the system tray without any third-party controls.
18 , taskbar.zip
This demonstrates how to Hide and Show the taskbar.
19 , wpchanger.zip
This shows how to change Windows' Desktop Wallpaper
20 , discad.zip
This shows how to disable control alt and delete by tricking the computer into thinking that the screensaver is running.
21 , windowfrompoint.zip
Get a window's handle from the current cursor position.
22 , api.zip
api function collection
23 , benchmark.zip
This program is very usefull program which gets the details of your computer and have an ability of changing some system details.
24 , menustructure.zip
This program will retrieve the full menu structure of a Form, up to three levels, and allow the user to modify it.
25 , crackPassword.zip
This is a very unusual program which will let you read behind those ******* in password fields and recover captions from Dialogs, Labels, Command Buttons, TextBoxes...
26 , hotkey_source.zip
Hotkey Manager Beta Version: Manages and implements hotkey in Windows 95/98/NT.
27 , rjsoftapisamples.zip
The samples included in this project use the few API
28,sysmetrics.zip
This is a windows information viewer. You can use this sample to find or select an open window, and view information about the window, such as its hwnd, size, and parent window.
29,launcher.zip
This is an ActiveX DLL that causes a client app to wait for another app to finish. The library takes care of launching the new app and doing all of the synchronization. It also returns the exit code for the process.
30,servcont.zip
It enables you to start and stop NT Services through the Win32 API, change the startup type and the security account associated with it. Included is a test harness so that people can see how it works. The code has been tested under NT4 SP6a
31,passdemo.zip
This is a very good example of how to use the registry to save data. It shows how to create, store and save a password to the registry and also encrypts it to keep out prying eyes.
32,delay.zip
This is a rough translation of the GetTickCount API and includes three different ways to pause an application.
33,cdromsystray.zip
This excellent program which was sent to us annoymously adds an icon to the systray (bottom right on the start menu bar) and allows you to control the opening and closing of the CDROM.. Easily adaptable, and if you wrote this and want to be credited
34,rgbdemo.zip
Very small, very fast. Complete source included to demonstrate how to translate a long to red, green and blue values
35,sleep2.zip
This is a small project showing how to use the Sleep API call from within your program to pause for a set period of time. Its much better than looping round as it uses very little CPU time
36,threads.zip
This application is only used to show how a multithreaded program is structured through the 'eyes' of VB. If you follow the logic of the program it does teach a lot about multithreading and the necessary techniques to do this in a 'Thread Safe environmen
37,callback.zip
This small project is for the more advanced VB users and shows an undocumented VB function and an undocumented Win32 API function. Demonstrated in the project how to use these two functions in order to raise events in a class from a module
38,ctaskmanager.zip
This application contains the same basic functionality as the task manager in Windows. It allows you to see the loaded windows on your system as well as the class, position and process ID for each window. Remember that every process running on a system
39,cprocessfinished.zip
This little routine will test if a shelled process has finished executing and return true or false. Its bits of code like that we would like more of, so please send them.
40,apimsg.zip
API Message Box
41,freespc.zip
Get a Drive's Free Space
42,drvinfo.zip
Get Drive Information (S/N, Label, Format)
43,nodisk.zip
Show Message When There is No Disk in a Drive
44,fullpath.zip
Add Full Paths to a TreeView
45,disksrch.zip
Search for Disk in a Removable Drive
46,drvtype.zip
Determine Drive Type
47,findcd1.zip
Find the First CD-ROM
48,xxsShell32.zip
Shell32 functions and subs wrapper for VB developers.
49,api2.zip
This application is designed to help VB Developer to find Windows API Easely.
50,qsvb.zip
QuickSilver for Visual Basic, aims to provide a wrapper for all important Windows API functions by a simple class. All the operations are included as properties and methods that can used with the same ease as any other part of your dream project.
51,CPUInfo.zip
This code will quickly tell you a lot of your system information like computer name, IP address, OS, Service Pack, Processor Vendor, Processor Type, Processor Speed (Raw and Normal), RAM (Total and Available).
52,Callbacks.zip
It is nice little application, which demonstrates WinAPI Callbacks. It hides and restors all Yahoo chatting window in a single click.
53,ShellTrayIcon.zip
The CShellTrayIcon class allows your VB application to set, change and delete icons in the system's tray (note: the official term for the tray is the taskbar notification area). The class raises an event in your application when the user clicks an icon in the tray.
54,EventCtl.zip
This little control greatly simplifies the business of subclassing a form to get at the extra events that the Visual basic designers left out. i.e.:
55,EuroCalc2.zip
In place conversion between every one of the European Monetary Union member currencies and the Euro.
56,Edge.zip
In my program i have used few API functions to set 3D,Sunken,etched effects to the images of your image control.Another example shows how to change your label control to a 3D command button almost functionally.
57,Prjfloat.zip
I have used two APIFuctions 'Setwindowword' and 'Setparent' to make the child window float
freely and with in the parent window. Open with vb5 and vb6.
58,FilterTextBox.zip
This program shows how to filter out characters from TextBox control.Uses GetWindowLong and SetWindowLong APIs.
59,SysControl.zip
This is a program that will let you show, hide, alter text, capture a picture, change the parent, kill, close, enable, disable, get info on, minimize, maximize, restore, capture a picture of, make them stay-on-top, send a message to, edit the window style, and flash the title bar on almost any target!
60,LBApi.zip
This program uses Sendmessage API function for additem,removeitem,clear,selcount,listcount etc, with a horizontal scroll bar.(List/combo)
61,winnanny.zip
U can use Winnanny to restrict unauthorised people from running programs u don't want them to on your pc .It Uses simple api functions to do this.
62,ReadWriteIni.zip
Creates .ini file, writes to it and reads from it. Demo project shows how to write usernames and passwords. For clarity's sake I made it write user color preferences.
63,capture.zip
This program captures the active window and displays it to a Picture box.
64,TransIco.zip
An update to my previous code : Added a couple of features some ppl asked me for...like the ability to change the text colour of the icon and also keep the background transparent after a desktop refresh.
65,shutdown.zip
Shut Down Windows with Windows Shutdown Dialog.This is the real thing , not Kill , It is a real API Call, I hope you find it useful.
66,alarm.zip
A VB alarm clock.
67,clcViewWinInfo.zip
ViewWinInfo is a windows information viewer. You can use this sample to find or select an open window, and view information about the window, such as its hwnd, size, and parent window.
68,ptinrect.zip
Use the PtInRect API function to create an annoying program.
69,fliphorizvert.zip
Flips a picture using the StretchBlt API function.
70,animation.zip
Use BitBlt to crate flickerless animation
'窗体:______________ '声明:Public LastState As Integer '为图标定义窗体信息 '使用前: 'If WindowState = vbMinimized Then ' LastState = vbNormal 'Else ' LastState = WindowState 'End If '使用: 'AddToTray Me, mnuTray '加载图标 'SetTrayTip "VB Helper tray icon program" '图标标签 'RemoveFromTray'卸载图标 '模板:_________ Option Explicit Public OldWindowProc As Long Public TheForm As Form Public TheMenu As Menu Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long Public Const WM_USER = &H400 Public Const WM_LBUTTONUP = &H202 Public Const WM_MBUTTONUP = &H208 Public Const WM_RBUTTONUP = &H205 Public Const TRAY_CALLBACK = (WM_USER + 1001&) Public Const GWL_WNDPROC = (-4) Public Const GWL_USERDATA = (-21) Public Const NIF_ICON = &H2 Public Const NIF_TIP = &H4 Public Const NIM_ADD = &H0 Public Const NIF_MESSAGE = &H1 Public Const NIM_MODIFY = &H1 Public Const NIM_DELETE = &H2 Public Type NOTIFYICONDATA cbSize As Long hwnd As Long uID As Long uFlags As Long uCallbackMessage As Long hIcon As Long szTip As String * 64 End Type Private TheData As NOTIFYICONDATA ' ********************************************* ' The replacement window proc. ' ********************************************* Public Function NewWindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long If Msg = TRAY_CALLBACK Then ' The user clicked on the tray icon. ' Look for click events. If lParam = WM_LBUTTONUP Then '左击 ' On left click, show the form. If TheForm.WindowState = vbMinimized Then _ TheForm.WindowState = TheForm.LastState TheForm.SetFocus Exit Function End If If lParam = WM_RBUTTONUP Then '右 ' On right click, show the menu. TheForm.PopupMenu TheMenu Exit Function End If End If ' Send other messages to the original ' window proc. NewWindowProc = CallWindowProc( _ OldWindowProc, hwnd, Msg, _ wParam, lParam) End Function ' ********************************************* ' Add the form's icon to the tray. ' ********************************************* Public Sub AddToTray(frm As Form, mnu As Menu) ' ShowInTaskbar must be set to False at ' design time because it is read-only at ' run time. ' Save the form and menu for later use. Set TheForm = frm Set TheMenu = mnu ' Install the new WindowProc. OldWindowProc = SetWindowLong(frm.hwnd, _ GWL_WNDPROC, AddressOf NewWindowProc) ' Install the form's icon in the tray. With TheData .uID = 0 .hwnd = frm.hwnd .cbSize = Len(TheData) .hIcon = frm.Icon.Handle .uFlags = NIF_ICON .uCallbackMessage = TRAY_CALLBACK .uFlags = .uFlags Or NIF_MESSAGE .cbSize = Len(TheData) End With Shell_NotifyIcon NIM_ADD, TheData End Sub ' ********************************************* ' Remove the icon from the system tray. ' ********************************************* Public Sub RemoveFromTray() ' Remove the icon from the tray. With TheData .uFlags = 0 End With Shell_NotifyIcon NIM_DELETE, TheData ' Restore the original window proc. SetWindowLong TheForm.hwnd, GWL_WNDPROC, _ OldWindowProc End Sub ' ********************************************* ' Set a new tray tip. ' ********************************************* Public Sub SetTrayTip(tip As String) With TheData .szTip = tip & vbNullChar .uFlags = NIF_TIP End With Shell_NotifyIcon NIM_MODIFY, TheData End Sub ' ********************************************* ' Set a new tray icon. ' ********************************************* Public Sub SetTrayIcon(pic As Picture) ' Do nothing if the picture is not an icon. If pic.Type <> vbPicTypeIcon Then Exit Sub ' Update the tray icon. With TheData .hIcon = pic.Handle .uFlags = NIF_ICON End With Shell_NotifyIcon NIM_MODIFY, TheData End Sub

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧