第一课.创建窗体类及窗体,窗体过程函数
2014-04-24 17:05
369 查看
//以下为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;
}
相关文章推荐
- 第一课.创建窗体类及窗体,窗体过程函数
- MySQL存储过程和自定义函数、Navicat for mysql、创建存储过程和函数、调用存储过程和函数的区别
- oracle 创建,删除存储过程,参数传递,创建,删除存储函数,存储过程和函数的查看,包,系统包
- mysql-创建函数,存储过程以及视图
- 判断数据库中要创建的存储过程、函数等是否已经存在
- oracle 创建,删除存储过程,参数传递,创建,删除存储函数,存储过程和函数的查看,包,系统包
- MySQL存储过程和自定义函数、Navicat、创建存储过程和函数、调用存储过程和函数、三种方式、In和Out类型参数、
- (在hello,MFC的创建过程中,新建项目时所配置的属性出现错误)error LNK2019: 无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用 MSVCRTD.lib
- Oracle数据库—— 存储过程与函数的创建
- JS函数创建的具体过程
- MFC应用程序消息处理及其窗口创建和销毁过程函数调用顺序
- 浅谈函数的调用过程,栈帧的创建和销毁,附图讲解
- MFC应用程序中处理消息,创建窗口的过程,关闭窗口(非模态窗口),打开模式对话框等的函数调用顺序 .
- 初学oracle--创建函数和过程中的注意事项
- Oracle创建和调用存储过程,函数,视图
- mysql-创建函数,存储过程以及视图
- Oracle基础学习三:过程PROCEDURE 和函数FUNCTION 的创建及调用
- oracle 创建,删除存储过程,参数传递,创建,删除存储函数,存储过程和函数的查看,包,系统包
- 自己写的基于窗体函数的分页存储过程
- !!!我的Javascript之旅——对象的原型链之由来 函数对象的创建过程