I need more samples!!! Please, anybody have one with entry box, Combox, list, etc.
Regards
Like the examples in your tutorial, but this is in windows gdi
#include <windows.h> #include <stdlib.h> #include <stdio.h> void TextIn (HDC hdc, int x, int y, char *s); char name [MAX_PATH], s [MAX_PATH]; int age;
void mymain (HDC hdc, int cx, int cy) { TextOut (hdc, cx * 3, cy, s, sprintf (s, "Please input your age:")); TextIn (hdc, cx * 3, cy * 2, s); sscanf (s, "%i", &age); TextOut (hdc, cx * 3, cy * 4, s, sprintf (s, "%s %i %s", "Your are", age, "years old.")); TextOut (hdc, cx * 3, cy * 6, s, sprintf (s, "Please enter your name:")); TextIn (hdc, cx * 3, cy * 7, s); sscanf (s, "%s", name); TextOut (hdc, cx * 3, cy * 9, s, sprintf (s, "Your name is %s.", name)); TextOut (hdc, cx * 3, cy * 12, s, sprintf (s, "== press enter to continue ==")); TextIn (hdc, cx * 3, cy * 14, s); }
void TextIn (HDC hdc, int x, int y, char *s) { MSG msg; TEXTMETRIC tm; char str [2]; int cx, cy, i = 0; msg.wParam = 0; GetTextMetrics (hdc, &tm); cx = tm.tmAveCharWidth * 10 / 7; cy = tm.tmHeight + tm.tmExternalLeading; while (msg.message != WM_KEYDOWN || msg.wParam != VK_RETURN) { msg.wParam = 0; PeekMessage (&msg, NULL, 0, 0, PM_REMOVE); if (msg.message == WM_QUIT) ExitProcess (0); if (msg.message == WM_KEYDOWN && msg.wParam == VK_BACK) TextOut (hdc, x + cx * (--i), y, str, sprintf (str, "%*c", 3, ' ')); if (msg.message == WM_CHAR && msg.wParam >= 32 && msg.wParam <= 127) { if (i < MAX_PATH - 1) s [i++] = msg.wParam; TextOut (hdc, x + cx * (i - 1), y, str, sprintf (str, "%c", msg.wParam)); } TranslateMessage (&msg); DispatchMessage (&msg); } s [i] = 0; } LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { switch (iMsg) case WM_DESTROY: PostQuitMessage (0); return DefWindowProc (hwnd, iMsg, wParam, lParam); }
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { WNDCLASS wndclass; HWND hwnd; HDC hdc; TEXTMETRIC tm; char appname [] = "myapp"; int cx, cy; memset (&wndclass, 0, sizeof(WNDCLASSEX)); wndclass.lpfnWndProc = WndProc; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wndclass.lpszClassName = appname; RegisterClass (&wndclass); hwnd = CreateWindowEx (0, appname, "Window", WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 600, 400, NULL, NULL, hInstance, NULL); ShowWindow (hwnd, iCmdShow); hdc = GetDC (hwnd); GetTextMetrics (hdc, &tm); cx = tm.tmAveCharWidth; cy = tm.tmHeight + tm.tmExternalLeading; mymain (hdc, cx, cy); ReleaseDC (hwnd, hdc); }
tkorrovi
Sorry, forgot these special characters
#include <windows.h> #include <stdlib.h> #include <stdio.h> void TextIn (HDC hdc, int x, int y, char *s, int n); char name [MAX_PATH], s [MAX_PATH]; int age;
void mymain (HDC hdc, int cx, int cy) { TextOut (hdc, cx * 3, cy, s, sprintf (s, "Please input your age:")); TextIn (hdc, cx * 3, cy * 2, s, 20); sscanf (s, "%i", &age); TextOut (hdc, cx * 3, cy * 4, s, sprintf (s, "%s %i %s", "Your are", age, "years old.")); TextOut (hdc, cx * 3, cy * 6, s, sprintf (s, "Please enter your name:")); TextIn (hdc, cx * 3, cy * 7, s, 20); sscanf (s, "%s", name); TextOut (hdc, cx * 3, cy * 9, s, sprintf (s, "Your name is %s.", name)); TextOut (hdc, cx * 3, cy * 12, s, sprintf (s, "== press enter to continue ==")); TextIn (hdc, cx * 3, cy * 14, s, 20); }
void TextIn (HDC hdc, int x, int y, char *s, int n) { MSG msg; TEXTMETRIC tm; char str [2]; int cx, cy, i = 0; msg.wParam = 0; GetTextMetrics (hdc, &tm); cx = tm.tmAveCharWidth * 10 / 7; cy = tm.tmHeight + tm.tmExternalLeading; while (msg.message != WM_KEYDOWN || msg.wParam != VK_RETURN) { msg.wParam = 0; PeekMessage (&msg, NULL, 0, 0, PM_REMOVE); if (msg.message == WM_QUIT) ExitProcess (0); if (msg.message == WM_KEYDOWN && msg.wParam == VK_BACK) TextOut (hdc, x + cx * (--i), y, str, sprintf (str, "%*c", 3, ' ')); if (msg.message == WM_CHAR && msg.wParam >= 32 && i < n) TextOut (hdc, x + cx * i++, y, str, sprintf (str, "%c", s [i] = msg.wParam)); TranslateMessage (&msg); DispatchMessage (&msg); } s [i] = 0; } LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { switch (iMsg) case WM_DESTROY: PostQuitMessage (0); return DefWindowProc (hwnd, iMsg, wParam, lParam); }
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hwnd; HDC hdc; TEXTMETRIC tm; WNDCLASS wclass; char appname [] = "myapp"; int cx, cy; memset (&wclass, 0, sizeof (WNDCLASSEX)); wclass.lpfnWndProc = WndProc; wclass.hInstance = hInstance; wclass.hIcon = LoadIcon (NULL, IDI_APPLICATION); wclass.hCursor = LoadCursor (NULL, IDC_ARROW); wclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wclass.lpszClassName = appname; RegisterClass (&wclass); hwnd = CreateWindowEx (0, appname, "Window", WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 600, 400, NULL, NULL, hInstance, NULL); ShowWindow (hwnd, iCmdShow); hdc = GetDC (hwnd); GetTextMetrics (hdc, &tm); cx = tm.tmAveCharWidth; cy = tm.tmHeight + tm.tmExternalLeading; mymain (hdc, cx, cy); ReleaseDC (hwnd, hdc); }
Log in to post a comment.
I need more samples!!!
Please, anybody have one with entry box, Combox, list, etc.
Regards
Like the examples in your tutorial, but this is in windows gdi
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
void TextIn (HDC hdc, int x, int y, char *s);
char name [MAX_PATH], s [MAX_PATH];
int age;
void mymain (HDC hdc, int cx, int cy)
{
TextOut (hdc, cx * 3, cy, s, sprintf (s,
"Please input your age:"));
TextIn (hdc, cx * 3, cy * 2, s);
sscanf (s, "%i", &age);
TextOut (hdc, cx * 3, cy * 4, s, sprintf (s,
"%s %i %s", "Your are", age, "years old."));
TextOut (hdc, cx * 3, cy * 6, s, sprintf (s,
"Please enter your name:"));
TextIn (hdc, cx * 3, cy * 7, s);
sscanf (s, "%s", name);
TextOut (hdc, cx * 3, cy * 9, s, sprintf (s,
"Your name is %s.", name));
TextOut (hdc, cx * 3, cy * 12, s, sprintf (s,
"== press enter to continue =="));
TextIn (hdc, cx * 3, cy * 14, s);
}
void TextIn (HDC hdc, int x, int y, char *s)
{
MSG msg;
TEXTMETRIC tm;
char str [2];
int cx, cy, i = 0;
msg.wParam = 0;
GetTextMetrics (hdc, &tm);
cx = tm.tmAveCharWidth * 10 / 7;
cy = tm.tmHeight + tm.tmExternalLeading;
while (msg.message != WM_KEYDOWN ||
msg.wParam != VK_RETURN)
{
msg.wParam = 0;
PeekMessage (&msg, NULL, 0, 0, PM_REMOVE);
if (msg.message == WM_QUIT) ExitProcess (0);
if (msg.message == WM_KEYDOWN &&
msg.wParam == VK_BACK)
TextOut (hdc, x + cx * (--i), y, str,
sprintf (str, "%*c", 3, ' '));
if (msg.message == WM_CHAR &&
msg.wParam >= 32 && msg.wParam <= 127)
{
if (i < MAX_PATH - 1) s [i++] = msg.wParam;
TextOut (hdc, x + cx * (i - 1), y, str,
sprintf (str, "%c", msg.wParam));
}
TranslateMessage (&msg);
DispatchMessage (&msg);
}
s [i] = 0;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg,
WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
case WM_DESTROY: PostQuitMessage (0);
return DefWindowProc (hwnd, iMsg, wParam, lParam);
}
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
WNDCLASS wndclass;
HWND hwnd;
HDC hdc;
TEXTMETRIC tm;
char appname [] = "myapp";
int cx, cy;
memset (&wndclass, 0, sizeof(WNDCLASSEX));
wndclass.lpfnWndProc = WndProc;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground =
(HBRUSH) GetStockObject (WHITE_BRUSH);
wndclass.lpszClassName = appname;
RegisterClass (&wndclass);
hwnd = CreateWindowEx (0, appname, "Window",
WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT,
600, 400, NULL, NULL, hInstance, NULL);
ShowWindow (hwnd, iCmdShow);
hdc = GetDC (hwnd);
GetTextMetrics (hdc, &tm);
cx = tm.tmAveCharWidth;
cy = tm.tmHeight + tm.tmExternalLeading;
mymain (hdc, cx, cy);
ReleaseDC (hwnd, hdc);
}
tkorrovi
Sorry, forgot these special characters
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
void TextIn (HDC hdc, int x, int y, char *s, int n);
char name [MAX_PATH], s [MAX_PATH];
int age;
void mymain (HDC hdc, int cx, int cy)
{
TextOut (hdc, cx * 3, cy, s, sprintf (s,
"Please input your age:"));
TextIn (hdc, cx * 3, cy * 2, s, 20);
sscanf (s, "%i", &age);
TextOut (hdc, cx * 3, cy * 4, s, sprintf (s,
"%s %i %s", "Your are", age, "years old."));
TextOut (hdc, cx * 3, cy * 6, s, sprintf (s,
"Please enter your name:"));
TextIn (hdc, cx * 3, cy * 7, s, 20);
sscanf (s, "%s", name);
TextOut (hdc, cx * 3, cy * 9, s, sprintf (s,
"Your name is %s.", name));
TextOut (hdc, cx * 3, cy * 12, s, sprintf (s,
"== press enter to continue =="));
TextIn (hdc, cx * 3, cy * 14, s, 20);
}
void TextIn (HDC hdc, int x, int y, char *s, int n)
{
MSG msg;
TEXTMETRIC tm;
char str [2];
int cx, cy, i = 0;
msg.wParam = 0;
GetTextMetrics (hdc, &tm);
cx = tm.tmAveCharWidth * 10 / 7;
cy = tm.tmHeight + tm.tmExternalLeading;
while (msg.message != WM_KEYDOWN ||
msg.wParam != VK_RETURN)
{
msg.wParam = 0;
PeekMessage (&msg, NULL, 0, 0, PM_REMOVE);
if (msg.message == WM_QUIT) ExitProcess (0);
if (msg.message == WM_KEYDOWN &&
msg.wParam == VK_BACK)
TextOut (hdc, x + cx * (--i), y, str,
sprintf (str, "%*c", 3, ' '));
if (msg.message == WM_CHAR &&
msg.wParam >= 32 && i < n)
TextOut (hdc, x + cx * i++, y, str, sprintf (str,
"%c", s [i] = msg.wParam));
TranslateMessage (&msg);
DispatchMessage (&msg);
}
s [i] = 0;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg,
WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
case WM_DESTROY: PostQuitMessage (0);
return DefWindowProc (hwnd, iMsg, wParam, lParam);
}
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
HWND hwnd;
HDC hdc;
TEXTMETRIC tm;
WNDCLASS wclass;
char appname [] = "myapp";
int cx, cy;
memset (&wclass, 0, sizeof (WNDCLASSEX));
wclass.lpfnWndProc = WndProc;
wclass.hInstance = hInstance;
wclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wclass.hbrBackground =
(HBRUSH) GetStockObject (WHITE_BRUSH);
wclass.lpszClassName = appname;
RegisterClass (&wclass);
hwnd = CreateWindowEx (0, appname, "Window",
WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT,
600, 400, NULL, NULL, hInstance, NULL);
ShowWindow (hwnd, iCmdShow);
hdc = GetDC (hwnd);
GetTextMetrics (hdc, &tm);
cx = tm.tmAveCharWidth;
cy = tm.tmHeight + tm.tmExternalLeading;
mymain (hdc, cx, cy);
ReleaseDC (hwnd, hdc);
}
tkorrovi