I'm using below code to intract with the POP-Up/Message from webpage.
hWND = FindWindow(vbNullString, "Message from webpage")
hWND <> 0 Then childHWND = FindWindowEx(hWND, ByVal 0&, "Button", "OK")
If childHWND <> 0 Then SendMessage childHWND, BM_CLICK, 0, 0
The POP up displays a value, such as "CGPA : 10", I wish to save that text ("CGPA : 10") in a variable.
I'm coding in VBA.
Might suggest getting something either like Selnium or Playwright that will drive and test web based application. The main problem i'm seeing you are doing FindwindowEx and the native Win32 api's are for Win32 native apps and not web applications as Selenium and Playwright are. Either of them would be the right way to go.
Related
I got my project 95% done but a small issue remains. My code, run from a user form, opens a PDF document with its first line, identifies its window in the second and moves and resizes that window in the third.
ActiveWorkbook.FollowHyperlink Mail(0) & Mail(Me.Tag)
Wnd = FindWindow(vbNullString, AcrobatWindowID(Mail(Me.Tag)))
SetWindowPos Wnd, HWND_TOP, 1950, 10, 1100, 1300, SWP_NOACTIVATE
At the end of this operation the user form is dimmed out. The focus seems to remain with the PDF. That doesn't really matter because the form is fully developed and I can click on it or the PDF to activate either, just the way I wanted.
Nevertheless I tried to give the focus to the form and then to a particular control. I succeeded in finding the Excel window but failed to set the focus on the form, not to mention the control. In fact, I don't know how to check if I succeeded in setting the focus on the Excel window. I used this code in my attempt of whose syntax I'm not sure.
Public Const SWP_NOMOVE = &H2 ' ignore cx and cy
Public Const SWP_NOSIZE = &H1 ' ignore X and Y
SetWindowPos Wnd, HWND_TOP, 0, 0, 0, 0, (SWP_NOMOVE + SWP_NOSIZE)
Anyway, the form remains dimmed out. Does anyone have advice for me?
In order to obtain the form handler, you should proceed in this way:
Use API GetActiveWindow and create a Private variable on top of the form code module (in the declarations area):
Option Explicit
Private Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr
Private frmHwnd as LongPtr
Insert the next code line in the UserForm_Initialize event:
frmHwnd = GetActiveWindow
I have dialed a number using tapirequestmakecall function using Excel VBA.
https://msdn.microsoft.com/en-us/library/ms737210(v=vs.85).aspx
Declare Function tapiRequestMakeCall Lib "tapi32.dll" _
(ByVal stNumber As String, ByVal stDummy1 As String, _
ByVal stDummy2 As String, ByVal stDummy3 As String) As Long
Sub DialNumber(Number As String)
Dim lngStatus As Long
lngStatus = tapiRequestMakeCall(Number, "", "", "")
If lngStatus < 0 Then
MsgBox "Failed to dial number " & Number, vbExclamation
End If
End Sub
I have to transfer the call to extension like 100 after call is connected.
How to do this? Am using TAPI 2.2. Any help would be highly appreciated..
As far as I'm aware, this is not possible. The built-in office TAPI integration is only intended for making an outgoing call with a "1st party"-TAPI driver (a subset of drivers intended for single extension use). Office also limits the access to the API (for "easy" use), hence you do not have access to the normal output of a dial action (= the handle of the created call, to perform further actions).
I would suggest you do not use the built-in office methods but build directly on TAPI (tapi32.dll) itself. Unfortunately, that is a considerably more difficult job.
I'm developing an application from which I want to send EMail. When I click button/menu Outlook Sendmail window displays properly.
When I open Address Book, the dialog displays properly but the title of the dialog dispalys only "S".
Actually that title has to be displayed as " Selected Names: ... ".
Code:
HWND hWnd = this->GetSafeHwnd();
MAPIINIT_0 tMapInit = { 0, MAPI_MULTITHREAD_NOTIFICATIONS };
HRESULT hResult = MAPIInitialize( &tMapInit );
HMODULE hMapiMod = LoadLibrary(_T("mapi32.dll"));
ProcMapiLogon = (LPMAPILOGON)GetProcAddress( hMapiMod, "MAPILogon" );
(ProcMapiLogon)( (ULONG)hWnd, NULL, NULL, MAPI_LOGON_UI | MAPI_NEW_SESSION, 0, &hCurrentSession );
LPMAPISENDMAIL ProcMapiSendMail = NULL;
ProcMapiSendMail = (LPMAPISENDMAIL)GetProcAddress(hMapiMod, "MAPISendMail");
(ProcMapiSendMail)(hCurrentSession, (ULONG)hWnd, &myMsg, MAPI_DIALOG | MAPI_LOGON_UI, 0);
Note: This applicaion is build in command prompt with unicode flag _UNICODE set and the compiler is Visual Studio 2008.
Kindly help me to fix the problem.
Thanks in Advance.
Simple MAPI functions only work with ANSI strings. Also keep in mind that it is never a good idea to rely on conditional compile when interfacing with Simple or Extended MAPI. Always specify the string flavor (ANSI vs wide string) explicitly in your code.
If I use the code shown below on a vb.net winform the cue banner / watermark appears and behaves as expected (Win7 Pro 32bit VS2008 & 64bit VS2010). However when using the same style of code in a vb.net usercontrol the watermark is not displayed. Anyone got any clues?
Some hours later... This is looking like PEBKAC. Works in a test app. with user controls. Both those created at design time and those loaded at run-time, still doesn't work in the main app. though. Still puzzled. Still looking for a clue.
' Call from form / usercontrol load event handler.
Userhint.WatermarkSet(textbox1, "Some arbitrary text.")
' Noddy library class.
Friend Class Userhint
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>_
Private Shared Function SendMessage(ByVal hWnd As HandleRef, _
ByVal Msg As UInteger, _
ByVal wParam As IntPtr, _
ByVal lParam As String) As IntPtr
End Function
Public Shared Sub WatermarkSet(ByVal ctl As Control, _
byval hintText as string)
const EM_SETCUEBANNER as int32 = &h1501
dim retainOnFocus As IntPtr = new IntPtr(1)
SendMessage(New HandleRef(ctl, ctl.Handle), _
EM_SETCUEBANNER, _
retainOnFocus, _
hintText)
End sub
End Class
Not so much PEBKAC as yet another instance of M$ not documenting things as well as they might.
The short answer is to call Application.EnableVisualStyles() before the Run method.
Application.EnableVisualStyles()
Application.Run()
See questions/7518894/sendmessage-doesnt-work-in-one-project on this site for more info.
Is it possible, without an insane amount of work, to customize to location of the FolderBrowserDialog when it appears? I was hoping for the ability to position it at the left upper corner of the main form of my application.
Hoping for something like this:
Private Sub but_OpenFolderBrowser_MoveTo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_OpenFolderBrowser_MoveTo.Click
'Set up the folder browser
'Set description
Me.folderBrowser.Description = "Select the directory:"
'Set starting location on screen
Me.folderBrowser.Location = Me.Location
Unfortunately I realized that this property is not available and probably not feasible.
Anyone have a solution?