
1 #include <windows.h>
2 #include <locale.h>
3 #include <ctype.h>
4 #include <stdio.h>
5 #include "resource.h"
6
7 #define LEFT 1
8 #define RIGHT 2
9 #define UP 3
10 #define DOWN 4
11
12 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
13 BOOL CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
14 void gotoxy(int, int);
15
16 void gotoxy(int x, int y) {
17 COORD c;
18 c.X = x;
19 c.Y = y;
20 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
21 }
22
23 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
24 static TCHAR szAppName[] = TEXT("About1");
25 MSG msg;
26 HWND hwnd;
27 WNDCLASS wndclass;
28 wndclass.style = CS_HREDRAW | CS_VREDRAW;
29 wndclass.lpfnWndProc = WndProc;
30 wndclass.cbClsExtra = 0;
31 wndclass.cbWndExtra = 0;
32 wndclass.hInstance = hInstance;
33 wndclass.hIcon = LoadIcon(hInstance, szAppName);
34 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
35 wndclass.hbrBackground = (HBRUSH) COLOR_INACTIVECAPTION;
36 wndclass.lpszMenuName = szAppName;
37 wndclass.lpszClassName = szAppName;
38 if (!RegisterClass(&wndclass)) {
39 MessageBox(NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR);
40 return 0;
41 }
42 hwnd = CreateWindow(
43 szAppName, TEXT("Controla o Console"), WS_OVERLAPPEDWINDOW,
44 CW_USEDEFAULT, CW_USEDEFAULT, 290, 230,
45 NULL, NULL, hInstance, NULL
46 );
47
48 ShowWindow(hwnd, iCmdShow);
49 UpdateWindow(hwnd);
50
51 while(GetMessage(&msg, NULL, 0, 0)) {
52 TranslateMessage(&msg);
53 DispatchMessage (&msg);
54 }
55 return msg.wParam;
56 }
57
58 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
59 switch(message) {
60 case WM_CREATE:
61 CreateWindow(
62 TEXT("BUTTON"), TEXT("LEFT"), WS_VISIBLE | WS_CHILD,
63 20, 80, 80, 20,
64 hwnd, (HWND) LEFT, NULL, NULL
65 );
66 CreateWindow(
67 TEXT("BUTTON"), TEXT("RIGHT"), WS_VISIBLE | WS_CHILD,
68 160, 80, 80, 20,
69 hwnd, (HWND) RIGHT, NULL, NULL
70 );
71 CreateWindow(
72 TEXT("BUTTON"), TEXT("UP"), WS_VISIBLE | WS_CHILD,
73 90, 40, 80, 20,
74 hwnd, (HWND) UP, NULL, NULL
75 );
76 CreateWindow(
77 TEXT("BUTTON"), TEXT("DOWN"), WS_VISIBLE | WS_CHILD,
78 90, 120, 80, 20,
79 hwnd, (HWND) DOWN, NULL, NULL
80 );
81 return 0;
82 case WM_COMMAND:
83 if(LOWORD(wParam)==LEFT) {
84 setlocale(LC_ALL, "ptb");
85 SetConsoleTitle("Desenvolvedor APL Channel");
86 system("color 1f");
87 int x = 30, y = 10;
88 char ch;
89 gotoxy(x, y);
90 printf("Desenvolvedor APL");
91 ch = 75;
92 switch(ch) {
93 case 75: /**Direção: Para Esquerda*/
94 x=x-3;
95 break;
96 case 27:
97 exit(0);
98 }
99 system("cls");
100 gotoxy(x, y);
101 printf("Desenvolvedor APL");
102 }
103 if(LOWORD(wParam)==RIGHT) {
104 setlocale(LC_ALL, "ptb");
105 SetConsoleTitle("Desenvolvedor APL Channel");
106 system("color 1f");
107 int x = 30, y = 10;
108 char ch;
109 gotoxy(x, y);
110 printf("Desenvolvedor APL");
111 ch = 77;
112 switch(ch) {
113 case 77: /**Direção: Para Direita*/
114 x=x+3;
115 break;
116 case 27:
117 exit(0);
118 }
119 system("cls");
120 gotoxy(x, y);
121 printf("Desenvolvedor APL");
122 }
123 if(LOWORD(wParam)==UP) {
124 setlocale(LC_ALL, "ptb");
125 SetConsoleTitle("Desenvolvedor APL Channel");
126 system("color 1f");
127 int x = 30, y = 10;
128 char ch;
129 gotoxy(x, y);
130 printf("Desenvolvedor APL");
131 ch = 72;
132 switch(ch) {
133 case 72: /**Direção: Para Direita*/
134 y=y-3;
135 break;
136 case 27:
137 exit(0);
138 }
139 system("cls");
140 gotoxy(x, y);
141 printf("Desenvolvedor APL");
142 }
143 if(LOWORD(wParam)==DOWN) {
144 setlocale(LC_ALL, "ptb");
145 SetConsoleTitle("Desenvolvedor APL Channel");
146 system("color 1f");
147 int x = 30, y = 10;
148 char ch;
149 gotoxy(x, y);
150 printf("Desenvolvedor APL");
151 ch = 80;
152 switch(ch) {
153 case 80: /**Direção: Para Direita*/
154 y=y+3;
155 break;
156 case 27:
157 exit(0);
158 }
159 system("cls");
160 gotoxy(x, y);
161 printf("Desenvolvedor APL");
162 }
163 return 0;
164 case WM_DESTROY:
165 PostQuitMessage(0);
166 return 0;
167 }
168 return DefWindowProc(hwnd, message, wParam, lParam);
169 }
Comentários
Postar um comentário