Winapi variablen deklarieren
-
Hi,
habe Probleme mit dem deklarieren meiner Variable.#define STRICT #include <windows.h> #include <string> #include <iostream> #include <cstring> LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); char szClassName[ ] = "Window"; 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 (&wincl)) return 0; hwnd = CreateWindowEx ( 0, szClassName, "Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 344, 175, HWND_DESKTOP, NULL, hThisInstance, NULL ); ShowWindow (hwnd, nFunsterStil); UpdateWindow(hwnd); while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } return messages.wParam; } [b]char chStr[256] = "123456"; [/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("EDIT", "", ES_AUTOHSCROLL|WS_VISIBLE|WS_CHILD|WS_BORDER,10,100,300, 30, hwnd, (HMENU)1201, ((LPCREATESTRUCT) lParam) -> hInstance, 0); hButton = CreateWindow("button","Los",WS_CHILD | WS_VISIBLE,10,50,300, 30,hwnd,NULL,((LPCREATESTRUCT) lParam) -> 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)&chStr); MessageBox(hwnd, chStr, "hallo", MB_OK); InvalidateRect(hwnd, NULL, TRUE); } } return 0; } case WM_PAINT: { PAINTSTRUCT ps; HDC hDC; hDC = BeginPaint(hwnd, &ps); { TextOut(hDC, 10, 10, chStr, strlen(chStr)); } EndPaint(hwnd, &ps); return 0; } case WM_DESTROY: PostQuitMessage (0); break; default: return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }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 "123456" definiert.
Wo werden die Variablen denn deklariert und was muss ich tun damit ich chStr nicht als Globale Variable schreiben muss??
Mir bitte nicht den Kopf abreißen, sind meine ersten Versuche mit Winapi.Vielen Dank
Goodies
-
Entweder machst Du die auch statisch in der CALLBACK oder lässt sie global.