<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Grafik einfügen]]></title><description><![CDATA[<p>Hallo zusammen</p>
<p>Ich habe eine Frage: Da ich von C++ noch keine grosse Ahnung habe, wüsste ich gerne, wie man in ein Fenster ein Bild einfügt. Ich weiss, dass man das irgendwie laden muss, dann in den Speicher schreiben und schliesslich ins Fenster kopieren. Doch der Compiler spuckt nur Fehler. Wie geht es denn genau? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Ich wäre über Antwort wirklich sehr dankbar.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/205462/grafik-einfügen</link><generator>RSS for Node</generator><lastBuildDate>Sun, 26 Apr 2026 12:36:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/205462.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 14 Feb 2008 14:56:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Grafik einfügen on Thu, 14 Feb 2008 14:56:50 GMT]]></title><description><![CDATA[<p>Hallo zusammen</p>
<p>Ich habe eine Frage: Da ich von C++ noch keine grosse Ahnung habe, wüsste ich gerne, wie man in ein Fenster ein Bild einfügt. Ich weiss, dass man das irgendwie laden muss, dann in den Speicher schreiben und schliesslich ins Fenster kopieren. Doch der Compiler spuckt nur Fehler. Wie geht es denn genau? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Ich wäre über Antwort wirklich sehr dankbar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1455906</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1455906</guid><dc:creator><![CDATA[silvanm]]></dc:creator><pubDate>Thu, 14 Feb 2008 14:56:50 GMT</pubDate></item><item><title><![CDATA[Reply to Grafik einfügen on Thu, 14 Feb 2008 15:53:33 GMT]]></title><description><![CDATA[<p>Das hängt von der Fragestellung ab. Ein Icon in die Kopfleiste zu bringen, läuft anders, als eine Graphik auf einen Button (ist auch ein Fenster!) zu setzen. Das wiederum anders als eine Graphik in die Schaltfläche einer Toolbar (ebenfalls alles Fenster), und das wiederum anders als ein Bild in einem Dokumentfenster.</p>
<p>Davon abgesehen ist das keine frage von C++, sondern von WinAPI. Und die ist, obwohl selbst in C geschrieben, (neben anderen) in C, C++, Delphi, Pascal, FreeBasic und VisualBasic nutzbar.</p>
<p>Ich weiß, das hilft Dir jetzt nicht viel. Aber das liegt an Deiner unkonkreten Frage.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1455947</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1455947</guid><dc:creator><![CDATA[Elektronix]]></dc:creator><pubDate>Thu, 14 Feb 2008 15:53:33 GMT</pubDate></item><item><title><![CDATA[Reply to Grafik einfügen on Thu, 14 Feb 2008 16:18:11 GMT]]></title><description><![CDATA[<p>suche mal bei google nach BitBlt, bitmaps, WinAPI!</p>
<p>Der sollte dir eine menge ausspucken!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1455969</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1455969</guid><dc:creator><![CDATA[Showball]]></dc:creator><pubDate>Thu, 14 Feb 2008 16:18:11 GMT</pubDate></item><item><title><![CDATA[Reply to Grafik einfügen on Thu, 14 Feb 2008 16:19:23 GMT]]></title><description><![CDATA[<p>Ich möchte ein ganz normales .bmp Bild in das ganz normale hwnd-Fenster einblenden, welches mit CreateWindow erstellt wurde. Das das mit WinAPI geht ist mir schon klar, die Frage ist nur, wie? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>LG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1455972</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1455972</guid><dc:creator><![CDATA[silvanm]]></dc:creator><pubDate>Thu, 14 Feb 2008 16:19:23 GMT</pubDate></item><item><title><![CDATA[Reply to Grafik einfügen on Thu, 14 Feb 2008 19:26:45 GMT]]></title><description><![CDATA[<p>Friss und *:</p>
<pre><code class="language-cpp">#include &lt;string&gt;

#include &lt;windows.h&gt;

const unsigned int idm_load_image  = 1;
const unsigned int idm_exit        = 2;

std::wstring get_last_error_msg( ) {

	void *message_buffer = 0;

    FormatMessage(

        FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
        0,
        GetLastError( ),
        MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
        reinterpret_cast&lt; LPTSTR &gt;( &amp;message_buffer ),
        0,
        0
	);

	std::wstring error_message( reinterpret_cast&lt; LPTSTR &gt;( message_buffer ) );

	LocalFree( message_buffer );

	return error_message;
}

bool load_bitmap( HBITMAP &amp;bitmap, HWND window ) {

	wchar_t file_name[ MAX_PATH ] = { 0 };
	OPENFILENAME ofn = { 0 };

	memset( &amp;ofn, 0, sizeof( ofn ) );

	ofn.lStructSize	  = sizeof( ofn );
	ofn.hwndOwner     = window;
	ofn.lpstrFile     = file_name;
	ofn.nMaxFile      = sizeof( file_name ) / sizeof( file_name[ 0 ] );
	ofn.lpstrFilter   = L&quot;Bitmaps\0*.bmp\0All Files\0*.*\0&quot;;
	ofn.Flags         = OFN_ENABLESIZING | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

	if( !GetOpenFileName( &amp;ofn ) ) {

            return false;
	}

	bitmap = reinterpret_cast&lt; HBITMAP &gt;( LoadImage( 0, file_name, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ) );
	return true;
}

LRESULT __stdcall main_window_procedure( HWND window, UINT message, WPARAM wparam, LPARAM lparam ) {

	static HBITMAP bitmap = 0;

	switch( message ) {

		case WM_CREATE:

			return 0;

		case WM_CLOSE:

			DestroyWindow( window );
			return 0;

		case WM_DESTROY:

			DeleteObject( bitmap );
			PostQuitMessage( 0 );
			return 0;

		case WM_PAINT: {

			PAINTSTRUCT ps;

			BeginPaint( window, &amp;ps );

			if( bitmap ) {

				HDC     mem_dc      = CreateCompatibleDC( ps.hdc );
				HBITMAP old_bitmap  = reinterpret_cast&lt; HBITMAP &gt;( SelectObject( mem_dc, bitmap ) );
				RECT    rect        = { 0 };

				GetClientRect( window, &amp;rect );
				BitBlt( ps.hdc, 0, 0, rect.right, rect.bottom, mem_dc, 0, 0, SRCCOPY );

				SelectObject( mem_dc, old_bitmap );
				DeleteDC( mem_dc );
			}

			EndPaint( window, &amp;ps );			   
		}

		case WM_COMMAND:

			if( !HIWORD( wparam ) ) {

				switch( LOWORD( wparam ) ) {

					case idm_load_image: {

						HBITMAP new_bitmap; 

						if( load_bitmap( new_bitmap, window ) &amp;&amp;  !new_bitmap ) {

							MessageBox( window, L&quot;The bitmap couldn't be loaded!&quot;, L&quot;Error:&quot;, MB_OK );

						} else {

							DeleteObject( bitmap );
							bitmap = new_bitmap;
							InvalidateRect( window, 0, false );
						}
						break;
					}

					case idm_exit:

						DestroyWindow( window );
						break;
				}
			}

			return 0;
	}

	return DefWindowProc( window, message, wparam, lparam );
}

int __stdcall WinMain( HINSTANCE instance, HINSTANCE prev_instance, LPSTR command_line, int show_state ) {

	WNDCLASSEX window_class = { 0 };

	window_class.cbSize             = sizeof( window_class );
	window_class.hbrBackground      = reinterpret_cast&lt; HBRUSH &gt;( COLOR_WINDOW + 1 );
	window_class.hCursor            = reinterpret_cast&lt; HCURSOR &gt;( LoadImage( 0, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED ) );
	window_class.hIcon              = reinterpret_cast&lt; HICON &gt;( LoadImage( 0, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED ) );
	window_class.hInstance          = instance;
	window_class.lpfnWndProc        = main_window_procedure;
	window_class.lpszClassName      = L&quot;CodeFun Window Class&quot;;
	window_class.style              = CS_VREDRAW | CS_HREDRAW;

	ATOM window_class_atom = RegisterClassEx( &amp;window_class );

	if( !window_class_atom ) {

		MessageBox( 0, get_last_error_msg( ).c_str( ), L&quot;Error:&quot;, MB_OK );
		return 0;
	}

	HMENU main_menu = CreateMenu( );
	MENUITEMINFO menu_item = { 0 };

	menu_item.cbSize      = sizeof( menu_item );
	menu_item.fMask       = MIIM_ID | MIIM_STRING;
	menu_item.wID         = idm_load_image;
	menu_item.dwTypeData  = L&quot;&amp;Load Image...&quot;;

	InsertMenuItem( main_menu, idm_load_image, false, &amp;menu_item );

	menu_item.wID         = idm_exit;
	menu_item.dwTypeData  = L&quot;&amp;Exit&quot;;

	InsertMenuItem( main_menu, idm_exit, false, &amp;menu_item );

	HWND main_window = CreateWindowEx(

		WS_EX_OVERLAPPEDWINDOW,
		reinterpret_cast&lt; LPCTSTR &gt;( window_class_atom ),
		L&quot;CodeFun&quot;,
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		0,
		main_menu,
		instance,
		0
	);

	if( !main_window ) {

		MessageBox( 0, get_last_error_msg( ).c_str( ), L&quot;Error:&quot;, MB_OK );
		return 0;
	}

	UpdateWindow( main_window );
	ShowWindow( main_window, show_state );

	MSG message = { 0 };

	while( GetMessage( &amp;message, 0, 0, 0 ) ) {

		TranslateMessage( &amp;message );
		DispatchMessage( &amp;message );
	}

	return static_cast&lt; int &gt;( message.wParam );
}
</code></pre>
<p>greetz, Swordfish</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1456091</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1456091</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Thu, 14 Feb 2008 19:26:45 GMT</pubDate></item><item><title><![CDATA[Reply to Grafik einfügen on Thu, 14 Feb 2008 20:38:04 GMT]]></title><description><![CDATA[<p>Entweder so wie es Swordfish gemacht hat oder schau einfach mal nach dem STATIC Steuerelement in der MSDN, damit kannst du ohne viel Aufwand eine Bitmap zeichnen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1456160</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1456160</guid><dc:creator><![CDATA[0xDEADBEEF]]></dc:creator><pubDate>Thu, 14 Feb 2008 20:38:04 GMT</pubDate></item></channel></rss>