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];
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.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wcex);
_hWnd = CreateWindow((LPCTSTR)AppName, (LPCTSTR)AppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,NULL , 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)
{
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)
{
}
switch(uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_KEYDOWN:
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}