Win32 Click наблюдается через очередь сообщений, но не работает [закрыто]C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Win32 Click наблюдается через очередь сообщений, но не работает [закрыто]

Сообщение Anonymous »

Я делаю приложение Win32. В этом есть два окна - верхнее прозрачное, а нижний - нормальный. Я пытаюсь достичь этого эффекта: < /p>

Когда щелчок происходит в верхнем прозрачном окне, тогда щелчок мыши будет передаваться в базовое окно. не происходит. Например, если я нажимаю на прозрачное окно, где расположена кнопка «Закрыть базовое окно», то подходящее окно должно закрыться. Но этого не происходит, хотя щелчок мыши был получен в базовом окне через его wndproc из прозрачного окна. < /P>
Могу ли я узнать, почему это не работает?// delete_It.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "Windowsx.h"
#include "delete_It.h"

//Resource.h
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Gui_Automation_Win32.rc
//

#define IDS_APP_TITLE 103

#define IDR_MAINFRAME 128
#define IDD_GUI_AUTOMATION_WIN32_DIALOG 102
#define IDD_ABOUTBOX 103
#define IDM_ABOUT 104
#define IDM_EXIT 105
#define IDI_GUI_AUTOMATION_WIN32 107
#define IDI_SMALL 108
#define IDC_GUI_AUTOMATION_WIN32 109
#define IDC_MYICON 2
#ifndef IDC_STATIC
#define IDC_STATIC -1
#endif
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS

#define _APS_NO_MFC 130
#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

//////

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name

// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK Transparent_Window_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK Debug_Window_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
const wchar_t CLASS_NAME_TRANSPARENT[] = L"Custom_Class";
const wchar_t CLASS_NAME_DEBUG[] = L"Debug_Window_Class";
HWND hwnd_Window_Without_Title_Bar;
HWND required_Under_Window;

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_DELETE_IT, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DELETE_IT));

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}

//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//

ATOM MyRegisterClass(HINSTANCE hInstance)
{
//Transparent Window
WNDCLASS custom_Class={};
custom_Class.lpfnWndProc = Transparent_Window_WndProc;
custom_Class.hInstance = hInstance;
custom_Class.lpszClassName = CLASS_NAME_TRANSPARENT;
custom_Class.hCursor = LoadCursor(NULL, IDC_HAND);
custom_Class.style = CS_ENABLE;
RegisterClass(&custom_Class);

//Under lying Window

WNDCLASSEX Debug_Window_Class;

Debug_Window_Class.cbSize = sizeof(WNDCLASSEX);

Debug_Window_Class.style = CS_HREDRAW | CS_VREDRAW;
Debug_Window_Class.lpfnWndProc = Debug_Window_WndProc;
Debug_Window_Class.cbClsExtra = 0;
Debug_Window_Class.cbWndExtra = 0;
Debug_Window_Class.hInstance = hInstance;
Debug_Window_Class.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_GUI_AUTOMATION_WIN32));
Debug_Window_Class.hCursor = LoadCursor(NULL, IDC_ARROW);
Debug_Window_Class.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
Debug_Window_Class.lpszMenuName = MAKEINTRESOURCE(IDC_GUI_AUTOMATION_WIN32);
Debug_Window_Class.lpszClassName = CLASS_NAME_DEBUG;
Debug_Window_Class.hIconSm = LoadIcon(Debug_Window_Class.hInstance, MAKEINTRESOURCE(IDI_SMALL));

return RegisterClassEx(&Debug_Window_Class);
}

//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
//Underlying Window

int x_Debug_Window = CW_USEDEFAULT;
int y_Debug_Window = CW_USEDEFAULT;
int width_Debug_Window = CW_USEDEFAULT;
int height_Debug_Window = CW_USEDEFAULT;
required_Under_Window = CreateWindowEx(0,CLASS_NAME_DEBUG,L"Debug Window", WS_OVERLAPPEDWINDOW,x_Debug_Window, y_Debug_Window, width_Debug_Window, height_Debug_Window, NULL, NULL, hInstance, NULL);

if (!required_Under_Window)
{
return FALSE;
}
//nCmdShow = SW_MAXIMIZE;//SW_MINIMIZE;
ShowWindow(required_Under_Window, nCmdShow);
UpdateWindow(required_Under_Window);

//Transparent Window
int x_Trasparent_Window = 0;//CW_USEDEFAULT
int y_Trasparent_Window = 0;//CW_USEDEFAULT
int width_Trasparent_Window = GetSystemMetrics(SM_CXSCREEN);//CW_USEDEFAULT
int height_Trasparent_Window = GetSystemMetrics(SM_CYSCREEN);//CW_USEDEFAULT
hwnd_Window_Without_Title_Bar = CreateWindowEx(0,CLASS_NAME_TRANSPARENT,L"Transparent_Window",WS_BORDER| WS_EX_TRANSPARENT ,x_Trasparent_Window,y_Trasparent_Window,width_Trasparent_Window,height_Trasparent_Window,NULL,NULL,hInstance,NULL);

SetWindowLong(hwnd_Window_Without_Title_Bar,GWL_EXSTYLE,GetWindowLong(hwnd_Window_Without_Title_Bar,GWL_EXSTYLE)|WS_EX_LAYERED);

if (!hwnd_Window_Without_Title_Bar)
{
return FALSE;
}
ShowWindow(hwnd_Window_Without_Title_Bar, SW_MAXIMIZE);
UpdateWindow(hwnd_Window_Without_Title_Bar);

return TRUE;
}

LRESULT CALLBACK Transparent_Window_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
wchar_t buffer[50] ;
BOOL postResult;
switch (message)
{
case WM_LBUTTONUP:
POINT requiredMousePosition;
BOOL tempResult;
tempResult = GetCursorPos(&requiredMousePosition);
RECT required_Under_Window_Rect;
GetWindowRect(required_Under_Window,&required_Under_Window_Rect);
POINT adjusted_Point;
adjusted_Point.x = requiredMousePosition.x - required_Under_Window_Rect.left;
adjusted_Point.y = requiredMousePosition.y - required_Under_Window_Rect.top;
swprintf(buffer,sizeof(buffer),L"x => %ld,y => %ld",adjusted_Point.x,adjusted_Point.y);
if(MessageBox(NULL,buffer,L"Button Up: Message Sent From Transparent Window",MB_ICONEXCLAMATION|MB_YESNO) == IDYES)
{
postResult = PostMessage(required_Under_Window,message,wParam,MAKELPARAM( adjusted_Point.x,adjusted_Point.y));
}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

LRESULT CALLBACK Debug_Window_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
wchar_t buffer[50] ;

switch (message)
{
case WM_LBUTTONUP:
{
POINT point;
point.x = GET_X_LPARAM(lParam);
point.y = GET_Y_LPARAM(lParam);
swprintf(buffer,sizeof(buffer),L"x => %ld,y => %ld",point.x,point.y);
MessageBox(NULL,buffer,L"Button Up: Message Received In Debug Window",NULL);
break;
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}


Подробнее здесь: https://stackoverflow.com/questions/796 ... ot-working
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»