Implement custom input box (Inputbox) via messages

xiaoxiao2021-03-18  188

C Builder provides two functions of two display input dialogs: Inputbox and INPUTQUERY (where INPUTBOX is also implemented by calling InputQuery), this input dialog has a lot of shortcomings. In the previous article, I mentioned the use of modified VCL source code. To achieve a custom input dialog, later in Torry.net see an article is implemented using a custom message method, the original is Delphi code, Ccrun (old demon) rewritten with C , and appropriately modify the display effect better Some: Basic Thoughts: In the input dialog box, POST a message gives the main form, which is responsible for modifying the properties of the input dialog form and the properties of the input text editing box, by overloading in the main form. The WndProc function responds to custom messages.

The code and renderings are as follows: .h file: public: void __fastcall WndProc (TMESSAGE & MSG);

In .cpp file: // Customize a message, notify the main form for input box setting #define my_input_box WM_USER 101 / / --------------------- -------------------------------------------------- ---- // Rear load the WNDPROC of the main form to process the processing void __fastcall tfrmmain :: WndProc (tMSG == my_INPUT_BOX) {// msg.wpaam // 0: Ordinary Mode, 1: Password box mode // msg.lparam // 0: normal mode, 1: Tmorm * frm = screen-> Forms [0]; if (frm! = This) // Input box form {// Set the font of the input dialog to the main form, it is recommended to set the main window body to the Song No. 9 FRM-> font-> assign (font); // Change the title of the OK and Cancel button Handle HbTnok = FindWindowEx (FRM-> Handle, NULL, "TButton", "OK"); Handle Hbtncel = FindWindowEx (FRM-> Handle, Null, "TButton", "Cancel"); if (HBTNOK) SETWINDOWTEXT (HBTNOK, "OK (& O) "); if (hbtncel) setWindowText (HBTNCANCEL," Cancel (& C) "); // Do you need to display a picture if (msg.lparam == 1) {// Add a picture in the upper left corner of the form , Specify its Owner as the input box form, // this is input Automatically release TIMAGE resource time * img = new timage (fm); img-> icon; img-> = 11; img-> top = 60; IMG- > PARENT = frm; img-> show ();} // is a password box //63 63 72 75 6e 2e 63 6f 6d if (msg.wparam == 1) {handle hndit = findwindowex (frm-> handle , NULL, "TEDIT", NULL; if (Hedit) SendMessage (Hedit, EM_SETPASSWORDCHAR, WPARAM ('* "

), 0);}}} TFORM :: WndProc (msg);} // ------------------------------- ------------------------------------------- // Sorry, this prompt Also, in order to prevent irresponsible reprinters, there is only some information here. // by ccrun info@ccrun.com// Welcome to C Builder Research - http://www.ccrun.com//---------------- -------------------------------------------------- -------- original InputBox (Figure 1) Void __fastcall tfrmmain :: btnoldStyleClick (TOBJECT * sender) {string stratext = inputbox ("Original Input Dialog", "Please enter some characters:", " "); If (strText.trim (). Length ()> 0) showMessage (STRTEXT);} (Figure 1) You can see that the character display is not fully on the form, and the title of the two buttons is also English. / / -------------------------------------------------------------------------------------------- --------------------------- Improved effect (Figure 2) Void __fastcall tfrmmain :: btnnewstyleClick (Tobject * sender) {PostMessage (Handle , My_INPUT_BOX, 0, 0); // The focus is this String Strtext = INPUTBOX ("New Enter Dialog", "Please enter some characters:", ""); if (strText.trim (). Length () > 0) ShowMessage (strText);

(Figure 2) After the improvement, the character display is more beautiful, and the button title is also Chinese. / / -------------------------------------------------------------------------------------------- --------------------------- with pictures (Figure 3) void __fastcall tfrmmain :: btnwithImageclick (Tobject * sender) {// msg .Lparam = 1: Picture of pictures Postmessage (Handle, My_INPUT_BOX, 0, 1); String Strtext = INPUTBOX ("Input Box with Picture Effect", "Please enter some characters:", "Oh, taking pictures") ; If (strText.trim (). Length ()> 0) ShowMessage (StRTEXT);

(Figure 3) Input box with picture effect // ------------------------------------ ------------------------------------- Password input box effect (Figure 4) void __fastcall tfrmmain :: BtnpwdStyleClick (TOBJECT * Sender) {// msg.wparam = 1: Password box mode PostMessage (Handle, My_INPUT_BOX, 1, 0); String Strtext = InputBox ("Password Enter Box", "Please enter your password:", " 123 "); if (strText.trim (). Length ()> 0) showMessage (STRText);} (Figure 4) Effect of password input box

转载请注明原文地址:https://www.9cbs.com/read-129773.html

New Post(0)