<?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 variablen deklarieren]]></title><description><![CDATA[<p>Hi,<br />
habe Probleme mit dem deklarieren meiner Variable.</p>
<pre><code>#define STRICT
#include &lt;windows.h&gt;
#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;cstring&gt;

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

char szClassName[ ] = &quot;Window&quot;;

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               
    MSG messages;            
    WNDCLASSEX wincl;        

    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      
    wincl.style = CS_DBLCLKS;                 
    wincl.cbSize = sizeof (WNDCLASSEX);

    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 
    wincl.cbClsExtra = 0;                      
    wincl.cbWndExtra = 0;                      
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    if (!RegisterClassEx (&amp;wincl))
        return 0;

    hwnd = CreateWindowEx (
           0,                   
           szClassName,         
           &quot;Window&quot;,       
           WS_OVERLAPPEDWINDOW, 
           CW_USEDEFAULT,       
           CW_USEDEFAULT,       
           344,                 
           175,                 
           HWND_DESKTOP,        
           NULL,                
           hThisInstance,      
           NULL                 
           );

    ShowWindow (hwnd, nFunsterStil);
    UpdateWindow(hwnd);

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

    return messages.wParam;
}

[b]char chStr[256] = &quot;123456&quot;;
[/b]
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    const UINT TimerSec = 1;
    static HWND EdHwnd;
    static HWND hButton;

    switch (message)   
    {

	case WM_CREATE:
                  EdHwnd = CreateWindow(&quot;EDIT&quot;, &quot;&quot;, ES_AUTOHSCROLL|WS_VISIBLE|WS_CHILD|WS_BORDER,10,100,300, 30, hwnd, (HMENU)1201, ((LPCREATESTRUCT) lParam) -&gt; hInstance, 0);
                  hButton = CreateWindow(&quot;button&quot;,&quot;Los&quot;,WS_CHILD | WS_VISIBLE,10,50,300, 30,hwnd,NULL,((LPCREATESTRUCT) lParam) -&gt; hInstance,NULL);

        break;

        case WM_COMMAND:
        {

           InvalidateRect(hwnd, NULL, TRUE);
           if (lParam == (LPARAM)hButton)
           {
              if (HIWORD(wParam) == BN_CLICKED) {
           			SendMessage(EdHwnd, WM_GETTEXT, sizeof(chStr), (ULONG)&amp;chStr);
           			MessageBox(hwnd, chStr, &quot;hallo&quot;, MB_OK);
                    InvalidateRect(hwnd, NULL, TRUE);
              }      

           }

           return 0;
        }

    case WM_PAINT:
    {

                  PAINTSTRUCT ps;
                  HDC         hDC;
                  hDC = BeginPaint(hwnd, &amp;ps);
                  {
                               TextOut(hDC, 10, 10, chStr, strlen(chStr));
                  }
                  EndPaint(hwnd, &amp;ps);
                  return 0;
    }

        case WM_DESTROY:
            PostQuitMessage (0);       
            break;
        default:                     
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}
</code></pre>
<p>Die Variable chStr[256] kann ich nur als Globale deklarieren sobald ich die Variable in die Funktion(LRESULT CALLBACK WindowProcedure) schreibe, wird sie immer wieder mit der Zeichenkette &quot;123456&quot; definiert.<br />
Wo werden die Variablen denn deklariert und was muss ich tun damit ich chStr nicht als Globale Variable schreiben muss??<br />
Mir bitte nicht den Kopf abreißen, sind meine ersten Versuche mit Winapi.</p>
<p>Vielen Dank<br />
Goodies <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>
]]></description><link>https://www.c-plusplus.net/forum/topic/219365/winapi-variablen-deklarieren</link><generator>RSS for Node</generator><lastBuildDate>Thu, 08 Oct 2026 07:57:47 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/219365.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 02 Aug 2008 01:54:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Winapi variablen deklarieren on Sat, 02 Aug 2008 01:54:11 GMT]]></title><description><![CDATA[<p>Hi,<br />
habe Probleme mit dem deklarieren meiner Variable.</p>
<pre><code>#define STRICT
#include &lt;windows.h&gt;
#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;cstring&gt;

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

