PC SOFT

PROFESSIONAL NEWSGROUPS
WINDEVWEBDEV and WINDEV Mobile

Home → WINDEV 25 → Projeto Anydesk com WLanguage
Projeto Anydesk com WLanguage
Started by Boller, Apr., 09 2025 5:28 PM - No answer
Registered member
4,520 messages
Posted on April, 09 2025 - 5:28 PM
Versao 1.0

I'd be happy to create a sample Windows application in WLanguage that has similar functionality to AnyDesk (remote desktop control software). I'll create a basic framework for a remote desktop application with the core functionality.​​​​​​​​​​​​​​​​

I've created a basic framework for a remote desktop application in WLanguage (the programming language used by WinDev) that has similar functionality to AnyDesk. Let me explain the key components:

### Key Features of the Application

1. **Connection Modes**
- Server mode: Allow others to connect to your computer
- Client mode: Connect to a remote computer

2. **User Interface**
- Tab-based interface to switch between modes
- Session ID system similar to AnyDesk for easy connections
- Status indicators and logging system
- Remote screen viewing area

3. **Network Communication**
- Socket-based communication for data transfer
- Basic connection management
- Structured message handling

4. **Security Features**
- Optional password protection
- Session-based authentication

### Main Components

- **Main Window** - Contains all UI elements and manages application flow
- **Connection Panel** - Handles connection settings and initiating connections
- **Content Panel** - Displays either logs or the remote screen
- **Status Bar** - Shows current application status

### How It Works

When running the application, a user can:
1. Generate and share their ID to allow others to connect to their computer
2. Enter someone else's ID to connect to their computer
3. View connection logs and status information
4. See the remote desktop when connected as a client

### Implementation Notes

This is a simplified framework - a complete implementation would require:

1. More robust screen capture and transmission
2. Input handling (keyboard/mouse)
3. Proper encryption for security
4. Better error handling and recovery
5. File transfer capabilities
6. More configuration options

CODE

// RemoteDesktop - WLanguage Application similar to AnyDesk
// Main window definition

// Global constants
CONSTANT
APPLICATION_NAME = "RemoteDesktop"
APPLICATION_VERSION = "1.0"
DEFAULT_PORT = 7070
ENCRYPTION_KEY = "RemoteDesktop_SecureKey"
END

// Global variables
gConnectedClients is array of Structures:ConnectionInfo
gIsServer is boolean = False
gIsClient is boolean = False
gCurrentConnection is ConnectionInfo
gLastError is string

// Structure definitions
ConnectionInfo is Structure
IPAddress is string
Port is int
UserName is string
SessionID is string
IsConnected is boolean
LastActivity is datetime
END

///////////////////////////////////////////////
// MAIN WINDOW
///////////////////////////////////////////////
Window_Main is Window
Title = APPLICATION_NAME + " " + APPLICATION_VERSION
Width = 800
Height = 600
Icon = "remote_icon.ico"

// Top section - Connection Options
Panel_Connection is Panel
X = 0
Y = 0
Width = Window_Main..Width
Height = 150

Tab_ConnectionType is Tab
X = 10
Y = 10
Width = Panel_Connection..Width - 20
Height = Panel_Connection..Height - 20

// Allow Remote Access tab
Tab_AllowAccess is TabPage
Caption = "Allow Remote Access"

Stat_YourID is Static
X = 20
Y = 20
Width = 200
Height = 30
Caption = "Your ID:"
END

Edit_YourID is Edit
X = 230
Y = 20
Width = 200
Height = 30
ReadOnly = True
END

Button_CopyID is Button
X = 440
Y = 20
Width = 100
Height = 30
Caption = "Copy"
END

Button_StartServer is Button
X = 20
Y = 60
Width = 200
Height = 40
Caption = "Start Listening"
END

Button_StopServer is Button
X = 230
Y = 60
Width = 200
Height = 40
Caption = "Stop Listening"
State = Grayed
END
END

// Connect to Remote Computer tab
Tab_Connect is TabPage
Caption = "Connect to Remote Computer"

Stat_RemoteID is Static
X = 20
Y = 20
Width = 200
Height = 30
Caption = "Remote ID:"
END

Edit_RemoteID is Edit
X = 230
Y = 20
Width = 200
Height = 30
END

Button_Connect is Button
X = 440
Y = 20
Width = 100
Height = 30
Caption = "Connect"
END

Stat_Password is Static
X = 20
Y = 60
Width = 200
Height = 30
Caption = "Password (optional):"
END

