您的位置:首页 > 其它

第一课.创建窗体类及窗体,窗体过程函数

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: