Программа просмотра свободного места на жестком диске сервера
Рефераты >> Коммуникации и связь >> Программа просмотра свободного места на жестком диске сервера

//

// 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, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT, 0, 200, 256, NULL, NULL, hInstance, NULL);

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)

{

PAINTSTRUCT ps;

HDC hdc;

RECT rt;

int wmId, wmEvent,rc;

TCHAR szHello[MAX_LOADSTRING];

LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

unsigned char i,j, x,y;

switch (message)

{

case WM_CREATE:

WSADATA WSAData;

rc = WSAStartup(MAKEWORD(1, 1), &WSAData);

initme();

if (rc != 0){

MessageBox(NULL, "WSAStartup Error", "Error", MB_OK);

return FALSE;

} else {

return TRUE;

}

case WM_COMMAND:

wmId = LOWORD(wParam);

wmEvent = HIWORD(wParam);

// Parse the menu selections:

switch (wmId)

{

case IDM_ABOUT:

DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);

break;

case IDM_EXIT:

DestroyWindow(hWnd);

break;

case IDM_START:

if (! iamclient) {

iamserv = true;

startserv(hWnd);

} else {

MessageBox(NULL,"I am already client .","tip",MB_OK);

}

break;

case IDM_STOP:

iamserv = false;

iamclient = false;

break;

case IDM_CONNECT:

if ( ! iamserv && clientconnect(hWnd)) {

memset(&ar,0,sizeof(ar));

iamclient = true;

} else {

MessageBox(NULL,"I am already server .","tip",MB_OK);

}

break;

default:

return DefWindowProc(hWnd, message, wParam, lParam);

}

break;

case WM_PAINT:

hdc = BeginPaint(hWnd, &ps);

// TODO: Add any drawing code here .

GetClientRect(hWnd, &rt);

EndPaint(hWnd, &ps);

break;

case WM_DESTROY:

ServerStop(hWnd);

PostQuitMessage(0);

// return FORWARD_WM_DESTROY(hWnd, DefWindowProc);

break;

default:

return DefWindowProc(hWnd, message, wParam, lParam);

}

return DefWindowProc(hWnd, message, wParam, lParam);

}

// 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;

}

void err(char * pl) {

MessageBox(NULL,get_error_text(WSAGetLastError()), pl,MB_OK);

}


Страница: