<?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[WinAPI Window with Skins]]></title><description><![CDATA[<p>Hallo.</p>
<p>Folgender code geht nicht. Ich weiß nicht woran es liegt. Der Compiler meldet nichts. Jedenfalls wird ein window erstellt, aber wenn man die Leertaste oder 'Test' drückt, kein Skin.<br />
Könnt ihr mir helfen?</p>
<pre><code class="language-cpp">#define WIN32_LEAN_AND_MEAN

#include &lt;windows.h&gt;
#include &lt;iostream.h&gt;
#include &quot;resource.h&quot;

HINSTANCE hInst;
HDC     dcSkin;
HWND hWnd=NULL;
HBITMAP hSkinBmp, hOldBmp;

void SkinMe(HDC dc) { BitBlt(dc, 0,0,333,333, dcSkin, 0,0, SRCCOPY); }
void RegionMe();
void UnRegionMe();
bool MakeWindow(int iWidth, int iHeight);

BOOL CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    switch(uMsg)
    {
        case WM_INITDIALOG:
            /*
             * TODO: Add code to initialize the dialog.
             */
            return TRUE;

        case WM_CLOSE:
            EndDialog(hWnd, 0);
            return TRUE;

        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case IDC_BTN_QUIT:
                    EndDialog(hWnd, 0);
                    return TRUE;

                case IDC_BTN_TEST:
                   // MessageBox(hWnd, &quot;You clicked!&quot;, &quot;Information&quot;, MB_ICONINFORMATION);
                    SkinMe(GetDC(0));
                    return TRUE;
            }
          case WM_KEYDOWN:
          {

      switch (wParam)
      {
        case VK_ESCAPE:
          PostQuitMessage(0);
          break;

        case VK_SPACE:

            SkinMe(GetDC(0));
            break;

      }
      break;
    }

    case WM_PAINT:
    {
      // -------------------------------------------------
      // tell user to press SPACE to toggle region.
      // -------------------------------------------------

      PAINTSTRUCT ps;
      BeginPaint(hWnd,&amp;ps);

      SkinMe(ps.hdc);
      SetBkMode(ps.hdc,TRANSPARENT);
      SetTextColor(ps.hdc,RGB(255,0,0));
      TextOut(ps.hdc, 115,90, &quot;Press SPACE&quot;, 11);

      EndPaint(hWnd,&amp;ps);

      break;
    }
    }

    return DefWindowProc (hWnd, uMsg, wParam, lParam) ;
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {

  hInst = hInstance;

  // load the skin bitmap from resource
  hSkinBmp = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SKIN));
  if (!hSkinBmp) {
      cout &lt;&lt; &quot;cant load bitmap&quot; &lt;&lt; endl;
      return -1;
  }
  // create a device context for the skin
  dcSkin = GetDC(0);

  // select the skin bitmap
  hOldBmp = (HBITMAP)SelectObject(dcSkin, hSkinBmp);

  // -------------------------------------------------
  // create the application window.
  // -------------------------------------------------

  if ( !MakeWindow(320, 240) )  {
      cout &lt;&lt; &quot;cant makewindow&quot; &lt;&lt;endl;
  //    return -1;
  }
  // show window
  ShowWindow(hWnd, SW_SHOW);

  MSG mMsg;
/*
  while (1)
  {

    if(PeekMessage(&amp;mMsg, 0, 0, 0, PM_REMOVE))
    {
      if(mMsg.message == WM_QUIT) {
          break;
      }
      TranslateMessage(&amp;mMsg);
      DispatchMessage(&amp;mMsg);
    }

  }
  */
  SelectObject(dcSkin, hOldBmp);
  DeleteObject(hSkinBmp);
  DeleteDC(dcSkin);
  DestroyWindow(hWnd);

  return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, DialogProc);
}

// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------

void RegionMe() {
  DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE);
  dwStyle &amp;= ~(WS_CAPTION|WS_SIZEBOX);
  SetWindowLong(hWnd, GWL_STYLE, dwStyle);

  InvalidateRect(hWnd, NULL, TRUE);
  SetWindowPos(hWnd, NULL, 0,0,444,444, SWP_NOMOVE|SWP_NOZORDER);
}

void UnRegionMe() {
  SetWindowRgn(hWnd, NULL, true);
  DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE);
  dwStyle |= WS_CAPTION|WS_SIZEBOX;
  SetWindowLong(hWnd, GWL_STYLE, dwStyle);
  InvalidateRect(hWnd, NULL, TRUE);
  SetWindowPos(hWnd, NULL, 0,0,320,240, SWP_NOMOVE|SWP_NOZORDER);
}

bool MakeWindow(int iWidth, int iHeight)
{
  // our window class
  WNDCLASS wndWc;

  wndWc.style = CS_OWNDC;
  wndWc.lpfnWndProc = (WNDPROC) DialogProc;
  wndWc.cbClsExtra = 0;
  wndWc.cbWndExtra = 0;
  wndWc.hInstance = GetModuleHandle(NULL);
  wndWc.hIcon = NULL;
  wndWc.hCursor = LoadCursor(0, IDC_ARROW);
  wndWc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  wndWc.lpszMenuName = NULL;
  wndWc.lpszClassName = &quot;w32skin&quot;;

  if (!RegisterClass(&amp;wndWc)) {
      std::cout &lt;&lt;&quot;error reg&quot; &lt;&lt; std::endl;
      return false;
  }

  hWnd = CreateWindow(&quot;w32skin&quot;, &quot;       w32skin&quot;,
                      WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                      100,100, iWidth,iHeight,
                      NULL, NULL, GetModuleHandle(NULL), NULL
         );
         cout &lt;&lt; hWnd &lt;&lt; endl;
  GetLastError();
  return (hWnd);

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/233121/winapi-window-with-skins</link><generator>RSS for Node</generator><lastBuildDate>Thu, 09 Apr 2026 12:00:03 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/233121.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 01 Feb 2009 00:12:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to WinAPI Window with Skins on Sun, 01 Feb 2009 00:12:39 GMT]]></title><description><![CDATA[<p>Hallo.</p>
<p>Folgender code geht nicht. Ich weiß nicht woran es liegt. Der Compiler meldet nichts. Jedenfalls wird ein window erstellt, aber wenn man die Leertaste oder 'Test' drückt, kein Skin.<br />
Könnt ihr mir helfen?</p>
<pre><code class="language-cpp">#define WIN32_LEAN_AND_MEAN

#include &lt;windows.h&gt;
#include &lt;iostream.h&gt;
#include &quot;resource.h&quot;

HINSTANCE hInst;
HDC     dcSkin;
HWND hWnd=NULL;
HBITMAP hSkinBmp, hOldBmp;

void SkinMe(HDC dc) { BitBlt(dc, 0,0,333,333, dcSkin, 0,0, SRCCOPY); }
void RegionMe();
void UnRegionMe();
bool MakeWindow(int iWidth, int iHeight);

BOOL CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    switch(uMsg)
    {
        case WM_INITDIALOG:
            /*
             * TODO: Add code to initialize the dialog.
             */
            return TRUE;

        case WM_CLOSE:
            EndDialog(hWnd, 0);
            return TRUE;

        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case IDC_BTN_QUIT:
                    EndDialog(hWnd, 0);
                    return TRUE;

                case IDC_BTN_TEST:
                   // MessageBox(hWnd, &quot;You clicked!&quot;, &quot;Information&quot;, MB_ICONINFORMATION);
                    SkinMe(GetDC(0));
                    return TRUE;
            }
          case WM_KEYDOWN:
          {

      switch (wParam)
      {
        case VK_ESCAPE:
          PostQuitMessage(0);
          break;

        case VK_SPACE:

            SkinMe(GetDC(0));
            break;

      }
      break;
    }

    case WM_PAINT:
    {
      // -------------------------------------------------
      // tell user to press SPACE to toggle region.
      // -------------------------------------------------

      PAINTSTRUCT ps;
      BeginPaint(hWnd,&amp;ps);

      SkinMe(ps.hdc);
      SetBkMode(ps.hdc,TRANSPARENT);
      SetTextColor(ps.hdc,RGB(255,0,0));
      TextOut(ps.hdc, 115,90, &quot;Press SPACE&quot;, 11);

      EndPaint(hWnd,&amp;ps);

      break;
    }
    }

    return DefWindowProc (hWnd, uMsg, wParam, lParam) ;
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {

  hInst = hInstance;

  // load the skin bitmap from resource
  hSkinBmp = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SKIN));
  if (!hSkinBmp) {
      cout &lt;&lt; &quot;cant load bitmap&quot; &lt;&lt; endl;
      return -1;
  }
  // create a device context for the skin
  dcSkin = GetDC(0);

  // select the skin bitmap
  hOldBmp = (HBITMAP)SelectObject(dcSkin, hSkinBmp);

  // -------------------------------------------------
  // create the application window.
  // -------------------------------------------------

  if ( !MakeWindow(320, 240) )  {
      cout &lt;&lt; &quot;cant makewindow&quot; &lt;&lt;endl;
  //    return -1;
  }
  // show window
  ShowWindow(hWnd, SW_SHOW);

  MSG mMsg;
/*
  while (1)
  {

    if(PeekMessage(&amp;mMsg, 0, 0, 0, PM_REMOVE))
    {
      if(mMsg.message == WM_QUIT) {
          break;
      }
      TranslateMessage(&amp;mMsg);
      DispatchMessage(&amp;mMsg);
    }

  }
  */
  SelectObject(dcSkin, hOldBmp);
  DeleteObject(hSkinBmp);
  DeleteDC(dcSkin);
  DestroyWindow(hWnd);

  return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, DialogProc);
}

// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------

void RegionMe() {
  DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE);
  dwStyle &amp;= ~(WS_CAPTION|WS_SIZEBOX);
  SetWindowLong(hWnd, GWL_STYLE, dwStyle);

  InvalidateRect(hWnd, NULL, TRUE);
  SetWindowPos(hWnd, NULL, 0,0,444,444, SWP_NOMOVE|SWP_NOZORDER);
}

void UnRegionMe() {
  SetWindowRgn(hWnd, NULL, true);
  DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE);
  dwStyle |= WS_CAPTION|WS_SIZEBOX;
  SetWindowLong(hWnd, GWL_STYLE, dwStyle);
  InvalidateRect(hWnd, NULL, TRUE);
  SetWindowPos(hWnd, NULL, 0,0,320,240, SWP_NOMOVE|SWP_NOZORDER);
}

