I need to convert a QMouseEvent to MOUSEINPUT. MOUSEINPUT has so many flags like MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_LEFTUP but QMouseEvent has very limited number of actions. do there is any existing solution ? If I need to wrte it by myself how can I cover the gaps ?
QT covers all cases of mouse using, but it splitted them to different variables instead of MOUSEINPUT.
for example,
MOUSEEVENTF_LEFTDOWN would be
QMouseEvent with type = QEvent::MouseButtonPress , button = Qt::LeftButton.
and so on.
The only win events not covered by qt are strange events MOUSEEVENTF_XDOWN and MOUSEEVENTF_XUP
Related
I am assigning to the lpszIcon member of the MSGBOXPARAMSW structure(notice the W). I want to use one of the predefined icons like IDI_APPLICATION or IDI_WARNING but they are all ASCII (defined as MAKEINTRESOURCE). I tried doing this:
MSGBOXPARAMSW mbp = { 0 };
mbp.lpszIcon = (LPCWSTR) IDI_ERROR;
but then no icon displayed at all. So how can I use the unicode versions of the IDI_ icons?
There is no ANSI or Unicode variant of a numeric resource ID. The code that you use to set lpszIcon is correct. It is idiomatic to use the MAKEINTRESOURCE macro rather than a cast, but the cast has identical meaning. Your problem lies in the other code, the code that we cannot see.
Reading between the lines, I think that you are targeting ANSI or MBCS. You tried to use MAKEINTRESOURCE but that expands to MAKEINTRESOURCEA. That's what led you to cast. You should have used MAKEINTRESOURCEW to match MSGBOXPARAMSW. That would have resolved the compilation error you encountered. You could equally have changed the project to target UNICODE.
But none of that explains why the icon does not appear in the dialog. There has to be a problem elsewhere. If the dialog appears then the most likely explanation is that you have set hInstance to a value other than NULL. But the code to set lpszIcon is correct, albeit not idiomatic.
This C function can be used to disable or enable windows decorations in many window managers. If 'mode' is 'd' the window will hide the decorations, otherwise if the 'mode' is 'D' the window will show them.
void window_tune_decorations(Display *disp, Window win, char mode) {
long hints[5] = { 2, 0, 0, 0, 0};
Atom motif_hints = XInternAtom(disp, "_MOTIF_WM_HINTS", False);
switch (mode) {
case 'D':
hints[2] = 1;
/* fall through */
case 'd':
XChangeProperty(disp, win, motif_hints, motif_hints, 32, PropModeReplace, (unsigned char *)hints, 5);
break;
default:
fputs("Invalid mode.\n", stderr);
}
}
I would like to implement a ``toggle mode''. So my question is, there a way to detect if a windows has the decorations?
I tried using XGetWindowProperty with _MOTIF_WM_HINTS, but I am not sure how to interpret the output.
You interpret the data you get from XGetWindowProperty the same way you interpret data sent to XChangeProperty.
In the case of _MOTIF_WM_HINTS it's an array of 5 longs, or perhaps the struct MwmHints (syn. MotifWmHints). It's a struct of 5 long fields, plus several #defined bit flags. It is inherited from the Motif window manager, but we don't usually keep Motif includes and libraries around nowadays, so the struct gets copied to various places (bad practice but everyonee is doing it). You may find its definition in xprops.h of Gnome and several other places. Look it up on the 'net and copy to your code, or find it in an include file you already depend on, or just look at the definition and keep using the array of 5 longs, your choice.
You need to check the right flags in the right fields. For decorations, check if the window is override-redirect first. If it is, it is undecorated (obviously) and you cannot add any decorations. If the window manager is not running, it's undecorated as well, and you cannot add any decorations in this case too.
Otherwise, if the window does not have the property at all (XGetWindowProperty sets type to None), you may assume it's decorated.
If it does have the property, and MWM_HINTS_DECORATIONS bit is set in flags, then it has exactly the decorations specified in the decorations field by the MWM_DECOR_* bit values. If the field is non-zero, there are some decorations present. AFAIK if MWM_HINTS_DECORATIONS is unset, then the window is (surprisingly) decorated. But please test this yourself, I don't remember and don't have an X11 machine around at the moment so I can't check it.
Naturally, some window managers don't use _MOTIF_WM_HINTS (e.g. ones that were around before Motif). If you have one of those, you cannot check or set decorations with this method.
Don't forget to XFree(hints).
I have some existing Visual C++ code where I need to add the conversion of wide character strings to upper or lower case.
I know there are pitfalls to this (such as the Turkish "I"), but most of these can be ironed-out if you know the language. Fortunately in this area of code I know the LCID value (locale ID) which I guess is the same as knowing the language.
As LCID is a Windows type, is there a Windows function that will convert wide strings to upper or lower case?
The C runtime function _towupper_l() sounds like it would be ideal but it takes a _locale_t parameter instead of LCID, so I guess it's unsuitable unless there is a completely reliable way of converting an LCID to a _locale_t.
The function you're searching for is called LCMapString and it is part of the Windows NLS APIs. The LCMAP_UPPERCASE flag maps characters to uppercase, while the LCMAP_LOWERCASE maps characters to lowercase.
For applications targeting Windows Vista and later, there is an Ex variant that works on locale names instead of identifiers, which are what Microsoft now says you should prefer to use.
In fact, in the CRT implementation provided with VS 2010 (and presumably other versions as well), functions such as _towupper_l ultimately end up calling LCMapString after they extract the locale ID (LCID) from the specified _locale_t.
If you're like me, and less familiar with the i8n APIs than you should be, you probably already know about the CharUpper, CharLower, CharUpperBuff, and CharLowerBuff family of functions. These have been the old standbys from the early days of Windows for altering the case of chars/strings, but as their documentation warns:
Note that CharXxx always maps uppercase I to lowercase I ("i"), even when the current language is Turkish or Azeri. If you need a function that is linguistically sensitive in this respect, call LCMapString.
What it neglects to mention is filled in by a couple of posts on Michael Kaplan's wonderful blog on internationalization issues: What does "linguistic casing" mean?, How best to alter case. The executive summary is that you achieve the same results as the CharXxx family of functions by calling LCMapString and not specifying the LCMAP_LINGUISTIC_CASING flag, whereas you can be linguistically sensitive by ensuring that you do specify the LCMAP_LINGUISTIC_CASING flag.
Sample code:
std::wstring test("Does my code pass the Turkey test?");
if (!LCMapStringW(lcid, /* your LCID, defined elsewhere */
LCMAP_UPPERCASE | LCMAP_LINGUISTIC_CASING,
test.c_str(), /* input string */
test.length(), /* length of input string */
&test[0], /* output buffer (can reuse input) */
test.length())) /* length of output buffer (same as input) */
{
// Uh-oh! Something went wrong in the call to LCMapString, so you need to
// handle the error somehow here.
// A good start is calling GetLastError to determine the error code.
}
How do I programmatically trigger Flip 3D on Windows Vista and 7?
Is there an API for this and if so, what is it called and where can I find the relevant functions? (I need a specific answer, eg a web link to the actual functions, not something generic like "Oh, it's in DirectX.")
On a related node, I have a Logitech mouse that has a "Document Flip" button that invokes Flip 3D (and then I can press up/down keys to page through the results.) I am curious if they are using an official Windows API or if there is some low level hackery going on.
you need to run a function from dwmapi
Sadly there is no proper funktion name only the ord-number 105
You can try this by executing %WinDir%\System32\rundll32.exe dwmapi #105 from Run-dialog or cmd.
edit
ive found out the Windows' API GetProcAddress Function accepts ord-numbers (the 105) as second parameter as well as proper name
lpProcName [in]
The function or variable name, or the function's ordinal value. If this parameter is an ordinal value, it must be in the low-order word; the high-order word must be zero.
so use this code
typedef vois (__cdecl *FlipProc)();
HINSTANCE hDwmApi = LoadLibrary(TEXT("dwmapi.dll"));
FlipProcAdd = (FlipProc) GetProcAddress(hDwmApi, (LPCSTR)105);
(FlipProcAdd)();
I have several keyboards and they type in different TMemos. In english, everything works fine, but in Korean the keystrokes get sent to the IME before it sends it to my onKeypress (which handles/identifies the different keyboards), so I can't exactly tell which keyboard it came from before that.
I don't exactly know how to use WinApi, but I need to learn to use the part that deals with the IME. There is a lot of information HERE, but I need to know how to apply it in delphi. I need to store each users keystrokes and send them to the IME.
Perhaps someone can help me learn to use IMM.PAS
Got it to work. Using ImmGetContext, ImmSetCompositon, ImmGetComposition and NormalizeString.
procedure TForm1.IMEFUNCTION(var msg: TMsg);
var
buf: array [0..20] of char;
hHimc: HIMC;
i, j: integer;
str: string;
temporary: PWideChar;
begin
hHimc:= ImmGetContext (msg.hwnd);
if hHimc = 0 then
Exit;
fillchar (buf, 20, 0);
ImmSetCompositionStringW (hHimc, SCS_SETSTR, PChar (''), Length(''), nil, 0);
ImmGetCompositionString (hHimc, GCS_COMPSTR, #buf, 20);
temporary:= PWideChar(Edit1.Text+buf[0]);
NormalizeString(5 , temporary, -1, buf, 20);
Edit1.Text:=buf;
end;//end if
end;//end for
ImmReleaseContext (handle, hHimc);
end;
Side note: I didn't really use TEdit, I used a StringGrid and a for-loop. (but the general idea is there)
I doubt that Windows supports what you want to do, and I doubt that you can make Windows work differently. It sounds like you are trying to use two physical keyboards on a single computer.
IMM.PAS is a wrapper for the Windows IME API, and does not appear to have been written to help you do exactly what you want to do.
Why aren't you using two computers, with two keyboards?