0
我已經制定了程序運行成功,併成功建立,但沒有表現出任何輸出有誰能夠告訴我什麼是錯誤的,或什麼,我錯過了在程序程序VC++ Win32應用程序出錯?
希望快速在VC++的Win32鼠標事件的程序和積極響應
// ttt.cpp : Defines the entry point for the application.
// TO Demonstrate the Mouse Events
#include "windows.h"
#include "stdafx.h"
#include "stdio.h"
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
int x=0 , y=0;
LPCWSTR msgdown = (LPCWSTR)"Left Mouse Button Down" ;
LPCWSTR msgup = (LPCWSTR)"Left Mouse Button UP" ;
LPCWSTR msgdblclk = (LPCWSTR)"Left Mouse Button Dbl clk" ;
LPCWSTR mouse = (LPCWSTR)"Mouse" ;
switch (msg)
{
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_LBUTTONDOWN:
MessageBox(hWnd,msgdown,mouse,MB_OK);
break;
case WM_LBUTTONUP:
MessageBox(hWnd,msgup,mouse,MB_OK);
break;
case WM_LBUTTONDBLCLK:
MessageBox(hWnd,msgdblclk,mouse,MB_OK);
break;
x=LOWORD(lParam);
y=HIWORD(lParam);
char text[50];
sprintf(text,"Mouse Position: X=%d, Y=%d",x,y);
LPCWSTR textmsg = (LPCWSTR)text;
SetWindowText(hWnd,textmsg);
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
LPCTSTR className=(LPCTSTR)"Mouse Test";
WNDCLASSEX wc;
wc.cbSize =sizeof(WNDCLASSEX);
wc.style =CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wc.lpfnWndProc =WndProc;
wc.cbClsExtra =0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW +1);
wc.lpszMenuName = NULL;
wc.lpszClassName = className;
wc.hIconSm = LoadIcon(NULL,IDI_WINLOGO);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL,(LPCWSTR)"Error Registering Class",(LPCWSTR)"Error RegisterClassEx",MB_OK | MB_ICONERROR);
return 1;
}
HWND hwmd = CreateWindowEx(0,className,(LPCWSTR)"Mouse Test",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,400,300,NULL,NULL,hInstance,NULL);
if(!hwmd)
{
MessageBox(NULL,(LPCWSTR)"Error Creating Window",(LPCWSTR)"Error CreateWindowEx",MB_OK | MB_ICONERROR);
return 1;
}
MSG msg;
while(GetMessage(&msg,NULL,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
@mr:我更新了我的答案。 – 2011-02-02 19:13:27
你是我得到它但運行後..我有屏幕。但是當我點擊一個鼠標按鈕它顯示。總和其他字符..不是我提到的那個 – 2011-02-02 19:13:54