Skip to content

Instantly share code, notes, and snippets.

@unxmaal
Created December 27, 2023 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unxmaal/eaf23959537f92bf8f3ec02024fd2e0e to your computer and use it in GitHub Desktop.
Save unxmaal/eaf23959537f92bf8f3ec02024fd2e0e to your computer and use it in GitHub Desktop.
#include <Types.h>
#include <Dialogs.h>
#include <Windows.h>
#include <Menus.h>
#include <TextEdit.h>
#include <Quickdraw.h>
#include <Events.h>
#include <Resources.h>
#include <Sound.h>
// Function Prototypes
void Initialize();
void EventLoop();
void DoEvent(EventRecord *event);
void HandleMouseDown(EventRecord *event);
void HandleWindowEvent(EventRecord *event);
void DoUpdate(EventRecord *event);
WindowPtr gMainWindow;
Rect buttonRect;
int main() {
Initialize();
EventLoop();
return 0;
}
void Initialize() {
InitGraf(&qd.thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(nil);
InitCursor();
// Load resources
gMainWindow = GetNewWindow(128, nil, (WindowPtr)-1L);
ShowWindow(gMainWindow);
}
void EventLoop() {
EventRecord event;
while (true) {
if (WaitNextEvent(everyEvent, &event, 60, nil)) {
DoEvent(&event);
}
}
}
void DoEvent(EventRecord *event) {
switch (event->what) {
case mouseDown:
HandleMouseDown(event);
break;
case updateEvt:
DoUpdate(event);
break;
}
}
void HandleMouseDown(EventRecord *event) {
WindowPtr window;
short part = FindWindow(event->where, &window);
switch (part) {
case inContent:
if (window == gMainWindow) HandleWindowEvent(event);
break;
case inDrag:
DragWindow(window, event->where, &qd.screenBits.bounds);
break;
}
}
void HandleWindowEvent(EventRecord *event) {
Point where = event->where;
GlobalToLocal(&where);
buttonRect.top = 50;
buttonRect.left = 50;
buttonRect.bottom = 100;
buttonRect.right = 150;
// Assuming the button's rectangle is predefined as buttonRect
if (PtInRect(where, &buttonRect)) {
// Code to display "Hello"
SysBeep(10); // Simple feedback
}
}
void DoUpdate(EventRecord *event) {
WindowPtr window = (WindowPtr)event->message;
BeginUpdate(window);
// Redrawing code here
EndUpdate(window);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment