在凌晨对mfc的分析中逐渐的了解了脉络,也逐渐清晰了windows程序的运行机制。也感觉到以前的概念根本一丁点也不能灌输进来进行参考,这是一个几乎全新的领域(对于我),从昨天的小笔记开始思考,microsoft给我们的工具是否正在一步一步让程序员走向傻瓜化?像照相机,现在不到十岁就知道,按下一个按钮就可以拍照了……像我之前,就知道用C#写网站写程序,但是,这都是进行封装过的,用起来顺手但是却不知道原理何在,很容易被他们蒙蔽了头脑,当根深蒂固的时候,想改变以往观念已经很难了,所以不能浪费时间,那东西用来入门可以,要求产量的时候可以,用来练级几乎是不可能的事情。所以开始研究一些源码。今天从IESpy小工具入手,它是一个开源的程序,慢慢分析,自己加注释。对,今天是纯粹的api。
- 原来,可以在直接绘制窗体资源,然后…就不用为手写界面而浪费时间了
- int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
- {
- ghInstance = hInstance;
- DialogBox( hInstance, //DialogBox()是从资源创建窗体的函数
- MAKEINTRESOURCE( IDD_DIALOG1 ), //MAKEINTRESOURCE 宏 后面跟窗体资源标识
- NULL,
- (DLGPROC)MainDlgProc ); //消息处理函数。
- return 1;
- }
- 一下为消息循环了,小图标更换
- static HCURSOR hDragCursor = NULL; //光标句柄
- static HCURSOR hRegularCursor = NULL;
- switch ( message )
- {
- case WM_INITDIALOG: //对话框初始化,msdn的解释是对话框出现之前的消息
- {
- hwndMain = hDlg;
- hDragCursor = LoadCursor( ghInstance, MAKEINTRESOURCE(IDC_CURSOR1) ); //初始化滑鼠拖拽时样式函数
- hRegularCursor = LoadCursor( NULL, IDC_ARROW ); //初始化常规光标
- #ifdef _WIN64 //如果是64位机器?
- SetClassLong( hwndMain, GCLP_HICON, ( long ) LoadIcon( GetModuleHandle( NULL ), MAKEINTRESOURCE( IDI_1MAIN ) ) ); //SetClassLong()大概是设置的东西。整句是小图标更换成资源的图标. GetModuleHandle返回一个特定句柄模型指针? If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process.
- #else
- SetClassLong( hwndMain, GCL_HICON, ( long ) LoadIcon( GetModuleHandle( NULL ), MAKEINTRESOURCE( IDI_1MAIN ) ) ); //LoadIcon取得特定鼠标资源。
- #endif
- return 1;
- }
- 获取控件咨询
- case WM_CTLCOLORSTATIC: //控件drawn后,返回给父窗口。wParam参数为控件的dc,lParam参数为静态控件句柄
- {
- if ( ( HWND ) lParam == GetDlgItem( hwndMain, IDC_CLASSNAME ) ) //GetDlgItem返回在资源窗体中的控件标识... 总句解释为是不是叫IDC_CLASSNAME的控件触发了此消息
- {
- if (lstrcmp("Internet Explorer_Server", lpClassName) == 0) //比较两者大小.如果一样.
- return FormatControl( ( HWND ) lParam, ( HDC ) wParam, FW_BOLD, 15, _TEXT_BLACK_, "MS Shell Dlg", FALSE, TRANSPARENT, NULL ); //稍后解释
- else
- return FormatControl( ( HWND ) lParam, ( HDC ) wParam, FW_BOLD, 15, _TEXT_BLACK_ , "MS Shell Dlg", FALSE, TRANSPARENT, NULL );
- }
- if ( ( HWND ) lParam == GetDlgItem( hwndMain, IDC_ABOUT ) )
- return FormatControl( ( HWND ) lParam, ( HDC ) wParam, FW_NORMAL, 15, _TEXT_BLUE_ , "MS Shell Dlg", TRUE, TRANSPARENT, WHITE_BRUSH );
- return 1;
- }
- 投递自定消息
- case WM_RBUTTONDOWN: //右击消息
- {
- PostMessage( hwndMain, WM_NCLBUTTONDOWN, HTCAPTION, 0 ); //给hwndMain投递消息。
- return 1;
- }
-
- case WM_LBUTTONDOWN: //左击消息
- {
- POINT pt = { LOWORD( lParam ), HIWORD( lParam )}; //获得鼠标坐标
- HWND hChild = ChildWindowFromPoint( hwndMain, pt ); //从point中得到子窗口句柄..
- if ( hChild != GetDlgItem( hwndMain, IDC_DRAGICON ) ) //如果单击的不是指定的控件
- {
- PostMessage( hwndMain, WM_NCLBUTTONDOWN, HTCAPTION, 0 ); //做默认消息
- return 1;
- }
- //否则
- SetCapture(hwndMain); //设置捕获
- SetCursor( hDragCursor ); //设置鼠标
- isDragging= TRUE; //设置拖拽标识
- return 1;
- }
-
- case WM_LBUTTONUP: //左键松开
- {
- POINT pt;
- isDragging= FALSE; //没有拖拽了
- SetCursor( hRegularCursor ); //恢复常规图标
- ReleaseCapture(); //释放捕获
- pt.x = LOWORD( lParam );
- pt.y = HIWORD( lParam );
- ClientToScreen( hwndMain, ( LPPOINT ) & pt ); //转换相对坐标到相对屏幕坐标
- hTarget = WindowFromPoint(pt); //从pt获得外界程序句柄
- if (hTarget == hwndMain || !hTarget) return TRUE;
- GetClassName(hTarget, lpClassName, 255 ); //获得CLASSNAME
- SetDlgItemText( hwndMain, IDC_CLASSNAME, lstrlen(lpClassName) ? lpClassName: "( none )"); //在控件写入文本
- if (lstrcmp("Internet Explorer_Server", lpClassName) == 0)
- {
- hIETarget = hTarget;
- StopFlashing(); //自定的后续解释
- GrabSource();
- }
- else
- {
- StopFlashing();
- MessageBox( NULL, "The target window you have specified is not an Internet Explorer control.", "Invalid Window", MB_TASKMODAL );
- SetDlgItemText( hwndMain, IDC_CLASSNAME, " ");
- }
- return TRUE;
- }
-
- case WM_MOUSEMOVE: //鼠标移动时
- {
- if (GetCapture()) //如果鼠标捕获到了
- {
- POINT pt;
- HWND hTarget;
- char lpClassName[255]="";
- pt.x = LOWORD( lParam );
- pt.y = HIWORD( lParam );
- ClientToScreen( hwndMain, ( LPPOINT ) & pt );
- hTarget = WindowFromPoint(pt);
- if (!hTarget || hTarget == hwndMain)
- {
- if (isDragging)
- SetCursor( hDragCursor ); //设置拖拽时
- else
- {
- SetCursor( hRegularCursor );
- ReleaseCapture(); //释放捕获
- }
- }
- else
- {
- HWND hwndChild = TopChildWindowFromPoint(hTarget, pt);
- while (hwndChild != NULL && hwndChild != hTarget)
- {
- hTarget = TopSiblingWindowFromPoint(hwndChild, pt);
- hwndChild = TopChildWindowFromPoint(hTarget, pt);
- }
- DWORD dwStyles = GetWindowLong(hTarget, GWL_STYLE); //获得额外句柄信息..
- DWORD dwExStyles = GetWindowLong(hTarget, GWL_EXSTYLE);
- if ((dwStyles & WS_CHILD) && !(dwExStyles & WS_EX_MDICHILD))
- hTarget = TopSiblingWindowFromPoint(hTarget, pt);
- if (hTarget != hTargetLast)
- {
- StopFlashing();
- hTargetLast = hTarget;
- StartFlashing(hTarget);
- }
- GetClassName(hTarget, lpClassName, 255 );
- SetDlgItemText( hwndMain, IDC_CLASSNAME, lpClassName);
- }
- }
- return TRUE;
- }
-
- case WM_QUIT:
- case WM_CLOSE:
- {
- ExitProcess (1); //退出所有句柄..
- return TRUE;
- }
- case WM_COMMAND:
- {
- switch ( LOWORD( wParam ) )
- {
- case IDOK:
- {
- ExitProcess (1);
- return 1;
- }
- case IDC_ABOUT:
- {
- MessageBox( hwndMain,
- "IESpy v1.1\n\n"
- "Reveals the HTML source code behind embedded Internet Explorer\n"
- "controls. Requires Windows 98/ME/2000. IESpy is free and open source.\n\n"
- "Written by Andrew Fawcett (afawcett@u.washington.edu)\n"
- "http://www.disoriented.com/labs/\n",
- "About IESpy", MB_APPLMODAL);
- }
- }
- }
今天分析到此为止…明儿继续.
搞了两天问题被你一个(POINT pt = { LOWORD( lParam ), HIWORD( lParam )};)搞定了,
非常感谢!!!交个朋友杂样?有QQ号就发到我邮箱,我加你。