VB获取资源管理器地址栏内容

前端之家收集整理的这篇文章主要介绍了VB获取资源管理器地址栏内容前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

http://zhidao.baidu.com/question/84802747.html

VB如何获取窗口地址栏内容

就是比如我打开D盘的aaa文件夹,窗口地址栏就是显示D:/aaa,请问我要怎么用VB写程序来获取窗口地址栏的内容?(不是IE的地址栏)
若打开了两个窗口,比如D盘的aaa文件夹和E盘的bbb文件夹下的ccc文件夹都打开的话,点击command1,text1就显示
D:/aaa
E:/bbb/ccc
请大家帮忙下,谢谢!

@H_502_11@Private Const GW_HWNDNEXT = 2 Private Const GW_HWNDFIRST = 0 Private Const WM_GETTEXT = &HD Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long,ByVal wFlag As Long) As Long Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long,ByVal wCmd As Long) As Long Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long,ByVal lpClassName As String,ByVal nMaxCount As Long) As Long Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long,ByVal hWnd2 As Long,ByVal lpsz1 As String,ByVal lpsz2 As String) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long,ByVal wMsg As Long,ByVal wParam As Long,ByVal lParam As String) As Long Private Function GetWindowList() As String Dim hwnd As Long Dim s As String hwnd = Me.hwnd hwnd = GetWindow(hwnd,GW_HWNDFIRST) While hwnd <> 0 s = String(256,Chr(0)) GetClassName hwnd,s,255 s = Replace(s,Chr(0),"") If s = "CabinetWClass" Then GetWindowList = GetWindowList & GetUrl(hwnd) & vbCrLf End If hwnd = GetNextWindow(hwnd,GW_HWNDNEXT) Wend End Function Private Function GetUrl(hwnd As Long) As String Dim NexthWnd As Long Dim s As String NexthWnd = 0 NexthWnd = FindWindowEx(hwnd,NexthWnd,vbNullString,vbNullString) While NexthWnd <> 0 s = String(256,Chr(0)) GetClassName NexthWnd,"") If s = "Edit" Then s = String(256,Chr(0)) SendMessage NexthWnd,WM_GETTEXT,255,s s = Replace(s,"") GetUrl = s If Len(s) > 0 Then Exit Function Else GetUrl = GetUrl(NexthWnd) If Len(GetUrl) > 0 Then Exit Function End If NexthWnd = FindWindowEx(hwnd,vbNullString) Wend End Function Private Sub Command1_Click() text1.text=GetWindowList End Sub

http://www.programfan.com/club/showtxt.asp?id=215815

 第@H_301_18@4楼

我把程序贴出来给你看看吧:caseWM_CREATE:GetClientRect(hWnd,&wRect);//将程序窗口区域保存到结构变量wRect//建立复选框hButtonCi=CreateWindow(TEXT("BUTTON"),TEXT("圆"),BS_CHECKBox|WS_CHILD|WS_VISIBLE,wRect.left+50,wRect.bottom-80,75,25,hWnd,(HMENU)0,hInst,NULL);hButtonSq=CreateWindow(TEXT("BUTTON"),TEXT("矩形"),wRect.bottom-40,(HMENU)1,NULL);break;caseWM_COMMAND:if(LOWORD(lParam)==(long)hButtonCi){//读取复选框状态nCheck=(WORD)SendMessage(hButtonCi,BM_GETCHECK,0L);if(nCheck==TRUE)SendMessage(hButtonCi,BM_SETCHECK,0L);elseSendMessage(hButtonCi,1,0L);}elseif(LOWORD(lParam)==(long)hButtonSq){//读取复选框状态nCheck=(WORD)SendMessage(hButtonSq,0L);elseSendMessage(hButtonSq,0L);}InvalidateRect(hWnd,NULL,TRUE);break;wmId=LOWORD(wParam);wmEvent=HIWORD(wParam);//Parsethemenuselections:switch(wmId){caseIDM_ABOUT:DialogBox(hInst,MAKEINTRESOURCE(IDD_ABOUTBox),About);break;caseIDM_EXIT:DestroyWindow(hWnd);break;default:returnDefWindowProc(hWnd,message,wParam,lParam);}break;caseWM_SIZE:xc=LOWORD(lParam)/2;yc=HIWORD(lParam)/2;caseWM_PAINT:hdc=BeginPaint(hWnd,&ps);//TODO:Addanydrawingcodehere...//检查复选框以决定是否绘图nCheck=(WORD)SendMessage(hButtonCi,0L);if(nCheck==TRUE)Ellipse(hdc,xc-100,yc-100,xc+100,yc+100);nCheck=(WORD)SendMessage(hButtonSq,0L);if(nCheck==TRUE){MoveToEx(hdc,(LPPOINT)NULL);LineTo(hdc,yc-100);LineTo(hdc,yc+100);LineTo(hdc,yc-100);}EndPaint(hWnd,&ps);break;在后面的WM_SIZE中,控件句柄的值根本没有(与前面得到的句柄不一样),不知道是为什么?

猜你在找的VB相关文章