我想 努力都不知道该在什么努力,
[此贴子已经被作者于2005-10-22 12:54:25编辑过]
[此贴子已经被作者于2005-10-22 16:48:53编辑过]
[此贴子已经被作者于2005-10-22 18:35:42编辑过]
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//窗口函数说明
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd) // WinMain函数说明 { HWND hwnd; MSG Msg; WNDCLASS wndclass; char lpszClassName [] = "Windows"; //窗口类名 char lpszTitle [] = "Windows Demo"; //窗口标题名
wndclass.cbClsExtra = 0; //窗口类型为默认类型 wndclass.cbWndExtra = 0;//窗口实例无扩展 wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);//背景为白色 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);//采用箭头光标 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);//默认最小化图标 wndclass.hInstance = hInstance;//当前实例句柄,有人说叫扶手 wndclass.lpfnWndProc = WndProc;//处理函数为WndProc wndclass.lpszClassName = lpszClassName;// wndclass.lpszMenuName = NULL;窗口无菜单 wndclass.style = 0;默认窗口类型
if(!RegisterClass(&wndclass))//注册返回值,没有声音 { return 0; }
hwnd = CreateWindow(lpszClassName,//窗口类名 lpszTitle,//标题名 WS_OVERLAPPEDWINDOW,//窗口风格 CW_USEDEFAULT, CW_USEDEFAULT,//左上角坐标为默认值 CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL,//没有主窗口和主菜单 hInstance,//当前句饼 NULL);//不使用 ShowWindow(hwnd, nShowCmd);//显示窗口 UpdateWindow(hwnd);//画出用户区 while(GetMessage(&Msg, NULL, 0, 0))//消息循环 { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam;//将信息返回系统 }
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)//窗口函数 { switch(message) { case WM_DESTROY: PostQuitMessage(0);//发回 WM_Quit消息 default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; }
这个题做好了,用了个笨方法,没有用循环处理颜色显示, 其实题不难,可我到现在才弄好,基础的东西没有例题太难做了.看了半天,就是不知道 画笔函数咋样创建.看了个例题才明白,原来是那么简单. WndProc 这个函数,它的工作就是响应,拦截,处理各种窗口消息. 它是一个回调函数,当注册窗口类的时候,要把窗口消息处理函数的地址告诉Windows,Windows通过调用此函数进行消息处理。 至于更深的认识我还在查, 如果要我说从这个函数看到了什么,深的认识还真的没有, 我只知道它是WINDOWS窗口必须要有的基本函数, 我想,那些过滤,截取的软件用的就是它把, 整个WINDOWS窗口创建过程,有的函数还是不理解,我正在找资料看,越基本的东西反而越难明白 不象画笔,用了一次,我就明白了, 程序我运行过 了,用了5种颜色.就是使用的方法太笨了. #include <windows.h> #include <stdio.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd) { HWND hwnd; MSG Msg; WNDCLASS wndclass; char lpszClassName [] = "hao"; char lpszTitle [] = "hao ya";
wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hInstance = hInstance; wndclass.lpfnWndProc = WndProc; wndclass.lpszClassName = lpszClassName; wndclass.lpszMenuName = NULL; wndclass.style = CS_HREDRAW | CS_VREDRAW;
if(!RegisterClass(&wndclass)) { return 0; }
hwnd = CreateWindow(lpszClassName, lpszTitle, WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, nShowCmd); UpdateWindow(hwnd); while(GetMessage(&Msg, NULL, 0, 0)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; }
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; HPEN h1; HPEN h2; HPEN h3; HPEN h4; HPEN h5; switch(message) { case WM_PAINT: h1=CreatePen(PS_SOLID,0,RGB(0,255,255)); h2=CreatePen(PS_SOLID,0,RGB(255,25,0)); h3=CreatePen(PS_SOLID,0,RGB(2,255,100)); h4=CreatePen(PS_SOLID,0,RGB(10,155,10)); h5=CreatePen(PS_SOLID,0,RGB(40,5,200)); hdc = BeginPaint(hwnd, &ps); SetMapMode(hdc,MM_TEXT); SelectObject(hdc,h1); MoveToEx(hdc,100,150,NULL); LineTo(hdc,350,150); SelectObject(hdc,h2); MoveToEx(hdc,100,250,NULL); LineTo(hdc,350,250); SelectObject(hdc,h3); MoveToEx(hdc,100,150,NULL); LineTo(hdc,100,250); SelectObject(hdc,h4); MoveToEx(hdc,350,150,NULL); LineTo(hdc,350,250); SelectObject(hdc,h5); MoveToEx(hdc,220,70,NULL); LineTo(hdc,220,340); EndPaint(hwnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }
[此贴子已经被作者于2005-10-24 2:20:59编辑过]