纯WINAPI编程.doc
《纯WINAPI编程.doc》由会员分享,可在线阅读,更多相关《纯WINAPI编程.doc(6页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、/ notepaper.cpp : 为应用程序定义一入口点#include windows.h#include resource.h#include commctrl.h#define WM_ADJUSTSIZE WM_USER+1BOOL InitInstance();BOOL InitApp();LRESULT CALLBACK MyWndProc (HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam);BOOL CALLBACK MyDlgProc (HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam
2、);void LoadIni(); void SaveIni();/全局变量 HWND hWnd;HWND hWndToolTip;HWND hEdit =NULL;HINSTANCE hInst;POINT point,oldpoint;RECT rect; char textshow256; INT IniX=0 ,IniY=0;BOOL bCaptured=FALSE; /-WinMain 函数-int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
3、 MSG msg;hInst=hInstance;if(!InitInstance()return -1;LoadIni(); / 导入INI文件内容InitCommonControls(); /注册或初始化窗口类if(!InitApp() return -1;while(GetMessage(&msg,NULL,NULL,NULL) TranslateMessage(&msg);DispatchMessage(&msg);return msg.lParam;/-BOOL InitInstance()WNDCLASSEX wcex;wcex.cbClsExtra=0;wcex.cbWndExt
4、ra=0;wcex.style=CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS;wcex.cbSize=sizeof(WNDCLASSEX);wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);wcex.hCursor=LoadCursor(NULL,IDC_ARROW);wcex.hIcon=LoadIcon(NULL,IDI_APPLICATION);wcex.hInstance=hInst;wcex.lpfnWndProc=(WNDPROC)MyWndProc;wcex.lpszClassName=NOTEPAPERWND;wcex.
5、lpszMenuName=NULL;wcex.hIconSm=NULL; if(RegisterClassEx(&wcex)=NULL)return 0;return 1;/-BOOL InitApp()TOOLINFO ti; / 工具提示消息(当鼠标放在窗口上时的提示信息) static char tooltip=桌面便条V1.5;hWnd=CreateWindowEx(WS_EX_TOPMOST|WS_EX_TOOLWINDOW,NOTEPAPERWND,NOTEPAPER,WS_BORDER|WS_POPUP,IniX,IniY,0,0,NULL,NULL,hInst,NULL); /
6、创建主窗口if(hWnd=NULL)return FALSE;hWndToolTip = CreateWindow(TOOLTIPS_CLASS, (LPSTR) NULL, TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, (HMENU) NULL, hInst, NULL); / 创建浮动条窗体 memset(&ti,0 ,sizeof(TOOLINFO);ti.cbSize=sizeof(TOOLINFO); /浮动条消息 ti.uFlags=TTF_IDISHWND; ti.
7、hwnd =hWnd; ti.uId =(UINT)hWnd; ti.lpszText=tooltip; SendMessage(hWndToolTip, TTM_ADDTOOL, 0,(LPARAM) (LPTOOLINFO) &ti) ;ShowWindow(hWnd,SW_SHOW);SendMessage(hWnd,WM_ADJUSTSIZE,0,0);UpdateWindow(hWnd);return TRUE;/-LRESULT CALLBACK MyWndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)HDChDC;PAI
8、NTSTRUCT ps;SIZEsize;MSGmsg ;POINTpt;HBRUSHhbr;HFONThfont , holdfont;staticCOLORREF clr=RGB(255,0,0), bkclr=RGB(0,255,255) ;HMENUhmenu ;msg.hwnd = hWnd; msg.message = uMsg; msg.wParam = wParam; msg.lParam = lParam; GetCursorPos(&pt); msg.pt.x = pt.x; msg.pt.y = pt.y;CHOOSECOLORcc; static DWORDadwCus
9、tColors16;memset(&cc, 0 , sizeof(CHOOSECOLOR);cc.lStructSize=sizeof(CHOOSECOLOR);cc.hwndOwner=hWnd;cc.Flags=CC_RGBINIT;cc.lpCustColors =adwCustColors;switch(uMsg)case WM_COMMAND :switch( wParam)case ID_MENUITEM40001: /单击About菜单MessageBox(hWnd,桌面便条(纯WINAPI调用),桌面便条,MB_OK);break; case ID_MENUITEM40002:
10、 /单击Text Color菜单cc.rgbResult=clr;if(:ChooseColor(&cc) clr=cc.rgbResult;InvalidateRect(hWnd ,NULL ,TRUE);break;case ID_MENUITEM40003: /单击Background Color菜单cc.rgbResult=bkclr;if(:ChooseColor(&cc) bkclr=cc.rgbResult;InvalidateRect(hWnd ,NULL ,TRUE);break;case ID_MENUITEM40004: /单击Write Words菜单PostMessa
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- WINAPI 编程
限制150内