>_<:use MOUSE_MOVE message refresh the position information.

>_<:use LOWORD(lParam) get position x and use HIWORD(lParam) get position y

 //{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by FE.RC
//
#define IDR_MAINFRAME 128
#define IDD_FE_DIALOG 102
#define IDD_ABOUTBOX 103
#define IDS_APP_TITLE 103
#define IDM_ABOUT 104
#define IDM_EXIT 105
#define IDS_HELLO 106
#define IDI_FE 107
#define IDI_SMALL 108
#define IDC_FE 109
#define IDC_MYICON 2
#define IDC_STATIC -1
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 129
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 110
#endif
#endif

resourse.h

 // stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_ #if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers // Windows Header Files:
#include <windows.h> // C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h> // Local Header Files // TODO: reference additional headers your program requires here //{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)

StdAfx.h

main.cpp

 #include "stdafx.h"
#include "stdio.h"
#include "resourse.h" #define MAX_LOADSTRING 100 // Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text // Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//======================================================================================== int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg; MyRegisterClass(hInstance);//调用函数向系统注册窗口类别,输入参数hInstance是目前运行程序的对象代码; // 调用InitInstance函数,进行初始化操作;
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
} // 消息循环(通过消息循环来获取信息,
//进行必要的键盘信息转换而后将控制权交给操作系统,
//有操作系统决定哪个程序的消息处理函数处理消息
while (GetMessage(&msg, NULL, , )) //获取程序消息
{
TranslateMessage(&msg);//转换伪码及字符
DispatchMessage(&msg);//将控制权交给系统,再有系统决定负责处理消息的程序;
} return msg.wParam;
}
//===================================================================================== //=============================================================================================
//在建立程序窗口实体之前,必须先定义一个窗口类别,其中包含所要建立窗口的信息,
//并向系统注册,这里的MyRegisterClass函数就是进行定义及注册窗口类别的函数。
//==============================================================================================
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex; //申请一个窗口类别“WNDCLASSEX”和结构”wcex“
//--------------------------------------------------------------
//定义vcex结构的各项信息,其中设定信息处理函数(lpfnWndProc)
//为WNDPROC,类别名称为(lpszClassName)为”fe";
//--------------------------------------------------------------
wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = ;
wcex.cbWndExtra = ;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hCursor = LoadCursor(NULL,IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "fe";
wcex.hIconSm = NULL; return RegisterClassEx(&wcex);//调用RegisterClassEx函数注册类别,返回一个“ATOM"形态的字符串
//此字符串即为类别名称”fe";
}
//============================================================================================ //============================================================================================
//按照前面所定义的窗口类别来建立并显示实际的程序窗口
//============================================================================================
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd; hInst = hInstance; // 把instance handle 储存在全局变量中; hWnd = CreateWindow("fe","绘图窗口",WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, , CW_USEDEFAULT, , NULL, NULL, hInstance, NULL);
//-----------------------------------------------
//调用CreateWindow函数来建立一个窗口对象
//第一个参数就是窗口建立依据的类别名称
//-----------------------------------------------
if (!hWnd)
{
return FALSE;
}
//------------------------------------------------
//设定窗口的位置及窗口的大小,然后绘制显示在设备上
//-------------------------------------------------
MoveWindow(hWnd,,,,,true);//位置及大小
ShowWindow(hWnd, nCmdShow);//改定窗口显示时的状态
UpdateWindow(hWnd);//将窗口绘制在显示设备上 return TRUE;
}
//============================================================================================ //============================================================================================
//显示光标所在位置的坐标函数
//============================================================================================
void MyPaint(HDC hdc,LPARAM lParam)
{
int x,y;
char str[]="";//空字符储存要输在屏幕上的文字 x = LOWORD(lParam); //取得鼠标x坐标值(低位字节的信息)
y = HIWORD(lParam); //取得鼠标y坐标值(高位字节的信息) SetTextColor(hdc,RGB(,,));//设定DC上文字颜色 TextOut(hdc,,,"鼠标坐标",strlen("鼠标坐标"));//格式化所要显示的字符串,并调用
sprintf(str,"X 坐标: %d ",x); //TextOut()将其输出在窗口上;
TextOut(hdc,,,str,strlen(str));//----||-BOOL TextOut(HDC hdc,int x,int y输出字符串的坐标,
sprintf(str,"Y 坐标: %d ",y); //----||-------------LPCTSTR 字符串指针,int 字符串长度);
TextOut(hdc,,,str,strlen(str));
}
//============================================================================================ //============================================================================================
//在前面定义类别的时候把WndProc定义为消息处理函数(当某些外部消息发生时,会按消息的类型
//来决定该如何进行处理。此外该函数也是一个回叫函数(CALLBACK)(windows系统函数)每一个
//程序都会接收信息,选择性接受、处理;
//============================================================================================
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc; switch (message) //判断消息类型
{
case WM_PAINT: //窗口重绘制
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_MOUSEMOVE: //鼠标移动消息
hdc = GetDC(hWnd);//BeginPaint()仅用在处理重绘消息上,在其他地方要获得DC要用GetDC();
MyPaint( hdc, lParam);//MyPaint(hdc,lParam);//lParam鼠标状态相关信息
ReleaseDC(hWnd,hdc);
break;
case WM_DESTROY: //处理窗口结束消息
PostQuitMessage();
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return ;
}
//============================================================================================