char szClassName[ ] = &quot;Window&quot;;

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               
    MSG messages;            
    WNDCLASSEX wincl;        

    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      
    wincl.style = CS_DBLCLKS;                 
    wincl.cbSize = sizeof (WNDCLASSEX);

    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 
    wincl.cbClsExtra = 0;                      
    wincl.cbWndExtra = 0;                      
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    if (!RegisterClassEx (&amp;wincl))
        return 0;

    hwnd = CreateWindowEx (
           0,                   
           szClassName,         
           &quot;Window&quot;,       
           WS_OVERLAPPEDWINDOW, 
           CW_USEDEFAULT,       
           CW_USEDEFAULT,       
           344,                 
           175,                 
           HWND_DESKTOP,        
           NULL,                
           hThisInstance,      
           NULL                 
           );

    ShowWindow (hwnd, nFunsterStil);
    UpdateWindow(hwnd);

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

    return messages.wParam;
}

[b]char chStr[256] = &quot;123456&quot;;
[/b]
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    const UINT TimerSec = 1;
    static HWND EdHwnd;
    static HWND hButton;

    switch (message)   
    {

	case WM_CREATE:
                  EdHwnd = CreateWindow(&quot;EDIT&quot;, &quot;&quot;, ES_AUTOHSCROLL|WS_VISIBLE|WS_CHILD|WS_BORDER,10,100,300, 30, hwnd, (HMENU)1201, ((LPCREATESTRUCT) lParam) -&gt; hInstance, 0);
                  hButton = CreateWindow(&quot;button&quot;,&quot;Los&quot;,WS_CHILD | WS_VISIBLE,10,50,300, 30,hwnd,NULL,((LPCREATESTRUCT) lParam) -&gt; hInstance,NULL);

        break;

        case WM_COMMAND:
        {

           InvalidateRect(hwnd, NULL, TRUE);
           if (lParam == (LPARAM)hButton)
           {
              if (HIWORD(wParam) == BN_CLICKED) {
           			SendMessage(EdHwnd, WM_GETTEXT, sizeof(chStr), (ULONG)&amp;chStr);
           			MessageBox(hwnd, chStr, &quot;hallo&quot;, MB_OK);
                    InvalidateRect(hwnd, NULL, TRUE);
              }      

           }

           return 0;
        }

    case WM_PAINT:
    {

                  PAINTSTRUCT ps;
                  HDC         hDC;
                  hDC = BeginPaint(hwnd, &amp;ps);
                  {
                               TextOut(hDC, 10, 10, chStr, strlen(chStr));
                  }
                  EndPaint(hwnd, &amp;ps);
                  return 0;
    }

        case WM_DESTROY:
            PostQuitMessage (0);       
            break;
        default:                     
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}
</code></pre>
<p>Die Variable chStr[256] kann ich nur als Globale deklarieren sobald ich die Variable in die Funktion(LRESULT CALLBACK WindowProcedure) schreibe, wird sie immer wieder mit der Zeichenkette &quot;123456&quot; definiert.<br />
Wo werden die Variablen denn deklariert und was muss ich tun damit ich chStr nicht als Globale Variable schreiben muss??<br />
Mir bitte nicht den Kopf abreißen, sind meine ersten Versuche mit Winapi.</p>
<p>Vielen Dank<br />
Goodies <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1557890</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1557890</guid><dc:creator><![CDATA[Goodies]]></dc:creator><pubDate>Sat, 02 Aug 2008 01:54:11 GMT</pubDate></item><item><title><![CDATA[Reply to Winapi variablen deklarieren on Sat, 02 Aug 2008 08:37:41 GMT]]></title><description><![CDATA[<p>Entweder machst Du die auch statisch in der CALLBACK oder lässt sie global.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1557928</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1557928</guid><dc:creator><![CDATA[Airdamn]]></dc:creator><pubDate>Sat, 02 Aug 2008 08:37:41 GMT</pubDate></item></channel></rss>