Ipc

Peterson

Grünschnabel
Hallo zusammen.

Hätte als Anhang (oder auch unten) ein c++ Programm, das mit InterProzessCommunikation zutun hat. Ich wollte dieses Programm jetzt in meinem Visual C++ kompilieren und ausführen. Doch leider bin ich noch nicht auf die richtigen Einstellungen gekommen damit dieses Dingens läuft.
Kann mir bitte jemand sagen, wie ich mein Projekt anlengen und welche Einstellungen ich vornehmen muss damit dieses Programm ohne Probleme läuft?

mfg Peterson






Quellcode

// WinMain-Beispielprogramm(s.Kap.8): Thread für 'Zaehler im Hintergrund'
//
#include <windows.h>
int count ;
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam );

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow )
{
static char szAppName[] = "WinThread";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;

if( !hPrevInstance )
{
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;

RegisterClass( &wndclass );
}

hwnd = CreateWindow( szAppName, // window class name
"The Countthread Programm", // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parentwindow handle
NULL, // window menu handle
hInstance, // program instance handle
NULL ); // creation parameters
// CreateWindow erzeugt WM_CREATE

ShowWindow( hwnd, nCmdShow );
UpdateWindow( hwnd ); // erzeugt WM_PAINT

while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}

return msg.wParam;
}


void CountThread() // Thread-Funktion
{
while(1)
{
count++;
Sleep(500);
}
}

LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam, LPARAM lParam )
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
HANDLE hThreadHandle;
DWORD threadID;
char szBuffer[40];
int iLength;
switch( uMsg )
{
case WM_CREATE: // 1. Message die WndProc erhaelt (von CreateWindow)
count = 0;
// Create a thread which executes the CountThread function
hThreadHandle = CreateThread( 0, 0,
(LPTHREAD_START_ROUTINE) CountThread,0, 0, &threadID);

if (hThreadHandle==0)
// Fehlermeldung ueber Messagebox ausgeben
{ LPVOID lpMsgBuf;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
// Default language
(LPTSTR)&lpMsgBuf, 0, NULL);
// Display the string.
MessageBox( NULL, lpMsgBuf, "GetLastError",
MB_OK|MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
}
return 0;

case WM_PAINT: // Message wird z.B. von UpdateWindow erzeugt

hdc = BeginPaint( hWnd, &ps );
GetClientRect( hWnd, &rect );
DrawText( hdc,
"LeftButton: Display count value\nRightButton: Clear Counter ",
-1, &rect, DT_CENTER | DT_VCENTER );
EndPaint( hWnd, &ps );
return 0;

case WM_LBUTTONDOWN:

hdc = GetDC (hWnd);
iLength = sprintf(szBuffer, "The count value: %d ", count);
TextOut(hdc, 100, 60, szBuffer, iLength);
ReleaseDC(hWnd, hdc);
return 0;

case WM_RBUTTONDOWN:

count = 0;
return 0;

case WM_DESTROY:
TerminateThread (hThreadHandle, 0);
PostQuitMessage( 0 );
return (LRESULT) NULL;
}
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
 

Anhänge

  • ipc.txt
    3,4 KB · Aufrufe: 40
sorry aber mit ipc haben hier die wenigsten wohl schon mal gearbeitet.
ich teste dein programm demnächst aber mal.

welche version von visual c++ haste denn?
 
Ok, ich hab mir mal erlaubt, deinen Code ein klein wenig zu ändern, nur ganz wenig *g*. Dann lies es sich als Win32 Anwendung kompilieren und ausführen.

Ich häng die Datei einfach wieder an.

Gruss Homer
 

Anhänge

  • ipc.txt
    3,6 KB · Aufrufe: 56

Neue Beiträge

Zurück