Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Displaying a button in a window

Posted on 1998-09-12
2
Medium Priority
?
176 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
boonstra earned 150 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

721 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