GVKun编程网logo

DLL中的CreateWindowEx()创build一个奇数标题的窗口(创建dll)

16

本文的目的是介绍DLL中的CreateWindowEx的详细情况,特别关注创build一个奇数标题的窗口的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解DLL中的Cr

本文的目的是介绍DLL中的CreateWindowEx的详细情况,特别关注创build一个奇数标题的窗口的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解DLL中的CreateWindowEx的机会,同时也不会遗漏关于c – 使用CreateWindowEx()创建的窗口中的默认按钮、FindWindow怎么find一个EnumChildWindows没有的窗口?、Python – 如何阅读Windows“媒体创build”date(不是文件创builddate)、Visual studio项目模板在c ++中创build一个Windows服务的知识。

本文目录一览:

DLL中的CreateWindowEx()创build一个奇数标题的窗口(创建dll)

DLL中的CreateWindowEx()创build一个奇数标题的窗口(创建dll)

感谢您花费了大量的时间来回答这个问题。

我试图创build一个DLL,从DLL内打开一个窗口。 我用C#运行创build的DLL。 该DLL是在VSC中创build的,而C#代码是使用VSC#编译的。

该窗口是通过调用C#中的Initalize(const char* title)或Initalize(string title)来实现的。 不pipe我怎么做,创build的窗口是创build的,运行的,但它的标题不是传递的string。 我尝试使用const wchar_t* , LPCSTR , LPCWSTR , System.String , [MarshalAs(UnmanagedType.LPStr)] , [MarshalAs(UnmanagedType.LPWStr)] 。 我试着复制传递的string到一个dynamic分配的数组,分配新/删除和malloc /免费。

我认为这是一个指针错误,但得到我最多的是在我的C ++代码printf("passed string: %s",title)打印正确的标题到控制台,但我的窗口如下所示:

Apache模块命令parsing器原型

在Unix中创build“系统调用”

OpenFileById失败,ERROR_ACCESS_DENIED

如何计算给定date的星期数?

在Linux中将filter连接到原始套接字 – C

我的C ++代码是:

// GameInterface.cpp : Defines the exported functions for the DLL application. // #include "GameInterface.h" #include <Windows.h> // OpenGL was origionally implimented into here,and removed to be asked on StackOverflow. LRESULT WINAPI DLLWindowProc(HWND hwnd,UINT msg,WParaM wParam,LParaM lParam); HINSTANCE hInstance = NULL; ATOM wclAtom = NULL; HWND hWnd = NULL; HDC hDC = NULL; HglrC hRC = NULL; bool running = false; #if _DEBUG #include <stdio.h> #endif BOOL APIENTRY DllMain( HMODULE hModule,DWORD ul_reason_for_call,LPVOID lpReserved ) { #if _DEBUG printf("GameInterface.dll::DllMain()n"); #endif switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: hInstance = hModule; break; case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: Shutdown(); break; } return TRUE; } GAMEINTERFACE_API int Initalize(const char* title) { if (hWnd != NULL) return 0; #if _DEBUG printf("GameInterface.dll::Initalize("%s")n",title); #endif int length = strlen(title); char* name = new char[length+1]; strcpy(name,title); WNDCLASSEXA wcl; wcl.cbSize = sizeof(WNDCLASSEXA); wcl.style = CS_OWNDC; wcl.lpfnWndProc = DLLWindowProc; wcl.cbClsExtra = 0; wcl.cbWndExtra = 0; wcl.hInstance = hInstance; wcl.hIcon = LoadIcon(NULL,IDI_APPLICATION); wcl.hCursor = LoadCursor(NULL,IDC_ARROW); wcl.hbrBackground = (HBrush)COLOR_APPWORKSPACE; wcl.lpszMenuName = NULL; wcl.lpszClassName = name; wcl.hIconSm = LoadIcon(NULL,IDI_APPLICATION); wclAtom = RegisterClassExA(&wcl); #if _DEBUG printf(" Registering Classn"); #endif if (!wclAtom) { #if _DEBUG printf(" Error: Could not Register Class.nExiting with error: %in",GetLastError() ); #endif return 1; } #if _DEBUG printf(" Creating Windown"); #endif hWnd = CreateWindowExA(0,(LPCSTR)wclAtom,(LPCSTR)name,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,512,NULL,hInstance,NULL); if (hWnd == NULL) { #if _DEBUG printf(" Error: Window Could not be created.nExiting with error: %in",GetLastError() ); #endif return 2; } #if _DEBUG printf(" displaying Windown"); #endif // to reduce size removed the code to initalize an OpenGL 3.1 context ShowWindow(hWnd,SW_SHOW); UpdateWindow(hWnd); running = true; delete [] name; #if _DEBUG printf("Returning from GameInterface.dll::Initalize(const char*) with errors: %in",GetLastError() ); #endif return 0; } GAMEINTERFACE_API void Shutdown() { if (running = false) return; #if _DEBUG printf("GameInterface.dll::Shutdown()n"); #endif running = false; wglMakeCurrent(NULL,NULL); if (hRC != NULL) wglDeleteContext(hRC); if (hDC != NULL) ReleaseDC(hWnd,hDC); hRC = NULL; hDC = NULL; DestroyWindow(hWnd); UnregisterClassA( (LPCSTR)wclAtom,hInstance); wclAtom = NULL; hWnd = NULL; running = false; } GAMEINTERFACE_API int Update() { if ( (running == false) && (hWnd == NULL) ) return 1; MSG msg; if ( PeekMessage(&msg,PM_REMOVE) ) { TranslateMessage(&msg); dispatchMessage(&msg); } if (running == false) return 1; return 0; } GAMEINTERFACE_API void DrawFrame() { // Contained some OpenGL code that has Now been removed. } LRESULT WINAPI DLLWindowProc(HWND hwnd,LParaM lParam) { switch (msg) { case WM_DESTROY: PostQuitMessage(0); running = false; break; // handle other messages. default: // anything we dont handle. return DefWindowProc(hwnd,msg,wParam,lParam); } return 0; // just in case } // GameInterface.h : Outlines the exported functions for the DLL application. // #pragma once #ifdef GAMEINTERFACE_EXPORTS #define GAMEINTERFACE_API __declspec(dllexport) #else #define GAMEINTERFACE_API __declspec(dllimport) #endif extern "C" { GAMEINTERFACE_API int Initalize(const char* title); GAMEINTERFACE_API void Shutdown(); GAMEINTERFACE_API int Update(); GAMEINTERFACE_API void DrawFrame(); };