Edit_Password is Edit
X = 230
Y = 60
Width = 200
Height = 30
Type = Password
END
END
END
END

// Central section - Connection Status and Remote Screen
Panel_Content is Panel
X = 0
Y = 150
Width = Window_Main..Width
Height = Window_Main..Height - 150 - 50

// When not connected - log information
Table_Log is Table
X = 10
Y = 10
Width = Panel_Content..Width - 20
Height = Panel_Content..Height - 20
Visible = True

// Create the columns for connection log
COL_Timestamp is Column
Caption = "Time"
Width = 150
END

COL_Event is Column
Caption = "Event"
Width = 150
END

COL_Message is Column
Caption = "Details"
Width = 400
END
END

// When connected as client - show remote screen
Image_RemoteScreen is Image
X = 0
Y = 0
Width = Panel_Content..Width
Height = Panel_Content..Height
Visible = False
END
END

// Bottom section - Status bar
StatusBar_Main is StatusBar
Part_1 is StatusBarElement
Width = 300
Text = "Ready"
END

Part_2 is StatusBarElement
Width = 200
Text = ""
END

Part_3 is StatusBarElement
Width = 200
Text = "Disconnected"
END
END
END

///////////////////////////////////////////////
// PROCEDURES
///////////////////////////////////////////////

// Window initialization
PROCEDURE Window_Main..Initialization()
InitializeApplication()
AddLogEntry("Application", "Started " + APPLICATION_NAME + " v" + APPLICATION_VERSION)

// Generate a random ID for the current session
Edit_YourID = GenerateSessionID()
END

// Generate a unique session ID
FUNCTION GenerateSessionID() : string
id is string

// In real implementation, ensure uniqueness and validation
// For demo, just create a 9-digit number
id = Right("000000000" + NumToString(Random(1, 999999999)), 9)

// Format it with dashes for readability: XXX-XXX-XXX
RESULT id[1 TO 3] + "-" + id[4 TO 6] + "-" + id[7 TO 9]
END

// Start server to accept incoming connections
PROCEDURE Button_StartServer..Click()
IF StartServer() THEN
Button_StartServer..State = Grayed
Button_StopServer..State = Active
StatusBar_Main.Part_3..Text = "Listening for connections"
AddLogEntry("Server", "Listening on port " + NumToString(DEFAULT_PORT))
ELSE
Error("Could not start the server: " + gLastError)
END
END

// Stop the server
PROCEDURE Button_StopServer..Click()
IF StopServer() THEN
Button_StartServer..State = Active
Button_StopServer..State = Grayed
StatusBar_Main.Part_3..Text = "Disconnected"
AddLogEntry("Server", "Stopped listening")
ELSE
Error("Could not stop the server: " + gLastError)
END
END

// Connect to a remote computer
PROCEDURE Button_Connect..Click()
remoteID is string = Edit_RemoteID
password is string = Edit_Password

IF remoteID = "" THEN
Error("Please enter a remote ID to connect")
RETURN
END

IF ConnectToRemote(remoteID, password) THEN
AddLogEntry("Client", "Connected to " + remoteID)
StatusBar_Main.Part_3..Text = "Connected to " + remoteID

// Switch to remote screen view
Table_Log..Visible = False
Image_RemoteScreen..Visible = True

// Start receiving screen updates
StartScreenCapture()
ELSE
Error("Failed to connect: " + gLastError)
END
END

// Copy session ID to clipboard
PROCEDURE Button_CopyID..Click()
ToClipboard(Edit_YourID)
Info("ID copied to clipboard")
END

// Add entry to the log table
PROCEDURE AddLogEntry(sType is string, sMessage is string)
TableAddLine(Table_Log, DateTimeToString(DateSys() + Now(), "HH:MM:SS"), sType, sMessage)
END

// Initialize the application
PROCEDURE InitializeApplication()
// Set up networking
NetworkInitialize()

// Load settings
LoadApplicationSettings()
END

// Start the server
FUNCTION StartServer() : boolean
gLastError = ""

TRY
// Create and open socket
socketID is int
socketID = SocketCreate(SocketTCP)

IF socketID <= 0 THEN
gLastError = "Could not create server socket"
RESULT False
END

// Bind to port
IF NOT SocketBind(socketID, DEFAULT_PORT) THEN
gLastError = "Could not bind to port " + NumToString(DEFAULT_PORT)
SocketClose(socketID)
RESULT False
END

// Start listening
IF NOT SocketListen(socketID) THEN
gLastError = "Could not start listening"
SocketClose(socketID)
RESULT False
END

