<?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[Bild in der Picturebox aktualisieren]]></title><description><![CDATA[<p>Servus,<br />
ich bin grad dabei ein Bildanzeigeprogramm zu schreiben und bin dabei auf den Sourcecode gestoßen, wie man jpgs... einbindet(<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39384.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-39384.html</a>). Alledings weiß ich jetzt nicht, wie man eine Picturebox aktualisiert und ich weiß nicht, wo man das machen muss. Hier ist mein aktueller Quelltext:</p>
<pre><code>#include &lt;windows.h&gt; 
#include &lt;olectl.h&gt; 
#include &lt;string.h&gt; 

class COlePicture { 
public: 
    COlePicture() : pPicture(NULL) { 
    } 
    ~COlePicture() { 
        if(pPicture != NULL) {
            pPicture-&gt;Release();     
        } 
    } 
    BOOL Load(LPCTSTR szFile) {

        HANDLE hFile = CreateFile(szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); 
        if(hFile == INVALID_HANDLE_VALUE) { 
            return FALSE; 
        } 

        DWORD dwFileSize = GetFileSize(hFile, NULL); 
        if(dwFileSize == -1) { 
            return FALSE; 
        } 

        LPVOID pvData = NULL; 
        HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize); 
        if(hGlobal == NULL) { 
            return FALSE; 
        } 

        pvData = GlobalLock(hGlobal); 
        if(pvData == NULL) { 
            return FALSE; 
        } 

        DWORD dwBytesRead = 0; 
        BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &amp;dwBytesRead, NULL); 
        if(bRead == FALSE) { 
            return FALSE; 
        } 
        GlobalUnlock(hGlobal); 
        CloseHandle(hFile); 

        LPSTREAM pstm = NULL; 
        HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &amp;pstm); 

        if(FAILED(hr) || pstm == NULL) { 
            return FALSE; 
        } 

        if(pPicture) { 
            pPicture-&gt;Release(); 
        } 
        hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID*)&amp;pPicture); 
        if(FAILED(hr) || pPicture == NULL) { 
            return FALSE; 
        }   
        pstm-&gt;Release(); 
        szFile=&quot;&quot;;

        return TRUE; 
    } 

    VOID Show(HWND hWindowHandle, LONG nX, LONG nY) { 
        HDC hDC = GetDC(hWindowHandle); 
        if(pPicture) { 
            LONG hmWidth; 
            LONG hmHeight; 
            pPicture-&gt;get_Width(&amp;hmWidth); 
            pPicture-&gt;get_Height(&amp;hmHeight); 
            INT nWidth  = MulDiv(hmWidth, GetDeviceCaps(hDC, LOGPIXELSX), 2540); 
            INT nHeight = MulDiv(hmHeight, GetDeviceCaps(hDC, LOGPIXELSY), 2540); 
            RECT rc; 
            GetClientRect(hWindowHandle, &amp;rc); 
            pPicture-&gt;Render(hDC, nX, nY, nWidth, nHeight, 0, hmHeight, hmWidth, -hmHeight, &amp;rc); 
        } 
    } 
private: 
    LPPICTURE pPicture; 
}; 

LRESULT CALLBACK MainWindowProcedure(HWND hWindowHandle, 
                                     UINT uMessage, 
                                     WPARAM wParam, 
                                     LPARAM lParam); 

LRESULT CALLBACK PictureBoxProcedure(HWND hWindowHandle, 
                                     UINT uMessage, 
                                     WPARAM wParam, 
                                     LPARAM lParam);

HWND        hButton1;
HWND        hText1;
HWND        hText2;
HWND        hzurueck;
HWND        hvor;

RECT rc; 

HINSTANCE hInst;

struct Daten{
       char Name[900];
       char nName[900];
       };

struct Daten Datei[800];

char *buffer = NULL;
char string[900];

int i;
int o=0;
int ja=0;

HANDLE fHandle; 
WIN32_FIND_DATA wfd;
DWORD code; 

HBITMAP hBmp;
HDC DC; 
HDC MemDC; 
PAINTSTRUCT ps;

float hh;
float hw;

float xx=900;
float yy=750;

char z[900];

char Oeffnung[900];
char Ordnername[900]; 

HWND hPictureBox2; 

char Mal[]={&quot;mspaint.exe &quot;};

