2. Fenster
-
Hi mikey...
danke für deine schnelle antwort...
habe deinen code unter case WM_CREATE folgent eingefügt:
hwnd2 = CreateWindow ( "Name", "CaptionText", WS_CHILD, 60, 80, 170, 30, hwnd, // Muss aber der Name des Parentfensters sein ! NULL, ((LPCREATESTRUCT) lParam) -> hInstance, NULL);und mein button sollte das dann eigentlich so aufrufen:
ShowWindow (hwnd2, SW_SHOW);macht er aber leider nicht. woran könnts denn liegen?

-
Hi,
sende mal bitte deinen kompletten Source, ich werde es dir verbessern ! (Zu viele Faktoren spielen da eine Rolle)
MfG mikey.
-
sry bin noch nicht angemeldet...aber ich setzte es mal hier rein...
ist nur ein minimaler code...#include <Windows.h> #include <commctrl.h> #pragma comment(lib,"Comctl32.lib") HWND hwnd, hwndButton1; HINSTANCE g_hInst; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR szCmdLine, int iCmdShow) { InitCommonControls(); static TCHAR szAppName[] = TEXT("LeWi-Player"); MSG msg; g_hInst=hInstance; WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = 0; wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)COLOR_WINDOW; wndclass.lpszClassName = szAppName; wndclass.lpszMenuName = NULL; RegisterClass(&wndclass); hwnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,szAppName, TEXT("LeWi-Player"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 350, 300, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.lParam; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: { hwndButton1 = CreateWindow(TEXT("Button"), "OK", WS_CHILD | WS_VISIBLE | BS_ICON, 0, 0, 100, 21, hwnd, NULL, ((LPCREATESTRUCT) lParam)->hInstance, NULL); return 0; } case WM_SIZE: { MoveWindow(hwndButton1, 1, 1,LOWORD(lParam)-1, 50, TRUE); return 0; } case WM_DESTROY: PostQuitMessage (0); return 0; } return DefWindowProc (hwnd, message, wParam, lParam); }
-
#include <Windows.h> #include <commctrl.h> #pragma comment(lib,"Comctl32.lib") HWND hwnd, hwndButton1, hwnd2; HINSTANCE g_hInst; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT("LeWi-Player"); MSG msg; g_hInst=hInstance; WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = 0; wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)COLOR_WINDOW; wndclass.lpszClassName = szAppName; wndclass.lpszMenuName = NULL; RegisterClass(&wndclass); hwnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,szAppName, TEXT("LeWi-Player"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 350, 300, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.lParam; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: { hwndButton1 = CreateWindow(TEXT("Button"), "OK", WS_CHILD | WS_VISIBLE, 0, 0, 100, 21, hwnd, NULL, ((LPCREATESTRUCT) lParam)->hInstance, NULL); hwnd2 = CreateWindow( "EDIT", "Neues Fenster", WS_OVERLAPPEDWINDOW, 200, 200, 100, 150, hwnd, NULL, ((LPCREATESTRUCT) lParam)->hInstance, NULL); ShowWindow (hwnd2, SW_SHOW); break; return 0; } case WM_SIZE: { MoveWindow(hwndButton1, 1, 1,LOWORD(lParam)-1, 50, TRUE); return 0; } case WM_DESTROY: PostQuitMessage (0); return 0; } return DefWindowProc (hwnd, message, wParam, lParam); }..und du verwendest Dev-C++, und möchtest den XP Style aktivieren ? Vergiss das mit dem "InitCommonControls();" geh einfach unter dem folgenden Menüpunkt von Dev-C++:
Projekt
Projekt Optionen
Windows XP Themen unterstützen...natürlich musst du vorher ein Projekt angelegt haben !
MfG mikey.
-
so...hab mich jetzt mal angemeldet...
danke für die super tips.
hab leider nur noch ein problem. hab jetzt die ShowWindow (hwnd2, SW_SHOW); in meinen button eingebaut. wenn ich jetzt aber das fenster schliese, lässt es sich kein 2. mal öffnen.
-
hab leider nur noch ein problem. hab jetzt die ShowWindow (hwnd2, SW_SHOW); in meinen button eingebaut.
Wie in deinen Button eingebaut ?!
-
case WM_COMMAND: { if (lParam == (LPARAM)hwndButton1) { if (HIWORD(wParam) == BN_CLICKED) { ShowWindow (hwnd2, SW_SHOW); } } }und kann man das fenster auch ohne editfeld anzeigen lassen?
-
Musst du mal warten, ich weis es nicht. Bin halt ein Noob in Sachen WinAPI. Aber muss man für das Childfenster nicht eine eigene WndProc einsetzen !?
-
*hochschieb*
wollte nochmal nach anderen meinungen ausschau halten. hat jemand von euch eine idee??
-
HWND DeinFenster; // g_MainWindow ist global und ist das Handle des Haupt-Fensters if(hwnd == g_MainWindow) // Sonst bekommst du unendlich viele Fenster { DeinFenster = CreateWindow ( "Name",// Muss genauso lauten wie die Class des Parent-Fensters "CaptionText", WS_VISIBLE|WS_MINIMIZEBOX|WS_SYSMENU,// WICHTIG!!! 60, 80, 170, 200, hwnd, // Muss aber der Name des Parentfensters sein ! NULL, ((LPCREATESTRUCT) lParam) -> hInstance, NULL); }
-
ist aber hwnd nicht normalerweise das handle zum hauptfenster??? leider funktioniert das bei mir nicht.