更新时间:2016-01-07 21:37:38浏览次数:1+次
int iState = GetKeyState(VK_CONTROL);
if(iState<0)
{
MessageBox(hwnd,_T("鼠标单击时按下了Ctrl键"),_T("C++技术网提示"),0);
}
else
{
MessageBox(hwnd,_T("鼠标单击时未按下了Ctrl键"),_T("C++技术网提示"),0);
}
if (wParam&MK_CONTROL)
{
MessageBox(hwnd,_T("鼠标单击时按下了Ctrl键"),_T("C++技术网提示"),0);
}
else
{
MessageBox(hwnd,_T("鼠标单击时未按下了Ctrl键"),_T("C++技术网提示"),0);
}
因此我们就得到了两种实现方法,实现的效果如下:
#include "windows.h"
#include <tchar.h>
TCHAR txt[100]=_T("C++技术网www.cjjjs.com");
// - 项目是Unicode字符集
LRESULT CALLBACK WinProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,txt,lstrlen(txt));
EndPaint(hwnd,&ps);
return 0;
case WM_LBUTTONDOWN:
{
//int iState = GetKeyState(VK_CONTROL);
//if(iState<0)
if (wParam&MK_CONTROL)
{
MessageBox(hwnd,_T("鼠标单击时按下了Ctrl键"),_T("C++技术网提示"),0);
}
else
{
MessageBox(hwnd,_T("鼠标单击时未按下了Ctrl键"),_T("C++技术网提示"),0);
}
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
break;//跳出到默认处理
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrev,LPSTR lpCmd,int iShow)
{
TCHAR ClassName[] = _T("MyClass");
TCHAR title1[] = _T("C++技术网http://www.cjjjs.com");
WNDCLASS wndClass;
wndClass.cbClsExtra=0;
wndClass.cbWndExtra=0;
wndClass.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH);
wndClass.hCursor=LoadCursor(NULL,IDC_HAND);
wndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndClass.hInstance = hInstance;
wndClass.lpfnWndProc = WinProc;
wndClass.lpszClassName = ClassName;
wndClass.lpszMenuName=NULL;
wndClass.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClass(&wndClass))return 0;
HWND hwnd = CreateWindow(ClassName,title1,WS_OVERLAPPEDWINDOW,0,0,650,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
相关资讯