关于窗口问题的
先谢谢你咯,回复的“老师”!我这里还有一个关于窗口的问题?谢谢咯,大虾!这个程序就这样执行不起,但是把我标注的话出去就行咯(算咯直接复制跟你哈!)嘿嘿
#include<windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMessage,UINT wParam,LONG lParam)
{
HDC hdc;
HBRUSH hBrush;
HPEN hPen;
PAINTSTRUCT Pt;
switch(iMessage)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&Pt);
SetMapMode(hdc,MM_ANISOTROPIC);
hPen=(HPEN)GetStockObject(BLACK_PEN);
SelectObject(hdc,hPen);
hBrush=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
RoundRect(hdc,50,50,100,150,15,14);
hBrush=(HBRUSH)GetStockObject(HOLLOW_BRUSH);
SelectObject(hdc,hBrush);
Pie(hdc,250,50,300,100,250,50,300,50);
EndPaint(hwnd,&Pt);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return(DefWindowProc(hwnd,iMessage,wParam,lParam));
}
}
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
{
HWND hwnd;
hwnd=CreateWindow("winfill","填充示例程序",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);
if(!hwnd)
return FALSE;
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
return TRUE;
}
BOOL InitWindowsClass(HINSTANCE hInstance)//如果出去这句话
{
WNDCLASS WndClass;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)(GetStockObject(WHITE_BRUSH));
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,"END");
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=WndProc;
WndClass.lpszClassName="winfil";
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW|CS_VREDRAW;
return RegisterClass(&WndClass);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG Message;
if(! InitWindowsClass(hInstance))
return FALSE;
if(! InitWindows(hInstance,nCmdShow))
return FALSE;
while(GetMessage(&Message,0,0,0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
/******************************改后的程序*****/
#include <windows.h>
#include <stdio.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(WHITE_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="Weixin2003";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("Weixin2003","北京心",WS_OVERLAPPEDWINDOW,
0,0,600,400,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;
PAINTSTRUCT Pt;
HPEN hPen;
HBRUSH hBrush;
switch(uMsg)
{
case WM_CHAR:
break;
case WM_LBUTTONDOWN:
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&Pt);
SetMapMode(hdc,MM_ANISOTROPIC);
hPen=(HPEN)GetStockObject(BLACK_PEN);
SelectObject(hdc,hPen);
hBrush=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
RoundRect(hdc,50,50,100,150,15,14);
hBrush=(HBRUSH)GetStockObject(HOLLOW_BRUSH);
SelectObject(hdc,hBrush);
Pie(hdc,250,50,300,100,250,50,300,50);
EndPaint(hwnd,&Pt);
return 0;
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","weixin",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}