Jump to content

vc++ 2008 -> Varias duvidas -> funçoes e scoop


j.c.

Recommended Posts

boas,

ja consegui fazer com que o browser que fiz em vc++ 2008 funciona-se, embora por so precisar, apenas tenho a caixa de texto para o url e o botao para aceitar o url e navegar ate la. isto esta tudo a funcionar e apresenta a pagina correctamente.

agora o que eu queria era conseguir interagir com o que esta na pagina, principalmente conseguir fazer um auto-login. sabem alguma maneira de fazer isso? ja andei no google e so apareçe para vb ou para c#, mas quer num quer noutro não entendo o que la esta.

desde ja deixo o meu obrigado a esta comunidade.

p.s.-- em breve devo deixar ca o projecto...

Link to comment
Share on other sites

ja consegui fazer isso.

o meu problema agora é fazer com que esse codigo so corra uma vez...

tenho-o no ficheiro form1.h em

private: System::Void webBrowser1_DocumentCompleted(System::Object^  sender, System::Windows::Forms::WebBrowserDocumentCompletedEventArgs^  e) 

la dentro tenho um codigo do genero:

this->webBrowser1->....

assim é claro que ele corre sempre que a pagina acaba de fazer o download, o que para alem de estar sempre a correr esse codigo desnecessariamente, faz com que entre em looping infinito se existirem os mesmos campos na nova pagina.

se me puderem dizer onde posso por o codigo de maneira a conseguir aceder na mesma ao webBrowser1 agradecia imenso.  ja tentei no main e nao deu, tal como no form1.h mas fora de qualquer funçao como a de cima e nao deu...

Link to comment
Share on other sites

Aqui tenho o codigo do programa. ele tem o browser a funcionar. podem testar indo a www.google.com  . Ele preenche o campo de pesquisa e carrega no botao para procurar, o que se passa é que o campo do texto da pesquisa e o botao continuam a existir e com o mesmo nome, por isso entra em loop infinito. eu queria poder por as linhas:

this->webBrowser1->Document->All["q"]->SetAttribute("value","teste");
this->webBrowser1->Document->All["btnG"]->InvokeMember("click");

em algum lado que so permita isto correr uma vez, talvez dentro do main? nao quero usar um if ou algo parecido pois depois de conseguir fazer isto funcionar queria fazer outro que nao estou a ver que o possa fazer com if's , alem de que o computador estava a testar essa hipotese para nada!

// aaa.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"
#include "windows.h"

using namespace aaa;

[sTAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false); 

// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}

e o aaa.h

#include "windows.h"
#include "string.h"

#pragma once


namespace aaa {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
///          'Resource File Name' property for the managed resource compiler tool
///          associated with all .resx files this class depends on.  Otherwise,
///          the designers will not be able to interact properly with localized
///          resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
	Form1(void)
	{
		InitializeComponent();
		//
		//TODO: Add the constructor code here
		//
	}

protected:
	/// <summary>
	/// Clean up any resources being used.
	/// </summary>
	~Form1()
	{
		if (components)
		{
			delete components;
		}
	}
private: System::Windows::Forms::Button^  button1;
protected: 
private: System::Windows::Forms::TextBox^  textBox1;
private: System::Windows::Forms::WebBrowser^  webBrowser1;

private:
	/// <summary>
	/// Required designer variable.
	/// </summary>
	System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
	/// <summary>
	/// Required method for Designer support - do not modify
	/// the contents of this method with the code editor.
	/// </summary>
	void InitializeComponent(void)
	{
		this->button1 = (gcnew System::Windows::Forms::Button());
		this->textBox1 = (gcnew System::Windows::Forms::TextBox());
		this->webBrowser1 = (gcnew System::Windows::Forms::WebBrowser());
		this->SuspendLayout();
		// 
		// button1
		// 
		this->button1->Location = System::Drawing::Point(0, 0);
		this->button1->Name = L"button1";
		this->button1->Size = System::Drawing::Size(75, 23);
		this->button1->TabIndex = 0;
		this->button1->Text = L"button1";
		this->button1->UseVisualStyleBackColor = true;
		this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
		// 
		// textBox1
		// 
		this->textBox1->Location = System::Drawing::Point(131, 2);
		this->textBox1->Name = L"textBox1";
		this->textBox1->Size = System::Drawing::Size(362, 20);
		this->textBox1->TabIndex = 1;
		this->textBox1->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::textBox1_KeyDown_1);
		// 
		// webBrowser1
		// 
		this->webBrowser1->Location = System::Drawing::Point(0, 48);
		this->webBrowser1->MinimumSize = System::Drawing::Size(20, 20);
		this->webBrowser1->Name = L"webBrowser1";
		this->webBrowser1->Size = System::Drawing::Size(586, 296);
		this->webBrowser1->TabIndex = 2;
		this->webBrowser1->DocumentCompleted += gcnew System::Windows::Forms::WebBrowserDocumentCompletedEventHandler(this, &Form1::webBrowser1_DocumentCompleted);
		// 
		// Form1
		// 
		this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
		this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
		this->ClientSize = System::Drawing::Size(579, 341);
		this->Controls->Add(this->webBrowser1);
		this->Controls->Add(this->textBox1);
		this->Controls->Add(this->button1);
		this->Name = L"Form1";
		this->Text = L"Form1";
		this->ResumeLayout(false);
		this->PerformLayout();

	}
#pragma endregion
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			  this->webBrowser1->Navigate(this->textBox1->Text);
		 }
private: System::Void webBrowser1_DocumentCompleted(System::Object^  sender, System::Windows::Forms::WebBrowserDocumentCompletedEventArgs^  e) {
			 this->textBox1->Text= this->webBrowser1->Url->ToString();			     
			 this->Text = this->webBrowser1->DocumentTitle;

			 this->webBrowser1->Document->All["q"]->SetAttribute("value","teste");       //mete o texto na caixa
			 this->webBrowser1->Document->All["btnG"]->InvokeMember("click");		//clica no botao		
		 }

	private: System::Void textBox1_KeyDown_1(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {
				 if ( e->KeyCode == System::Windows::Forms::Keys::Enter &&  !this->textBox1->Text->Equals( "" ) ){
				 this->webBrowser1->Navigate( this->textBox1->Text );
			 }
			 }
};

}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.