请VC++高手帮个忙,用TextOut()每隔一秒在窗口同一位置输出背景透明文字,会产生叠加,请问如何刷新
//以下代码在VC6.0中编译通过,要求输出文字时,能擦除之前的文字,不要前后叠加//不知如何实现,最好在下面代码基础上修改,完成后能发到本人邮箱更好,不胜感谢//邮箱地...
//以下代码在VC6.0中编译通过,要求输出文字时,能擦除之前的文字,不要前后叠加
//不知如何实现,最好在下面代码基础上修改,完成后能发到本人邮箱更好,不胜感谢
//邮箱地址:78381315@qq.com
#include "windows.h"
#include "stdio.h"
LRESULT CALLBACK LcyProc(HWND, UINT, WPARAM, LPARAM);
int tim=48;
int tima;
char timch[2]="A";
int testtimer(HWND hwnd);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wcex;
wcex.style= CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc= (WNDPROC)LcyProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance= hInstance;
wcex.hIcon= LoadIcon(NULL,IDI_QUESTION);
wcex.hCursor=LoadCursor(NULL,IDC_CROSS);
wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW-1);//可以用NULL试一种通明背景效果
wcex.lpszMenuName= NULL;//不显示菜单栏
wcex.lpszClassName="MyWindowTest";
RegisterClass(&wcex);
HWND hwnd;
hwnd=CreateWindow("MyWindowTest", "请大虾帮个忙啊", WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);//"快速高效自学教程"被改1,如果将WS_OVERLAPPEDWINDOW改为WS_DLGFRAME,将禁用右击关闭
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
testtimer(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK LcyProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_LBUTTONDOWN:
MessageBox(hwnd,"点击才可以刷新一次红色数字 ","我想自动刷新",0);
InvalidateRect(hwnd,NULL,TRUE);//把这句放到case WM_TIMER中会闪烁
break;
case WM_PAINT:
HDC hDc;
PAINTSTRUCT ps;
hDc=BeginPaint(hwnd,&ps);
SetBkMode(hDc, TRANSPARENT);
SetTextColor(hDc, RGB(0, 255, 0));
TextOut(hDc,0,10,"我希望能刷新,且不闪烁",strlen("我希望能刷新,且不闪烁"));
EndPaint(hwnd,&ps);
break;
case WM_TIMER:
if (1 == wParam)
{
tim +=1;
if(tim>99)
tim=10;
HDC hdc;
hdc=GetDC(hwnd);
_itoa(tim, timch, 10 );
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(255, 0, 0));
TextOut(hdc,55,30,timch,2);
ReleaseDC(hwnd,hdc);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}
testtimer(HWND hwnd)
{tima=SetTimer(hwnd,1,1000,0 );
return NULL;
}
谢谢回答!用你的方法还是有点闪烁,听说双缓冲方法效果最好,不知代码如何写,如何加进去? 展开
//不知如何实现,最好在下面代码基础上修改,完成后能发到本人邮箱更好,不胜感谢
//邮箱地址:78381315@qq.com
#include "windows.h"
#include "stdio.h"
LRESULT CALLBACK LcyProc(HWND, UINT, WPARAM, LPARAM);
int tim=48;
int tima;
char timch[2]="A";
int testtimer(HWND hwnd);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wcex;
wcex.style= CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc= (WNDPROC)LcyProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance= hInstance;
wcex.hIcon= LoadIcon(NULL,IDI_QUESTION);
wcex.hCursor=LoadCursor(NULL,IDC_CROSS);
wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW-1);//可以用NULL试一种通明背景效果
wcex.lpszMenuName= NULL;//不显示菜单栏
wcex.lpszClassName="MyWindowTest";
RegisterClass(&wcex);
HWND hwnd;
hwnd=CreateWindow("MyWindowTest", "请大虾帮个忙啊", WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);//"快速高效自学教程"被改1,如果将WS_OVERLAPPEDWINDOW改为WS_DLGFRAME,将禁用右击关闭
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
testtimer(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK LcyProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_LBUTTONDOWN:
MessageBox(hwnd,"点击才可以刷新一次红色数字 ","我想自动刷新",0);
InvalidateRect(hwnd,NULL,TRUE);//把这句放到case WM_TIMER中会闪烁
break;
case WM_PAINT:
HDC hDc;
PAINTSTRUCT ps;
hDc=BeginPaint(hwnd,&ps);
SetBkMode(hDc, TRANSPARENT);
SetTextColor(hDc, RGB(0, 255, 0));
TextOut(hDc,0,10,"我希望能刷新,且不闪烁",strlen("我希望能刷新,且不闪烁"));
EndPaint(hwnd,&ps);
break;
case WM_TIMER:
if (1 == wParam)
{
tim +=1;
if(tim>99)
tim=10;
HDC hdc;
hdc=GetDC(hwnd);
_itoa(tim, timch, 10 );
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(255, 0, 0));
TextOut(hdc,55,30,timch,2);
ReleaseDC(hwnd,hdc);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}
testtimer(HWND hwnd)
{tima=SetTimer(hwnd,1,1000,0 );
return NULL;
}
谢谢回答!用你的方法还是有点闪烁,听说双缓冲方法效果最好,不知代码如何写,如何加进去? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询