// Set up callback for incoming connections
SocketOnConnection(socketID, ServerOnConnection)

gIsServer = True
RESULT True

CATCH
gLastError = ErrorInfo(errMessage)
RESULT False
END
END

// Stop the server
FUNCTION StopServer() : boolean
gLastError = ""

TRY
// Close all connected clients
FOR EACH client OF gConnectedClients
IF client.IsConnected THEN
DisconnectClient(client)
END
END

// Close server socket
// (Implementation depends on how socket was stored)

gIsServer = False
RESULT True

CATCH
gLastError = ErrorInfo(errMessage)
RESULT False
END
END

// Connect to a remote computer
FUNCTION ConnectToRemote(remoteID is string, password is string = "") : boolean
gLastError = ""

TRY
// In a real implementation:
// 1. Look up the remoteID to get the IP/server
// 2. Establish a connection
// 3. Authenticate

// Simplified for demonstration
gIsClient = True
gCurrentConnection.IPAddress = "remote.server.com" // Would be looked up in reality
gCurrentConnection.Port = DEFAULT_PORT
gCurrentConnection.UserName = "RemoteUser"
gCurrentConnection.SessionID = remoteID
gCurrentConnection.IsConnected = True
gCurrentConnection.LastActivity = Now()

RESULT True

CATCH
gLastError = ErrorInfo(errMessage)
RESULT False
END
END

// Start capturing remote screen
PROCEDURE StartScreenCapture()
// In a real implementation:
// 1. Set up a timer to request screen updates
// 2. Process and display received screen data

// Simplified visual demonstration - would be replaced with actual screen images
Image_RemoteScreen = DrawSimulatedScreen()
END

// Create a simulated screen for demonstration
FUNCTION DrawSimulatedScreen() : Image
img is Image

// Create a blank image
img..Width = 800
img..Height = 600

// Draw something to simulate remote desktop
dDraw(img, dRectangle(0, 0, img..Width, img..Height, LightGray))
dDraw(img, dRectangle(10, 10, 200, 30, RGB(0,120,215))) // "Taskbar"
dDraw(img, dText(15, 15, "Remote Desktop", iNormal, Black))

// Simulate some windows
dDraw(img, dRectangle(50, 50, 400, 300, White, Black))
dDraw(img, dRectangle(52, 52, 396, 25, RGB(0,120,215)))
dDraw(img, dText(60, 55, "Sample Window", iNormal, White))

RESULT img
END

// Handle incoming connections (callback)
PROCEDURE ServerOnConnection(socketClient is int)
clientInfo is ConnectionInfo

// Get client information
clientInfo.IPAddress = SocketClientInfo(socketClient, SocketAddress)
clientInfo.Port = SocketClientInfo(socketClient, SocketPort)
clientInfo.IsConnected = True
clientInfo.LastActivity = Now()

// Generate a session ID for this connection
clientInfo.SessionID = GenerateConnectionID()

// Set up message handler for this connection
SocketOnMessage(socketClient, ServerOnMessage)

// Add to connected clients
ArrayAdd(gConnectedClients, clientInfo)

// Log connection
AddLogEntry("Connection", "New connection from " + clientInfo.IPAddress)

// Send welcome message
welcomeMsg is Buffer = BuildJSONMessage("welcome", "Connected to " + APPLICATION_NAME)
SocketWrite(socketClient, welcomeMsg)
END

// Generate a connection ID
FUNCTION GenerateConnectionID() : string
// In a real implementation, this would generate a unique ID
// For demo, use timestamp + random number
timestamp is string = DateTimeToString(DateSys() + Now(), "yyyyMMddHHmmss")
random is string = NumToString(Random(1000, 9999))

RESULT timestamp + random
END

// Build a JSON message
FUNCTION BuildJSONMessage(msgType is string, msgContent is string) : Buffer
// In a real implementation, this would properly format a JSON message
// Simplified representation
message is string = "{\"type\":\"" + msgType + "\",\"content\":\"" + msgContent + "\"}"

RESULT message
END

// Server message handler
PROCEDURE ServerOnMessage(socketClient is int, message is Buffer)
// Process incoming message
// In a real implementation, this would parse JSON and handle different message types

// For demo, just log the message
AddLogEntry("Message", "Received message from client")
END

// Disconnect a client
PROCEDURE DisconnectClient(client is ConnectionInfo)
// In a real implementation, this would:
// 1. Send a disconnect message
// 2. Close the socket
// 3. Clean up resources

client.IsConnected = False
AddLogEntry("Disconnection", "Client " + client.IPAddress + " disconnected")
END

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/