第一课.创建窗体类及窗体,窗体过程函数
2012-01-29 17:17
344 查看
//以下为cc.c源代码
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinCCProc(HWND hwnd, //窗体句柄
UINT uMsg, //消息标识
WPARAM wParam,
LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
//设计窗口类
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinCCProc;
wndcls.lpszClassName="chanchaw的窗体类";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
//创建窗口
HWND cc_hwnd;
//char cc_char[5];
cc_hwnd=CreateWindow("chanchaw的窗体类","http://www.sunxin.org",
WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);
//cc_char="陈超";
MessageBox(cc_hwnd,"不管怎样,先出来再说吧!","又是个标题栏",0);
//MessageBox(cc_hwnd,"创建窗体返回的句柄是:" && "速度","标题栏",0);
//显示及刷新窗口
ShowWindow(cc_hwnd,SW_SHOWNORMAL);
UpdateWindow(cc_hwnd);
//定义消息结构体,开始消息循环
MSG cc_msg;
BOOL cc_bool;
/*
while(cc_bool=GetMessage(&cc_msg,cc_hwnd,0,0)!=0)
{
if (cc_bool==-1)
{
MessageBox(cc_hwnd,"点我是确定","这里是标题栏吧!",0);
return -1;
}
else
{
TranslateMessage(&cc_msg);
DispatchMessage(&cc_msg);
}
}
*/
while(GetMessage(&cc_msg,NULL,0,0))
{
TranslateMessage(&cc_msg);
DispatchMessage(&cc_msg);
}
return cc_msg.wParam;
}
//编写窗口过程函数
LRESULT CALLBACK WinCCProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_CHAR:
char cc_Char[20];
sprintf(cc_Char,"char code is %d",wParam);
MessageBox(hwnd,cc_Char,"char",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse is clicked","message",0);
HDC cc_hdc;
cc_hdc=GetDC(hwnd);
TextOut(cc_hdc,0,50,"程序员之家",strlen("程序员之家"));
ReleaseDC(hwnd,cc_hdc);
break;
case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,"http://www.sunxin.org",strlen("http://www.sunxin.org"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","message",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinCCProc(HWND hwnd, //窗体句柄
UINT uMsg, //消息标识
WPARAM wParam,
LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
//设计窗口类
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinCCProc;
wndcls.lpszClassName="chanchaw的窗体类";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
//创建窗口
HWND cc_hwnd;
//char cc_char[5];
cc_hwnd=CreateWindow("chanchaw的窗体类","http://www.sunxin.org",
WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);
//cc_char="陈超";
MessageBox(cc_hwnd,"不管怎样,先出来再说吧!","又是个标题栏",0);
//MessageBox(cc_hwnd,"创建窗体返回的句柄是:" && "速度","标题栏",0);
//显示及刷新窗口
ShowWindow(cc_hwnd,SW_SHOWNORMAL);
UpdateWindow(cc_hwnd);
//定义消息结构体,开始消息循环
MSG cc_msg;
BOOL cc_bool;
/*
while(cc_bool=GetMessage(&cc_msg,cc_hwnd,0,0)!=0)
{
if (cc_bool==-1)
{
MessageBox(cc_hwnd,"点我是确定","这里是标题栏吧!",0);
return -1;
}
else
{
TranslateMessage(&cc_msg);
DispatchMessage(&cc_msg);
}
}
*/
while(GetMessage(&cc_msg,NULL,0,0))
{
TranslateMessage(&cc_msg);
DispatchMessage(&cc_msg);
}
return cc_msg.wParam;
}
//编写窗口过程函数
LRESULT CALLBACK WinCCProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_CHAR:
char cc_Char[20];
sprintf(cc_Char,"char code is %d",wParam);
MessageBox(hwnd,cc_Char,"char",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse is clicked","message",0);
HDC cc_hdc;
cc_hdc=GetDC(hwnd);
TextOut(cc_hdc,0,50,"程序员之家",strlen("程序员之家"));
ReleaseDC(hwnd,cc_hdc);
break;
case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,"http://www.sunxin.org",strlen("http://www.sunxin.org"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","message",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
相关文章推荐
- 第一课.创建窗体类及窗体,窗体过程函数
- 函数的调用过程,栈帧的创建和销毁
- 从最简单的add函数调用过程分析函数栈桢创建和销毁的过程
- 创建和销毁过程几个函数的执行顺序
- 创建和销毁过程几个函数的执行顺序
- dbus 创建Client过程中几个有用的函数
- MFC应用程序中处理消息,创建窗口的过程,关闭窗口(非模态窗口),打开模式对话框等的函数调用顺序
- 创建存储过程和函数【weber出品必属精品】
- 光脚丫学LINQ(022):在关系设计器中创建映射到存储过程的函数
- 深入mysql创建自定义函数与存储过程的详解
- 子窗体创建过程
- Oracle数据库—— 存储过程与函数的创建
- oracle创建-存储过程和函数
- Delphi MDI程序 父窗体如何调用当前活动子窗体的函数/过程
- oracle 创建,删除存储过程,参数传递,创建,删除存储函数,存储过程和函数的查看,包,系统包
- 带有按钮并且可以执行单击事件的WINFORM窗体,体悟C#的创建过程
- mysql-创建函数,存储过程以及视图
- MS SQL Server中数据表、视图、函数/方法、存储过程是否存在判断及创建
- 判断数据库中要创建的存储过程、函数等是否已经存在
- 函数的调用过程,栈帧的创建和销毁