Guidance
指路人
g.yi.org
software / RapidQ / System / Win32 / Rapid-Q++ / test2.cpp

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
// This Rapid-Q++ example is more or less the same one found in Chapter 4
// With some additions of course

#include <iostream.h>
#include "rapidqw32.h"

// Initialize Rapid-Q, our CALLBACK procedure is named WindowProcedure
RQ_INITIALIZE(WindowProcedure);

// Global components
RQForm form(application, WindowProcedure);
RQMainMenu mainMenu;
RQMenuItem fileItem("&File");
RQMenuItem openItem("&Open");
RQMenuItem saveItem("&Save");
RQMenuItem break1Item("-");
RQMenuItem printItem("&Print");
RQMenuItem break2Item("-");
RQMenuItem exitItem("E&xit");
RQStatusBar statusBar;
RQLabel nameLabel("Name:");
RQLabel addressLabel("Address:");
RQLabel cityLabel("City:");
RQLabel phoneLabel("Phone #:");
RQEdit nameEdit;
RQEdit addressEdit;
RQEdit cityEdit;
RQEdit phoneEdit;
RQButton addButton("&Add");
RQButton clearButton("&Clear");
RQButton sortButton("&Sort");
RQListBox listbox;

void menuItemClick (RQMenuItem& sender)
{
    statusBar.setPanelCaption(0, sender.getCaption());
    if (String(sender.getCaption()) == String("E&xit")) form.close();
}

void addButtonClick (RQButton& sender)
{
    if (listbox.getItemCount() > 0)
        listbox.addItem("--------------------------------");

    listbox.addItem(nameEdit.getText());
    listbox.addItem(addressEdit.getText());
    listbox.addItem(cityEdit.getText());
    listbox.addItem(phoneEdit.getText());
}

void clearButtonClick (RQButton& sender)
{
    listbox.clear();
}

void sortButtonClick (RQButton& sender)
{
    listbox.setSorted(!listbox.getSorted());
    if (listbox.getSorted())
        sender.setCaption("&Unsort");
    else
        sender.setCaption("&Sort");
}

void formPaint (RQForm& sender)
{
    sender.canvas.fillRect(205, 10, 270, 110, 0xff8800);
    sender.canvas.rectangle(205, 10, 270, 110, 0);
    sender.font.setFontName("Arial");
    sender.font.setFontSize(9);
    sender.canvas.textOut(210, 15, "HELP", 0xffffff, -1);
    sender.font.setFontSize(8);
    sender.canvas.textOut(210, 35, "Add", 0, -1);
    sender.font.setFontSize(7);
    sender.canvas.textOut(210, 45, "  to listbox", 0, -1);
    sender.canvas.textOut(210, 55, "Clear", 0, -1);
    sender.canvas.textOut(210, 65, "  listbox", 0, -1);
    sender.canvas.textOut(210, 75, "Sort", 0, -1);
    sender.canvas.textOut(210, 85, "  items", 0, -1);
}

//-------------------------- MAIN PROGRAM ---------------------------//

BEGIN_GUI
    // Populate menu
    mainMenu.setParent(form);
    mainMenu.addMenu(fileItem);
    fileItem.addMenu(openItem);
    fileItem.addMenu(saveItem);
    fileItem.addMenu(break1Item);
    fileItem.addMenu(printItem);
    fileItem.addMenu(break2Item);
    fileItem.addMenu(exitItem);

    // Set OnClick event handler
    openItem.onClick = menuItemClick;
    saveItem.onClick = menuItemClick;
    printItem.onClick = menuItemClick;
    exitItem.onClick = menuItemClick;

    // Add a statusbar to the form to display which menuitem was clicked
    statusBar.setParent(form);
    statusBar.addPanel("Status");

    // Set labels
    nameLabel.setParent(form);
    nameLabel.setTop(10); nameLabel.setLeft(10);
    addressLabel.setParent(form);
    addressLabel.setTop(40); addressLabel.setLeft(10);
    cityLabel.setParent(form);
    cityLabel.setTop(70); cityLabel.setLeft(10);
    phoneLabel.setParent(form);
    phoneLabel.setTop(100); phoneLabel.setLeft(10);

    // Set editboxes
    nameEdit.setParent(form);
    nameEdit.setTop(7); nameEdit.setLeft(70);
    addressEdit.setParent(form);
    addressEdit.setTop(37); addressEdit.setLeft(70);
    cityEdit.setParent(form);
    cityEdit.setTop(67); cityEdit.setLeft(70);
    phoneEdit.setParent(form);
    phoneEdit.setTop(97); phoneEdit.setLeft(70);

    // Set buttons
    addButton.setParent(form);
    addButton.setTop(127); addButton.setLeft(10);
    addButton.onClick = addButtonClick;
    clearButton.setParent(form);
    clearButton.setTop(127); clearButton.setLeft(100);
    clearButton.onClick = clearButtonClick;
    sortButton.setParent(form);
    sortButton.setTop(127); sortButton.setLeft(190);
    sortButton.onClick = sortButtonClick;

    // Set listbox
    listbox.setParent(form);
    listbox.setTop(160); listbox.setLeft(10);
    listbox.setWidth(260); listbox.setHeight(150);

    // Center form and display form
    form.onPaint = formPaint;
    form.setHeight(380); form.setWidth(290);
    form.setCaption("Data entry example");
    form.center();
    form.showModal();
END_GUI
// END OF PROGRAM
掌柜推荐
 
 
¥860.00 ·
 
 
¥410.00 ·
 
 
¥288.00 ·
 
 
¥918.00 ·
 
 
¥288.00 ·
 
 
¥264.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-08-20 12:34:45