Pelles C forum

C language => Windows questions => Topic started by: czerny on April 29, 2013, 03:17:47 PM

Title: TTN_GETDISPINFO not send
Post by: czerny on April 29, 2013, 03:17:47 PM
Hallo,

this is a problem I am searching the error for hours now. It would be nice, if anyone could help!

I have a simple toolbar, composed of the standard bitmap (IDB_STD_LARGE_COLOR) with 15 Buttons and an own bitmap with 5 Buttons (120x24). I use 5 Buttons from the former bitmap, 3 separators and my 5 Buttons.

The toolbar is working ok. There is only one error: the tooltip from the very first button is not working. There is no TTN_GETDISPINFO notification send for this Button. All other Buttons have their tooltips.

A strange observation: If I use one more button as defined (and with luck the program is not crashing) all works ok????
Maybe this could be a hint .

Code: [Select]
#include "windows.h"
#include "res.h"

#define NUMBUTTONS 13

HWND CreateMyToolbar(HWND hparent)
{
int i;

TBBUTTON tbb[NUMBUTTONS] = {0};
        TBADDBITMAP tbab;

HWND hTool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS, 0, 0, 0, 0,
        hparent, (HMENU)IDC_MAIN_TOOL, GetModuleHandle(NULL), NULL);

  SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);

tbab.hInst = HINST_COMMCTRL;
    tbab.nID = IDB_STD_LARGE_COLOR;
    SendMessage(hTool, TB_ADDBITMAP, 0, (LPARAM)&tbab);

tbab.hInst = NULL;
    tbab.nID = (UINT_PTR)LoadImage(GetModuleHandle(NULL),
                                MAKEINTRESOURCE(ID_BMPOWN),
                                IMAGE_BITMAP, 0, 0,
                                LR_DEFAULTSIZE | LR_DEFAULTCOLOR | LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT);
    int own = SendMessage(hTool, TB_ADDBITMAP, 5, (LPARAM)&tbab);

  i=0;
tbb[i].iBitmap = STD_FILENEW; // 0
    tbb[i].fsState = TBSTATE_ENABLED;
    tbb[i].fsStyle = TBSTYLE_BUTTON;
    tbb[i].idCommand = IDM_FILE_NEW;

i++;
    tbb[i].iBitmap = STD_FILEOPEN; // 1
    tbb[i].fsState = TBSTATE_ENABLED;
    tbb[i].fsStyle = TBSTYLE_BUTTON;
    tbb[i].idCommand = IDM_FILE_OPEN;

i++;
    tbb[i].iBitmap = STD_FILESAVE; // 2
    tbb[i].fsState = 0; //TBSTATE_ENABLED;
    tbb[i].fsStyle = TBSTYLE_BUTTON;
    tbb[i].idCommand = IDM_FILE_SAVE;
   
i++;
tbb[i].fsState = TBSTATE_ENABLED; // 3
    tbb[i].fsStyle = TBSTYLE_SEP;

i++;
    tbb[i].iBitmap = own; // 4
    tbb[i].fsState = 0; //TBSTATE_ENABLED;
    tbb[i].fsStyle = TBSTYLE_BUTTON;
    tbb[i].idCommand = IDM_METHODE_RUN;

i++;
    tbb[i].iBitmap = own + 1; // 5
    tbb[i].fsState = 0; //TBSTATE_ENABLED;
    tbb[i].fsStyle = TBSTYLE_BUTTON;
    tbb[i].idCommand = IDM_METHODE_STOP;

i++;
tbb[i].fsState = TBSTATE_ENABLED; // 6
    tbb[i].fsStyle = TBSTYLE_SEP;

i++;
    tbb[i].iBitmap = own + 2; // 7
    tbb[i].fsState = TBSTATE_ENABLED;
    tbb[i].fsStyle = TBSTYLE_BUTTON;
    tbb[i].idCommand = IDM_DATEN_FILTER;

i++;
    tbb[i].iBitmap = own + 3; // 8
    tbb[i].fsState = TBSTATE_ENABLED;
    tbb[i].fsStyle = TBSTYLE_BUTTON;
    tbb[i].idCommand = IDM_DATEN_FILTERRAD;

i++;
    tbb[i].iBitmap = own + 4; // 9
    tbb[i].fsState = TBSTATE_ENABLED;
    tbb[i].fsStyle = TBSTYLE_BUTTON;
    tbb[i].idCommand = IDM_DATEN_FILTERSEQ;

i++;
tbb[i].fsState = TBSTATE_ENABLED; // 10
    tbb[i].fsStyle = TBSTYLE_SEP;

i++;
    tbb[i].iBitmap = STD_PROPERTIES; // 11
    tbb[i].fsState = TBSTATE_ENABLED;
    tbb[i].fsStyle = TBSTYLE_BUTTON;
    tbb[i].idCommand = IDM_FILE_NEW;

i++;
    tbb[i].iBitmap = STD_HELP; // 12
    tbb[i].fsState = TBSTATE_ENABLED;
    tbb[i].fsStyle = TBSTYLE_BUTTON;
    tbb[i].idCommand = IDM_HELP_LUMINA;
