创建“附加"窗口.反对“实例"? [英] Creating windows "attached" to object "instances"?

查看:57
本文介绍了创建“附加"窗口.反对“实例"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

再见.

我有一个Com服务器DLL,该窗口仅供我参考
从Windows消息队列中检索消息的过程.窗口是在其他线程中创建的.我从codeguru.com上的帖子中获得了此代码.

这很好用.并提供了我所追求的IPC.是的.

但是,我想要的是将单独的窗口附加到类工厂中创建的对象实例"上(因为缺少更好的词).尽管可以尝试,但我不太了解需要更改的内容.

现在,当我希望有一个新窗口与第一个窗口分开时,更改的每个对象实例都将更改相同的可见窗口的名称,以反映当前对象实例ID.

在我看来,如果可以动态更改窗口结构的名称
请在可能会这样做的每个创作上命名.

这是窗口代码.

WindowName是指向创建的对象实例名称的指针,该对象实例名称是在
上创建的 对象创建时间.一旦一切正常,我会将窗口更改为不可见消息,仅显示窗口
可以通过窗口名称找到谁. (对象实例ID).

提前谢谢.

Hi again.

I have a Com server DLL that I have given a window to that is for the sole purpose
of retrieving messages from the Windows message queue. The window is created in a different thread. I got the code for this from a post over at the codeguru.com

This works nicely. And provides the IPC I was after. Yay.

What I would like however, is individual windows attached (for lack of a better word) to object "instances" that are created in the classfactory. While I could try and try, I don''t quite know what I need to change.

Right now with each instance of the object created the same visible window''s name is changed to reflect the current object instance ID, when I expected a new window separate and apart from the first.

It seems to me that if I could dynamically change the name of the window structure
name upon each creation that might do it, maybe not.

Here is the window code.

WindowName is a pointer to the created object instance name that is created upon
object creation time. Once it is all working I will change the windows to be invisible message only windows
who will be found by the window name. (object instance ID).

Thanks in advance.

//////////////////////////////////////////////////////////////////////////////////

Cbcrshimcontrol::CMyWindow::CMyWindow(char *WindowName,const int width,const int height)
 {
	 Cbcrshimcontrol::CMyWindow::WindowName = WindowName;
		 _beginthread( &CMyWindow::thread_entry, 0, this);
 }

Cbcrshimcontrol::CMyWindow::~CMyWindow(void)
    {
        SendMessage(_hWnd, WM_CLOSE, NULL, NULL);
    }


void Cbcrshimcontrol::CMyWindow::thread_entry(void * p_userdata)
    {
        CMyWindow * p_win = static_cast <CMyWindow*> (p_userdata);
        p_win->create_window();
        p_win->message_loop();
    }
void Cbcrshimcontrol::CMyWindow::create_window()
    {
		
		
		char AppName[10]; // the object instanceID holder
		strcpy(AppName,Cbcrshimcontrol::CMyWindow::WindowName);
        WNDCLASSEX wcex;

        wcex.cbSize             = sizeof(WNDCLASSEX);
        wcex.style              = CS_HREDRAW | CS_VREDRAW;
        wcex.lpfnWndProc    = &CMyWindow::WindowProc;
        wcex.cbClsExtra         = 0;
        wcex.cbWndExtra         = 0;
        wcex.hInstance          = GetModuleHandle(NULL);
        wcex.hIcon              = LoadIcon(NULL, IDI_APPLICATION);
        wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
        wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
        wcex.lpszMenuName   = NULL;
		wcex.lpszClassName  = (LPCTSTR)AppName;  
//		wcex.lpszClassName  = g_AppName;
        wcex.hIconSm            = LoadIcon(NULL, IDI_APPLICATION);

        RegisterClassEx(&wcex);

        _hWnd = CreateWindow((LPCTSTR)AppName, (LPCTSTR)AppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,NULL /*HWND_MESSAGE*/ , NULL, GetModuleHandle(NULL), NULL);

        ShowWindow(_hWnd, SW_SHOWDEFAULT);
        UpdateWindow(_hWnd);
    }

void Cbcrshimcontrol::CMyWindow::message_loop()
    {
        MSG msg = {0};

        while (GetMessage(&msg, NULL, 0, 0))
        {
            if(msg.message == WM_QUIT)
            {
                break;
            }

            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

	void strappnd(char *dest, char *src)
{
	/* appends one string to another */
             while(*dest != ''\0'')
             {
                     *dest++;
             }
	while (*src != ''\0'')
		*dest++ = *src++;

	*dest = ''\0'';
}

 LRESULT WINAPI Cbcrshimcontrol::CMyWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
		if(uMsg == g_uiProcCommMsg)  // Registered Messages not working yet.
		{
			// do something
		}

        switch(uMsg)
        {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;

		      case WM_KEYDOWN:      /// IPC Receive Message Testing
           // AfxMessageBox("WM_KEYDOWN");  /// Works.
			
            return 0;
 
        }

        return DefWindowProc(hWnd, uMsg, wParam, lParam);
  }

推荐答案

每次调用CreateWindow()时,您正在创建一个窗口的独立实例...因此,如果要创建一个单独的实例在一个类中,然后只需在该类的任何非静态成员方法中执行即可.
Every time you call CreateWindow() you''re creating an independent instance of a window... so if you want to create a separate instance within a class, then just do it within any non-static member method of the class.


这篇关于创建“附加"窗口.反对“实例"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