[英]Error in Program VC++ Win32 application?
I have developed a program for mouse event in VC++ Win32 the program is running successfully and building up with success but not showing any output can anybody tell me what is error in it or anything i missed in program 我已经在VC ++ Win32中开发了一个用于鼠标事件的程序,该程序已成功运行并成功建立,但未显示任何输出,任何人都可以告诉我它有什么错误或我在程序中错过了什么
hoping for quick and positive response 希望能迅速而积极地回应
// 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;
}
Put these lines 把这些线
ShowWindow(hwmd, SW_SHOW);
UpdateWindow(hwmd);
after HWND hwmd = CreateWindowEx(0,...
HWND hwmd = CreateWindowEx(0,...
之后HWND hwmd = CreateWindowEx(0,...
You're trying to use char
for functions that require wchar_t
. 您正在尝试将char
用于需要wchar_t
函数。 Instead of casting all your strings to LPCWSTR
, put an L
in front of each string, eg 不要将所有字符串都强制转换为LPCWSTR
,而应在每个字符串前加上一个L
,例如
LPCWSTR msgdown = L"Left Mouse Button Down" ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.