和C#代码:

// GameInterface.cs // using System; using System.Runtime.InteropServices; class GameInterface { const string GameInterfaceFile = "GameInterface_d.dll"; [DllImport(GameInterfaceFile)] public extern static int Initalize(string title); [DllImport(GameInterfaceFile)] public extern static void Shutdown(); [DllImport(GameInterfaceFile)] public extern static int Update(); [DllImport(GameInterfaceFile)] public extern static void DrawFrame(); }; // Program.cs // using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { public static void Main() { string title = "OpenGL Window Title"; if (GameInterface.Initalize(title) != 0) return; while ( GameInterface.Update() == 0 ) { // game logic. GameInterface.DrawFrame(); } GameInterface.Shutdown(); } }

我很难过,现在已经有一段时间了。

标识符未加载到c

全球包括在VS2013上的Windows上的path

调用Windows计算器c#

将程序链接到Eclipse中的C ++项目? Linux的

尝试在共享内存中写入时发生总线错误

你在你的C ++版本中定义了UNICODE和_UNICODE吗? 你需要做的就是让C#像这样谈话。

在您的C ++项目的Visual Studio属性中,在常规下,将字符集设置使用Unicode字符集 。 仔细检查/D "UNICODE"和/D "_UNICODE"出现在C / C ++ /命令行页面上。

(相反的方法是将您的出口声明为ANSI,但这是一个较差的解决方案,您应该支持Unicode。)

这可能是因为代码需要ANSI。

如果你这样做会发生什么:

[DllImport(GameInterfaceFile,CharSet=CharSet.Ansi)] public extern static int Initalize(string title)

c – 使用CreateWindowEx()创建的窗口中的默认按钮

c – 使用CreateWindowEx()创建的窗口中的默认按钮

我使用CreateWindowEx创建了一个窗口,它使用以下代码作为向导对话框;

DWORD dwStyle = WS_DLGFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_OVERLAPPEDWINDOW;
m_hWnd = CreateWindowEx(WS_EX_APPWINDOW,_T("WIZARD"),_T("SETUP"),dwStyle,CW_USEDEFAULT,WIZARD_WIDTH,WIZARD_HEIGHT,NULL,g_hInstance,this);

