16,548
社区成员




#include "stdio.h"
#include "windows.h"
LRESULT CALLBACK wndproc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
HINSTANCE hInstance;
class win
{
public:
BOOL W_class();
BOOL create();
};
BOOL win::W_class()
{
WNDCLASS wdnclass;//设计窗口
wdnclass.style=CS_HREDRAW|CS_VREDRAW;;//窗口
wdnclass.lpfnWndProc=wndproc;//窗口指针很重要
wdnclass.cbClsExtra=0;//通常为0
wdnclass.cbWndExtra=0;//通常为0
wdnclass.hInstance=hInstance;//句柄
wdnclass.hIcon=LoadIcon(NULL,IDI_ERROR);//图标句柄
wdnclass.hCursor=LoadCursor(NULL,IDC_CROSS);//光标句柄
wdnclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);//背色句柄
wdnclass.lpszMenuName=NULL;
wdnclass.lpszClassName="zhuzi";//类的名字
return (RegisterClass(&wdnclass));//注册窗口
}
BOOL win::create()
{
HWND hwnd;
hwnd=CreateWindow("zhuzi","猪",WS_OVERLAPPEDWINDOW,
200,200,600,400,NULL,NULL,
hInstance,NULL);
//显示窗口
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
return hwnd;
}
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
win window
if(!window.W_class())
return 0;
if(!window.create())
return 0;
//消息循环
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);//接收消息
DispatchMessage(&msg);//将接收的消息处理
}
return 0;
}
//过程函数
LRESULT CALLBACK wndproc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
HDC hdc;
PAINTSTRUCT ps;
switch(uMsg)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,"猪",strlen("猪"));
EndPaint(hwnd,&ps);
break;
case WM_CHAR:
char szchar[20];
sprintf(szchar,"ch%d",wParam);
MessageBox(hwnd,szchar,"zhuzi",MB_OK);
break;
case WM_LBUTTONDOWN:
if(IDYES==MessageBox(hwnd,"猪编程","zhuzi",MB_YESNO))
{
HDC hDC;
hDC=GetDC(hwnd);
TextOut(hDC,150,150,"猪万岁",strlen("猪万岁"));
ReleaseDC(hwnd,hDC);
}
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"真的退出","zhuzi",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
break;
}
return 0;
// Win32App3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int main(int argc, char* argv[])
{
printf("我是老大我发飙!\n");
return 0;
}
// WinApp1.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
return 0;
}