我正在尝试使用C中的X11 / Xlib创建一个窗口。我的主要目标是为我的程序创建一个GUI界面,如下所示。 (注意:我已经尝试为窗口编码,但它一直说我没有监视器或说有分段错误。
#include <stdio.h>
#include <stdlib.h>
#include<X11/Xlib.h>
int main(int argc, char *argv[])
{
Display *Monitor;
Window DrawWindow;
GC WindowGC;
Monitor=XOpenDisplay(NULL);
if (Monitor == NULL)
{
printf("Unable to open graphic display\n");
exit(0);
}
DrawWindow=XCreateSimpleWindow(Monitor,RootWindow(Monitor,0),
10,10,
100,50,
2,
BlackPixel(Monitor,0),
WhitePixel(Monitor,0));
XMapWindow(Monitor,DrawWindow);
XFlush(Monitor);
sleep(10);
XCloseDisplay(Monitor);
int return_val = 0;
int pin_number = 5309;
int usr_pin = 0;
int valid_pin = 0;
// Pin # Validation
while(1)
{
printf ("\nPlease enter the 4 digit pin number:\n");
return_val = scanf("%d", &usr_pin);
while (getchar() != '\n'); /* Clear keyboard input buffer */
if((pin_number > 999) && (pin_number < 9999))
{
if (return_val == 1)
{
while(1)
{
if(usr_pin != pin_number)
{
//while (getchar() != '\n'); /* Clear keyboard input buffer */
printf("Incorrect Pin\n");
printf("Re-enter pin number");
break;
}
else
{
valid_pin = 1;
break;
}
}
}
}
if (valid_pin == 1) {
break;
}
}
// Successful account setup prompt
printf("\nPin Correct!\n");
printf("Pin #: %d\n", pin_number);
printf("Have a nice day.\n");
return 0;
}