Megadringend Hilfe mit Variablenausgabe



  • hi... kann mir jemand sagen, wie ich eine variable in winapi ausgebe:

    [cpp]for (;x<=500,y<=500;x=x+20,y=y+20,a++)
    			TextOut (dc,x,y,a,1);
    		ReleaseDC(hwnd,dc);
    		return 0;[/cpp]
    

    ... möchte variable a ausgeben und leider keine ahnung wie das geht.

    -sry, bin neu in winapi-

    thx



  • Mittels sprintf bzw. _stprintf in einen String umwandeln und dann den String ausgeben.



  • wie jetzt?!.. jetzt genauer.. Bitte!



  • TCHAR szBuffer[100];
      int iWert = 12;
      _stprintf(szBuffer, _T("%d"), iWert);
      TextOut(hDc, 0, 0, szBuffer, _tcslen(szBuffer));
    


  • sry seh leider jetzt gar nich mehr durch...

    hier mal das komplette prog..

    [code]

    //aufgabe3.cpp (by) Matthias Walter
    
    #include <windows.h>
    #include <string>
    using namespace std;
    
    HDC dc;
    MSG n;
    static int x, y;
    
    //static char a='A';
    
    LRESULT CALLBACK Fensterfunktion(HWND hwnd,UINT message,
    								 WPARAM wparam, LPARAM lparam) {
    	switch(message) {
    
    	case WM_LBUTTONDOWN:
    		x=LOWORD(lparam);
    		y=HIWORD(lparam);
    		dc=GetDC (hwnd);
    		if (dc != NULL)
    
    			for (;x<=500,y<=500;x=x+20,y=y+20,a++)
    				TCHAR szBuffer[100]; 
    
    			_stprintf(szBuffer, _T("%d"), a); 
    			TextOut(hDc, x, y, szBuffer, _tcslen(szBuffer));
    
    			//TextOut (dc,x,y,a,1);
    
    		ReleaseDC(hwnd,dc);
    		return 0;
    
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    
    	}	
    	return DefWindowProc(hwnd, message, wparam, lparam);
    }
    HDC GEtDC(HWND hwnd);
    int Release(HWND hwnd, HDC dc);
    
    int WINAPI WinMain(HINSTANCE dieseInstanz,HINSTANCE
    				   vorigeInstanz,LPSTR t, int d) {
    
    	HWND f;
    	char szAppName[]="Eine neue Fensterklasse";
    	WNDCLASS wc;
    	wc.style		= CS_HREDRAW | CS_VREDRAW ;
    	wc.lpfnWndProc	= Fensterfunktion;
    	wc.cbClsExtra	= 0;
    	wc.cbWndExtra	= 0;
    	wc.hInstance	= dieseInstanz;
    	wc.hIcon		= LoadIcon(NULL, IDI_HAND);
    	wc.hCursor		= LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground= CreateSolidBrush(RGB(255,255,255));
    	wc.lpszMenuName	= NULL;
    	wc.lpszClassName= szAppName;
    
    	if (!RegisterClass(&wc))	{		
    
    		return 0;
    	};
    
    	f = CreateWindow ( szAppName,
    			"Wir experimentieren",
    			WS_OVERLAPPEDWINDOW |  WS_VISIBLE,
    			100,
    			150,
    			600,
    			500,
    			NULL,
    			NULL,
    			dieseInstanz,
    			NULL);
    	while (GetMessage(&n,NULL,0,0) ) {
    		DispatchMessage(&n);
    	};
    	return n.wParam;
    
    }[/
    

    code]

    naja... es soll halt eine ascii zeichenkette ausgegeben werden diie mit a beginnt....

    also müsst ich jetzt dein iwert als character nehmen oder wie?



  • //aufgabe3.cpp (by) Matthias Walter
    
    #include <windows.h>
    #include <string>
    using namespace std;
    
    HDC dc;
    MSG n;
    static int x, y;
    
    //static char a='A';
    
    LRESULT CALLBACK Fensterfunktion(HWND hwnd,UINT message,
                                     WPARAM wparam, LPARAM lparam) {
        switch(message) {
    
        case WM_LBUTTONDOWN:
            x=LOWORD(lparam);
            y=HIWORD(lparam);
            dc=GetDC (hwnd);
            if (dc != NULL) 
            {               // <- neuer Code-Block
                TCHAR szBuffer[100]; // vor der iteration
                for (;x<=500,y<=500;x=x+20,y=y+20,a++)
                {
                    _stprintf(szBuffer, _T("%d"), a);
                    TextOut(hDc, x, y, szBuffer, _tcslen(szBuffer));
                } // end for
            } // end if
    
                //TextOut (dc,x,y,a,1);
    
            ReleaseDC(hwnd,dc);
            return 0;
    
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
    
        }   
        return DefWindowProc(hwnd, message, wparam, lparam);
    }
    HDC GEtDC(HWND hwnd);
    int Release(HWND hwnd, HDC dc);
    
    int WINAPI WinMain(HINSTANCE dieseInstanz,HINSTANCE
                       vorigeInstanz,LPSTR t, int d) {
    
        HWND f;
        char szAppName[]="Eine neue Fensterklasse";
        WNDCLASS wc;
        wc.style        = CS_HREDRAW | CS_VREDRAW ;
        wc.lpfnWndProc    = Fensterfunktion;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance    = dieseInstanz;
        wc.hIcon        = LoadIcon(NULL, IDI_HAND);
        wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground= CreateSolidBrush(RGB(255,255,255));
        wc.lpszMenuName    = NULL;
        wc.lpszClassName= szAppName;
    
        if (!RegisterClass(&wc))    {       
    
            return 0;
        };
    
        f = CreateWindow ( szAppName,
                "Wir experimentieren",
                WS_OVERLAPPEDWINDOW |  WS_VISIBLE,
                100,
                150,
                600,
                500,
                NULL,
                NULL,
                dieseInstanz,
                NULL);
        while (GetMessage(&n,NULL,0,0) ) {
            DispatchMessage(&n);
        };
        return n.wParam;
    
    }
    

    Du hast immer wieder TCHAR szBuffer[100] in der for-Schleife angelegt, und dann einmal den Wert von a in den String kopiert.
    Schau dir den Code oben mal an.


Anmelden zum Antworten