Solved

Displaying a button in a window

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a Shell script to start a service checking the port 6 52
tripleUp challenge 7 86
canBalance challenge 34 98
changeXy challenge 13 89
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 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