#include <windows.h>
#include <stdio.h>
#include <stdlib.h>LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(SYSTEM_FONT | DEFAULT_PALETTE );
wndcls.hCursor=LoadCursor(NULL,IDC_HELP );
wndcls.hIcon=LoadIcon(NULL,NULL);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="feifei";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls); HWND hwnd;
hwnd=CreateWindow("feifei","飞飞 Ьù屌妳",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL); ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd); MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
HDC hDC;
RECT rect;
PAINTSTRUCT ps;
TEXTMETRIC tm;
static int cxChar,cyChar,cxCaps;
int cxClient,cyClient;
HBRUSH brush;
HPEN p;
HRGN hrgn; switch(uMsg)
{
/* DrawText(hdc,TEXT("hello,windowXP!"),-1,&rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
break;
*/
case WM_CREATE:
PlaySound(TEXT("xopen.wav"),NULL, /*SND_APPLICATION | SND_FILENAME| SND_SYNC |*/SND_ASYNC );
hDC=GetDC(hwnd); GetTextMetrics(hDC,&tm);
cxChar=tm.tmAveCharWidth; //字符宽
cyChar=tm.tmHeight+tm.tmExternalLeading; //字符高 ReleaseDC(hwnd,hDC);
break;
case WM_CHAR:
hDC=GetDC(hwnd);
ReleaseDC(hwnd,hDC);
case WM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
case WM_PAINT:
TCHAR szBuffer[200];
hDC=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
// MoveToEx(hDC,50,500,NULL); //50从左向右 500从上向下 线的起始位置
// LineTo(hDC,900,500); //线的结尾位置
// MoveToEx(hDC,50,30,NULL);
// LineTo(hDC,900,30);
// MoveToEx(hDC,50,30,NULL);
// LineTo(hDC,50,500);
// MoveToEx(hDC,900,30,NULL);
// LineTo(hDC,900,500);
SetTextColor(hDC,RGB(100,5,255));
p=CreatePen(PS_SOLID,20,RGB(255,0,255)); //建立画笔
SelectObject(hDC,p);
Rectangle(hDC,0,0,cxClient,cyClient);
//TextOut(hDC,400,320,szBuffer,wsprintf(szBuffer,"AbC"));
// SelectObject(hDC,GetStockObject(GRAY_BRUSH));
// SetRect(&rect,10,10,cxClient-10,cxClient/2+50);
// FrameRect(hDC,&rect,brush);
//RoundRect(hDC,40,20,910,510,20,20); // 圆角矩形 20 ,20 是圆角的圆的直径
SelectObject(hDC,GetStockObject(GRAY_BRUSH));
SetRect(&rect,50,50,cxClient-50,cxClient/2+20);
//SelectObject(hDC,GetStockObject(HOLLOW_BRUSH ));
FrameRect(hDC,&rect,brush);
// SelectObject(hDC,GetStockObject(GRAY_BRUSH));
SetRect(&rect,53,53,cxClient-53,cxClient/2+17);
FrameRect(hDC,&rect,brush);
DeleteObject(SelectObject(hDC,GetStockObject(GRAY_BRUSH)));
//Rectangle(hDC,40,20,910,510); // 画 矩形 40,20矩形左上角 910,510矩形右下角
EndPaint(hwnd,&ps);
break;
case WM_KEYDOWN:
switch(LOWORD(lParam))
{
case VK_UP:
TextOut(hDC,50,50,"feifei",strlen("feifei"));
}
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否要退出程序?","飞飞",MB_YESNO))
{
DestroyWindow(hwnd);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}如果有别的程序窗口当住我的程序的窗口后当再次看我窗口后图形就没了,也没重画
不是说在WM_PAINT里的图形和字符串当被别的窗口遮住后会自己重画的吗?
你们谁知道的话可以告诉我是怎么回事吗?
或者是不是还要加什么函数来重画?
#include <stdio.h>
#include <stdlib.h>LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(SYSTEM_FONT | DEFAULT_PALETTE );
wndcls.hCursor=LoadCursor(NULL,IDC_HELP );
wndcls.hIcon=LoadIcon(NULL,NULL);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="feifei";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls); HWND hwnd;
hwnd=CreateWindow("feifei","飞飞 Ьù屌妳",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL); ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd); MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
HDC hDC;
RECT rect;
PAINTSTRUCT ps;
TEXTMETRIC tm;
static int cxChar,cyChar,cxCaps;
int cxClient,cyClient;
HBRUSH brush;
HPEN p;
HRGN hrgn; switch(uMsg)
{
/* DrawText(hdc,TEXT("hello,windowXP!"),-1,&rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
break;
*/
case WM_CREATE:
PlaySound(TEXT("xopen.wav"),NULL, /*SND_APPLICATION | SND_FILENAME| SND_SYNC |*/SND_ASYNC );
hDC=GetDC(hwnd); GetTextMetrics(hDC,&tm);
cxChar=tm.tmAveCharWidth; //字符宽
cyChar=tm.tmHeight+tm.tmExternalLeading; //字符高 ReleaseDC(hwnd,hDC);
break;
case WM_CHAR:
hDC=GetDC(hwnd);
ReleaseDC(hwnd,hDC);
case WM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
case WM_PAINT:
TCHAR szBuffer[200];
hDC=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
// MoveToEx(hDC,50,500,NULL); //50从左向右 500从上向下 线的起始位置
// LineTo(hDC,900,500); //线的结尾位置
// MoveToEx(hDC,50,30,NULL);
// LineTo(hDC,900,30);
// MoveToEx(hDC,50,30,NULL);
// LineTo(hDC,50,500);
// MoveToEx(hDC,900,30,NULL);
// LineTo(hDC,900,500);
SetTextColor(hDC,RGB(100,5,255));
p=CreatePen(PS_SOLID,20,RGB(255,0,255)); //建立画笔
SelectObject(hDC,p);
Rectangle(hDC,0,0,cxClient,cyClient);
//TextOut(hDC,400,320,szBuffer,wsprintf(szBuffer,"AbC"));
// SelectObject(hDC,GetStockObject(GRAY_BRUSH));
// SetRect(&rect,10,10,cxClient-10,cxClient/2+50);
// FrameRect(hDC,&rect,brush);
//RoundRect(hDC,40,20,910,510,20,20); // 圆角矩形 20 ,20 是圆角的圆的直径
SelectObject(hDC,GetStockObject(GRAY_BRUSH));
SetRect(&rect,50,50,cxClient-50,cxClient/2+20);
//SelectObject(hDC,GetStockObject(HOLLOW_BRUSH ));
FrameRect(hDC,&rect,brush);
// SelectObject(hDC,GetStockObject(GRAY_BRUSH));
SetRect(&rect,53,53,cxClient-53,cxClient/2+17);
FrameRect(hDC,&rect,brush);
DeleteObject(SelectObject(hDC,GetStockObject(GRAY_BRUSH)));
//Rectangle(hDC,40,20,910,510); // 画 矩形 40,20矩形左上角 910,510矩形右下角
EndPaint(hwnd,&ps);
break;
case WM_KEYDOWN:
switch(LOWORD(lParam))
{
case VK_UP:
TextOut(hDC,50,50,"feifei",strlen("feifei"));
}
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否要退出程序?","飞飞",MB_YESNO))
{
DestroyWindow(hwnd);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}如果有别的程序窗口当住我的程序的窗口后当再次看我窗口后图形就没了,也没重画
不是说在WM_PAINT里的图形和字符串当被别的窗口遮住后会自己重画的吗?
你们谁知道的话可以告诉我是怎么回事吗?
或者是不是还要加什么函数来重画?
对吗?而不是静态的变量出了函数就释放掉了当再次调用时不保留里面的数据