我的scrollbar程序在运行时
总是不停的刷新屏幕,我不知道是那个动作发送了WM_PAINT,即使我鼠标无任何动作。
代码如下:
//////////////////////
#include <windows.h>LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow) {
static TCHAR szAppName[]=TEXT("ScrollBar");
MSG msg;
HWND hwnd;
WNDCLASS wndclass;
wndclass.style=CS_VREDRAW|CS_HREDRAW;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szAppName;
RegisterClass(&wndclass);
hwnd=CreateWindow(szAppName,szAppName,WS_OVERLAPPEDWINDOW|WS_VSCROLL,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) {
static int current=0;
static int height=0;
char buffer[40];
int size=0;
HDC hdc;
TEXTMETRIC tm;
switch(message) {
case WM_CREATE:
SetScrollRange(hwnd,SB_VERT,0,100,FALSE);
hdc=GetDC(hwnd);
GetTextMetrics(hdc,&tm);
height=tm.tmHeight;
ReleaseDC(hwnd,hdc);
return 0;
case WM_SIZE:
current=0;
return 0;
case WM_LBUTTONDOWN:
current=0;
InvalidateRect(hwnd,NULL,TRUE);
return 0;
case WM_VSCROLL:
if(LOWORD(wParam)==SB_THUMBTRACK) {
hdc=GetDC(hwnd);
TextOut(hdc,0,current*height,TEXT("Thumb is tracking now."),22);
++current;
ReleaseDC(hwnd,hdc);
}
if(LOWORD(wParam)==SB_THUMBPOSITION) {
hdc=GetDC(hwnd);
size=wsprintf(buffer,TEXT("The position is: %d now."),HIWORD(wParam));
TextOut(hdc,0,current*height,buffer,size);
++current;
SetScrollPos(hwnd,SB_VERT,HIWORD(wParam),TRUE);
ReleaseDC(hwnd,hdc);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
总是不停的刷新屏幕,我不知道是那个动作发送了WM_PAINT,即使我鼠标无任何动作。
代码如下:
//////////////////////
#include <windows.h>LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow) {
static TCHAR szAppName[]=TEXT("ScrollBar");
MSG msg;
HWND hwnd;
WNDCLASS wndclass;
wndclass.style=CS_VREDRAW|CS_HREDRAW;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szAppName;
RegisterClass(&wndclass);
hwnd=CreateWindow(szAppName,szAppName,WS_OVERLAPPEDWINDOW|WS_VSCROLL,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) {
static int current=0;
static int height=0;
char buffer[40];
int size=0;
HDC hdc;
TEXTMETRIC tm;
switch(message) {
case WM_CREATE:
SetScrollRange(hwnd,SB_VERT,0,100,FALSE);
hdc=GetDC(hwnd);
GetTextMetrics(hdc,&tm);
height=tm.tmHeight;
ReleaseDC(hwnd,hdc);
return 0;
case WM_SIZE:
current=0;
return 0;
case WM_LBUTTONDOWN:
current=0;
InvalidateRect(hwnd,NULL,TRUE);
return 0;
case WM_VSCROLL:
if(LOWORD(wParam)==SB_THUMBTRACK) {
hdc=GetDC(hwnd);
TextOut(hdc,0,current*height,TEXT("Thumb is tracking now."),22);
++current;
ReleaseDC(hwnd,hdc);
}
if(LOWORD(wParam)==SB_THUMBPOSITION) {
hdc=GetDC(hwnd);
size=wsprintf(buffer,TEXT("The position is: %d now."),HIWORD(wParam));
TextOut(hdc,0,current*height,buffer,size);
++current;
SetScrollPos(hwnd,SB_VERT,HIWORD(wParam),TRUE);
ReleaseDC(hwnd,hdc);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
解决方案 »
- 大神们,求救!microsoft speech sdk,模拟键盘消息,窗口焦点
- 网页调用ActiveX,在同一页面打开IE卡死的问题
- 帮忙看看,代码有什么问题,一调用内存就增加
- 创建一个可以改变大小的窗体,又不想要WS_THICKFRAME的边框怎么办?
- 两个程序之间传递数据结构。
- 有没有什么类,能得到网页中的返回值???急待解决,请帮忙!!!
- 那有关于windows shell 的电子书下栽
- 如何得到它的倾斜的角度
- 菜鸟问题,关于函数的动态参数
- 是否若要使一矩形区无效,应该先把它转换成设备坐标才行?
- 躺问:现在聊天室网页版的已经做得很好,为什么还有这么多的人要用vc来做呢??????!!!很费解,请高手赐教!!!
- 发现一个奇怪的错误:我在建一个SDI工程,单击一个菜单,出来一个对话框。
不过我的建议是对于WM_PAINT最好还是手工处理:-) 因为:
DefWindowProc(hwnd,message,wParam,lParam);中间似乎也是会有的,而其实很难说就没有东西不发WM_PAINT消息了,TranslateMessage(&msg)也可能是祸手,所有还是手工处理吧:-)