int WINAPI WinMain(HINSTANCE hInstanceHandle, 
                   HINSTANCE hPreviousInstanceHandle, 
                   LPSTR lpszCommandLine, 
                   INT nShowState) { 

    WNDCLASSEX MainWindowClass = {0}; 
    MainWindowClass.cbSize = sizeof(WNDCLASSEX); 
    MainWindowClass.hInstance = hInstanceHandle; 
    MainWindowClass.lpszClassName = &quot;Bild&quot;; 
    MainWindowClass.lpfnWndProc = MainWindowProcedure; 
    MainWindowClass.style = CS_HREDRAW | CS_VREDRAW; 
    MainWindowClass.hbrBackground = GetSysColorBrush(COLOR_3DFACE); 
    MainWindowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); 
    MainWindowClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); 
    MainWindowClass.hCursor = LoadCursor(NULL, IDC_ARROW); 
    MainWindowClass.lpszMenuName = NULL; 
    MainWindowClass.cbClsExtra = 0; 
    MainWindowClass.cbWndExtra = 0; 

    if(RegisterClassEx(&amp;MainWindowClass) == FALSE) { 
        MessageBox(NULL, &quot;Can't register MainWindowClass!&quot;, 
            &quot;Information&quot;, MB_OK); 
        return EXIT_FAILURE; 
    } 

    //strcpy(Datei[0].Name,&quot;C:\\test1.jpg&quot;);

    WNDCLASSEX PictureBoxWindowClass = {0}; 
    PictureBoxWindowClass.cbSize = sizeof(WNDCLASSEX); 
    PictureBoxWindowClass.hInstance = hInstanceHandle; 
    PictureBoxWindowClass.lpszClassName = &quot;PictureBox&quot;; 
    PictureBoxWindowClass.lpfnWndProc = PictureBoxProcedure; 
    PictureBoxWindowClass.style = CS_HREDRAW | CS_VREDRAW; 
    PictureBoxWindowClass.hbrBackground = GetSysColorBrush(COLOR_3DFACE); 
    PictureBoxWindowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); 
    PictureBoxWindowClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); 
    PictureBoxWindowClass.hCursor = LoadCursor(NULL, IDC_ARROW); 
    PictureBoxWindowClass.lpszMenuName = NULL; 
    PictureBoxWindowClass.cbClsExtra = 0; 
    PictureBoxWindowClass.cbWndExtra = 0; 

    if(RegisterClassEx(&amp;PictureBoxWindowClass) == FALSE) { 
        MessageBox(NULL, &quot;Can't register PictureBoxWindowClass!&quot;, 
            &quot;Information&quot;, MB_OK); 
        return EXIT_FAILURE; 
    } 

    HWND hMainWindow = CreateWindowEx( 
        0, &quot;Bild&quot;, &quot;PictureViewer&quot;, 
        WS_OVERLAPPEDWINDOW | WS_VISIBLE, 
        CW_USEDEFAULT, CW_USEDEFAULT, 
        CW_USEDEFAULT, CW_USEDEFAULT, 
        HWND_DESKTOP, NULL, 
        GetModuleHandle(NULL), NULL); 

    if(hMainWindow == NULL) { 
        MessageBox(NULL, &quot;Can't create main window!&quot;, &quot;Information&quot;, MB_OK); 
        return EXIT_FAILURE; 
    } 

   hPictureBox2 = CreateWindowEx( 
        0, &quot;PictureBox&quot;, Datei[o].Name, 
        WS_CHILD | WS_VISIBLE, 
        10, 120, 
        500, 500, 
        hMainWindow, (HMENU) 1001, 
        GetModuleHandle(NULL), NULL); 

    if(hPictureBox2 == NULL) { 
        MessageBox(NULL, &quot;Can't create PictureBox 2!&quot;, &quot;Information&quot;, MB_OK); 
        return EXIT_FAILURE; 
    } 

    hText1 = CreateWindow(&quot;STATIC&quot;, &quot;Von welchem Ordner wollen Sie die Bilder anschauen:&quot;,
                    WS_VISIBLE | WS_CHILD, 10, 20, 300, 20, hMainWindow, NULL, hInstanceHandle, NULL);
    if(!hText1) return FALSE;

    hText2 = CreateWindow(&quot;STATIC&quot;, &quot;&quot;,
                    WS_VISIBLE | WS_CHILD, 350, 80, 300, 20, hMainWindow, NULL, hInstanceHandle, NULL);
    if(!hText2) return FALSE;

    hButton1 = CreateWindow(&quot;BUTTON&quot;, &quot;Bilder anschauen&quot;,
                       WS_VISIBLE | WS_CHILD, 350, 40, 200, 20,
                       hMainWindow, NULL, hInstanceHandle, NULL);
    if(!hButton1) return FALSE;

    hzurueck = CreateWindow(&quot;BUTTON&quot;, &quot;letztes Bild&quot;,
                       WS_VISIBLE | WS_CHILD, 50, 80, 200, 20,
                       hMainWindow, NULL, hInstanceHandle, NULL);
    if(!hzurueck) return FALSE;

    hvor = CreateWindow(&quot;BUTTON&quot;, &quot;nächstes Bild&quot;,
                       WS_VISIBLE | WS_CHILD, 650, 80, 200, 20,
                       hMainWindow, NULL, hInstanceHandle, NULL);
    if(!hvor) return FALSE;

    SendMessage(hText1, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
    SendMessage(hText2, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);    
    SendMessage(hButton1, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
    SendMessage(hzurueck, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
    SendMessage(hvor, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);

    hInst = hInstanceHandle;

    MSG Message = {0}; 
    while(GetMessage(&amp;Message, NULL, 0, 0)) { 
        TranslateMessage(&amp;Message); 
        DispatchMessage(&amp;Message); 
    } 
    return Message.wParam; 
} 

LRESULT CALLBACK MainWindowProcedure(HWND hWindowHandle, 
                                     UINT uMessage, 
                                     WPARAM wParam, 
                                     LPARAM lParam) { 
    static HWND hEdit;

    switch(uMessage) {

    case WM_CREATE: 
        { 
            hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
                                   &quot;edit&quot;,
                                   buffer,    
                                   WS_CHILD | WS_VISIBLE,
                                   10, 40, 300, 20,
                                   hWindowHandle,
                                   NULL,
                                   ((LPCREATESTRUCT) lParam) -&gt; hInstance,
                                   NULL);

            free(buffer);
            SendMessage(hEdit, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);    
        }                 

    case WM_COMMAND:
                        switch(LOWORD(wParam)) { 
                                               case 1001: 

                                               STARTUPINFO si;
	                                           PROCESS_INFORMATION pi;

	                                           ZeroMemory( &amp;si, sizeof(si) );
	                                           si.cb = sizeof(si);
	                                           ZeroMemory( &amp;pi, sizeof(pi) );
	                                           strcat(Mal,Datei[o].Name);

                                               CreateProcess( NULL,Mal, NULL, NULL, FALSE, 0, NULL, NULL, &amp;si, &amp;pi);  
                                               strcpy(Mal,&quot;mspaint.exe &quot;),
                                               CloseHandle( pi.hThread );
                                               CloseHandle( pi.hProcess );
                                               break; 
                                               } 

                        i=0;
                        if(lParam == (LPARAM)hButton1)        
                        {
                                  ja=1;
                                  int iLength;

                                  iLength = GetWindowTextLength(hEdit);
                                  buffer = (char*) malloc(iLength);
                                  GetWindowText(hEdit, buffer, iLength+1);
                                  strcpy(Ordnername,buffer);
                                  strcpy(Oeffnung,Ordnername);
                                  strcat(Oeffnung,&quot;\\*&quot;);

                                  fHandle=FindFirstFile(Oeffnung,&amp;wfd); 

                                  do 
                                  { 
                                                                        if (!( (wfd.cFileName[0]=='.') &amp;&amp; ( (wfd.cFileName[1]=='.' &amp;&amp; wfd.cFileName[2]==0) || wfd.cFileName[1]==0 ) )) 
                                                                        { 
                                                                               if (wfd.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY) 
                                                                               { 
                                                                                   continue;
                                                                               } 
                                                                               else 
                                                                               {   
                                                                                    if(strstr(wfd.cFileName,&quot;.bmp&quot;)||strstr(wfd.cFileName,&quot;.BMP&quot;)||strstr(wfd.cFileName,&quot;.jpg&quot;)||strstr(wfd.cFileName,&quot;.JPG&quot;))
                                                                                    {                    
                                                                                                         strcpy(Datei[i].Name,Ordnername);
                                                                                                         strcat(Datei[i].Name,&quot;\\\\&quot;);
                                                                                                         strcat(Datei[i].Name,wfd.cFileName);
                                                                                                         strcpy(Datei[i].nName,wfd.cFileName);
                                                                                                         i++;
                                                                                    }
                                                                               }    
                                                                        } 
                                  }while (FindNextFile(fHandle,&amp;wfd)); 
                                  FindClose(fHandle);
                                  i--;
                                  o=0;
                                  SendMessage(hText2, WM_SETTEXT, 0,(LPARAM)Datei[0].nName);
                                  ja=1;

                                  UpdateWindow(hWindowHandle);
                                  UpdateWindow(hPictureBox2);
                                  InvalidateRect(hWindowHandle, NULL, TRUE); 
                                  GetClientRect(hWindowHandle,&amp;rc); 
                                  RedrawWindow(hWindowHandle,&amp;rc,NULL, RDW_ERASE | RDW_INVALIDATE);
                        } 
                  if(lParam == (LPARAM)hzurueck)        
                  {
                            o--;
                            SendMessage(hText2, WM_SETTEXT, 0,(LPARAM)Datei[o].nName);

                            UpdateWindow(hWindowHandle);
                            UpdateWindow(hPictureBox2);
                            InvalidateRect(hWindowHandle, NULL, TRUE); 
                            GetClientRect(hWindowHandle,&amp;rc); 
                            RedrawWindow(hWindowHandle,&amp;rc,NULL, RDW_ERASE | RDW_INVALIDATE);
                  }
                  if(lParam == (LPARAM)hvor)        
                  {
                            o++;
                            SendMessage(hText2, WM_SETTEXT, 0,(LPARAM)Datei[o].nName);

                            UpdateWindow(hWindowHandle);
                            UpdateWindow(hPictureBox2);
                            InvalidateRect(hWindowHandle, NULL, TRUE); 
                            GetClientRect(hWindowHandle,&amp;rc); 
                            RedrawWindow(hWindowHandle,&amp;rc,NULL, RDW_ERASE | RDW_INVALIDATE);
                  } 
        break; 
        case WM_DESTROY: 
            PostQuitMessage(0); 
            break; 
        default: 
            return DefWindowProc(hWindowHandle, uMessage, wParam, lParam); 
    } 
    return 0; 
} 

LRESULT CALLBACK PictureBoxProcedure(HWND hWindowHandle, 
                                     UINT uMessage, 
                                     WPARAM wParam, 
                                     LPARAM lParam) { 
    switch(uMessage) { 
    case WM_CREATE: 
        { 
            COlePicture* pPicture = new COlePicture; 
            CHAR WindowText[MAX_PATH]; 
            GetWindowText(hWindowHandle, WindowText, MAX_PATH);
            pPicture-&gt;Load(Datei[o].Name); 
            SetWindowLong(hWindowHandle, GWL_USERDATA, (LONG) pPicture);

        } 
        break; 
    case WM_DESTROY: 
        { 
            COlePicture* pPicture = (COlePicture*) GetWindowLong(hWindowHandle, GWL_USERDATA); 
            if(pPicture != NULL) { 
                delete pPicture; 
            } 
        } 
        break; 
    case WM_LBUTTONDOWN: 
        SendMessage(GetParent(hWindowHandle), WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hWindowHandle), 0), (LPARAM)hWindowHandle);
        break; 
    case WM_PAINT: 
        { 
            UpdateWindow(hWindowHandle);
            UpdateWindow(hPictureBox2);
            InvalidateRect(hWindowHandle, NULL, TRUE); 
            GetClientRect(hWindowHandle,&amp;rc); 
            RedrawWindow(hWindowHandle,&amp;rc,NULL, RDW_ERASE | RDW_INVALIDATE);

            PAINTSTRUCT ps; 
            HDC hDC = BeginPaint(hWindowHandle, &amp;ps); 
            COlePicture* pPicture = (COlePicture*) GetWindowLong(hWindowHandle, GWL_USERDATA); 
            if(pPicture != NULL) {
                pPicture-&gt;Show(hWindowHandle, 0, 0); 
            } 
            EndPaint(hWindowHandle, &amp;ps); 
        } 
        break; 
    default: 
        return DefWindowProc(hWindowHandle, uMessage, wParam, lParam); 
    } 
    return 0; 
}
</code></pre>
<p>Danke,</p>
<p>Felix</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/189184/bild-in-der-picturebox-aktualisieren</link><generator>RSS for Node</generator><lastBuildDate>Fri, 03 Jul 2026 00:47:41 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/189184.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 09 Aug 2007 13:05:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bild in der Picturebox aktualisieren on Thu, 09 Aug 2007 13:05:30 GMT]]></title><description><![CDATA[<p>Servus,<br />
ich bin grad dabei ein Bildanzeigeprogramm zu schreiben und bin dabei auf den Sourcecode gestoßen, wie man jpgs... einbindet(<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39384.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-39384.html</a>). Alledings weiß ich jetzt nicht, wie man eine Picturebox aktualisiert und ich weiß nicht, wo man das machen muss. Hier ist mein aktueller Quelltext:</p>
<pre><code>#include &lt;windows.h&gt; 
#include &lt;olectl.h&gt; 
#include &lt;string.h&gt; 

class COlePicture { 
public: 
    COlePicture() : pPicture(NULL) { 
    } 
    ~COlePicture() { 
        if(pPicture != NULL) {
            pPicture-&gt;Release();     
        } 
    } 
    BOOL Load(LPCTSTR szFile) {

        HANDLE hFile = CreateFile(szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); 
        if(hFile == INVALID_HANDLE_VALUE) { 
            return FALSE; 
        } 

        DWORD dwFileSize = GetFileSize(hFile, NULL); 
        if(dwFileSize == -1) { 
            return FALSE; 
        } 

        LPVOID pvData = NULL; 
        HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize); 
        if(hGlobal == NULL) { 
            return FALSE; 
        } 

        pvData = GlobalLock(hGlobal); 
        if(pvData == NULL) { 
            return FALSE; 
        } 

        DWORD dwBytesRead = 0; 
        BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &amp;dwBytesRead, NULL); 
        if(bRead == FALSE) { 
            return FALSE; 
        } 
        GlobalUnlock(hGlobal); 
        CloseHandle(hFile); 

        LPSTREAM pstm = NULL; 
        HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &amp;pstm); 

        if(FAILED(hr) || pstm == NULL) { 
            return FALSE; 
        } 

        if(pPicture) { 
            pPicture-&gt;Release(); 
        } 
        hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID*)&amp;pPicture); 
        if(FAILED(hr) || pPicture == NULL) { 
            return FALSE; 
        }   
        pstm-&gt;Release(); 
        szFile=&quot;&quot;;

        return TRUE; 
    } 

    VOID Show(HWND hWindowHandle, LONG nX, LONG nY) { 
        HDC hDC = GetDC(hWindowHandle); 
        if(pPicture) { 
            LONG hmWidth; 
            LONG hmHeight; 
            pPicture-&gt;get_Width(&amp;hmWidth); 
            pPicture-&gt;get_Height(&amp;hmHeight); 
            INT nWidth  = MulDiv(hmWidth, GetDeviceCaps(hDC, LOGPIXELSX), 2540); 
            INT nHeight = MulDiv(hmHeight, GetDeviceCaps(hDC, LOGPIXELSY), 2540); 
            RECT rc; 
            GetClientRect(hWindowHandle, &amp;rc); 
            pPicture-&gt;Render(hDC, nX, nY, nWidth, nHeight, 0, hmHeight, hmWidth, -hmHeight, &amp;rc); 
        } 
    } 
