How to activate a window in Windows 2003?

  • I have a program which only allow one instance under windows. If a user clicked the program link when the program have already started, the new program instance will activate the old running program. My code:
    @//only allow to run one single instance
    HANDLE hMutex = CreateMutex(NULL, TRUE, TEXT("ChavSoftRecorderServer"));
    if (ERROR_ALREADY_EXISTS == GetLastError()) {
    HWND hWnd = FindWindow(NULL, TEXT("畅远信息录音系统-服务端"));
    ShowWindow(hWnd, SW_SHOWDEFAULT);
    return 0;
    But the result turn out to be t!!

    I have write a sample using MFC and the same mutex code as above. The MFC edition works fine under both win7 and 2003.
    But qt version only works fine under win7.

  • You should review the Win32 SDK for detail about the two functions you called.

  • But I have tested it with another simple application using mfc, it works well.
    [quote author="henryxuv" date="1345431032"]You should review the Win32 SDK for detail about the two functions you called.[/quote]

  • The suggestion still stands, since this question has nothing to do with Qt.

    It is possible that your compiler is mangling the extended characters because UNICODE is not defined so TEXT() treats the string as a plain C string. See winnt.h

  • Moderators

    Can you please show the Qt version of your program to us?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.