Hi friends:
As a third year student, I was looking at the scanuser example from IFS kit…a consola application but i was thinking in a win32 implementation…so here is my code…
A problem is when I like to connect to port
…at OnDlgCommunication_ConnectDriver(…)
Thanking you in advance for your kind of help and time; I am…
const PWSTR ScannerPortName = L"\ScannerPort";
typedef struct _SCANNER_THREAD_CONTEXT {
HANDLE Port;
HANDLE Completion;
} SCANNER_THREAD_CONTEXT, *PSCANNER_THREAD_CONTEXT;
LRESULT OnDlgCommunication_ConnectDriver(hDlgCommunication, wParam, lParam)
{
HRESULT hresult;
HANDLE port, completion;
SCANNER_THREAD_CONTEXT context;
hresult = FilterConnectCommunicationPort ( ScannerPortName,
0,
NULL,
0,
NULL,
&port );
if (IS_ERROR ( hresult ))
{
MessageBox(NULL, “Cant not connect to port”, NULL, MB_ICONERROR| MB_SYSTEMMODAL);
return 2;
}
//
// Create a completion port to associate with this handle.
//
completion = CreateIoCompletionPort ( port,
NULL,
0,
0 );
if (completion == NULL)
{
MessageBox(NULL, “Error when creating a completion port”, NULL, MB_ICONERROR| MB_SYSTEMMODAL);
CloseHandle ( port );
return 3;
}
context.Port = port;
context.Completion = completion;
return hresult;
}
LRESULT CALLBACK DlgCommunication(HWND hDlgCommunication, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_CONNECT:
break;
return OnDlgCommunication_ConnectDriver(hDlgCommunication, wParam, lParam);
…
…
…
case IDC_EXIT:
DestroyWindow(hWndMainWin);
hWndMainWin = NULL;
return TRUE;
}
break;
case WM_CLOSE:
EndDialog(hDlgCommunication,0);
return FALSE;
}
return FALSE;
}
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
RECT rctMainWnd, rctToolbox;
switch(Msg)
{
case WM_SIZE:
GetClientRect(hWndMainWin, &rctMainWnd);
GetWindowRect(hWndFrame, &rctToolbox);
SetWindowPos(hWndFrame, HWND_TOP, rctMainWnd.left,
rctMainWnd.top,
rctMainWnd.right,
rctMainWnd.bottom,
SWP_NOACTIVATE | SWP_NOOWNERZORDER);
break;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hWndMainWin, Msg, wParam, lParam);
}
return 0;
}
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
WNDCLASSEX WndClsEx;
WndClsEx.cbSize = sizeof(WNDCLASSEX);
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = WndProcedure;
WndClsEx.cbClsExtra = 0;
WndClsEx.cbWndExtra = 0;
WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
…
…
…
RegisterClassEx(&WndClsEx);
hInst = hInstance;
// Create the window object
hWndMainWin = CreateWindow(windows_class,
WndName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if( !hWndMainWin ) return 0;
hWndFrame = CreateDialog(hInst, MAKEINTRESOURCE(IDD_INTERFACE), hWndMainWin, (DLGPROC)DlgCommunication);
ShowWindow (hWndFrame, SW_SHOW);
ShowWindow(hWndMainWin, SW_SHOWNORMAL);
while( GetMessage(&Msg, NULL, 0, 0) )
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
?Sobre autos lo sabemos todo, y te podemos ayudar!
Ya sea para comprar, vender o comparar autos, entra en el canal de autos de Terra.com
Te aconsejamos, te informamos y te mostramos todo lo que necesitas saber.
http://www.terra.com/autos