Skip navigation.
Home
The QNX Community Portal

View topic - beginner c++ material

beginner c++ material

Isn't the name clear?

beginner c++ material

Postby peroxidechicken » Fri Oct 03, 2003 2:00 pm

What's the smallest file size for a program the opens a photon window, does some IO (gfx or text) and allows the user to maybe make menu selections and quit via the close button? AND has the C++ source to show how it was done?

I figure a small file size is the result of a fairly small, self contained source file(s). Fingers crossed. :)
peroxidechicken
New Member
 
Posts: 6
Joined: Mon Jul 22, 2002 3:33 am

Re: beginner c++ material

Postby rgallen » Fri Oct 03, 2003 3:30 pm

peroxidechicken wrote:What's the smallest file size for a program the opens a photon window, does some IO (gfx or text) and allows the user to maybe make menu selections and quit via the close button? AND has the C++ source to show how it was done?

I figure a small file size is the result of a fairly small, self contained source file(s). Fingers crossed. :)


Well, if you want to use C++ a complete example (using standard QNX tools) would be fairly long. I do have a personal C++ class lib that (if it was used to create a similar app) would be comparable to the Java, perhaps even smaller (but non-portable).

If however, you want to step into the 90's and use Java (he says ducking ;-), here is a test app that does what you ask.

(please excuse the poor indentation, it is the wacky editor on this site)

-------
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;

public final class App {
Display display;
Shell shell;
Text txt;
Button btn;
Color blue;

public static void main(String[] args) {
new App();
}

public App() {
display = new Display ();

shell = new Shell (display);

txt = new Text(shell, SWT.BORDER);
txt.setBounds(100,100,100, 20);

btn = new Button(shell, SWT.PUSH);
btn.setBounds(100,50,100,20);

btn.setText("Say Hello");

btn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (txt.getText().equals("Hello World!"))
txt.setText("");
else
txt.setText("Hello World!");
}
});
blue=display.getSystemColor(SWT.COLOR_BLUE);

Canvas canvas=new Canvas(shell, SWT.BORDER);
canvas.setSize(400,400);
canvas.setLocation(400,400);
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
GC gc=e.gc;
gc.setForeground(blue);
gc.drawLine(80,20,100,80);
}
});

shell.open ();

GC gc=new GC(canvas);
gc.setForeground(blue);
gc.drawLine(80,20,100,80);

while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
rgallen
QNX Master
 
Posts: 671
Joined: Thu Jul 11, 2002 6:48 pm

Postby noc » Fri Oct 03, 2003 4:43 pm

There is a bbcode called "code" that you might want to try to wrap your code. Test it out in the Test Forum and see if you like it.
noc
Senior Member
 
Posts: 1634
Joined: Sat Jul 06, 2002 4:34 am

Postby rgallen » Fri Oct 03, 2003 4:46 pm

noc wrote:There is a bbcode called "code" that you might want to try to wrap your code. Test it out in the Test Forum and see if you like it.


Thanks for the pointer !
rgallen
QNX Master
 
Posts: 671
Joined: Thu Jul 11, 2002 6:48 pm


Return to GUI Programming

Who is online

Users browsing this forum: No registered users and 4 guests