69,371
社区成员
发帖
与我相关
我的任务
分享
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
char szWinName[] = "MyWin"; // name of window class
char outStr[255] = ""; // holds output string
char savechar[65525];
int savect= 0;
int curX = 1; //****************defind posts to the left top corner
int curY = 1; //****************
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInstance, LPSTR IpszArgs, int nWinMode)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wcl;
wcl.cbSize = sizeof(wcl);
wcl.hInstance = hThisInst; // handle to this instance
wcl.lpszClassName = szWinName; // window class name
wcl.lpfnWndProc = WindowFunc; // name of the window callback function
wcl.style = 0; // default window style
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION); // large icon
wcl.hIconSm = NULL; // use small version of large icon
wcl.hCursor = LoadCursor(NULL, IDC_ARROW); // cursor style
wcl.lpszMenuName = NULL; // no class menu
wcl.cbClsExtra = 0; // no extra memory needed
wcl.cbWndExtra = 0; // no extra memory needed
wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
if(!RegisterClassEx(&wcl))
return 0; // exit if failed to register the window
hwnd = CreateWindow(szWinName,"LAB 3",WS_OVERLAPPEDWINDOW | WS_HSCROLL,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL, NULL, hThisInst,NULL);
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg); // translate keyboard messages
DispatchMessage(&msg); // return control to Windows 2000
};
return msg.wParam;
}
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message,WPARAM wParam, LPARAM lParam)
{
HDC hdc;
int i;
switch(message)
{
case WM_CHAR: // process keystroke
hdc = GetDC(hwnd);
savechar[savect]=(char) wParam;
savect++;
sprintf(outStr, "%c", (char) wParam);
TextOut(hdc, curX, curY, outStr, strlen(outStr)); // output char
sprintf(outStr, "%c", (char) wParam); //clean output
TextOut(hdc, 460, 410, " ", 10); //clean output
sprintf(outStr, "The cursor position (x, y) at %d, %d", curX, curY); //output cursor position
TextOut(hdc, 250, 410, outStr, strlen(outStr)); //output cursor position
if(curY>400) //
{
break;
}
else if(curX<190) // set the line only have 20 characters
{
curX +=10;
}
else
{
curY +=20; //when the line over 20 characters
curX = 0; //it have pass the new line
PlaySound ("DING.wav", NULL, SND_FILENAME | SND_ASYNC) ;
}
ReleaseDC(hwnd, hdc); // release device context
break;
case WM_PAINT:
for(i=0; i<strlen(savechar);i++)
{
TextOut(hdc,charX[],charY[],savechar[i],strlen(savechar);
}
case WM_DESTROY: // terminate the program
PostQuitMessage(0);
break;
default:
/* Let Windows 2000 process any messages not specified in
the preceding switch statement. */
return DefWindowProc(hwnd, message, wParam, lParam);
EndPaint(hwnd,hdc);
}
return 0;
}
#include <windows.h>
#include <stdio.h>
struct charInfo{
int x, y;
char ch;
};// 这个结构体用来保存每个char的信息
LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
char szWinName[] = "MyWin"; // name of window class
char outStr[255] = ""; // holds output string
charInfo chInfo[65525]; // 保存char的结构数组
int currentChar = 0; // 记录当前总字符数
int curX = 1; //****************defind posts to the left top corner
int curY = 1; //****************
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInstance, LPSTR IpszArgs, int nWinMode)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wcl;
wcl.cbSize = sizeof(wcl);
wcl.hInstance = hThisInst; // handle to this instance
wcl.lpszClassName = szWinName; // window class name
wcl.lpfnWndProc = WindowFunc; // name of the window callback function
wcl.style = 0; // default window style
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION); // large icon
wcl.hIconSm = NULL; // use small version of large icon
wcl.hCursor = LoadCursor(NULL, IDC_ARROW); // cursor style
wcl.lpszMenuName = NULL; // no class menu
wcl.cbClsExtra = 0; // no extra memory needed
wcl.cbWndExtra = 0; // no extra memory needed
wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
if(!RegisterClassEx(&wcl))
return 0; // exit if failed to register the window
hwnd = CreateWindow(szWinName,"EX",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL, NULL, hThisInst,NULL);
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg); // translate keyboard messages
DispatchMessage(&msg); // return control to Windows 2000
};
return msg.wParam;
}
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message,WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
int i;
switch(message)
{
case WM_PAINT:// 处理PAINT消息
hdc = BeginPaint(hwnd, &ps);
// TODO: Add any drawing code here...
TextOut(hdc, 250, 410, outStr, strlen(outStr)); //output cursor position
for ( i = 0; i < currentChar; i++)// 顺序画出之前所有char
{
sprintf(outStr, "%c", chInfo[i].ch); //clean output
TextOut(hdc, chInfo[i].x, chInfo[i].y, outStr, 1); // output char
}
EndPaint(hwnd, &ps);
break;
case WM_CHAR: // process keystroke
// 在这里保存下每个char的信息到数组里
hdc = GetDC(hwnd);
sprintf(outStr, "%c", (char) wParam);
chInfo[currentChar].x = curX;
chInfo[currentChar].y = curY;
chInfo[currentChar].ch = (char) wParam;
currentChar++;
TextOut(hdc, curX, curY, outStr, strlen(outStr)); // output char
sprintf(outStr, "%c", (char) wParam); //clean output
TextOut(hdc, 460, 410, " ", 10); //clean output
sprintf(outStr, "The cursor position (x, y) at %d, %d", curX, curY); //output cursor position
TextOut(hdc, 250, 410, outStr, strlen(outStr)); //output cursor position
if(curY>400) //
{
break;
}
else if(curX <190) // set the line only have 20 characters
{
curX +=10;
}
else
{
curY +=20; //when the line over 20 characters
curX = 0; //it have pass the new line
//PlaySound ("DING.wav", NULL, SND_FILENAME | SND_ASYNC) ;
}
ReleaseDC(hwnd, hdc); // release device context
break;
case WM_DESTROY: // terminate the program
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
char szWinName[] = "MyWin"; // name of window class
char outStr[255] = ""; // holds output string
char savechar[6325]="";
char pac[6325];
char locat[255] = "The cursor position (x, y) at ";
int savect= 0;
int xx[6325] ;
int yy[6325] ;
int a = 0;
int c = 0;
int curX = 1; //****************defind posts to the left top corner
int curY = 1; //****************
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInstance, LPSTR IpszArgs, int nWinMode)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wcl;
wcl.cbSize = sizeof(wcl);
wcl.hInstance = hThisInst; // handle to this instance
wcl.lpszClassName = szWinName; // window class name
wcl.lpfnWndProc = WindowFunc; // name of the window callback function
wcl.style = 0; // default window style
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION); // large icon
wcl.hIconSm = NULL; // use small version of large icon
wcl.hCursor = LoadCursor(NULL, IDC_ARROW); // cursor style
wcl.lpszMenuName = NULL; // no class menu
wcl.cbClsExtra = 0; // no extra memory needed
wcl.cbWndExtra = 0; // no extra memory needed
wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
if(!RegisterClassEx(&wcl))
return 0; // exit if failed to register the window
hwnd = CreateWindow(szWinName,"LAB 3",WS_OVERLAPPEDWINDOW | WS_HSCROLL,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL, NULL, hThisInst,NULL);
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg); // translate keyboard messages
DispatchMessage(&msg); // return control to Windows 2000
};
return msg.wParam;
}
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message,WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT paintstruct;
int i = 0;
switch(message)
{
case WM_CHAR: // process keystroke
hdc = GetDC(hwnd);
sprintf(outStr, "%c", (char) wParam);
savechar[savect]=(char) wParam;
savect = savect + 1;
TextOut(hdc, curX, curY, outStr, strlen(outStr)); // output char
//locat[31]="The cursor position (x, y) at "; // , curX, curY; //output cursor position
TextOut(hdc, 250, 410, locat, strlen(locat)); //output cursor position
if(curY>400) //
{
break;
}
else
if(curX<190) // set the line only have 20 characters
{
xx[a]=curX;
yy[a]=curY;
curX +=10;
a=a+1;
}
else
{
xx[a]=curX;
yy[a]=curY;
a=a+1;
curY +=20; //when the line over 20 characters
curX = 0; //it have pass the new line
PlaySound ("DING.wav", NULL, SND_FILENAME | SND_ASYNC) ;
}
ReleaseDC(hwnd, hdc); // release device context
break;
case WM_PAINT:
hdc = BeginPaint (hwnd, &paintstruct);
for(i=0; i<a;i++)
{
pac[0]=savechar[i];
TextOut(hdc,xx[c],yy[c],pac,1);
c++;
}
c = 0;
EndPaint(hwnd, &paintstruct);
break;
case WM_DESTROY: // terminate the program
PostQuitMessage(0);
break;
default:
/* Let Windows 2000 process any messages not specified in
the preceding switch statement. */
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}