Solved

Displaying a button in a window

Posted on 1998-09-12
2
171 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 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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
Replacement selected text 2 69
Change to event 1 138
how to split multiple lines delimiter : 8 133
Notepad++ Question 11 28
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: 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…
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.

752 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