WXwidgets for GUI in C++: - c++

I am totally beginner in creating GUIS and I am using wxwidgets to create GUI programs in CodeBlocks. I am following this tutorials here:
http://wiki.codeblocks.org/index.php?title=WxSmith_tutorials
I have figured out how to create dialog boxes and frames. Now, I have created in C++ a program that reads information from a .txt file and calls a method displayInfo() that prints this information using cout. What I would like to do is to print this information on a single window, by clicking a button, say: "Print Information".
The part that I am finding hard, is how to call my displayInfo() method from the main.cpp of the frame, and how to display that information on a window, instead of the terminal. I tried to import the header file of my class in the main.cpp of the frame, and called displayInfo(), but I do not think this is the right way to do it.
Any help would be appreciated.

wxWidgets has some predefined dialog boxes for display small quantities of text.
See wxMessageBox description
Otherwise you will have to use a DrawText method on the panel or window.

I reccomend using a text control and then redirecting cout to the text control
Like this:
#include <iostream>
wxTextCtrl *control = new wxTextCtrl(...);
wxStreamToTextRedirector redirect(control);
// all output to cout goes into the text control until the exit from current
// scope
For more discussion of neat variations on this trick, take a look at:
http://docs.wxwidgets.org/2.8/wx_wxtextctrl.html
Scroll down to the section titled: wxTextCtrl and C++ streams

Related

display printf output in main window in QT

I am new to Qt programming, I have made a simple gui with a single push button. Basically I have written a program in C++ now I want to make Gui for my project. I want to display output of all printf statement in my gui. printf statements showing their output in console but I want to add something similar to console in my gui so that whenever I call printf statement it shows its result in the gui. Could you please guide me how can I do this?
You can use a QLabel to show your output in the GUI.
Everytime you call printf, you call setText(...) instead. Now the debug text will be shown in the text label in your GUI.
You can add several QLabels for different debug outputs, if you want.
EDIT:
This could also be of interest.
use QProcess start your CLI program and use readData/writeData to get your information and put them into a QTextEdit
I have found the answer of my question, I have used textbrowser in gui and make a function which I call for printing my data in gui. I can not show the picture of my gui because I have less reputations.
here is the function that I have used for printing.
void MainWindow::print(const QString &input){
data_lab += input;//to display all data in stream
ui->label->setText(input);
ui->textBrowser->setText(data_lab);
}
and here is the call of function from main.
w.print("hellok\n");
w.print("l\n");
I hope this will help somebody like me.

adding text to another programs text box c++

i have already managed to send text to a custom text box i created using c++, and to notepad, calc and other programs all with 1 window and 1 text box. however, i want to send text to another program that has more than one text box and is in tabs too. it is structured like so:
open program
choose from a selection of 2 tabs: a. stats b. config(which contains the text boxes)
fill in the 4 text boxes to desired values
i have tried winspy++ with no luck, here is simple code i have been working with.
#include <windows.h>
int main()
{
HWND hNote;
HWND hChild;
if (!(hNote=FindWindow("windowname",NULL)))
exit(1);
if (!(hChild=FindWindowEx(hNote,NULL,"EDIT",NULL)))
exit(2);
SendMessage(hChild,WM_SETTEXT,NULL,(LPARAM)"texttoadd");
return 0;
}
Can anyone help me how can resolve this issue ?
So the problem is to get a handle of the specific control. You may use for example following ways for finding control's handle:
Control can be distinguished by control id, then use GetDlgItem function to get the its handle. Control id can be found using tools like Spy++ or InqSoft Windows Scanner or other.
MSDN says that control can be found by coordinates of the point within parent window by ChildWindowFromPoint , ChildWindowFromPointEx or RealChildWindowFromPoint function.
Or all controls can be enumerated within parent window by EnumChildWindows and an appropriate one can be found using custom rules.

Key logger wont record key strokes without console

I created a small basic key logger in C++. For some reason when I compile and run the program with the console displayed, it will record every key stroke I make in whatever program I am using such as a browser and store it in a text file. However when I make it so that it WON'T display a console window, it will not record anything and it's just a process in the background doing nothing. Here is the link to my code: http://pastebin.com/4wqQyLJ9
The function that is giving me trouble with hiding the console, is the Stealth() function. Any suggestions, tips or hints will be helpful.
Use this function , it works for me pretty well.
ShowWindow(GetConsoleWindow(), SW_HIDE);
Instead of hiding the window after the program starts, I solved this by not
having a window to begin with. Compile with -mwindows and a window is not
created when the program starts.
Example
I would consider a Windows Service for this kind of thing if you don't need UI. Also using GetAsyncKeyState can be more stealthy if required. This C++ source might be of use...
Windows Service Keylogger

(MFC Visual C++): How to write inside an edit control box & save to .txt?

I'm trying to create a simple program, if you can even call it that.
It has a main dialog and inside an edit box/control thing. picture
When I try to debug (I'm using MS Visual Studio 2013) I get the "I-beam" (the flashing text-thing pointer) but I can't input any text. picture
Questions: Why? How to fix?
Also, later on I want to try writing the inputted text into a txt file. I've tried searching for it, and found that you have to use the string method... Beyond that I could not understand the explanations ;(
CODE:
void Cedit2textDlg::OnEnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialogEx::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
program is called edit2text. This is the ONLY part about the edit box I have in my main edit2textDlg.cpp file. The .rc you can see in the first picture.
I have found a somehow similar problem that was solved using dlg.DoModal(); and creating a variable for the edit box with a value-category, but could not understand how and why I should use it.

How do I open a new window on start up using C++?

I don't know how to make a window when I start up Windows. I just want a simple window that has some text in it, such as a reminder. I don't want to download anything, and I think C++ is the easiest way to do it.
The easiest way to display a window with a message in Windows would be use use VBScript. Create a text file with the following in it.
msgbox("hello world")
Now, name the file MyProgram.vbs or anything else with a .vbs extension.
Double click on the file to run it. The message "hello world" should be shown in a small window on your screen. As seen in the image below.
To run it at start up, just drag it in your Startup folder in your Start Menu.