fokus
-
warum bekomme ich in das childwindow keinen Fokus??
#define STRICT #include <windows.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK ChildProc (HWND, UINT, WPARAM, LPARAM); const char szAppName[] = "Chat-Client"; const char szChildName[] = "child"; int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { MSG msg; HWND hWnd; WNDCLASS wc; addr.sin_addr.s_addr = inet_addr ("127.0.0.1"); addr.sin_port = htons (12345); addr.sin_family = AF_INET; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hbrBackground = GetSysColorBrush(0); wc.lpszClassName = szAppName; wc.lpszMenuName = NULL; RegisterClass(&wc); wc.hIcon = NULL; wc.lpfnWndProc = ChildProc; wc.lpszClassName = szChildName; RegisterClass (&wc); hWnd = CreateWindow( szAppName, szAppName, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX, 0, 0, 600, 500, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } WSACleanup (); return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HMENU hMenu; static HMENU hSubMenu; static HWND hWndIn, hWndOut, hWndSend, hChild; HWND hButton; switch (message) { case WM_PAINT: { break; } case WM_CREATE: { hWndIn = CreateWindowEx (WS_EX_CLIENTEDGE, "edit", "", WS_CHILD | WS_VISIBLE | ES_LEFT | ES_AUTOHSCROLL | ES_MULTILINE | WS_VSCROLL, 10, 350, 440, 100, hWnd, (HMENU) 1, ((LPCREATESTRUCT) lParam) ->hInstance, NULL); hWndOut = CreateWindowEx (WS_EX_CLIENTEDGE, "edit", "", WS_CHILD | WS_VISIBLE | ES_LEFT | ES_AUTOHSCROLL | ES_MULTILINE | WS_VSCROLL, 10, 10, 570, 300, hWnd, (HMENU) 2, ((LPCREATESTRUCT) lParam) ->hInstance, NULL); hWndSend = CreateWindowEx (0, "button", "Senden", WS_CHILD | WS_VISIBLE, 470, 350, 100, 25, hWnd, (HMENU) 3, ((LPCREATESTRUCT) lParam) ->hInstance, NULL); hChild = CreateWindowEx (0, szChildName, NULL, WS_CHILD | WS_DLGFRAME | WS_SYSMENU | WS_OVERLAPPED | WS_CAPTION, 90, 20, 400, 300, hWnd, 0, ((LPCREATESTRUCT) lParam) ->hInstance, NULL); hMenu = CreateMenu(); hSubMenu = CreateMenu (); AppendMenu (hMenu, MF_STRING | MF_POPUP,(UINT) hSubMenu, "&Datei"); AppendMenu (hSubMenu, MF_STRING, 9001, "Verbinden"); AppendMenu (hSubMenu, MF_STRING, 9002, "Trennen"); AppendMenu (hSubMenu, MF_STRING | MF_SEPARATOR, 9003, ""); AppendMenu (hSubMenu, MF_STRING, 9004, "Beenden"); SetMenu (hWnd, hMenu); break; } case WM_COMMAND: { switch (LOWORD (wParam)) { case 3: { break; } case 9001: { ShowWindow (hChild, SW_RESTORE); SetFocus (hChild); SetForegroundWindow (hChild); break; } case 9002: { break; } case 9004: { PostQuitMessage(0); return 0; } default: break; } break; } case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefWindowProc(hWnd, message, wParam, lParam); } LRESULT CALLBACK ChildProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HWND hButton; switch (message) { case WM_CREATE: { hButton = CreateWindowEx (0, "button", "Test", WS_CHILD | WS_VISIBLE, 1, 1, 200, 200, hWnd, (HMENU) 2001, ((LPCREATESTRUCT) lParam) ->hInstance, NULL); break; } case WM_COMMAND: { switch (LOWORD (wParam)) { case 2001: MessageBox (hWnd, "Test", "", MB_OK); break; } break; } default: break; } return DefWindowProc(hWnd, message, wParam, lParam); }
bin für jede Hilfe dankbar
-
Hilfe?
-
problem vereinfachen -> unnützen code rausnehmen
-
#define STRICT #include <windows.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK ChildProc (HWND, UINT, WPARAM, LPARAM); const char szAppName[] = "Chat-Client"; const char szChildName[] = "child"; int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { MSG msg; HWND hWnd; WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hbrBackground = GetSysColorBrush(0); wc.lpszClassName = szAppName; wc.lpszMenuName = NULL; RegisterClass(&wc); wc.hIcon = NULL; wc.lpfnWndProc = ChildProc; wc.lpszClassName = szChildName; RegisterClass (&wc); hWnd = CreateWindow( szAppName, szAppName, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX, 0, 0, 600, 500, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HMENU hMenu; static HMENU hSubMenu; static HWND hWndIn, hWndOut, hWndSend, hChild; HWND hButton; switch (message) { case WM_PAINT: { break; } case WM_CREATE: { hWndIn = CreateWindowEx (WS_EX_CLIENTEDGE, "edit", "", WS_CHILD | WS_VISIBLE | ES_LEFT | ES_AUTOHSCROLL | ES_MULTILINE | WS_VSCROLL, 10, 350, 440, 100, hWnd, (HMENU) 1, ((LPCREATESTRUCT) lParam) ->hInstance, NULL); hWndOut = CreateWindowEx (WS_EX_CLIENTEDGE, "edit", "", WS_CHILD | WS_VISIBLE | ES_LEFT | ES_AUTOHSCROLL | ES_MULTILINE | WS_VSCROLL, 10, 10, 570, 300, hWnd, (HMENU) 2, ((LPCREATESTRUCT) lParam) ->hInstance, NULL); hWndSend = CreateWindowEx (0, "button", "Senden", WS_CHILD | WS_VISIBLE, 470, 350, 100, 25, hWnd, (HMENU) 3, ((LPCREATESTRUCT) lParam) ->hInstance, NULL); hChild = CreateWindowEx (0, szChildName, NULL, WS_CHILD | WS_DLGFRAME | WS_SYSMENU | WS_OVERLAPPED | WS_CAPTION|WS_VISIBLE, 0, 0, 400, 300, hWnd, 0, ((LPCREATESTRUCT) lParam) ->hInstance, NULL); hMenu = CreateMenu(); hSubMenu = CreateMenu (); AppendMenu (hMenu, MF_STRING | MF_POPUP,(UINT) hSubMenu, "&Datei"); AppendMenu (hSubMenu, MF_STRING, 9001, "Verbinden"); AppendMenu (hSubMenu, MF_STRING, 9002, "Trennen"); AppendMenu (hSubMenu, MF_STRING | MF_SEPARATOR, 9003, ""); AppendMenu (hSubMenu, MF_STRING, 9004, "Beenden"); SetMenu (hWnd, hMenu); break; } case WM_COMMAND: { switch (LOWORD (wParam)) { case 30: { break; } case 3: { ShowWindow (hChild, SW_SHOW); SetFocus (hChild); SetForegroundWindow (hChild); InvalidateRect(hChild,NULL,TRUE); UpdateWindow(hChild); break; } case 9002: { break; } case 9004: { PostQuitMessage(0); return 0; } default: break; } break; } case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefWindowProc(hWnd, message, wParam, lParam); } LRESULT CALLBACK ChildProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HWND hButton; switch (message) { case WM_CREATE: { hButton = CreateWindowEx (0, "button", "Test", WS_CHILD | WS_VISIBLE, 1, 1, 200, 200, hWnd, (HMENU) 2001, ((LPCREATESTRUCT) lParam) ->hInstance, NULL); break; } case WM_COMMAND: { switch (LOWORD (wParam)) { case 2001: MessageBox (hWnd, "Test", "", MB_OK); break; } break; } default: break; } return DefWindowProc(hWnd, message, wParam, lParam); }
-
was ist das denn für ein komisches programm? was soll überhaupt da dieses child fenster auf dem edit? das stört doch nur :p
erstell es doch als neues elternfenster und nicht als child fenster
-
case 9001: { RECT theRect; ShowWindow (hChild, SW_RESTORE); GetClientRect (hWnd, &theRect); ValidateRect (hWnd, &theRect); InvalidateRect (hChild, NULL, TRUE); SetForegroundWindow (hChild); SetFocus (hChild); UpdateWindow (hChild); BringWindowToTop (hChild); break; }
dankw, für antworten, der Tipp mit den Koordinaten (von Stealth) hat zur Lösung
geführt. so wie' s oben steht, gehts!![ Dieser Beitrag wurde am 10.06.2003 um 22:33 Uhr von N00Bie editiert. ]