bool MakeWindow(int iWidth, int iHeight)
{
  // our window class
  WNDCLASS wndWc;

  wndWc.style = CS_OWNDC;
  wndWc.lpfnWndProc = (WNDPROC) DialogProc;
  wndWc.cbClsExtra = 0;
  wndWc.cbWndExtra = 0;
  wndWc.hInstance = GetModuleHandle(NULL);
  wndWc.hIcon = NULL;
  wndWc.hCursor = LoadCursor(0, IDC_ARROW);
  wndWc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  wndWc.lpszMenuName = NULL;
  wndWc.lpszClassName = &quot;w32skin&quot;;

  if (!RegisterClass(&amp;wndWc)) {
      std::cout &lt;&lt;&quot;error reg&quot; &lt;&lt; std::endl;
      return false;
  }

  hWnd = CreateWindow(&quot;w32skin&quot;, &quot;       w32skin&quot;,
                      WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                      100,100, iWidth,iHeight,
                      NULL, NULL, GetModuleHandle(NULL), NULL
         );
         cout &lt;&lt; hWnd &lt;&lt; endl;
  GetLastError();
  return (hWnd);

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1655758</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655758</guid><dc:creator><![CDATA[DieSeenDerHerrlichkeit]]></dc:creator><pubDate>Sun, 01 Feb 2009 00:12:39 GMT</pubDate></item><item><title><![CDATA[Reply to WinAPI Window with Skins on Sun, 01 Feb 2009 07:51:26 GMT]]></title><description><![CDATA[<p>Schlägt SelectObject() da nicht fehl?</p>
<pre><code>// create a device context for the skin
  dcSkin = GetDC(0);

  // select the skin bitmap
  hOldBmp = (HBITMAP)SelectObject(dcSkin, hSkinBmp);
</code></pre>
<p>Gemeint ist wohl eher:</p>
<pre><code>// create a device context for the skin
  dcSkin = CreateCompatibleDC(NULL);

  // select the skin bitmap
  hOldBmp = (HBITMAP)SelectObject(dcSkin, hSkinBmp);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1655787</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655787</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Sun, 01 Feb 2009 07:51:26 GMT</pubDate></item><item><title><![CDATA[Reply to WinAPI Window with Skins on Sun, 01 Feb 2009 09:53:19 GMT]]></title><description><![CDATA[<p>blödsinn, wie wärs mit GetDC(hwnd)?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655800</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655800</guid><dc:creator><![CDATA[besserwisser]]></dc:creator><pubDate>Sun, 01 Feb 2009 09:53:19 GMT</pubDate></item><item><title><![CDATA[Reply to WinAPI Window with Skins on Sun, 01 Feb 2009 10:35:36 GMT]]></title><description><![CDATA[<p>Gut,<br />
ich habe mal zudem jedes GetDC(0) zu GetDC(hWnd) geändert.<br />
Dennoch geht es nicht.</p>
<p>Das Problem ist immernoch das gleiche.</p>
<p>Was wir aufgefallen ist:<br />
MakeWindow wird ausgeführt, aber das Fenster verschwindet direkt wieder und ein neues, mit einer anderen größe tritten in Erscheinung. Das verwundert mich, weil ich doch eigentlich nur MakeWindow aufgerufen habe.</p>
<p>Das aktuelle Komplette Projekt:<br />
<strong>main.cpp:</strong></p>
<pre><code class="language-cpp">#define WIN32_LEAN_AND_MEAN

#include &lt;windows.h&gt;
#include &lt;iostream.h&gt;
#include &quot;resource.h&quot;

HINSTANCE hInst;
HDC     dcSkin;
HWND hWnd;
HBITMAP hSkinBmp, hOldBmp;

void SkinMe(HDC dc) { BitBlt(dc, 0,0,333,333, dcSkin, 0,0, SRCCOPY); }
bool MakeWindow(int iWidth, int iHeight);

BOOL CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {

    switch(uMsg) {
        case WM_INITDIALOG:
            SkinMe(GetDC(hWnd));
            return TRUE;

        case WM_CLOSE:
            EndDialog(hWnd, 0);
            return TRUE;

        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case IDC_BTN_QUIT:
                    EndDialog(hWnd, 0);
                    return TRUE;

                case IDC_BTN_TEST:
                    MessageBox(hWnd, &quot;You clicked!&quot;, &quot;Information&quot;, MB_ICONINFORMATION);
                    SkinMe(GetDC(hWnd));
                    return TRUE;
            }
          case WM_KEYDOWN: {

            switch (wParam) {
                case VK_ESCAPE:
                    PostQuitMessage(0);
                    break;
                case VK_SPACE:
                    SkinMe(GetDC(hWnd));
                    break;
            }
            break;
          }

    case WM_PAINT:
      {
      PAINTSTRUCT ps;
      BeginPaint(hWnd,&amp;ps);

      SkinMe(ps.hdc);
      SetBkMode(ps.hdc,TRANSPARENT);
      SetTextColor(ps.hdc,RGB(255,0,0));
      TextOut(ps.hdc, 115,90, &quot;Press SPACE&quot;, 11);

      EndPaint(hWnd,&amp;ps);
      break;
      }
    }

    return DefWindowProc (hWnd, uMsg, wParam, lParam) ;
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
  hInst = hInstance;

  // load the skin bitmap from resource
  hSkinBmp = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SKIN));
  if (!hSkinBmp) {
      cout &lt;&lt; &quot;cant load bitmap&quot; &lt;&lt; endl;
      return -1;
  }
  // create a device context for the skin
  dcSkin = GetDC(hWnd);

  // select the skin bitmap
  hOldBmp = (HBITMAP)SelectObject(dcSkin, hSkinBmp);

  if ( !MakeWindow(320, 840) )  {
      cout &lt;&lt; &quot;cant makewindow&quot; &lt;&lt;endl;
      return -1;
  }
  // show window
  ShowWindow(hWnd, SW_SHOW);

  SkinMe(dcSkin);
  SelectObject(dcSkin, hOldBmp);
  DeleteObject(hSkinBmp);
  DeleteDC(dcSkin);
  DestroyWindow(hWnd);

  return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, DialogProc);
}

// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------

bool MakeWindow(int iWidth, int iHeight)
{
  // our window class
  WNDCLASS wndWc;

  wndWc.style = CS_OWNDC;
  wndWc.lpfnWndProc = (WNDPROC) DialogProc;
  wndWc.cbClsExtra = 0;
  wndWc.cbWndExtra = 0;
  wndWc.hInstance = GetModuleHandle(NULL);
  wndWc.hIcon = NULL;
  wndWc.hCursor = LoadCursor(0, IDC_ARROW);
  wndWc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  wndWc.lpszMenuName = NULL;
  wndWc.lpszClassName = &quot;w32skin&quot;;

  if (!RegisterClass(&amp;wndWc)) {
      std::cout &lt;&lt;&quot;error reg&quot; &lt;&lt; std::endl;
      return false;
  }

  hWnd = CreateWindow(&quot;w32skin&quot;, &quot;       w32skin&quot;,
                      WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                      100,100, iWidth,iHeight,
                      NULL, NULL, GetModuleHandle(NULL), NULL
         );
         cout &lt;&lt; hWnd &lt;&lt; endl;
  GetLastError();
  return (hWnd);

}
</code></pre>
<p><strong>resource.h:</strong></p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

// ID of Main Dialog
#define DLG_MAIN 102

#define IDB_BITMAP1                     101
#define IDB_SKIN                        101

// ID of Button Controls
#define IDC_BTN_TEST 1001
#define IDC_BTN_QUIT 1002
</code></pre>
<p><strong>resource.rc:</strong></p>
<pre><code class="language-cpp">#include &quot;resource.h&quot;

IDB_SKIN BITMAP DISCARDABLE  &quot;skin.bmp&quot;
DLG_MAIN DIALOGEX 6, 5, 194, 106

CAPTION &quot;Tofino GamerzTalk&quot;

FONT 8, &quot;MS Sans Serif&quot;, 0, 0, 1

STYLE 0x10CE0804

BEGIN
  CONTROL &quot;&amp;Test&quot;, IDC_BTN_TEST, &quot;Button&quot;, 0x10010000, 138,  5, 46, 15
  CONTROL &quot;&amp;Quit&quot;, IDC_BTN_QUIT, &quot;Button&quot;, 0x10010000, 138, 29, 46, 15
END
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1655805</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655805</guid><dc:creator><![CDATA[DieSeenDerHerrlichkeit]]></dc:creator><pubDate>Sun, 01 Feb 2009 10:35:36 GMT</pubDate></item><item><title><![CDATA[Reply to WinAPI Window with Skins on Sun, 01 Feb 2009 11:39:52 GMT]]></title><description><![CDATA[<p>Du rufst ja auch direkt DestroyWindow auf <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=";D"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655860</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655860</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Sun, 01 Feb 2009 11:39:52 GMT</pubDate></item><item><title><![CDATA[Reply to WinAPI Window with Skins on Sun, 01 Feb 2009 14:54:08 GMT]]></title><description><![CDATA[<p>Du hast recht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Dennoch erscheint in dem Window der Skin nicht. Nur ein ganz großer fehler: Ein Teil des Desktops wird im wondow eingeblendet. Wie man es kennt wenn der rechner nicht ganz mitkommt <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=";D"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655984</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655984</guid><dc:creator><![CDATA[DHs]]></dc:creator><pubDate>Sun, 01 Feb 2009 14:54:08 GMT</pubDate></item><item><title><![CDATA[Reply to WinAPI Window with Skins on Sun, 01 Feb 2009 15:11:30 GMT]]></title><description><![CDATA[<p>So wie ich den Code verstehe soll in dcSkin die Skin-Bitmap selektiert werden und mit SkinMe (bzw. BitBlt) dann ins Fenster gezeichnet werden.</p>
<p>Wenn du da noch dcSkin=GetDC(hWnd) stehen hast wird das darauffolgende SelectObject() fehlschlagen - Man kann meines Wissens Bitmaps nur in Memory-DCs selektieren, welche man z.B. mit CreateCompatibleDC() erzeugen kann.</p>
<p>Im Moment ist bei SkinMe() Ziel- und Quelle identisch (In WM_PAINT bekommst du einen DC deines Fensters und GetDC() liefert auch einen DC deines Fensters).<br />
GetDC(0) würde den DC des Desktops liefern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655997</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655997</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Sun, 01 Feb 2009 15:11:30 GMT</pubDate></item><item><title><![CDATA[Reply to WinAPI Window with Skins on Sun, 01 Feb 2009 16:38:27 GMT]]></title><description><![CDATA[<p>Danke geeky,<br />
erst dachte ich es wäre ein 'nicht-meine-schuld'-Aufreger.</p>
<p>Na gut. Um ganz erlich zu sein, verstehe ich dein letzten Post nicht komplett <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>
<blockquote>
<p>So wie ich den Code verstehe soll in dcSkin die Skin-Bitmap selektiert werden und mit SkinMe (bzw. BitBlt) dann ins Fenster gezeichnet werden.</p>
</blockquote>
<p>Korrekt.</p>
<blockquote>
<p>Wenn du da noch dcSkin=GetDC(hWnd) stehen hast wird das darauffolgende SelectObject() fehlschlagen - Man kann meines Wissens Bitmaps nur in Memory-DCs selektieren, welche man z.B. mit CreateCompatibleDC() erzeugen kann.</p>
</blockquote>
<p>Ich habe mal alle dcSkin=GeDC(hWnd) rausgenommen, da es ja anscheinbar komplett falsch ist. Den zweiten Teil des Satzes verstehe ich nicht. GetDC funktioniert. Warum dann CreateCompatibleDC?<br />
Geladen wir die BITMAP hier:</p>
<pre><code class="language-cpp">hSkinBmp = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SKIN));
</code></pre>
<blockquote>
<p>Im Moment ist bei SkinMe() Ziel- und Quelle identisch (In WM_PAINT bekommst du einen DC deines Fensters und GetDC() liefert auch einen DC deines Fensters).<br />
GetDC(0) würde den DC des Desktops liefern.</p>
</blockquote>
<p>WM_PAINT hab ich mal komplett gelöscht. Es soll da eh nicht drinn stehen und das was da zZ dirnn steht ist eh falsch. Wo das Ziel und die Quelle identisch sein soll, sehe ich leider nicht.</p>
<pre><code class="language-cpp">SkinMe(HDC dc) { BitBlt(dc, 0,0,333,333, dcSkin, 0,0, SRCCOPY);
</code></pre>
<p>Der Parameter den ich übergebe ist ja der DC des Window (hWnd) - darein wird mit BitBlt dcSkin geklatscht.<br />
Get(0) ist auf jeden fall falsch - kapiere ich nun. Das mit dem desktop wusste ich nicht.</p>
<p>Ich frag mich 2 Dinge:<br />
Warum werden 2 Fenster angezeigt. Warum wird das bild skin.bmp nicht reingeladen. Kann es sein, dass es so direkt garnicht möglich ist den SKin in eine DialogBox zu laden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1656035</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1656035</guid><dc:creator><![CDATA[DieSeenDerHerrlichkeit]]></dc:creator><pubDate>Sun, 01 Feb 2009 16:38:27 GMT</pubDate></item><item><title><![CDATA[Reply to WinAPI Window with Skins on Sun, 01 Feb 2009 17:13:46 GMT]]></title><description><![CDATA[<pre><code>dcSkin = GetDC(hWnd);
hOldBmp = (HBITMAP)SelectObject(dcSkin, hSkinBmp);
</code></pre>
<p>...würde bedeuten du selektierst die Bitmap hSkinBmp in den DeviceContext der zu hWnd gehört, die Bitmap quasi in dein Fenster selektieren.<br />
Würde sowas funktionieren wäre BitBlt() überflüssig.</p>
<p>Für gewöhnlich lädt man eine Bitmap in einen Memory-DC um sie dann mittels BitBlt() auf einen Display-DC zu kopieren.<br />
GetDC(FensterHandle) liefert für gewöhnlich einen Display-DC.<br />
CreateCompatibleDC(DeviceContextHandle) liefert einen Memory-DC mit denselben Farbeinstellungen, etc. wie der DeviceContextHandle-DC.<br />
CreateCompatibleDC(NULL) erzeugt quasi einen zum aktuellen Desktop kompatiblen Memory-DC. Dort kann dann eine Bitmap rein-selektiert werden, welche dann mit BitBlt() auf x-beliebige andere DCs (wie z.B. dem deines Fensters) kopiert werden kann.</p>
<p>Das zweite Fenster kommt durch return DialogBox(...), welches einen irgendwo in den Resourcen definierte Dialog-Box anzeigt und dafür die MessageLoop übernimmt. Ansonsten hat dein Programm bislang auch keine Message-Loop.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1656059</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1656059</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Sun, 01 Feb 2009 17:13:46 GMT</pubDate></item><item><title><![CDATA[Reply to WinAPI Window with Skins on Sun, 01 Feb 2009 17:25:25 GMT]]></title><description><![CDATA[<p>Der Code, den DieSeenDerHerrlichkeit gepostet hat, ist komplett falsch, hier gibt es nichts zu diskutieren. Habe nämlich aus Neugier versucht, zum Laufen zu bekommen...<br />
Dann musste ich es wenig bearbeiten und das ist bei mir rausgekommen (wobei ich nicht weiss, ob das Ergebnis genau das, was DieSeenDerHerrlichkeit habe möchte):<br />
Das ist main.c:</p>
<pre><code class="language-cpp">#define WIN32_LEAN_AND_MEAN

#include &lt;windows.h&gt;
#include &quot;resource.h&quot;

HBITMAP hSkinBmp;

BOOL CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;
    HDC hdcMem;

    switch (uMsg)
    {
        case WM_INITDIALOG:
            {
                return TRUE;
            }

        case WM_CLOSE:
            {
                EndDialog(hWnd, 0);
                return TRUE;
            }

        case WM_PAINT:
            {
                hdc = BeginPaint(hWnd, &amp;ps);
                hdcMem = CreateCompatibleDC(hdc);
                SelectObject(hdcMem, hSkinBmp);

                BitBlt(hdc, 0, 0, 200, 100, hdcMem, 0, 0, SRCCOPY);

                DeleteDC(hdcMem);
                EndPaint(hWnd,&amp;ps);
                break;
            }

        default:
            {
                break;
            }
    }

    return FALSE;
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    hSkinBmp = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SKIN));

    if (NULL == hSkinBmp)
    {
        MessageBox(NULL, TEXT(&quot;cant load bitmap&quot;), TEXT(&quot;Error&quot;), MB_OK);
        return -1;
    }

    return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, DialogProc);
}
</code></pre>
<p>Das ist main.rc:</p>
<pre><code>#include &quot;resource.h&quot; 

IDB_SKIN BITMAP DISCARDABLE  &quot;skin.bmp&quot; 

DLG_MAIN DIALOG DISCARDABLE 100, 100, 200, 100
STYLE WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 
CAPTION &quot;abc.w&quot; 
FONT 8, &quot;MS Sans Serif&quot;
BEGIN 
END
</code></pre>
<p>Das ist resource.h:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt; 

// ID of Main Dialog 
#define DLG_MAIN 102 

#define IDB_BITMAP1                     101 
#define IDB_SKIN                        101
</code></pre>
<p>Und hier mein Makefile:</p>
<pre><code>all:
	mingw32-gcc -c main.c -o main.o -mwindows
	windres main.rc -o main_Rc.o
	mingw32-gcc main_Rc.o main.o -o main.exe -mwindows
</code></pre>
<p>Wie gesagt, der Code läuft, ist aber sicherlich nicht &quot;das Gelbe vom Ei&quot;...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1656064</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1656064</guid><dc:creator><![CDATA[abc.w]]></dc:creator><pubDate>Sun, 01 Feb 2009 17:25:25 GMT</pubDate></item></channel></rss>