在WM_CREATE处理程序中,我创建了底部的’Next’,’Back’和’Cancel’按钮,在Next’按钮上我设置了样式BS_DEFPUSHBUTTON,我将DM_SETDEFID发送到具有下一个按钮ID的窗口.该按钮显示为下一个按钮,但在任何输入字段上返回返回都不执行任何操作(无设置ES_WANTRETURN).

我究竟做错了什么?如果我错过任何重要信息,我可以发布更多代码.

谢谢,
Ĵ

解决方法

DM_SETDEFID消息通常由DefDlgProc处理.如果您正在调用DefWindowProc,那么您需要自己处理该消息,以便当IsDialogMessage向您的窗口发送DM_GETDEFID消息时,您将知道如何响应.

FindWindow怎么find一个EnumChildWindows没有的窗口?

FindWindow怎么find一个EnumChildWindows没有的窗口?

我正在寻找一个窗口,其类名是“CLIPBRDWNDCLASS”(它可以在办公室应用程序和其他应用程序中find)。

如果我使用FindWindow或findwindowex,我find了第一个有这个类的HWND,但是我想要所有带有这个类的窗口,所以我决定使用recursionEnumChildWindows枚举所有窗口并find我想要的窗口:

//------------------------------------------------------------------------------- BOOL CALLBACK enum_wnd_proc(HWND h,LParaM lp) { char cls[1024] = {0}; ::GetClassNameA(h,cls,1024); if(std::string(cls) == "CLIPBRDWNDCLASS") { // match! } ::EnumChildWindows(h,enum_wnd_proc,NULL); return TRUE; } //------------------------------------------------------------------------------- int _tmain(int argc,_TCHAR* argv[]) { ::EnumWindows(enum_wnd_proc,NULL); return 0; } //-------------------------------------------------------------------------------

这就是这个窗口不能被EnumWindows返回,只能通过FindWindow返回。

有没有人可以告诉它为什么不起作用?

如何使用Python 2.7创build一个希伯来文名称的文件?

是否有任何可视化工具来实现作为输出结果的SQL查询数据的分层样式?

如何loggingWindows窗体应用程序中的键,而不是集中在窗体上?

Windows:如何在新的命令窗口中运行某些东西,使窗口在进程完成或崩溃时closures?

Python Socket绑定在0.0.0.0上,不能通过127.0.0.1连接

ContactManager.RequestStoreAsync()抛出System.UnauthorizedAccessException

C ++崩溃转储,在Win32exception(使用catch(…)时)的堆栈展开 – VS 2003

分期环境与现场环境相等多less?

在Windows上使用Ruby读取PNG文件失败

Windows控制台中的C ++键input

EnumWindows不起作用的原因是您正在寻找的窗口是一个消息窗口 。

findwindowex可以在两种情况下找到它们:

如果hwndParent和hwndChildAfter都是NULL。

如果您指定“HWND_MESSAGE”作为您的父窗口。

此代码将为您找到所有相关的窗口( 这里是一个解决方案的修改版本):

