|
Posted by Oliver Schad on December 13, 2005, 7:48 am
Please log in for more thread options
Hi,
I've created a dialog based application in C++. If I start another
application my application runs in background. If I start the
application again I want to activate the first instance.
The previous instance is shown and I can edit text boxes. But the menu
bar appears 30 seconds later. What is going wrong? I found similar
questions with google but no answer.
I tried to use the generated code from embedded Visual C++ for Hello World.
The "standard mechanism" uses CreateMutex(NULL, FALSE, pszClass),
FindWindow(pszClass, pszTitle) and SetForegroundWindow((HWND) (((ULONG)
hwnd) | 0x01)) to find a older instance and bring it to the front.
I've added ShowWindow(hwnd, SW_SHOW) after SetForegroundWindow().
Without that, only the title of the application appears, 30 seconds
later the dialog and the menu bar.
Another problem:
I don't use CreateMutex for now because I don't know how this works with
dialogs. I can set the class name of a window with WNDCLASS struct. What
is the class name of my dialog? How can I set/get this?
Any hints?
Best regards
Oli
|
|
Posted by dsr2008 on December 13, 2005, 9:51 am
Please log in for more thread options
I've got the same problem too. The solution I found is that the dialog should
be created with WS_VISIBLE & WS_SYSMENU & WS_CAPTION styles (check the .rc
file). After I do that, the 30 seconds delay problem gone.
"Oliver Schad" wrote:
> Hi,
>
> I've created a dialog based application in C++. If I start another
> application my application runs in background. If I start the
> application again I want to activate the first instance.
>
> The previous instance is shown and I can edit text boxes. But the menu
> bar appears 30 seconds later. What is going wrong? I found similar
> questions with google but no answer.
>
> I tried to use the generated code from embedded Visual C++ for Hello World.
>
> The "standard mechanism" uses CreateMutex(NULL, FALSE, pszClass),
> FindWindow(pszClass, pszTitle) and SetForegroundWindow((HWND) (((ULONG)
> hwnd) | 0x01)) to find a older instance and bring it to the front.
>
> I've added ShowWindow(hwnd, SW_SHOW) after SetForegroundWindow().
> Without that, only the title of the application appears, 30 seconds
> later the dialog and the menu bar.
>
> Another problem:
>
> I don't use CreateMutex for now because I don't know how this works with
> dialogs. I can set the class name of a window with WNDCLASS struct. What
> is the class name of my dialog? How can I set/get this?
>
> Any hints?
>
> Best regards
> Oli
>
|
|
Posted by Oliver Schad on December 13, 2005, 11:10 am
Please log in for more thread options Hi,
dsr2008 wrote:
> I've got the same problem too. The solution I found is that the dialog should
> be created with WS_VISIBLE & WS_SYSMENU & WS_CAPTION styles (check the .rc
> file). After I do that, the 30 seconds delay problem gone.
That's my style:
STYLE WS_POPUP | WS_VISIBLE | WS_VSCROLL | WS_SYSMENU | WS_CAPTION
Same problem. The menu bar appears later. Which other styles do you use?
Regards
Oli
|
|
Posted by dsr2008 on December 13, 2005, 9:57 pm
Please log in for more thread options WS_POPUP ? Anyway, here is my sample code(at least works for me at 2003 SE &
WM5, both emu and device). The point is, when app is running, if user press
Home, app is still running at background. when back key is pressed at home
screen, OS try bring back our app to foreground, a long delay may occur if
style is not right. CE build-in MS apps have no delay, but i am unable check
the resource in MS app binary to verify the style. I got this guess from
browsing wm5 SDK samples. CE SPY may be a helper.
// from resource.rc
IDD_MAIN DIALOG 0, 0, 113, 116
STYLE WS_VISIBLE | WS_CAPTION | WS_SYSMENU
BEGIN
EDITTEXT IDC_INPUT,7,7,85,82,ES_MULTILINE | ES_AUTOVSCROLL |
ES_WANTRETURN | WS_VSCROLL
END
// from winmain.cpp
#include <windows.h>
#include <aygshell.h>
#include <tpcshell.h>
#include "resource.h"
static HINSTANCE g_hInstance = NULL;
const TCHAR APP_TITLE[] = L"Test";
static void InitDialog(HWND hwnd)
{
// Zoom dialog
SHINITDLGINFO shidi;
ZeroMemory(&shidi, sizeof(shidi));
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;
shidi.hDlg = hwnd;
SHInitDialog(&shidi);
// Setup menu bar
SHMENUBARINFO shmbi;
ZeroMemory(&shmbi, sizeof(shmbi));
shmbi.cbSize = sizeof(shmbi);
shmbi.hwndParent = hwnd;
shmbi.nToolBarId = IDR_MENUBAR;
shmbi.hInstRes = g_hInstance;
SHCreateMenuBar(&shmbi);
SendMessage(shmbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK,
MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, SHMBOF_NODEFAULT |
SHMBOF_NOTIFY));
// Setup window title
SetWindowText(hwnd, APP_TITLE);
}
BOOL CALLBACK MainDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
lParam)
{
switch (msg)
{
case WM_INITDIALOG:
InitDialog(hwnd);
return TRUE;
case WM_HOTKEY:
// The following is necessary to get the appropriate Backspace
key behavior
// for our edit control
if (HIWORD(lParam) == VK_TBACK)
SHSendBackToFocusWindow(msg, wParam, lParam);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
EndDialog(hwnd, 0);
return TRUE;
}
break;
}
return FALSE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR, int)
{
// Switch to previous instance if it is found
HWND hwnd = FindWindow(L"Dialog", APP_TITLE);
if (hwnd)
{
SetForegroundWindow(hwnd);
return 0;
}
g_hInstance = hInstance;
DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, MainDialogProc);
return 0;
}
"Oliver Schad" wrote:
> Hi,
>
> dsr2008 wrote:
> > I've got the same problem too. The solution I found is that the dialog
should
> > be created with WS_VISIBLE & WS_SYSMENU & WS_CAPTION styles (check the .rc
> > file). After I do that, the 30 seconds delay problem gone.
>
> That's my style:
> STYLE WS_POPUP | WS_VISIBLE | WS_VSCROLL | WS_SYSMENU | WS_CAPTION
>
> Same problem. The menu bar appears later. Which other styles do you use?
>
> Regards
> Oli
>
|
|
Posted by Oliver Schad on December 14, 2005, 9:28 am
Please log in for more thread options dsr2008 wrote:
> "Oliver Schad" wrote:
>> That's my style:
>> STYLE WS_POPUP | WS_VISIBLE | WS_VSCROLL | WS_SYSMENU | WS_CAPTION
>>
>> Same problem. The menu bar appears later. Which other styles do you
>> use?
> WS_POPUP ? Anyway, here is my sample code(at least works for me at 2003 SE &
That's it. With WS_POPUP you have to wait a long time until the
application window comes up. Without it everything works fine. Thanks a lot.
Regards
Oli
|
| Similar Threads | Posted | | ActivatePreviousInstance can¡¯t Activate Previous dialog Instance successfully | December 5, 2005, 9:18 am |
| Program to activate speaker phone and dial | June 30, 2005, 5:18 pm |
| How to activate media player from a mobile page? | August 25, 2005, 3:03 pm |
| Re: How would you answer a call then activate bluetooth headset | April 10, 2006, 9:53 pm |
| How to get rid of 'The program you have installed may not display properly because it was designed for a previous version of Windows Mobile'? | January 19, 2008, 4:37 pm |
| How to Catch Windows Media Player Buttons (Previous, Play/Pause, Next ) on smartphone 2005 ? | December 9, 2005, 10:21 am |
| Class not registered | May 14, 2008, 5:05 am |
| custom CBitmap class | July 18, 2005, 3:50 am |
| FileSystemWatcher class for NetFramework2 | August 11, 2005, 12:52 am |
| Can’t override BACK key with Class Specified | March 1, 2006, 7:32 pm |
|