孙鑫VC++深入详解:Lesson1
来源:互联网 发布:网络彩票何时恢复 编辑:程序博客网 时间:2024/05/17 23:45
1. 开始我从MSDN 中copy WinMain原型时,搞错了
下面的代码编译是说 WinMain不能重载.....原来是参数不对. LPWSTR, 指向宽字符串的指针,16位=2个字节=一个字word
LPCWSTR--- Pointer to a constant null-terminated string of 16-bit Unicode characters. For more information, see Character Sets Used By Fonts.
下面这个WinMain是基于WIN CE
This function is called by the system as the initial entry point for WindowsCE-based applications.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd );
下面这个是基于Windows , for a Windows-based application.
The WinMain function is called by the system as the initial entry point for a Windows-based application.
应是这个, LPSTR
LPCSTR--- Pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.
int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow // show state);
2. 用couter 来统计 WM_PAINT 的消息.
最小化,最大化,被其他程序盖住界面,改变窗口的宽度 都会产生 WM_PAINT
奇怪的是 改变窗口高度 不会产生 WM_PAINT消息
#include <windows.h>#include <stdio.h>LRESULT CALLBACK WindowProc(HWND hwnd, // handle to windowUINT uMsg, // message identifierWPARAM wParam, // first message parameterLPARAM lParam // second message parameter);int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow // show state ){ WNDCLASS wc={0};//wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);wc.hCursor = LoadCursor(NULL,IDC_CROSS);wc.hIcon = LoadIcon(NULL,IDI_ASTERISK);wc.hInstance = hInstance;wc.lpfnWndProc = WindowProc;wc.lpszClassName ="weixin2003";wc.lpszMenuName = NULL;wc.style = CS_HREDRAW |CS_HREDRAW;RegisterClass(&wc);HWND hwnd;hwnd = CreateWindow("weixin2003","--窗口标题--",WS_OVERLAPPEDWINDOW &~WS_MAXIMIZEBOX,/* 不是WS_MAXIMIZE */200,200,600,400, NULL,NULL, hInstance, NULL); ShowWindow(hwnd,SW_SHOWNORMAL); UpdateWindow(hwnd); MSG msg; while(GetMessage(&msg,NULL,0,0)) {TranslateMessage(&msg);DispatchMessage(&msg); }//---return msg.wParam;}LRESULT CALLBACK WindowProc(HWND hwnd, // handle to windowUINT uMsg, // message identifierWPARAM wParam, // first message parameterLPARAM lParam // second message parameter){char szChar[20]; HDC hdc; char pchar[40]; //输出 window painted 的次数信息 static int cnt=0; // 统计WM_PAINT的次数,看看那些操作会导致WM_PAINTswitch(uMsg) {case WM_CHAR:sprintf(szChar,"char is %d",wParam);MessageBox(hwnd,szChar,"weixin",MB_OKCANCEL|MB_ICONQUESTION); break;case WM_LBUTTONDOWN: MessageBox(hwnd,"mouse clicked","caption",0); hdc = GetDC(hwnd); TextOut(hdc,0,50,"mouse clicked",strlen("mouse clicked")); ReleaseDC(hwnd,hdc); break;case WM_PAINT: cnt++;// sprintf(pchar,"window painted: %d",cnt);PAINTSTRUCT ps; hdc = BeginPaint(hwnd,&ps); TextOut(hdc,0,0,pchar, sprintf(pchar,"window painted: %d",cnt)); EndPaint(hwnd,&ps);break;case WM_CLOSE: DestroyWindow(hwnd);break;case WM_DESTROY:PostQuitMessage(0);break;default:return DefWindowProc(hwnd,uMsg,wParam,lParam);}return 0;}
- 孙鑫VC++深入详解:Lesson1
- 《VC++深入详解》学习笔记----Lesson1: Windows程序运行原理及程序编写流程
- lesson1:Windows程序运行原理及程序编写流程(vc++深入详解)
- 孙鑫VC视频教程笔记——Lesson1
- 孙鑫VC++深入详解:Lesson3
- 孙鑫VC++深入详解:Lesson4
- 孙鑫VC++深入详解笔记
- Lesson1 深入.Net框架
- VC++笔记(Lesson1-Lesson4)
- Lesson1 Windows程序内部运行原理 ---孙鑫VC++教程
- Lesson1 Windows程序内部运行原理 ---孙鑫VC++教程
- 孙鑫 VC++ 深入详解 笔记 1
- 孙鑫《VC++深入详解》完整版PDF 下载
- 孙鑫VC++(深入详解)视频教程
- 孙鑫VC++深入详解(5):菜单
- 阅读笔记《孙鑫-VC++深入详解》
- 《VC++深入详解,孙鑫》读书总结
- 孙鑫《VC++深入详解》完整版PDF 下载
- 博弈论入门导论
- Rails 调试
- wait、sleep、interrupt、notify
- 深入理解Java中的多线程
- 【自动回帖器/原理】自动回帖器的原理与实现(二)代码篇
- 孙鑫VC++深入详解:Lesson1
- 判别模型和生成模型
- 动态规划知识点
- C内存管理函数
- Linux CP文件夹略过目录的解决
- SED来自WIKI
- DEDECMS织梦全站动态化访问(包括自由列表freelist)及发布内容时自动动态化设置
- WebView的使用
- c++回调函数(下)