SfyLer
Messages postés38Date d'inscriptionvendredi 4 avril 2003StatutMembreDernière intervention31 décembre 2006
-
30 mai 2003 à 16:15
BruNews
Messages postés21040Date d'inscriptionjeudi 23 janvier 2003StatutModérateurDernière intervention21 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
// 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;
// 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;
//
// 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
//
// 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);
BruNews
Messages postés21040Date d'inscriptionjeudi 23 janvier 2003StatutModérateurDernière intervention21 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...
SfyLer
Messages postés38Date d'inscriptionvendredi 4 avril 2003StatutMembreDernière intervention31 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 :)
BruNews
Messages postés21040Date d'inscriptionjeudi 23 janvier 2003StatutModérateurDernière intervention21 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...