/*
i++;
    tbb[i].iBitmap = STD_HELP; // 13 (an illegal 14. button)
    tbb[i].fsState = TBSTATE_ENABLED;
    tbb[i].fsStyle = TBSTYLE_BUTTON;
    tbb[i].idCommand = IDM_HELP_LUMINA;
*/
    SendMessage(hTool, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);
   
return hTool;
}

I must have done a silly mistake.

czerny
Title: Re: TTN_GETDISPINFO not send
Post by: jj2007 on April 29, 2013, 04:18:26 PM
Use TTN_GETDISPINFOW.
Title: Re: TTN_GETDISPINFO not send
Post by: TimoVJL on April 29, 2013, 06:15:58 PM
Dublicated id IDM_FILE_NEW ?
Title: Re: TTN_GETDISPINFO not send
Post by: jj2007 on April 29, 2013, 08:32:24 PM
It has nothing to do with your IDs. Tooltips don't send the ANSI notification, that's all.
Try something along these lines... and yes, I know it's assembler and this is a C forum.

  .if uMsg==WM_NOTIFY
      .if [ecx.NMHDR.code]==TTN_GETDISPINFOW
            lea edi, lvh
            invoke GetCursorPos, edi
            invoke ScreenToClient, hList, edi
            movi [edi.LV_HITTESTINFO.flags], LVHT_ONITEM
            invoke SendMessage, hList, LVM_HITTEST, 0, edi
Title: Re: TTN_GETDISPINFO not send
Post by: czerny on April 29, 2013, 09:00:40 PM
Dublicated id IDM_FILE_NEW ?
Timovjl, you are my hero!!!

The most stupid errors take the most time. :'(

Thank you jj2007, for your time.
Title: Re: TTN_GETDISPINFO not send
Post by: jj2007 on April 30, 2013, 01:20:23 PM
Thank you jj2007, for your time.

Some time ago I wasted a lot of time chasing a problem with TTN_GETDISPINFO, and it turned out the control sent the Unicode version, but here I was obviously on the wrong track.
Title: Re: TTN_GETDISPINFO not send
Post by: czerny on April 30, 2013, 02:40:06 PM
Some time ago I wasted a lot of time chasing a problem with TTN_GETDISPINFO, and it turned out the control sent the Unicode version, but here I was obviously on the wrong track.
My tooltips are string resources. I have tried to save the resource file as unicode file. There are non-ascii chars in the strings. But all is working with TTN_GETDISPINFO, ansi or unicode. Have you provided the strings directly?
What are your experiences? Are there at all drawbacks to save the rc file in unicode?
Title: Re: TTN_GETDISPINFO not send
Post by: jj2007 on April 30, 2013, 04:27:06 PM
Have you provided the strings directly?
What are your experiences? Are there at all drawbacks to save the rc file in unicode?

No drawbacks met so far. Attached is a sample app, the exe shows tooltips in several languages. Open the *.asc in Wordpad and scroll to the end to see how the rc file is structured. Search for SetLanguage and/or ToolTips to see relevant code.
Title: Re: TTN_GETDISPINFO not send
Post by: TimoVJL on April 30, 2013, 06:56:57 PM
Another example to use multilanguage menu/tooltips from resource with this function:
Code: [Select]
void SetLang(HWND hwnd, LANGID lid)
{
typedef LANGID (WINAPI *fnSetThreadUILanguage) (LANGID wReserved);
HMENU hMenu;
if ((GetVersion() & 0x00FF) > 5) // Vista =>
{
fnSetThreadUILanguage fnPtr = (fnSetThreadUILanguage)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "SetThreadUILanguage");
if (fnPtr)
(*fnPtr) (lid);
} else
SetThreadLocale(MAKELCID(lid, SORT_DEFAULT));
hMenu = GetMenu(hwnd);
SetMenu(hwnd, NULL);
DestroyMenu(hMenu);
hMenu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(2001));
SetMenu(hwnd, hMenu);
}
EDIT: Fix for WinXP and Win8 ???
Title: Re: TTN_GETDISPINFO not send
Post by: czerny on April 30, 2013, 08:18:24 PM
No drawbacks met so far. Attached is a sample app, the exe shows tooltips in several languages. Open the *.asc in Wordpad and scroll to the end to see how the rc file is structured. Search for SetLanguage and/or ToolTips to see relevant code.
The tooltips are working in english, russian and arabic, not in chinese (but thats a missing font). The label and editbox texts are only working in english.
Title: Re: TTN_GETDISPINFO not send
Post by: czerny on April 30, 2013, 08:29:09 PM
Another example to use multilanguage menu/tooltips from resource with this function:
Are there any non ascii characters in suomi?
Title: Re: TTN_GETDISPINFO not send
Post by: jj2007 on April 30, 2013, 10:58:50 PM
Another example...

Seems not to work, I see English only, and "Finnish" gets never checked. Win XP SP3...
Title: Re: TTN_GETDISPINFO not send
Post by: jj2007 on May 01, 2013, 06:01:13 AM
The label and editbox texts are only working in english.
Clicking "Pushme" or "Sayhi" shows something in the editbox. The rest is not implemented.
Title: Re: TTN_GETDISPINFO not send
Post by: czerny on May 01, 2013, 10:13:08 PM
Another example...
Seems not to work, I see English only, and "Finnish" gets never checked. Win XP SP3...
No problem with good old win2k! ;D
Title: Re: TTN_GETDISPINFO not send
Post by: czerny on May 01, 2013, 10:21:18 PM
The label and editbox texts are only working in english.
Clicking "Pushme" or "Sayhi" shows something in the editbox. The rest is not implemented.
Yes, but what it shows are black lines in all languages but english.(http://Image.jpg) See picture for russian.

I have installed simsun.ttf and wordpad shows now the chinese chars while your application shows still strings of undef chars.
Title: Re: TTN_GETDISPINFO not send
Post by: jj2007 on May 01, 2013, 10:34:46 PM
Must be a font problem. Here it works...
Interesting, though, that it works for your tooltips.
Title: Re: TTN_GETDISPINFO not send
Post by: czerny on May 01, 2013, 10:54:58 PM
Must be a font problem.
In wordpad and in word all the strings of your asc file are shown correctly, so it could not be a font problem.
Title: Re: TTN_GETDISPINFO not send
Post by: jj2007 on May 02, 2013, 07:17:33 AM
Slightly mysterious, but Unicode under Windows is very messy.

Can you display Chinese in a self-built Unicode control? E.g. by copying from Wordpad and pasting into the control?

> I have installed simsun.ttf and wordpad shows now the chinese chars while your application shows still strings of undef chars.

My app uses GetStockObject(ANSI_VAR_FONT) for the edit and static controls, and that works fine for Russian, Arabic and Chinese sets on my XP SP3 system with East Asian fonts enabled - you can even display all of them together.

In contrast, the ToolTips macro does not explicitly set a font, so the OS chooses what to use. Why tooltips work with your system but the edit control doesn't isn't clear to me.

I attach a modified version that sets "SimSun" instead of ANSI_VAR_FONT - see line 144. It allows to switch between SimSun and DEFAULT_GUI_FONT. Apparently, there is no UNICODE_VAR_FONT available...

Grateful for feedback from others, too.
Title: Re: TTN_GETDISPINFO not send
Post by: czerny on May 02, 2013, 08:00:13 PM
I attach a modified version that sets "SimSun" instead of ANSI_VAR_FONT - see line 144. It allows to switch between SimSun and DEFAULT_GUI_FONT. Apparently, there is no UNICODE_VAR_FONT available...
It seems to me that the menu and the statusbar text is always DEFAULT_GUI_FONT.
The buttons and the label below the buttons are always SIMSUN.

The 'set font' button is only switching the editbox font.

The text is ok under the buttons and in the edit box with simsun and chinese. The tooltips are undef chars as before.
With simsun the text in other languages than chinese is ugly and for arabic only working for the tooltips.
Title: Re: TTN_GETDISPINFO not send
Post by: czerny on May 02, 2013, 08:07:46 PM
Can you display Chinese in a self-built Unicode control?
No, I get undef chars.
Title: Re: TTN_GETDISPINFO not send
Post by: jj2007 on May 02, 2013, 08:28:15 PM
OK, I don't claim to be an expert for these things, but one likely scenario could be:

- it works on my system because Chinese fonts are enabled "OS-wide" (Khmer, for example, does not work for me - not part of the East Asian package (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/int_pr_install_languages.mspx?mfr=true))
- on your system, the fonts are not OS-wide installed, but after installation of simsun.ttf, controls show this font correctly if the font is explicitly set.

This does not solve the mystery why Russian and Arabic work for your tooltips, though.

Other ideas? It's not C or assembler-specific, I find it generically interesting why Unicode does not work properly a quarter century after its invention...
Title: Re: TTN_GETDISPINFO not send
Post by: TimoVJL on May 02, 2013, 09:17:12 PM
This does not solve the mystery why Russian and Arabic work for your tooltips, though.
use charmap.exe to look at fonts, russian and arabic codepages could be there in systems UNICODE fonts. Arial Unicode MS (arialuni.ttf (http://www.microsoft.com/typography/fonts/font.aspx?fmid=1081)) is interesting too.
Title: Re: TTN_GETDISPINFO not send
Post by: jj2007 on May 03, 2013, 01:52:01 AM
This does not solve the mystery why Russian and Arabic work for your tooltips, though.
use charmap.exe to look at fonts, russian and arabic codepages could be there in systems UNICODE fonts. Arial Unicode MS (arialuni.ttf (http://www.microsoft.com/typography/fonts/font.aspx?fmid=1081)) is interesting too.

Good hint indeed, thanks. I have invested some energy in this last version featuring a font dialog. Though it won't help to solve my mystery - even good ol' FixedSys displays all four languages flawlessly on my system...