只是一画几条线的程序,为何运行后关闭该窗口,该程序还在任务栏中的进程表里?? 然怪我的电脑老卡着, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 贴出你的onpaint或者ondraw内代码 #include<windows.h>LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // pointer to command line int nCmdShow // show state of window){ static TCHAR szAppName[]=TEXT("linedemo"); WNDCLASS wndclass; HWND hwnd; MSG msg; wndclass.style=CS_HREDRAW|CS_VREDRAW; wndclass.lpszMenuName=NULL; wndclass.lpszClassName=szAppName; 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.cbWndExtra=0; wndclass.cbClsExtra=0; if(!RegisterClass(&wndclass)) { MessageBox(NULL,TEXT("Oh,No!"),szAppName,MB_ICONERROR); return 0; } hwnd=CreateWindow(szAppName, TEXT("LINEDEMO"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg,hwnd,0,0) ) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam;}LRESULT CALLBACK WndProc( HWND hwnd, // handle to window UINT message, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter){ HDC hdc; PAINTSTRUCT ps; static int cxClient,cyClient; switch(message) { case WM_SIZE: cxClient=LOWORD(lParam); cyClient=HIWORD(lParam); return 0; case WM_PAINT: hdc=BeginPaint(hwnd,&ps); MoveToEx(hdc,0,0,NULL); LineTo(hdc,cxClient,cyClient); MoveToEx(hdc,cxClient,0,NULL); LineTo(hdc,0,cyClient); Rectangle(hdc,cxClient/8,cyClient/8,7*cxClient/8,7*cyClient/8); Ellipse(hdc,cxClient/8,cyClient/8,7*cxClient/8,7*cyClient/8); RoundRect(hdc,cxClient/4,cyClient/4,3*cxClient/4,3*cyClient/4,cxClient/4,cyClient/4); EndPaint(hwnd,&ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc( hwnd, // handle to window message, // message identifier wParam, // first message parameter lParam // second message parameter);} 还有,使用了BeginPaint需要使用EndPaint 我写了EndPaint(hwnd,&ps);啊 将while(GetMessage(&msg,hwnd,0,0))改成while(GetMessage(&msg,NULL,0,0)) to happyboy086(红尘有爱) 为何将while(GetMessage(&msg,hwnd,0,0))改成while(GetMessage(&msg,NULL,0,0))就不会出现这样的问题 只有WM_QUIT才能使GetMessage返回FALSE,这样while循环才能结束。而WM_QUIT不是发送给hwnd的,你的程序永远都不能接收到WM_QUIT消息,当然驻留在内存里面了 如何做事件穿透 (急)用VC绘制九宫格菜单界面(手机界面) 请大侠们帮忙纠错~ 高分求助:dll中显示对话框的问题 请问这么写是什么意思?fscanf(v_fp, "<m_orientation> %d\n", &wk_int); 急问,想在一个多边形上画张图片 総算混上個星 如何获得Edit控件中的内容阿,郁闷中..... 寻VC++ 5.0的ID KEY! 请教各位高手!! ★★★高手请进:怎样使我的程序可以在CMD的命令行下,直接输入程序名称不输入路径名就能运行?★★★ 请问写再runservice下得程序,注销得时候进程结束吗?
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
static TCHAR szAppName[]=TEXT("linedemo");
WNDCLASS wndclass;
HWND hwnd;
MSG msg;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szAppName;
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.cbWndExtra=0;
wndclass.cbClsExtra=0;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("Oh,No!"),szAppName,MB_ICONERROR);
return 0;
}
hwnd=CreateWindow(szAppName,
TEXT("LINEDEMO"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,hwnd,0,0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}LRESULT CALLBACK WndProc(
HWND hwnd, // handle to window
UINT message, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
HDC hdc;
PAINTSTRUCT ps;
static int cxClient,cyClient;
switch(message)
{
case WM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
MoveToEx(hdc,0,0,NULL);
LineTo(hdc,cxClient,cyClient);
MoveToEx(hdc,cxClient,0,NULL);
LineTo(hdc,0,cyClient);
Rectangle(hdc,cxClient/8,cyClient/8,7*cxClient/8,7*cyClient/8);
Ellipse(hdc,cxClient/8,cyClient/8,7*cxClient/8,7*cyClient/8);
RoundRect(hdc,cxClient/4,cyClient/4,3*cxClient/4,3*cyClient/4,cxClient/4,cyClient/4);
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(
hwnd, // handle to window
message, // message identifier
wParam, // first message parameter
lParam // second message parameter
);
}
EndPaint(hwnd,&ps);
啊
while(GetMessage(&msg,hwnd,0,0))
改成
while(GetMessage(&msg,NULL,0,0))
为何
将
while(GetMessage(&msg,hwnd,0,0))
改成
while(GetMessage(&msg,NULL,0,0))就不会出现这样的问题
而WM_QUIT不是发送给hwnd的,你的程序永远都不能接收到WM_QUIT消息,当然驻留在内存里面了