Solved

Displaying a button in a window

Posted on 1998-09-12
2
167 Views
Last Modified: 2013-12-26
'lo
I want to display and (of course!) use  buttons in a window
i tried to use the GetnewControl() function with  a cntl
ressource but it doesn't work. How can I do this?
thx
0
Comment
Question by:corwin_
2 Comments
 
LVL 3

Accepted Solution

by:
boonstra earned 50 total points
ID: 1291523
You have not given much information about what did not work, but the following program demonstrates how to use buttons in a window, either with GetNewControl or with GetControl.  It puts up two buttons, one of which beeps, and one of which quits the program.

WindowPtr      gWindow;
ControlHandle gBeepButton,gQuitButton;
      
static int DoMouse(EventRecord *ev)
{
  WindowPtr front, wind;
  short part,modifiers;
  Point where;
  int res = 0;

  front = FrontWindow();
  part = FindWindow(ev->where, &wind);
  where = ev->where;
  modifiers = ev->modifiers;
   
  switch (part) {
    case inSysWindow:
      SystemClick(ev, wind);
      break;
    case inContent:
    {
      ControlHandle theControl;
      int part;
      Point pt;
      pt = ev->where;
      GlobalToLocal(&pt);
      part = FindControl(pt, wind, &theControl);
      if (theControl==gBeepButton) {
        TrackControl(theControl,pt,nil);
        SysBeep(1);
      } else if (theControl==gQuitButton) {
        TrackControl(theControl,pt,nil);
        res=1;
      }
      break;
    }
  }
 
  return res;
}

int main(void)
{
  EventRecord theEvent;
  Rect r;
  int res;
  Boolean done=false,gotEvent;
 
  /* Initialize all the needed managers. */
  InitGraf(&qd.thePort);
  InitFonts();
  InitWindows();
  InitMenus();
  TEInit();
  InitDialogs(nil);
  InitCursor();

  SetRect(&r,40,60,200,100);
  gWindow = NewCWindow(nil, &r, "\pButton Demo", true, documentProc, (WindowPtr) -1, false, 0);
  SetRect(&r,16,10,76,30);
  gBeepButton = NewControl(gWindow, &r, "\pBeep", true, 1, 0, 1, pushButProc, 0);
  OffsetRect(&r,80,0);
  gQuitButton = NewControl(gWindow, &r, "\pQuit", true, 1, 0, 1, pushButProc, 0);
// alternatively, you could get the controls from a resource file
//  gBeepButton = GetNewControl(128, gWindow);
//  gQuitButton = GetNewControl(129, gWindow);
//  
  SetPort(gWindow);
  ShowWindow(gWindow);
 
  while (!done) {
    WindowPtr wind;
    gotEvent = WaitNextEvent(everyEvent,&theEvent,0,NULL);
    if (gotEvent) {
      switch (theEvent.what) {
      case activateEvt:
        break;
      case updateEvt:
        wind = (WindowPtr)theEvent.message;
        if (wind == gWindow) {
          BeginUpdate(gWindow);
          UpdateControls(wind, wind->visRgn);
          EndUpdate(gWindow);
        }
        break;
      case mouseDown:
        res = DoMouse(&theEvent);
        if (res!=0) done=true;
        break;
      }
    }
  }
 
  return 0;  
}


0
 

Author Comment

by:corwin_
ID: 1291524
thx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now