|
Thank you, I will try and let you know what I've done.
|
|
|
|
|
Now goes. Thanks.
modified 19-Oct-11 3:03am.
|
|
|
|
|
If you're trying to select a particular item from the list you can do this-
m_ListFeature.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
|
|
|
|
|
No, I don't want to select an specific item, just to make a virtual click on listcontrol.
|
|
|
|
|
Why? Since clicking has the effect of selecting an item selecting it as Superman suggested is superior.
Steve
|
|
|
|
|
I open an custom control on listcontrol and this custom control is hidden on clicked anywhere on list ... that's why I need click message and not select an specific item.
|
|
|
|
|
This is what I've come up with so far but need to find & add values to the form elements for user input and password input, then submit. I'm using C++Builder6.
#include <mshtml.h>
//
TComInterface<IHTMLDocument2>HTMLDoc;
Browser->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&HTMLDoc);
//get all the forms
TComInterface<IHTMLElementCollection>HTMLforms;
HTMLDoc->get_forms(&HTMLforms);
//Get form 0 since login pages have only one form
TComInterface<IHTMLFormElement>HTMLform;
//Get User,Password fields & set values
TComInterface<IHTMLElement>HTMLfield;
//Then submit form
HTMLform->submit();
Thanks!
|
|
|
|
|
I hope this Boland C++ Builder 6 code might work..
#include utilcls.h
#include Mshtml.h
template<class ParentIntf, class ItemIntf>
HRESULT __fastcall GetHTMLItem(ParentIntf *CollectionOrElement, const
WideString &name, ItemIntf** ppIntf)
{
TVariant vName = name;
TVariant vIndex = 0;
TComInterface disp;
HRESULT hRes = CollectionOrElement->item(vName, vIndex, &disp);
if( SUCCEEDED(hRes) )
hRes = disp->QueryInterface(__uuidof(ItemIntf),(LPVOID*)ppIntf);
return hRes;
}
void __fastcall TForm1::CppWebBrowser1DocumentComplete (TObject*
Sender, LPDISPATCH pDisp, TVariant *URL)
{
if( CppWebBrowser->Document )
{
TComInterface HTMLDoc;
if(SUCCEEDED(CppWebBrowser->Document->QueryInterface(
IID_IHTMLDocument2,(LPVOID*)&HTMLDoc) ) )
{
TComInterface forms;
if( SUCCEEDED(HTMLDoc->get_forms(&forms)) )
{
TComInterface form;
if( SUCCEEDED(GetHTMLItem(forms, "loginform", &form)) )
{
TComInterface userid;
TComInterface password;
GetHTMLItem(form, "userid", &userid);
GetHTMLItem(form, "password", &password);
if( userid )
userid->put_value(WideString("username"));
if( password )
password->put_value(WideString("password"));
}
}
}
}
}
I hope this Boland C++ Builder 6 code might work too..
bool TForm1::Login(char* inputname, const AnsiString& text)
{
bool done = false;
IHTMLDocument2* HTMLDoc = NULL;
if(SUCCEEDED(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&HTMLDoc)))
{
IHTMLElementCollection* pAll = NULL;
if(SUCCEEDED(HTMLDoc->get_all(&pAll)))
{
Variant name = inputname;
Variant index = 0;
IDispatch* pDisp = NULL;
if(SUCCEEDED(pAll->item(name, index, &pDisp)))
{
if ( pDisp )
{
IHTMLInputElement* pInput = NULL;
pDisp->QueryInterface(IID_IHTMLInputElement, (LPVOID*)&pInput);
pDisp->Release();
if(pInput)
{
pInput->put_value(WideString(text));
done = true;
pInput->Release();
}
}
}
pAll->Release();
}
HTMLDoc->Release();
}
return done;
}
|
|
|
|
|
/* Well I got this far I get 3 errors in the BrowserDocumentComplete event:
(C++ Error)BrowserFrm.cpp(53): E2285 Could not find match for 'TBrowserFrame::GetHTMLItem<ParentIntf>TComInterface<IHTMLElementCollection,&GUID_NULL>,char *,IHTMLFormElement * *)'
(C++ Error)BrowserFrm.cpp(58): E2285 Could not find match for 'TBrowserFrame::GetHTMLItem<ParentIntf>TComInterface<IHTMLFormElement,&GUID_NULL>,char *,IHTMLInputElement* *)'
(C++ Error)BrowserFrm.cpp(59): E2285 Could not find match for 'TBrowserFrame::GetHTMLItem<ParentIntf>TComInterface<IHTMLFormElement,&GUID_NULL>,char *,IHTMLInputElement* *)' */
//I marked the lines with the errors below:
//BrowserFrm.cpp
#include <vcl.h>
#pragma hdrstop
#include "BrowserFrm.h"
#include <utilcls.h>
#include <mshtml.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SHDocVw_OCX"
#pragma resource "*.dfm"
TBrowserFrame *BrowserFrame;
//---------------------------------------------------------------------------
__fastcall TBrowserFrame::TBrowserFrame(TComponent* Owner)
: TFrame(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TBrowserFrame::Go(AnsiString url)
{
Browser->Navigate(StringToOleStr(url),0,NULL,NULL,NULL);
}
//---------------------------------------------------------------------------
template<class ParentIntf, class ItemIntf>
HRESULT __fastcall TBrowserFrame::GetHTMLItem(ParentIntf *CollectionOrElement, const
WideString &name, ItemIntf** ppIntf)
{
TVariant vName = name;
TVariant vIndex = 0;
TComInterface disp;
HRESULT hRes = CollectionOrElement->item(vName, vIndex, &disp);
if( SUCCEEDED(hRes) )
hRes = disp->QueryInterface(__uuidof(ItemIntf),(LPVOID*)ppIntf);
return hRes;
}
//---------------------------------------------------------------------------
void __fastcall TBrowserFrame::BrowserDocumentComplete(TObject *Sender,
LPDISPATCH pDisp, Variant *URL)
{
if( Browser->Document )
{
TComInterface<IHTMLDocument2>HTMLDoc;
if(SUCCEEDED(Browser->Document->QueryInterface(
IID_IHTMLDocument2,(LPVOID*)&HTMLDoc) ) )
{
TComInterface<IHTMLElementCollection>forms;
if( SUCCEEDED(HTMLDoc->get_forms(&forms)) )
{
TComInterface<IHTMLFormElement>form;
/*Line 53 error*/ if( SUCCEEDED(GetHTMLItem(forms, "loginform", &form)) )
{
TComInterface<IHTMLInputElement>userid;
TComInterface<IHTMLInputElement>password;
/*Line 58 error*/ GetHTMLItem(form, "userid", &userid);
/*Line 59 error*/ GetHTMLItem(form, "password", &password);
if( userid )
{
userid->put_value(WideString("username"));
}
if( password )
{
password->put_value(WideString("password"));
}
form->submit();
}
}
}
}
}
//---------------------------------------------------------------------------
//BrowserFrm.h file
#ifndef BrowserFrmH
#define BrowserFrmH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "SHDocVw_OCX.h"
#include <OleCtrls.hpp>
#include <utilcls.h>
#include <mshtml.h>
//---------------------------------------------------------------------------
class TBrowserFrame : public TFrame
{
__published: // IDE-managed Components
TCppWebBrowser *Browser;
void __fastcall BrowserDocumentComplete(TObject *Sender,
LPDISPATCH pDisp, Variant *URL);
private: // User declarations
template<class ParentIntf, class ItemIntf>
HRESULT __fastcall GetHTMLItem(ParentIntf *CollectionOrElement, const
WideString &name, ItemIntf** ppIntf);
public: // User declarations
__fastcall TBrowserFrame(TComponent* Owner);
void __fastcall Go(AnsiString url);
};
//---------------------------------------------------------------------------
extern PACKAGE TBrowserFrame *BrowserFrame;
//---------------------------------------------------------------------------
#endif
-- modified 15-Oct-11 21:04pm.
|
|
|
|
|
Change this line:
HRESULT __fastcall GetHTMLItem(ParentIntf *CollectionOrElement, const WideString &name, ItemIntf** ppIntf)
To this:
HRESULT __fastcall GetHTMLItem(TComInterface<ParentIntf> &CollectionOrElement, const WideString &name, ItemIntf** ppIntf)
|
|
|
|
|
That Worked! It Fills the values but when I submit the form the web browser comes up with a dialog with a caption of: _ASSERTE: and Message of:
intf = 0 @ C:\Program Files\Borland\CBuilder6\Include\Vcl\utilcls.h/2916
Press[Y]es to terminate, [N]o to continue and [C]ancel to Debug
My code:
template<class ParentIntf, class ItemIntf>
HRESULT __fastcall TBrowserFrame::GetHTMLItem(TComInterface<ParentIntf> &CollectionOrElement, const WideString &name, ItemIntf** ppIntf)
{
TVariant vName = name;
TVariant vIndex = 0;
TComInterface<IDispatch>disp;
HRESULT hRes = CollectionOrElement->item(vName, vIndex, &disp);
if( SUCCEEDED(hRes) )
hRes = disp->QueryInterface(__uuidof(ItemIntf),(LPVOID*)ppIntf);
return hRes;
}
//---------------------------------------------------------------------------
void __fastcall TBrowserFrame::BrowserDocumentComplete(TObject *Sender,
LPDISPATCH pDisp, Variant *URL)
{
if( Browser->Document )
{
TComInterface<IHTMLDocument2>HTMLDoc;;
if(SUCCEEDED(Browser->Document->QueryInterface(
IID_IHTMLDocument2,(LPVOID*)&HTMLDoc) ) )
{
TComInterface<IHTMLElementCollection>forms;
if( SUCCEEDED(HTMLDoc->get_forms(&forms)) )
{
TComInterface<IHTMLFormElement>form;;
if( SUCCEEDED(GetHTMLItem(forms, "idpform", &form)) )
{
TComInterface<IHTMLInputElement>userid;
TComInterface<IHTMLInputElement>password;
GetHTMLItem(form, "txtUsername", &userid);
GetHTMLItem(form, "txtPassword", &password);
if( userid )
userid->put_value(WideString(username));
if( password )
password->put_value(WideString(pass));
//form->submit();
}
}
}
}
}
//---------------------------------------------------------------------------
|
|
|
|
|
What you are likely seeing is a call to MessageBox() before the
exception is thrown. To turn that off, you can go into the Project
Options and add NO_PROMPT_ON_HRCHECK_FAILURE to the Conditionals list.
The exception will then be thrown without any prompting.
If you are still using the TComInterface wrapper, the '->' operator
validates whether the interface pointer is available or not. If it is
not, an ASSERT is thrown. To disable the prompt on that error, you
can define NO_PROMPT_ON_ASSERTE_FAILURE in the Project Options.
If you implement a try..catch block, it will catch errors normally without messagebox prompt interruptions.
(sample try catch)
try {
buf = new char[512];
if( buf == 0 ) throw "Memory allocation failure!";
}
catch( char * str ) {
cout << "Exception raised: " << str << '\n';
}
|
|
|
|
|
Thankyou very much...every thing worked I added NO_PROMPT_ON_HRCHECK_FAILURE to the Conditionals list. and inserted a try/catch block around my code in the document complete event.
Now if every login page had the same names for their form & input names!
|
|
|
|
|
Is there any difference between the following loops
bool test;
do
{
}
while(!test);
and
bool test;
do
{
}
while(test==false);
Also what is the default value of boolean variable?
|
|
|
|
|
Both loops are the same.
The default value of boolean is false, but You should never rely on the default value of a variable, if one is assigned (it might also be garbage) which depends on the compiler. For readability and to avoid possible problems always assign a initial value during variable declaration.
<Edit - default value boolean statement>
0100000101101110011001000111001011101001
modified 15-Oct-11 13:33pm.
|
|
|
|
|
Both code blocks behave in the same way.
ALWAYS initialize your variables before use:
In the C++ standard, only global variables get default value of zero
if they are not explicitly initialized. For local variables it's not required
for the complier to clean up the content of the memory they are assigned to.
A local variable - if not explicitly initialized - will contain a garbage value.
Code 1
bool test=0;
int i=0;
do
{
i++;
cout<<i<<" ";
}
while(!test);
if test==false then we are stuck in an eternal loop forever.
However if test==true then we only loop once.
The same goes for
Code 2
bool test=0;
int i=0;
do
{
i++;
cout<<i<<" ";
}
while(test==false);
if test==false then we are stuck in an eternal loop forever.
However if test==true then we only loop once.
|
|
|
|
|
Top coder is right, default values are not part of the standard. So it could be different from compiler to compiler, or completely random garbage.
Edit: changed my vote after your correction.
modified 15-Oct-11 20:12pm.
|
|
|
|
|
They are the same loops. both compile to a cmp to the value 0 instruction. you would get an unitialized variable warning when compiled. the default is whatever happened to be randomly in that location on the stack or in that register (optimized into a register) previously (usually true, but not specified).
|
|
|
|
|
If you are asking about default value, it will completely compiler dependent. Even if you work on release or debug build, don't surprise to see different results. Better idea is to explicitly initialize the value. Even in other cases, like by default Class members are private and structure members are public. Don't rely on defaults, explicitly write what you want.
Regards
|
|
|
|
|
never, Never, NEVER rely on any "default initialization" ever happening.
Always, and I cannot say this strongly enough, ALWAYS initialize your variables if you are depending on them having some value when you start.
Over your lifetime of programming, you will be far happier and successful if you burn that idea into your brain and you will spend far less time chasing "unitialized variable" bugs. Others will come to you for debugging help and you will say 'did you look for unitialized variables' and they will say 'no' and solve their problem and you will look like a genius.
Take this advice to heart.
|
|
|
|
|
I'm making a progress window for my Program, that is MDI. The progress window will show progress when a windows service is starting or stopping.
I wanted to make the progress window sort of universal, in which the Master Window owns it, and not the MDIChild Window,
I sort of confused here. I need the HWND from the master window to use in CreateWindowEx, but quite sure how to get it, Because I'm loading the Progress Windows from an MDIChild Window, and my create window fails. Actually I'm modeling the window first to make sure it works and looks right before I fully implement it.
BOOL ProgressBar_Popup::_show_ProgressWindow( HINSTANCE hInstance, HWND cWnd )
{
LPWSTR windowTitle = L"Progress";
HDC hdc;
gProgressBar_Popup_GAC = cWnd;
hdc = GetDC(cWnd);
hProgressBar_Popup_Instance = hInstance;
LoadString(hProgressBar_Popup_Instance, IDC_PROGRESSBAR_POPUP, sz_ProgressBar_Popup_Class, MAX_LOADSTRING);
_register_ProgressBar_Popup_Class(hInstance);
hProgressBar_Popup = _create_ProgressBar_Popup(hInstance, windowTitle);
_progressbar_Popup_Center( gProgressBar_Popup_GAC, hProgressBar_Popup );
return TRUE;
}
ATOM ProgressBar_Popup::_register_ProgressBar_Popup_Class(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC) _progressbar_Popup_WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_NASE2012_SUWIZARD));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
wcex.lpszMenuName = NULL;
wcex.lpszClassName = sz_ProgressBar_Popup_Class;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
if (!RegisterClassEx(&wcex))
{
MessageBox(NULL,
_T("Call to RegisterClassEx failed!"),
_T("Win32 Guided Tour"),
NULL);
}
return RegisterClassEx(&wcex);
}
HWND ProgressBar_Popup::_create_ProgressBar_Popup(HINSTANCE hInstance, LPWSTR windowTitle)
{
HWND hWnd = CreateWindowEx(
WS_EX_TOPMOST,
sz_ProgressBar_Popup_Class,
windowTitle,
WS_POPUPWINDOW,
10, 10,
200, 200,
gProgressBar_Popup_GAC,
NULL,
hInstance,
NULL
);
if ( !hWnd )
{
MessageBox(hWnd,
L"Progress Bar Popup has failed",
L"Progress Bar Popup",
MB_ICONEXCLAMATION | MB_OK);
}
else
{
ShowWindow(hWnd, SW_SHOW );
UpdateWindow(hWnd);
}
return hWnd;
}
|
|
|
|
|
Have you considered just showing progress bar in a status bar pane[^]?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I went to lunch and came back, with a new idea, so I deleted the stuff I wrote, and will try to create a some sort of dialog box in the main.cpp.
I have a status bar, but haven't figured out what to put in it, or how to access it.
|
|
|
|
|
|
I thought it would be a good lesson for to learn how create various windows, and at the time, I was thinking in consumer mode. The progress bar looks very difficult for me now, so I will just create a message or popup window saying that the service is starting or stopping.
Thanks for the suggestion, I'm going to skip ahead to the next task, which is trying to figure out how to delete text I made with drawtext.
|
|
|
|
|