Article View: comp.os.ms-windows.programmer.misc
Article #16252 Non-MDI Windows w/ Same Msg Loop?
From: Scott Harper
Date: Thu, 15 Oct 1992 19:44
Date: Thu, 15 Oct 1992 19:44
60 lines
2980 bytes
2980 bytes
In my application there is an option to open a second window.
The second window is of the same window class as the main
window, and uses the same window procedure. It also uses
the same accelerator table. The second window is not
a true child window of the main window (the hwndParent parameter
in the CreateWindow call is NULL), but it is owned by the
same application instance. The message loop in my WinMain
dispatches messages for both windows. I can tell which window
to operate on in the window procedure by the hwnd parameter
passed to it. Both windows are style WS_OVERLAPPEDWINDOW.
The client area of each window is completely filled with an
owner drawn listbox. Thus, the WM_SETFOCUS message case performs
a SetFocus to that window's listbox handle. The listbox handle
for each window (among other things) is stored in that window's
extra bytes.
I am able to successfully create the second window, get focus
back and forth, and close it. But I am having the following
problems:
1. After I open the 2nd window (with CreateWindow) and then
close it (with DestroyWindow) once, I cannot open it again.
CreateWindow returns NULL. What are some of the reasons
why CreateWindow will fail? In the WM_DESTROY case for the
2nd window I don't do anything much... I just set the (global)
window handle for the 2nd window to NULL, so next time I
go to open it I know there's not already one there. Does
DestroyWindow do something internally that's fouling me up
(like maybe unregistering the window class)?
2. In the message loop I need to translate the same accelerator
keys, but I want to translate the message to the active
window. I tried using msg.hwnd in the TranslateAccelerators
call, but it doesn't seem to work.
I also tried something like this:
while (GetMessage(&msg, NULL, NULL, NULL))
{
if (!TranslateAccelerator(GetActiveWindow(), hAccTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
This still doesn't seem to work *exactly* right, but might be OK...
I am a little concerned about the efficiency of calling GetActiveWindow
once every time through the loop, however.
Has anyone been able to do this (translate accelerator events to
two different windows from withing the same message loop)?
Any insight or suggestions will be greatly appreciated!
--
Scott Harper Optical Data Systems, Inc.
scott@ods.com 1101 E. Arapaho Road
(214) 234-6400 Richardson, TX 75081
Technical Details
Message-ID:
<1992Oct15.194451.7434@ods.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!ods!scottShow Full Headers
Complete Article Headers
Newsgroups: comp.os.ms-windows.programmer.misc Path: arc1-ca.pugleaf.net!sparky!uunet!ods!scott From: scott@ods.com (Scott Harper) Subject: 2 Non-MDI Windows w/ Same Msg Loop? Message-ID: <1992Oct15.194451.7434@ods.com> Organization: Optical Data Systems, Inc. X-Newsreader: TIN [version 1.1 PL6] Date: Thu, 15 Oct 1992 19:44:51 GMT Lines: 60