[游戏模版4] Win32 显示鼠标位置的更多相关文章

  1. [游戏模版15] Win32 飞机射击

    >_<:Only give you the code,try to understand it! >_<:picture resource #include <windo ...

  2. [游戏模版16] Win32 飞机射击 敌人追踪

    >_<:AI introduction. >_<:According the plane position (nowX,nowY) relative to birds' pos ...

  3. [游戏模版17] Win32 推箱子 迷宫

    >_<:Here introduce a simple game: >_<:resource >_<:only can push a box and finally ...

  4. [游戏模版2] Win32最小框架

    >_<:Just the minimum Win32  frame don't have any other special function. //{{NO_DEPENDENCIES}} ...

  5. [游戏模版18] Win32 五子棋

    >_<:Learning its AI logic. >_<:resource >_<:code: #include <windows.h> // C ...

  6. [游戏模版3] Win32 画笔 画刷 图形

    >_<:introduce the functions of define\create\use pen and brush to draw all kinds of line and s ...

  7. [游戏模版5] Win32 折线 弧线

    >_<:first build some points put in poly1[],poly2[] and poly3[] in the function of InitInstance ...

  8. [游戏模版6] Win32 graph

    >_<:there in the MyPaint(...) function respectively use Ellipse(...) draw ellipse, use RoundRe ...

  9. [游戏模版7] Win32 最简单贴图

    >_<:this is the first using mapping. >_<:There will be introducing how to do: First load ...

随机推荐

  1. Node.js 的初步理解

    Node.js 是一个采用C++语言编写的后端的 Javascript 的运行环境, 它使用了 google 的 V8虚拟机来解释和执行代码.Node.js 的有许多有用的内置的模块,比如 http, ...

  2. C语言基础_2

    scanf函数可以从键盘上读取数据并记录到变量中.为了使用这个函数也需要在文件开头使用如下的预处理指令#include <stdio.h>scanf函数使用的时候所需要的初始数据和prin ...

  3. 各种音视频编解码学习详解 h264 ,mpeg4 ,aac 等所有音视频格式

    编解码学习笔记(一):基本概念 媒体业务是网络的主要业务之间.尤其移动互联网业务的兴起,在运营商和应用开发商中,媒体业务份量极重,其中媒体的编解码服务涉及需求分析.应用开发.释放 license收费等 ...

  4. 手机抓包xcode自带命令行工具配合wireshark实现

    三.最佳方式:rvictl命令 优点:简单,而且可以抓所有网络接口的数据: 缺点:似乎没有,要求手机iOS5以上不算要求吧?如果说缺点,就是这个命令是Xcode的Command Line Tools ...

  5. Spring 通过工厂配置Bean

    1.通过静态工厂方法配置Bean 要声明通过静态方法创建的 Bean, 需要在 Bean 的 class 属性里指定拥有该工厂的方法的类, 同时在 factory-method 属性里指定工厂方法的名 ...

  6. JAVA学习<三>

    1.Java中运算符的优先级: 2.条件语句If: 如果 if 条件成立时的执行语句只有一条,是可以省略大括号滴!但如果执行语句有多条,那么大括号就是不可或缺的. public class Hello ...

  7. 改进的SQL Express LocalDBB

    介绍一种改进的SQL Express LocalDB LocalDB专门为开发商.它是非常容易安装,无需管理,但它提供了相同的T-SQL语言,编程表面和客户端供应商定期的SQL Server Expr ...

  8. 小甲鱼python视频弟十二讲(关于字符串的方法及注释下)

    1,ljust(width[, fillchar])  width -- 指定字符串长度. fillchar -- 填充字符,默认为空格. 用法:返回一个原字符串左对齐,并使用空格填充至指定长度的新字 ...

  9. cookie 的“Value”=“xxxxx,xxxxx”部分无效

    cookie 的“Value”=“xxxxx,xxxxx”部分无效 在一些网站中有时候会遇到Cookie的值为逗号 但是在.Net中Cookie的值是不能直接使用逗号的 如果使用形如 C#代码 1.C ...

  10. 数据字典和动态性能视图<五>

    数据字典和动态性能视图 介绍:数据字典是什么 数据字典是 oracle 数据库中最重要的组成部分,它提供了数据库的一些系统信息. 动态性能视图记载了例程启动后的相关信息.  数据字典 数据字典记录了 ...