Eingabefeld im Hauptfenster, wie?
-
hallo,
habe gerade angefangen mich mit der WinAPI zu beschäftigen.
bin da nun aber auf ein problem gestoßen. und zwar möchte ich in meinem hauptfenster, welches auch zu beginn da ist, ein eingabefeld haben.
da ich mir auch schon mit resourcen ein menü erstellt habe, habe ich mir gedacht, dass ich damit auch mein eingabefeld machen kann. so wie ich das sehe geht das aber nur wenn ich ein neues fenster benutze, was ich aber nicht möchte.
eine andere möglichkeit, welche ich gefunden habe ist diese:
HWND hEdit;
hEdit = CreateWindowEx(0, "EDIT", "EDIT", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 190, 145, 100, 20, hwnd, reinterpret_cast<HMENU>(ID_BUTTON1), hThisInstance, 0);das mit den resourcen wäre mir aber lieber.
wie wird das in der regel gehandhabt?
thx
slower
-
Dazu brauchst du schon einen Dialog. So einen Dialog bindet man auch als Resource in sein Programm ein. Anzeigen kannst du ihn z.B. durch die Funktion DialogBox(). Aber sobald du ein Fenster mit CreateWindow() erstellst, musst du alle anderen Controls darauf (z.B. ein Edit) ebenfalls per CreateWindow() erstellen und anzeigen.
-
Hier ein Auszug aus der Microsoft Tools Reference:
The DIALOG statement defines a window that an application can use to create dialog boxes. The statement defines the position and dimensions of the dialog box on the screen as well as the dialog box style.
SyntaxnameID DIALOG [ load-mem] x, y, width, height
[optional-statements]
BEGIN
control-statement
. . .
ENDParameters
nameID
Identifies the dialog box. This is either a unique name or a unique 16-bit unsigned integer value in the range 1 to 65,535.
load-mem
Specifies loading and memory attributes for the resource. For more information, see Common Resource Attributes.
option-statements
Specifies options for the dialog box. This can be zero or more of the following statements:
CAPTION "text"
Specifies the caption of the dialog box if it has a title bar. See CAPTION for more information.
CHARACTERISTICS dword
Specifies a user-defined double-word value for use by resource tools. This value is not used by Windows. For more information, see CHARACTERISTICS.
CLASS class
Specifies a 16-bit unsigned integer or a string, enclosed in double quotation marks ("), that identifies the class of the dialog box. See CLASS for more information.
LANGUAGE language,sublanguage
Specifies the language of the dialog box. See LANGUAGE for more information.
STYLE styles
Specifies the styles of the dialog box. See STYLE for more information.
EXSTYLE=extended-styles
Specifies the extended styles of the dialog box. See EXSTYLE for more information.
VERSION dword
Specifies a user-defined doubleword value. This statement is intended for use by additional resource tools and is not used by Windows. For more information, see VERSION.
For more information on the x, y, width, and height parameters, see Common Statement Parameters.
Remarks
The GetDialogBaseUnits function returns the dialog base units in pixels. The exact meaning of the coordinates depends on the style defined by the STYLE option statement. For child-style dialog boxes, the coordinates are relative to the origin of the parent window, unless the dialog box has the style DS_ABSALIGN; in that case, the coordinates are relative to the origin of the display screen.
Do not use the WS_CHILD style with a modal dialog box. The DialogBox function always disables the parent/owner of the newly created dialog box. When a parent window is disabled, its child windows are implicitly disabled. Since the parent window of the child-style dialog box is disabled, the child-style dialog box is too.If a dialog box has the DS_ABSALIGN style, the dialog coordinates for its upper-left corner are relative to the screen origin instead of to the upper-left corner of the parent window. You would typically use this style when you wanted the dialog box to start in a specific part of the display no matter where the parent window may be on the screen.
The name DIALOG can also be used as the class-name parameter to the CreateWindow function to create a window with dialog box attributes.Example
The following demonstrates the usage of the DIALOG statement:
#include <windows.h>
ErrorDialog DIALOG 10, 10, 300, 110
STYLE WS_POPUP|WS_BORDER
CAPTION "Error!"
BEGIN
CTEXT "Select One:", 1, 10, 10, 280, 12
PUSHBUTTON "&Retry", 2, 75, 30, 60, 12
PUSHBUTTON "&Abort", 3, 75, 50, 60, 12
PUSHBUTTON "&Ignore", 4, 75, 80, 60, 12
END
-
Eine Methode wäre es auch, Dein Hauptfenster selbst als Dialog Ressource anzulegen, wodurch Du natürlich dann auch ein Textfeld im Ressourceneditor hinzufügen kannst.
Die WinMain() Methode sieht dann aber auch ein bißchen anders aus (sogar einfacher als normal). Im Prinzip mußt Du da nur das Dialogfenster öffnen (CreateDialog() bzw. DialogBox() ) und eine Zeile um die Nachrichten an die entsprechende Dialog Callback Funktion weiterzuleiten.
-
FrodoSix schrieb:
Eine Methode wäre es auch,...
Wie bereits oben von mir erläutert!
-
Sorry.. ich hab das so verstanden, daß Du zusätzlich zum Hauptfenster eine Dialogbox aufmachen willst, wo dann der ganze Krams drin ist.
-
danke für eure antworten
will es jetzt mit folgendem code versuchen:
main.cpp#include <windows.h> #include "resource.h" /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); BOOL CALLBACK DialogProc (HWND, UINT, WPARAM, LPARAM); /* Make the class name into a global variable */ char szClassName[ ] = "WindowsApp"; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { return DialogBox (hInstance, "DIALOG_0", NULL, DialogProc); } LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) /* handle the messages */ { case WM_DESTROY: PostQuitMessage (0); /* send a WM_QUIT to the message queue */ break; default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0; } BOOL CALLBACK DialogProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_KEYDOWN: switch (wParam) { case VK_ESCAPE: EndDialog(hDlg,0); return (TRUE); } case WM_INITDIALOG: // Hier das machen, was man sonst in WM_CREATE machen würde return (TRUE); case WM_DESTROY: case WM_CLOSE: // Hier wird der Dialog geschlossen EndDialog(hDlg,0); return (TRUE); case WM_COMMAND: // Hier werden die beiden Buttons, vom Standard-Dialog // des MS Visual Studio Resourcengenerators abgefragt. switch (LOWORD(wParam)) { case 207: EndDialog(hDlg,0); return (TRUE); default: break; } return (FALSE); } return (FALSE); }
.rc
/********************************************* File: D:\ANWENDER-XP\C-PROGRAMMIEREN\PROGRAMME\WINDOWS\FIRST\RSRC2.RC Generated by Resource Builder 2.0. *********************************************/ // Below are important 3 lines, don't change them! /* OutputExt=RES */ #include <windows.h> 501 MENU MOVEABLE PURE LOADONCALL DISCARDABLE LANGUAGE LANG_NEUTRAL, 0 BEGIN POPUP "&Datei" BEGIN MENUITEM "&New", 200 MENUITEM "&Open...", 201 MENUITEM "&Save", 202 MENUITEM "Save &as...", 203 MENUITEM SEPARATOR MENUITEM "&Print...", 204 MENUITEM "Page se&tup...", 205 MENUITEM "P&rinter setup...", 206 MENUITEM SEPARATOR MENUITEM "E&xit", 207 END POPUP "&Edit" BEGIN MENUITEM "&Undo", 208 MENUITEM SEPARATOR MENUITEM "&Reset Port", 209 MENUITEM "&Copy\x09Ctrl+Ins", 210 MENUITEM "&Paste\x09Shift+Ins", 211 END POPUP "&Hilfe" BEGIN MENUITEM "&Contents\x09F1", 212 MENUITEM "&Search", 213 MENUITEM "&Using help", 214 MENUITEM SEPARATOR MENUITEM "&About...", 215 END END DIALOG_0 DIALOG 0, 0, 252, 218 STYLE DS_SETFONT |WS_POPUP |WS_CAPTION |WS_VISIBLE |WS_SYSMENU |WS_THICKFRAME |WS_MAXIMIZEBOX |WS_MINIMIZEBOX FONT 8, "MS Sans Serif" LANGUAGE LANG_NEUTRAL, 0 BEGIN CONTROL "Beenden",0,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,49,62,53,14 CONTROL "",1,"EDIT",ES_LEFT |WS_CHILD |WS_BORDER |WS_TABSTOP |WS_VISIBLE ,51,21,99,14 END
jetzt ergeben sich aber wieder problem:
wie bekomme ich mein menü wieder?
warum kann ich keine keyabfrage machen(escape beenden)?
wie frage ich den button ab?oder ist dies eine methode, welche allgemein nicht verwendet wird?
thx
slower
-
das mit dem menü und dem button hab ich hinbekommen.
zu dem problem mit der ESCAPE-taste habe ich folgenden ungelösten beitrag gefunden:
http://www.c-plusplus.net/forum/viewtopic.php?t=15480&highlight=keydown+dialogdie space taste geht tatsächlich, aber aber woran liegt das nun?
-
Bin mir grad nicht mehr ganz sicher, aber bekommt man da nicht IDCANCEL im LOWORD(wParam) in WM_COMMAND
Kann auch sein, dass ich mich gerade irre