HWND hWindow = findwindowexA(HWND_MESSAGE,NULL,"CLIPBRDWNDCLASS",NULL); while (hWindow ) { // Do something here with window... // Find next window hWindow = findwindowexA(HWND_MESSAGE,hWindow,NULL); }

还要注意的是,不同于上面的链接中写的,只有消息窗口的GetParent() 返回HWND_MESSAGE (至少不是我的测试)。

我简单的方法来枚举所有消息窗口:

EnumChildWindows(GetAncestor(findwindowex(HWND_MESSAGE,0,0),GA_PARENT),addr EnumChildProc,0)

// GetAncestor(findwindowex(HWND_MESSAGE,0,0),GA_PARENT)=“GetMessageWindow”(“Message”类)

// GetAncestor(findwindowex(HWND_DESKTOP,0,0),GA_PARENT)= GetDesktopWindow(class“#32769”)

Python – 如何阅读Windows“媒体创build”date(不是文件创builddate)

Python – 如何阅读Windows“媒体创build”date(不是文件创builddate)

我有几个旧的video文件,我正在转换,以节省空间。 由于这些文件是个人video,我希望新文件具有旧文件的创build时间。

Windows有一个名为“媒体创build”的属性,它具有相机logging的实际时间。 这些文件的修改时间通常是不正确的,所以有数百个文件无法工作。

我如何在Python中访问这个“媒体创build”date? 我一直在疯狂search,找不到它。 下面是创builddate和修改date匹配的代码示例:

files = [] for file in glob.glob("*.AVI"): files.append(file) for orig in files: origmtime = os.path.getmtime(orig) origatime = os.path.getatime(orig) mark = (origatime,origmtime) for target in glob.glob("*.mp4"): firstroot = target.split(".mp4")[0] if firstroot in orig: os.utime(target,mark)

鼠标双击不工作相当好

如何以编程方式在C#/ WPF中访问Windows Media Player库?

Windows Media编码器安装问题

在8秒内检测16 GB笔式驱动器上的内容更改

如何在C#中与Windows Media Player交互

将媒体别名设置为其他服务器

AVI文件使用WMP本地播放,但不能closures我的网站WMP ActiveX

如何通过Nginx提供django媒体文件?

在WPF中embeddedWindows Media Player

C#:WMP,时间戳,以毫秒/十分之一秒为单位

正如Borealid指出的,“媒体创造”的价值不是文件系统元数据。 Windows shell从文件本身获取这个值作为元数据。 它可以在Windows中作为Windows属性访问 。 如果您使用Windows Vista或更高版本,并且安装了Windows的Python扩展,则可以轻松访问Windows外壳属性。 只需调用SHGetPropertyStoreFromParsingName ,你可以在propsys模块中找到它。 它返回一个PyIPropertyStore实例。 标记为“媒体创建”的属性是System.Media.DateEncoded 。 您可以使用属性键PKEY_Media_DateEncoded访问此属性,您可以在propsys.pscon找到该键。 在Python 3中,返回的值是一个datetime.datetime子类,UTC时间。 在Python 2中,值是具有提供strftime样式格式的Format方法的自定义时间类型。 如果您需要将该值转换为本地时间,则pytz模块具有IANA时区数据库。

例如:

import pytz import datetime from win32com.propsys import propsys,pscon properties = propsys.SHGetPropertyStoreFromParsingName(filepath) dt = properties.GetValue(pscon.PKEY_Media_DateEncoded).GetValue() if not isinstance(dt,datetime.datetime): # In Python 2,PyWin32 returns a custom time type instead of # using a datetime subclass. It has a Format method for strftime # style formatting,but let's just convert it to datetime: dt = datetime.datetime.fromtimestamp(int(dt)) dt = dt.replace(tzinfo=pytz.timezone('UTC')) dt_tokyo = dt.astimezone(pytz.timezone('Asia/Tokyo'))

如果您所说的属性来自相机,则不是文件系统权限:它是视频中的元数据,Windows正在读取并呈现给您。

这种类型的元数据的一个例子是JPEG图像的EXIF数据:什么类型的相机拍摄了照片,使用了什么设置等等。

您将需要打开.mp4文件并解析元数据,最好使用一些现有的库来做到这一点。 你不能从文件系统获取信息,因为它不在那里。

另一方面,如果你想要的只是文件创建日期(实际上并不是来自相机,而是在文件首次被放到当前计算机上时被设置,并且可能已被初始化为某个值以前在相机上)…可以用os.path.getctime(orig) 。

Visual studio项目模板在c ++中创build一个Windows服务

Visual studio项目模板在c ++中创build一个Windows服务

Microsoft Visual Studio 2010中是否有可用于在c ++中创buildWindows服务的项目模板?

Windows照片查看器如何从Windows资源pipe理器中获取幻灯片的文件?

我在哪里可以findsql Server版本的友好的string?

在Windows中使用资源

对名为guid的目录进行sorting

我可以通过任务pipe理器来处理我的Windows进程吗?

在VS 2013中,您可以使用ATL Project向导来创建一个Windows服务程序。 你还可以设置你的服务类继承一个ServiceBase类。 从MSDN:如何:以编程方式编写服务

不幸的是,从Visual Studio 2010中删除了C ++ / CLI Windows服务模板。如果您想要利用Windows服务的.Net Framework支持,向导的C#版本仍然存在。 如果您想开发Native Windows服务,可以使用ATL Project向导并选择“Service(EXE)”应用程序类型。

总结

以上是小编为你收集整理的Visual studio项目模板在c ++中创build一个Windows服务全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

今天关于DLL中的CreateWindowEx创build一个奇数标题的窗口的讲解已经结束,谢谢您的阅读,如果想了解更多关于c – 使用CreateWindowEx()创建的窗口中的默认按钮、FindWindow怎么find一个EnumChildWindows没有的窗口?、Python – 如何阅读Windows“媒体创build”date(不是文件创builddate)、Visual studio项目模板在c ++中创build一个Windows服务的相关知识,请在本站搜索。

本文标签: