Solved

Displaying a button in a window

Posted on 1998-09-12
2
164 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
paragon account problem 9 96
Turn a spreadsheet into a vba executable. 2 66
while loop over for loop 7 79
haveThree challenge 22 100
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

13 Experts available now in Live!

Get 1:1 Help Now