help on windows
newbie
newbie at dummy.com
Tue Jun 5 12:40:49 PDT 2007
hi all,
can anybody tell me how to translate a callback and the dialog stuff to D?
i searched, but could not find a sample code on how to deal with that dialog stuff.
appreciate any help
till
snip ...
define in header as :
#pragma pack( push, 8 )
#pragma comment( lib, "PServer" )
#define PSERVERLIB extern "C" __declspec( dllimport )
typedef BOOL (CALLBACK *ONCONNECTPROC)( PCONNECTION pConnection );
//###############################################################################################################//
BOOL CALLBACK OnConnect( PCONNECTION pConnection )
{
InterlockedIncrement( &g_lOnConnectCount );
// Allocate connection data buffer.
pConnection->pvPerConnectionUserData = (PCONNECTION_DATA) malloc( sizeof( CONNECTION_DATA ) );
if( NULL == pConnection->pvPerConnectionUserData ){
LogError( "malloc()", 0 );
return FALSE;
}
PCONNECTION_DATA pConnectionData = (PCONNECTION_DATA) pConnection->pvPerConnectionUserData;
pConnectionData->dwBytesTransferred = 0;
pConnectionData->dwDataSize = 0;
pConnectionData->dwIndex = 0;
pConnectionData->hFile = INVALID_HANDLE_VALUE;
// Receive request.
if( PServer.PostRecv( pConnection,
pConnectionData->bBuffer,
BUF_SIZE,
NULL ) != ERROR_SUCCESS ){ return FALSE; }
return TRUE;
}
snip ...
//###############################################################################################################//
BOOL DlgMain_OnInitDialog( HWND hWnd, HWND hWndFocus, LPARAM lParam )
{
g_hwndMain = hWnd;
SetDlgItemInt( hWnd, ID_EDIT_PORT, 6060, FALSE );
return TRUE;
}
//###############################################################################################################//
void DlgMain_OnTimer( HWND hWnd, UINT id )
{
INFORMATION info = {0};
PServer.QueryInformation( &info );
SetDlgItemInt( hWnd, ID_STATIC_CPUUSAGE, info.dwCpuUsage, FALSE );
SetDlgItemInt( hWnd, ID_STATIC_WORKER_THREADS, info.dwWorkerThreadsCount, FALSE );
SetDlgItemInt( hWnd, ID_STATIC_WORKER_THREADS_BUSY, info.dwWorkerThreadsBusyCount, FALSE );
SetDlgItemInt( hWnd, ID_STATIC_WORKER_IOLEN, info.dwIoCompletionLen, FALSE );
SetDlgItemInt( hWnd, ID_STATIC_USER_THREADS, info.dwUserThreadsCount, FALSE );
SetDlgItemInt( hWnd, ID_STATIC_USER_THREADS_BUSY, info.dwUserThreadsBusyCount, FALSE );
SetDlgItemInt( hWnd, ID_STATIC_USER_IOLEN, info.dwUserIoCompletionLen, FALSE );
SetDlgItemInt( hWnd, ID_STATIC_CONNECTIONS, info.dwConnectionsCount, FALSE );
SetDlgItemInt( hWnd, ID_STATIC_ONCONNECT, g_lOnConnectCount, FALSE );
SetDlgItemInt( hWnd, ID_STATIC_ONDISCONNECT, g_lOnDisconnectCount, FALSE );
SetDlgItemInt( hWnd, ID_STATIC_ONREMOVECONNECTION, g_lOnRemoveConnectionCount, FALSE );
}
//###############################################################################################################//
void DlgMain_OnClose( HWND hWnd )
{
if( g_fStarted ){
SendMessage( hWnd, WM_COMMAND, ID_BUTTON_STOP, NULL );
}
EndDialog( hWnd, 0 );
}
//###############################################################################################################//
int WINAPI Dialog_Main( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
switch( message ){
Dlg_Proc( hWnd, WM_INITDIALOG, DlgMain_OnInitDialog );
Dlg_Proc( hWnd, WM_COMMAND, DlgMain_OnCommand );
Dlg_Proc( hWnd, WM_TIMER, DlgMain_OnTimer );
Dlg_Proc( hWnd, WM_CLOSE, DlgMain_OnClose );
}
return 0;
}
//##############################################################################################################//
int WINAPI _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
DialogBox( hInstance, MAKEINTRESOURCE( IDD_DIALOG_MAIN ), NULL, Dialog_Main );
return 0;
}
snip ...
More information about the Digitalmars-d-learn
mailing list