private: 
    LPPICTURE pPicture; 
}; 

LRESULT CALLBACK MainWindowProcedure(HWND hWindowHandle, 
                                     UINT uMessage, 
                                     WPARAM wParam, 
                                     LPARAM lParam); 

LRESULT CALLBACK PictureBoxProcedure(HWND hWindowHandle, 
                                     UINT uMessage, 
                                     WPARAM wParam, 
                                     LPARAM lParam);

HWND        hButton1;
HWND        hText1;
HWND        hText2;
HWND        hzurueck;
HWND        hvor;

RECT rc; 

HINSTANCE hInst;

struct Daten{
       char Name[900];
       char nName[900];
       };

struct Daten Datei[800];

char *buffer = NULL;
char string[900];

int i;
int o=0;
int ja=0;

HANDLE fHandle; 
WIN32_FIND_DATA wfd;
DWORD code; 

HBITMAP hBmp;
HDC DC; 
HDC MemDC; 
PAINTSTRUCT ps;

float hh;
float hw;

float xx=900;
float yy=750;

char z[900];

char Oeffnung[900];
char Ordnername[900]; 

HWND hPictureBox2; 

char Mal[]={&quot;mspaint.exe &quot;};

int WINAPI WinMain(HINSTANCE hInstanceHandle, 
                   HINSTANCE hPreviousInstanceHandle, 
                   LPSTR lpszCommandLine, 
                   INT nShowState) { 

    WNDCLASSEX MainWindowClass = {0}; 
    MainWindowClass.cbSize = sizeof(WNDCLASSEX); 
    MainWindowClass.hInstance = hInstanceHandle; 
    MainWindowClass.lpszClassName = &quot;Bild&quot;; 
    MainWindowClass.lpfnWndProc = MainWindowProcedure; 
    MainWindowClass.style = CS_HREDRAW | CS_VREDRAW; 
    MainWindowClass.hbrBackground = GetSysColorBrush(COLOR_3DFACE); 
    MainWindowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); 
    MainWindowClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); 
    MainWindowClass.hCursor = LoadCursor(NULL, IDC_ARROW); 
    MainWindowClass.lpszMenuName = NULL; 
    MainWindowClass.cbClsExtra = 0; 
    MainWindowClass.cbWndExtra = 0; 

    if(RegisterClassEx(&amp;MainWindowClass) == FALSE) { 
        MessageBox(NULL, &quot;Can't register MainWindowClass!&quot;, 
            &quot;Information&quot;, MB_OK); 
        return EXIT_FAILURE; 
    } 

    //strcpy(Datei[0].Name,&quot;C:\\test1.jpg&quot;);

    WNDCLASSEX PictureBoxWindowClass = {0}; 
    PictureBoxWindowClass.cbSize = sizeof(WNDCLASSEX); 
    PictureBoxWindowClass.hInstance = hInstanceHandle; 
    PictureBoxWindowClass.lpszClassName = &quot;PictureBox&quot;; 
    PictureBoxWindowClass.lpfnWndProc = PictureBoxProcedure; 
    PictureBoxWindowClass.style = CS_HREDRAW | CS_VREDRAW; 
    PictureBoxWindowClass.hbrBackground = GetSysColorBrush(COLOR_3DFACE); 
    PictureBoxWindowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); 
    PictureBoxWindowClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); 
    PictureBoxWindowClass.hCursor = LoadCursor(NULL, IDC_ARROW); 
    PictureBoxWindowClass.lpszMenuName = NULL; 
    PictureBoxWindowClass.cbClsExtra = 0; 
    PictureBoxWindowClass.cbWndExtra = 0; 

    if(RegisterClassEx(&amp;PictureBoxWindowClass) == FALSE) { 
        MessageBox(NULL, &quot;Can't register PictureBoxWindowClass!&quot;, 
            &quot;Information&quot;, MB_OK); 
        return EXIT_FAILURE; 
    } 

    HWND hMainWindow = CreateWindowEx( 
        0, &quot;Bild&quot;, &quot;PictureViewer&quot;, 
        WS_OVERLAPPEDWINDOW | WS_VISIBLE, 
        CW_USEDEFAULT, CW_USEDEFAULT, 
        CW_USEDEFAULT, CW_USEDEFAULT, 
        HWND_DESKTOP, NULL, 
        GetModuleHandle(NULL), NULL); 

    if(hMainWindow == NULL) { 
        MessageBox(NULL, &quot;Can't create main window!&quot;, &quot;Information&quot;, MB_OK); 
        return EXIT_FAILURE; 
    } 

   hPictureBox2 = CreateWindowEx( 
        0, &quot;PictureBox&quot;, Datei[o].Name, 
        WS_CHILD | WS_VISIBLE, 
        10, 120, 
        500, 500, 
        hMainWindow, (HMENU) 1001, 
        GetModuleHandle(NULL), NULL); 

    if(hPictureBox2 == NULL) { 
        MessageBox(NULL, &quot;Can't create PictureBox 2!&quot;, &quot;Information&quot;, MB_OK); 
        return EXIT_FAILURE; 
    } 

    hText1 = CreateWindow(&quot;STATIC&quot;, &quot;Von welchem Ordner wollen Sie die Bilder anschauen:&quot;,
                    WS_VISIBLE | WS_CHILD, 10, 20, 300, 20, hMainWindow, NULL, hInstanceHandle, NULL);
    if(!hText1) return FALSE;

    hText2 = CreateWindow(&quot;STATIC&quot;, &quot;&quot;,
                    WS_VISIBLE | WS_CHILD, 350, 80, 300, 20, hMainWindow, NULL, hInstanceHandle, NULL);
    if(!hText2) return FALSE;

    hButton1 = CreateWindow(&quot;BUTTON&quot;, &quot;Bilder anschauen&quot;,
                       WS_VISIBLE | WS_CHILD, 350, 40, 200, 20,
                       hMainWindow, NULL, hInstanceHandle, NULL);
    if(!hButton1) return FALSE;

    hzurueck = CreateWindow(&quot;BUTTON&quot;, &quot;letztes Bild&quot;,
                       WS_VISIBLE | WS_CHILD, 50, 80, 200, 20,
                       hMainWindow, NULL, hInstanceHandle, NULL);
    if(!hzurueck) return FALSE;

    hvor = CreateWindow(&quot;BUTTON&quot;, &quot;nächstes Bild&quot;,
                       WS_VISIBLE | WS_CHILD, 650, 80, 200, 20,
                       hMainWindow, NULL, hInstanceHandle, NULL);
    if(!hvor) return FALSE;

    SendMessage(hText1, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
    SendMessage(hText2, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);    
    SendMessage(hButton1, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
    SendMessage(hzurueck, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
    SendMessage(hvor, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);

    hInst = hInstanceHandle;

    MSG Message = {0}; 
    while(GetMessage(&amp;Message, NULL, 0, 0)) { 
        TranslateMessage(&amp;Message); 
        DispatchMessage(&amp;Message); 
    } 
    return Message.wParam; 
} 

LRESULT CALLBACK MainWindowProcedure(HWND hWindowHandle, 
                                     UINT uMessage, 
                                     WPARAM wParam, 
                                     LPARAM lParam) { 
    static HWND hEdit;

    switch(uMessage) {

    case WM_CREATE: 
        { 
            hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
                                   &quot;edit&quot;,
                                   buffer,    
                                   WS_CHILD | WS_VISIBLE,
                                   10, 40, 300, 20,
                                   hWindowHandle,
                                   NULL,
                                   ((LPCREATESTRUCT) lParam) -&gt; hInstance,
                                   NULL);

            free(buffer);
            SendMessage(hEdit, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);    
        }                 

    case WM_COMMAND:
                        switch(LOWORD(wParam)) { 
                                               case 1001: 

                                               STARTUPINFO si;
	                                           PROCESS_INFORMATION pi;

	                                           ZeroMemory( &amp;si, sizeof(si) );
	                                           si.cb = sizeof(si);
	                                           ZeroMemory( &amp;pi, sizeof(pi) );
	                                           strcat(Mal,Datei[o].Name);

                                               CreateProcess( NULL,Mal, NULL, NULL, FALSE, 0, NULL, NULL, &amp;si, &amp;pi);  
                                               strcpy(Mal,&quot;mspaint.exe &quot;),
                                               CloseHandle( pi.hThread );
                                               CloseHandle( pi.hProcess );
                                               break; 
                                               } 

                        i=0;
                        if(lParam == (LPARAM)hButton1)        
                        {
                                  ja=1;
                                  int iLength;

                                  iLength = GetWindowTextLength(hEdit);
                                  buffer = (char*) malloc(iLength);
                                  GetWindowText(hEdit, buffer, iLength+1);
                                  strcpy(Ordnername,buffer);
                                  strcpy(Oeffnung,Ordnername);
                                  strcat(Oeffnung,&quot;\\*&quot;);

                                  fHandle=FindFirstFile(Oeffnung,&amp;wfd); 

                                  do 
                                  { 
                                                                        if (!( (wfd.cFileName[0]=='.') &amp;&amp; ( (wfd.cFileName[1]=='.' &amp;&amp; wfd.cFileName[2]==0) || wfd.cFileName[1]==0 ) )) 
                                                                        { 
                                                                               if (wfd.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY) 
                                                                               { 
                                                                                   continue;
                                                                               } 
                                                                               else 
                                                                               {   
                                                                                    if(strstr(wfd.cFileName,&quot;.bmp&quot;)||strstr(wfd.cFileName,&quot;.BMP&quot;)||strstr(wfd.cFileName,&quot;.jpg&quot;)||strstr(wfd.cFileName,&quot;.JPG&quot;))
                                                                                    {                    
                                                                                                         strcpy(Datei[i].Name,Ordnername);
                                                                                                         strcat(Datei[i].Name,&quot;\\\\&quot;);
                                                                                                         strcat(Datei[i].Name,wfd.cFileName);
                                                                                                         strcpy(Datei[i].nName,wfd.cFileName);
                                                                                                         i++;
                                                                                    }
                                                                               }    
                                                                        } 
                                  }while (FindNextFile(fHandle,&amp;wfd)); 
                                  FindClose(fHandle);
                                  i--;
                                  o=0;
                                  SendMessage(hText2, WM_SETTEXT, 0,(LPARAM)Datei[0].nName);
                                  ja=1;

                                  UpdateWindow(hWindowHandle);
                                  UpdateWindow(hPictureBox2);
                                  InvalidateRect(hWindowHandle, NULL, TRUE); 
                                  GetClientRect(hWindowHandle,&amp;rc); 
                                  RedrawWindow(hWindowHandle,&amp;rc,NULL, RDW_ERASE | RDW_INVALIDATE);
                        } 
                  if(lParam == (LPARAM)hzurueck)        
                  {
                            o--;
                            SendMessage(hText2, WM_SETTEXT, 0,(LPARAM)Datei[o].nName);

                            UpdateWindow(hWindowHandle);
                            UpdateWindow(hPictureBox2);
                            InvalidateRect(hWindowHandle, NULL, TRUE); 
                            GetClientRect(hWindowHandle,&amp;rc); 
                            RedrawWindow(hWindowHandle,&amp;rc,NULL, RDW_ERASE | RDW_INVALIDATE);
                  }
                  if(lParam == (LPARAM)hvor)        
                  {
                            o++;
                            SendMessage(hText2, WM_SETTEXT, 0,(LPARAM)Datei[o].nName);

                            UpdateWindow(hWindowHandle);
                            UpdateWindow(hPictureBox2);
                            InvalidateRect(hWindowHandle, NULL, TRUE); 
                            GetClientRect(hWindowHandle,&amp;rc); 
                            RedrawWindow(hWindowHandle,&amp;rc,NULL, RDW_ERASE | RDW_INVALIDATE);
                  } 
        break; 
        case WM_DESTROY: 
            PostQuitMessage(0); 
            break; 
        default: 
            return DefWindowProc(hWindowHandle, uMessage, wParam, lParam); 
    } 
    return 0; 
} 

LRESULT CALLBACK PictureBoxProcedure(HWND hWindowHandle, 
                                     UINT uMessage, 
                                     WPARAM wParam, 
                                     LPARAM lParam) { 
    switch(uMessage) { 
    case WM_CREATE: 
        { 
            COlePicture* pPicture = new COlePicture; 
            CHAR WindowText[MAX_PATH]; 
            GetWindowText(hWindowHandle, WindowText, MAX_PATH);
            pPicture-&gt;Load(Datei[o].Name); 
            SetWindowLong(hWindowHandle, GWL_USERDATA, (LONG) pPicture);

        } 
        break; 
    case WM_DESTROY: 
        { 
            COlePicture* pPicture = (COlePicture*) GetWindowLong(hWindowHandle, GWL_USERDATA); 
            if(pPicture != NULL) { 
                delete pPicture; 
            } 
        } 
        break; 
    case WM_LBUTTONDOWN: 
        SendMessage(GetParent(hWindowHandle), WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hWindowHandle), 0), (LPARAM)hWindowHandle);
        break; 
    case WM_PAINT: 
        { 
            UpdateWindow(hWindowHandle);
            UpdateWindow(hPictureBox2);
            InvalidateRect(hWindowHandle, NULL, TRUE); 
            GetClientRect(hWindowHandle,&amp;rc); 
            RedrawWindow(hWindowHandle,&amp;rc,NULL, RDW_ERASE | RDW_INVALIDATE);

            PAINTSTRUCT ps; 
            HDC hDC = BeginPaint(hWindowHandle, &amp;ps); 
            COlePicture* pPicture = (COlePicture*) GetWindowLong(hWindowHandle, GWL_USERDATA); 
            if(pPicture != NULL) {
                pPicture-&gt;Show(hWindowHandle, 0, 0); 
            } 
            EndPaint(hWindowHandle, &amp;ps); 
        } 
        break; 
    default: 
        return DefWindowProc(hWindowHandle, uMessage, wParam, lParam); 
    } 
    return 0; 
}
</code></pre>
<p>Danke,</p>
<p>Felix</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1341523</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1341523</guid><dc:creator><![CDATA[Felix15]]></dc:creator><pubDate>Thu, 09 Aug 2007 13:05:30 GMT</pubDate></item><item><title><![CDATA[Reply to Bild in der Picturebox aktualisieren on Thu, 09 Aug 2007 15:38:43 GMT]]></title><description><![CDATA[<p>Was meinst Du mit aktualisieren? InvalidateRect? Vielleicht reduzierst Du den Code mal auf das Wesentliche...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1341583</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1341583</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Thu, 09 Aug 2007 15:38:43 GMT</pubDate></item><item><title><![CDATA[Reply to Bild in der Picturebox aktualisieren on Thu, 09 Aug 2007 14:26:11 GMT]]></title><description><![CDATA[<p>Funktionsweise meines Programmes:<br />
Man gibt einen Ordner an. Mit dem Programm kann man dann die Bilder nach einander betrachten.</p>
<p>Das Problem ist, dass das Programm die Bilder nicht anzeigt, obwohl diese gefunden werden.</p>
<pre><code>pPicture-&gt;Load(Datei[o].Name);
</code></pre>
<p>Diese Zeile wird nicht aktualisiert, weil wenn ich den Code so umändere:</p>
<pre><code>pPicture-&gt;Load(&quot;C:\\test1.jpg&quot;);
</code></pre>
<p>dann wird die ganze Zeit dieses Bild angezeigt.</p>
<p>InvalidateRect: Wo müsste ich diese Funktion hinschreiben, damit dieses Problem gelöst wird?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1341600</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1341600</guid><dc:creator><![CDATA[Felix15]]></dc:creator><pubDate>Thu, 09 Aug 2007 14:26:11 GMT</pubDate></item><item><title><![CDATA[Reply to Bild in der Picturebox aktualisieren on Thu, 09 Aug 2007 15:37:21 GMT]]></title><description><![CDATA[<p>Eij, ei, ei...was ein Spaghetti-Code <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /> .</p>
<p>Also, Du solltest Dir erstmal globale Variablen abgewöhnen bzw. nur da verwenden, wo das wirklich nötig ist - sonst nie! Des weiteren sollte man nur da dynamisch allokieren, wenn es auch dynamisch sein muss; kennst Du das Schlüsselwort static? (vergleiche folgende Codeabschnitte und mach Dir darüber nochmal Gedanken <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> :<br />
<strong>1.</strong></p>
<pre><code class="language-cpp">COlePicture* pPicture = new COlePicture;
// ...
COlePicture* pPicture = (COlePicture*) GetWindowLong(hWindowHandle, GWL_USERDATA);
if(pPicture != NULL) {
    delete pPicture;
}
</code></pre>
<p><strong>2.</strong></p>
<pre><code class="language-cpp">struct Daten{
       char Name[900];
       char nName[900];
       };

struct Daten Datei[800];
</code></pre>
<p>). Dies hat aber nichts mit Deinem Fehler zu tun.</p>
<p>Also, wenn ich nichts übersehen habe, würde ich sagen, der Fehler liegt hier (in der Funktion 'PictureBoxProcedure'):</p>
<pre><code class="language-cpp">case WM_CREATE:
        {
            COlePicture* pPicture = new COlePicture;
            CHAR WindowText[MAX_PATH];
            GetWindowText(hWindowHandle, WindowText, MAX_PATH);
            pPicture-&gt;Load(Datei[o].Name);
            SetWindowLong(hWindowHandle, GWL_USERDATA, (LONG) pPicture);

        }
        break;
</code></pre>
<p>Der WM_CREATE Handler wird nur einmal beim Erstellen des Controls aufgerufen. Damit wird das Objekt ('pPicture') der Klasse 'COlePicture' auch nur einmal mit der Bilddatei initialisiert. Lass den murks einfach raus und ändere den WM_PAINT-Handler wie folgt ab:</p>
<pre><code class="language-cpp">case WM_PAINT:
        {
            /*
            UpdateWindow(hWindowHandle);
            UpdateWindow(hPictureBox2);
            InvalidateRect(hWindowHandle, NULL, TRUE);
            GetClientRect(hWindowHandle,&amp;rc);
            RedrawWindow(hWindowHandle,&amp;rc,NULL, RDW_ERASE | RDW_INVALIDATE);
            */
            PAINTSTRUCT ps;
            BeginPaint(hWindowHandle, &amp;ps);
            COlePicture Image;
            Image.Load(Datei[o].Name);
            Image.Show(hWindowHandle, 0, 0);
            EndPaint(hWindowHandle, &amp;ps);
        }
        break;
</code></pre>
<p>PS: InvalidateRect und Kammerade in WM_PAINT zu verwenden ist nicht nur schwachsinnig, sondern eigentlich auch falsch (-&gt;Endlosschleife).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1341683</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1341683</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Thu, 09 Aug 2007 15:37:21 GMT</pubDate></item><item><title><![CDATA[Reply to Bild in der Picturebox aktualisieren on Thu, 09 Aug 2007 18:31:06 GMT]]></title><description><![CDATA[<p>Jetzt klappt's. Vielen vielen Dank CodeFinder. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1341801</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1341801</guid><dc:creator><![CDATA[Felix15]]></dc:creator><pubDate>Thu, 09 Aug 2007 18:31:06 GMT</pubDate></item></channel></rss>