MAIN PROJECT
#include "stdafx.h"
#include "Form1.h"
#include <stdio.h>
#include "windows.h"
#include <conio.h>
#include <iostream>
using namespace std;
using namespace MouseDynamixel;
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;
Label ^ lblMouseX = gcnew Label;
Label ^ lblMouseY;
//get the position of cursor first
POINT pos;
GetCursorPos(&pos);
int x=pos.x;
int y=pos.y;
lblMouseX->Text = "Hi";
//lblMouseX->Text= Convert::ToString(x);
//lblMouseY->Text= Convert::ToString(y);
}
Form1.h
#pragma once
namespace MouseDynamixel {
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;
}
}
public: System::Windows::Forms::Label^ lblMouseX;
protected:
protected:
protected:
private: System::Windows::Forms::PictureBox^ pictureBox1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
public: System::Windows::Forms::Label^ lblMouseY;
private:
private: System::Windows::Forms::Label^ label3;
public:
public:
public:
private:
protected:
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)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->lblMouseX = (gcnew System::Windows::Forms::Label());
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->lblMouseY = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
this->SuspendLayout();
//
// lblMouseX
//
this->lblMouseX->BackColor = System::Drawing::SystemColors::ControlLight;
this->lblMouseX->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
this->lblMouseX->Location = System::Drawing::Point(135, 240);
this->lblMouseX->Name = L"lblMouseX";
this->lblMouseX->Size = System::Drawing::Size(35, 24);
this->lblMouseX->TabIndex = 1;
this->lblMouseX->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
//
// pictureBox1
//
this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox1.Image")));
this->pictureBox1->InitialImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox1.InitialImage")));
this->pictureBox1->Location = System::Drawing::Point(36, 12);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(224, 225);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
this->pictureBox1->Waitonload = true;
this->pictureBox1->Click += gcnew System::EventHandler(this, &Form1::pictureBox1_Click);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(12, 246);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(81, 13);
this->label1->TabIndex = 2;
this->label1->Text = L"Current Position";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(111, 246);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(17, 13);
this->label2->TabIndex = 3;
this->label2->Text = L"X:";
//
// lblMouseY
//
this->lblMouseY->BackColor = System::Drawing::SystemColors::ControlLight;
this->lblMouseY->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
this->lblMouseY->Location = System::Drawing::Point(234, 240);
this->lblMouseY->Name = L"lblMouseY";
this->lblMouseY->Size = System::Drawing::Size(35, 24);
this->lblMouseY->TabIndex = 4;
this->lblMouseY->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(199, 246);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(17, 13);
this->label3->TabIndex = 5;
this->label3->Text = L"Y:";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 266);
this->Controls->Add(this->label3);
this->Controls->Add(this->lblMouseY);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->lblMouseX);
this->Controls->Add(this->pictureBox1);
this->ForeColor = System::Drawing::SystemColors::ControlText;
this->Name = L"Form1";
this->Text = L"Form1";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) {
}
};
}
As you can see in the main program, I have tried many ways to do things, based on advice I saw on other posts, but nothing has worked. I am sure I am probably just missing some simple error, however, I cannot find it. Any advice to help me out would be greatly appreciate. The labels I am trying to display the text in are lblMouseX (for X coordinate) and lblMouseY (for Y coordinate).
Thanks
Note: Some parts of my code that I thought might be useful are commented out.
This post has been edited by SpartanGuy07: 08 September 2011 - 01:50 PM

New Topic/Question
Reply


MultiQuote




|