游客已登陆 (0)未知
笔行证 257310
昵称 kuan 
笔贝 Score1
加为好友 发送短信
<< << 2009 一月 >> >>
123
45678910
11121314151617
18192021222324
25262728293031

访问计数:26982
本文:223 今天:1 本月 223

本地音乐播放器



 
       用C函数封装Windows程序
2007-06-28 晴



//用C函数封装Windows程序
#include<windows.h>
#include<stdio.h>

//定义全局变量
HINSTANCE hInst;
HWND hWnd;
MSG msg;
char lpszClassName[]="窗口";
char *ShowText;


//函数声明
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL Create(HINSTANCE,int);
int Run();
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);


//主函数
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MyRegisterClass(hInstance);//定义和注册窗口类
Create(hInstance,nCmdShow);//创建窗口
ShowWindow(hWnd,nCmdShow);//显示窗口
UpdateWindow(hWnd);
return Run();

}



//------------------------下面是函数的定义-------------------------
//注册窗口类的函数
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASS wc;
wc.style=0;
wc.lpfnWndProc=WndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName=NULL;
wc.lpszClassName=lpszClassName;
return RegisterClass(&wc);
}

//创建窗口的函数
BOOL Create(HINSTANCE hInstance,int nCmdShow)
{
hWnd=CreateWindow(lpszClassName,
"Windows",
WS_OVERLAPPEDWINDOW,
120,50,800,600,
NULL,
NULL,
hInstance,
NULL);
return TRUE;
}

//消息循环函数
int Run()
{
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}


//窗口函数
LRESULT CALLBACK WndProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch(message)
{
case WM_LBUTTONDOWN:
ShowText="kuanlovefeng";
InvalidateRect(hWnd,NULL,1);
break;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
TextOut(hdc,50,50,ShowText,12);
EndPaint(hWnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);

}
return 0;
}.
# posted by kuan @ 2007-06-28 13:27:59 评论(0)
 








 
笔 名:
*
评 论:
最多1000字。当前字数:0
*
联系方式: