PB EditBox

SfyLer Messages postés 38 Date d'inscription vendredi 4 avril 2003 Statut Membre Dernière intervention 31 décembre 2006 - 30 mai 2003 à 16:15
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019 - 30 mai 2003 à 17:15
Bonjour à tous !
J'ai créé un scanner de port sous dos, et j'ai commencer a le faire sous windows, j'ai presque fini le seul pb que j'ai c'est que je ne sait pas comment les editbox peuvent ecrire dans les variables IP et PORT.
Voici la source vous comprendrez mieu

#include "stdafx.h"
#include "resource.h"
#include <stdio.h>
#include
#include <time.h>
#include <conio.h>
#include
#pragma comment(lib, "ws2_32.lib")
#include <winsock2.h>

#define MAX_LOADSTRING 100
#define ID_BUTTON 100
#define ID_EDITBOX 100

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text

// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_SCANNERBYSFYLER, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SCANNERBYSFYLER);

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return msg.wParam;
}

//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SCANNERBYSFYLER);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
wcex.lpszMenuName = (LPCSTR)IDC_SCANNERBYSFYLER;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

return RegisterClassEx(&wcex);
}

//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 180, 250, HWND_DESKTOP, NULL, hInstance, NULL);
HWND edithWnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, "EDIT", "", WS_VISIBLE|WS_CHILD|ES_AUTOHSCROLL|ES_NOHIDESEL,
10, 10, 150, 25, hWnd, (HMENU)ID_EDITBOX, hInstance, NULL);
SetWindowText(edithWnd, "IP");

HWND edithWnd1 = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, "EDIT", "", WS_VISIBLE|WS_CHILD|ES_AUTOHSCROLL|ES_NOHIDESEL,
10, 50, 150, 25, hWnd, (HMENU)ID_EDITBOX, hInstance, NULL);
SetWindowText(edithWnd1, "PORT");
// Création du bouton
HWND cmdhWnd = CreateWindowEx(0, "BUTTON", "", WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON|BS_NOTIFY|BS_TEXT,
10, 150, 150, 30, hWnd, (HMENU)ID_BUTTON, hInstance, NULL);
SetWindowText(cmdhWnd, "Scan");

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam); if ((LOWORD(wParam) ID_BUTTON) && (HIWORD(wParam) BN_CLICKED))
{
MessageBox(hWnd, "Scan en cours", "Scanner", MB_OK|MB_ICONINFORMATION);

WSADATA WSAData; // tout les prog de
WSAStartup(MAKEWORD(2,0),&WSAData);

SOCKET sock;

SOCKADDR_IN sin;
//ICI JAIMERAIS QUE CE SOIT LES EDIT BOX QUI REMPLISSE IP ET PORT
sin.sin_addr.s_addr = inet_addr(IP); // definit les propriétés
sin.sin_family = AF_INET; // de la socket
sin.sin_port = htons(PORT);

sock = socket(AF_INET,SOCK_STREAM,0);
n = connect(sock,(SOCKADDR *)&sin,sizeof(sin));
if(n == 0) // si on peut se connecter (donc si le port est ouvert)
{
MessageBox(hWnd, "Le port est ouvert", "Scanner", MB_OK|MB_ICONINFORMATION);
}
else
{
MessageBox(hWnd, "Le port est fermé", "Scanner", MB_OK|MB_ICONINFORMATION);

}
closesocket(sock);
WSACleanup();


//execution du code
}
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);

EndPaint(hWnd, &ps);
break;

case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:if (LOWORD(wParam) IDOK || LOWORD(wParam) IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}

http://totalpcone.free.fr :)

4 réponses

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
30 mai 2003 à 16:23
GetWindowText(hedit, szbuff, lenbuff);
ou alors:
GetDlgItemText(hdlg, IDED_IP, szbuff, lenbuff);
donc si tu as char szIP[20]:
nbrcaracs = GetWindowText(hedit, szIP, 20);
BruNews, ciao...
0
SfyLer Messages postés 38 Date d'inscription vendredi 4 avril 2003 Statut Membre Dernière intervention 31 décembre 2006
30 mai 2003 à 17:07
merci beaucoup ! mais jai encore un blem pour le port:
char *LePORT = NULL;
unsigned int TextLen = 0;
TextLen = GetWindowTextLength(EditHandle);
LeText = new char[(TextLen + 2)];
TextLen = GetWindowText(EditHandle, LeText, (TextLen + 1));

Le pb c'est que sa, sa prend ce ke ya ecri dans le edit box et sa le met dans une variable char, et je narrive pas a ce ki prennent une variable int, pouvez vous juste modifier ce code pour ke sa marche ?
http://totalpc.free.fr :)
0
SfyLer Messages postés 38 Date d'inscription vendredi 4 avril 2003 Statut Membre Dernière intervention 31 décembre 2006
30 mai 2003 à 17:09
eeeee je rectifie la source:
> char *LePORT = NULL; <----- c'est pas sa, c'est ca:
char *LeText = NULL;

http://totalpc.free.fr :)
0
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
30 mai 2003 à 17:15
ival = GetDlgItemInt(hdlg, IDED_IP, 0, 0);
je mets 0 sur desrnier, tu mets 1 si est nbr signe.
Sinon tu fais avec solution d'avant:
ival = atoi(szbuff);
BruNews, ciao...
0
Rejoignez-nous