简体   繁体   English

程序VC ++ Win32应用程序中的错误?

[英]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.

相关问题 如何在VC ++ Win32应用程序中打印鼠标坐标? - How to print mouse coordinates in VC++ Win32 application? 是否可以在 Windows 8 环境下运行在 Visual Studio 2005 上编译的 VC++、Win32 应用程序? - Is it possible to run VC++, Win32 application compiled on Visual Studio 2005 on Windows 8 environment? 如何在VC++ Win32应用程序中鼠标光标位置打印句子? - How to print sentence in the position of the mouse cursor in VC++ Win32 application? 如何在vc++ win32 api中控制滚动条 - how to control scrollbar in vc++ win32 api 如何在vc ++ win32中制作可滚动窗口 - how to make a scrollable window in vc++ win32 如何使图片适合静态控件vc ++ win32 - how to make a picture fit in a static control vc++ win32 ReadFile(客户端命名管道)挂起 - Win32 VC ++ - ReadFile(Client end named pipe) Hangs - Win32 VC++ 哪个更有效:Win32函数。 或类似的CRT功能。 在VC ++应用中。 - Which is more efficient:A Win32 func. or a similar CRT func. in a VC++ app.? 如何在代码块的特定win32异常类型上禁用VC ++破坏? - How can I disable VC++ breaking on a specific win32 exception type for a block of code? 如何使用WIN32核心和VC ++将位图图像拉伸到某些特定的Co Ordinates? - How to stretch a bitmap image to some specific Co Ordinates using WIN32 core and VC++?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM