1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
#pragma once
#include <Windows.h>
#include <iostream>
#include <fstream>
int varx;
int vary;
namespace ProjectA {
using namespace std;
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
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
ifstream in;
in.open("Settings.txt");
in >> varx;
in >> vary;
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::PictureBox^ pictureBox1;
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->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->BackColor = System::Drawing::Color::Transparent;
this->pictureBox1->Cursor = System::Windows::Forms::Cursors::Hand;
resources->ApplyResources(this->pictureBox1, L"pictureBox1");
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->TabStop = false;
this->pictureBox1->Click += gcnew System::EventHandler(this, &Form1::pictureBox1_Click);
//
// Form1
//
this->AccessibleRole = System::Windows::Forms::AccessibleRole::None;
this->AllowDrop = true;
resources->ApplyResources(this, L"$this");
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::SystemColors::Window;
this->ControlBox = false;
this->Controls->Add(this->pictureBox1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
this->MaximizeBox = false;
this->MinimizeBox = false;
this->Name = L"Form1";
this->ShowIcon = false;
this->SizeGripStyle = System::Windows::Forms::SizeGripStyle::Show;
this->TopMost = true;
this->TransparencyKey = System::Drawing::Color::Transparent;
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) {
}
};
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//Add these two static variables
static int xClick;
static int yClick;
//...other declarations...
switch (message)
{
//...other handlers...
case WM_LBUTTONDOWN:
//Restrict mouse input to current window
SetCapture(hWnd);
//Get the click position
xClick = LOWORD(lParam);
yClick = HIWORD(lParam);
break;
case WM_LBUTTONUP:
//Window no longer requires all mouse input
ReleaseCapture();
break;
case WM_MOUSEMOVE:
{
if (GetCapture() == hWnd) //Check if this window has mouse input
{
//Get the window's screen coordinates
RECT rcWindow;
GetWindowRect(hWnd,&rcWindow);
//Get the current mouse coordinates
int xMouse = LOWORD(lParam);
int yMouse = HIWORD(lParam);
//Calculate the new window coordinates
int xWindow = rcWindow.left + xMouse - xClick;
int yWindow = rcWindow.top + yMouse - yClick;
//Set the window's new screen position (don't resize or change z-order)
SetWindowPos(hWnd,NULL,xWindow,yWindow,0,0,SWP_NOSIZE|SWP_NOZORDER);
}
break;
}
//...rest of switch block...
}
//...rest of procedure...
}
}
|