Get Symbols On Win32 Button Control - winapi

I'm a noob to C++ / Win32 programming and I'm working on a basic calculator ( using windows calculator as a reference ). I was wondering how I'd be able to get a check mark ( square root ) to appear on one of the buttons, as well as the plus over the minus symbol ( negative to positive number ) as well. Would I have to create images for them or is there a simpler way? Also the arrow would be nice to that way I'm not using "<=" haha. :)

The easy way is to open 'Character Map' on Windows (type that into the Help). (or use windows run utility [Win_Key+R] and type "charmap" and press ok) You can find most characters you may want as 16 bit codes in some font or other. Then you just set the font for the button (SetFont API) and write the character code to it.
You can paint a button any way you like by using its owner-draw style. That means you get to paint the whole thing in WM_DRAWITEM.

// Unicode Build
// -------------
HWND hWndButtonSquareRoot;
[...]
SetWindowText( hWndButtonSquareRoot, L"\u221A" );
HWND hWndButtonPlusMinus;
[...]
SetWindowText( hWndButtonPlusMinus, L"\u00B1" );
If you do no want to switch to an UNICODE build, you have to create a UNICODE button using the UNICODE version of the API.
CreateWindowW( L"Button", L"\u221A", [...]

Related

VB 6 and Right to Left layout windows application

I have an old windows application with it's Ocxs. I want to localize it's OCX to arabic. no problem on changing labels and strings.
but I can't change layout to Right to left.
I find some resources about using Mirroring in windows. but the provided samples don't help me. Link1 & Link2
I'm not a VB fan and don't have enough experience.
Is there any clear and tested approach for VB to mirroring UI?
From Platform SDK 2001
Complex Scripts in Edit Controls
A complex script is a language whose printed form is not laid out in a simple way. For example, a complex script may allow bi-directional rendering, contextual shaping of glyphs, or combining characters. The standard edit controls have been extended to support multilingual text and complex scripts. This includes not only input and display, but also correct cursor movement over character clusters (in Thai and Devanagari script, for example).
A well-written application will receive this support automatically, without modification. Again, you should consider adding support for right-to-left reading order and right alignment. In this case, toggle the extended style flags of the edit control window to control these attributes, as shown in the following example:
// ID_EDITCONTROL is the control ID in the resource file.
HANDLE hWndEdit = GetDlgItem(hDlg, ID_EDITCONTROL);
LONG lAlign = GetWindowLong(hWndEdit, GWL_EXSTYLE) ;
// To toggle alignment
lAlign ^= WS_EX_RIGHT ;
// To toggle reading order
lAlign ^= WS_EX_RTLREADING ;
After setting the lAlign value, enable the new display by setting the extended style of the edit control window as follows:
// This assumes your edit control is in a dialog box. If not,
// get the edit control handle from another source.
SetWindowLong(hWndEdit, GWL_EXSTYLE, lAlign);
InvalidateRect(hWndEdit, NULL, FALSE);
Windows 2000/XP: The standard edit control supports a context menu that allows the user to toggle the reading order and insert/display Unicode bi-directional control characters.

What does ( WM_NCLBUTTONDOWN ) do?

i was studying the example of how to make round-shape form in Visual Basic 6, and i stopped at the code :
Public Const WM_NCLBUTTONDOWN = &HA1
I only know that this is a message to the windows passed as Const ...
What i want to know is :
what is &HA1 ?
what does Const WM_NCLBUTTONDOWN do ? what message does it send to Windows ?
anything else about it .
Please, thanks
You are working with messages that Windows sends to a window to tell your code that something interesting happened. You'll find this constant used in the WndProc() method of a form, the method that runs when Windows sends a message.
The WM_NCLBUTTONDOWN message is one of those messages. WM = Window Message. NC = Non Client, the part of the window that's not the client area, the borders and the title bar. L = Left button, you can figure out BUTTONDOWN.
These messages are declared in a Windows SDK file. You'll have it on your machine, the VS2008 version of that file is located in C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\WinUser.h. Open it with a text editor or VS to see what's inside. Search for the message identifier to find this line:
#define WM_NCLBUTTONDOWN 0x00A1
The Windows SDK was written to work with C programs. #define is equivalent to Const in VB.NET. The 0x prefix means 'hexadecimal' in the C language, just like &H does in VB.NET. The Windows calculator is helpful to convert hexadecimal values to decimal and back, use View + Programmer. You'll see the reason that &H is used in a VB.NET program, these constants started out in hexadecimal in the core declaration. But Private Const WM_NCLBUTTONDOWN = 161 will work just as well (10 x 16 + 1).
So within WndProc() you'd use a Select Case or If statement to detect the message. And you can do something special when the user clicks the left mouse button on the window title bar. If you ignore it then MyBase.WndProc(m) runs and the normal thing happens: Windows starts a modal loop that lets the user move the window. It is actually very rare that you want to stop or alter that behavior, users are pretty fond of that default behavior since all windows in Windows behave that way. The only message whose behavior you'd typically want to customize is WM_NCHITTEST. Very useful to give a borderless window border-like behavior. But that's another story.
That's a hexadecimal integer literal
It declares a constant; it doesn't actually do anything.
The WM_NCLBUTTONDOWN message is posted when the user presses the left mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor
&HA1 means the hexadecimal number A1, i.e., 161 (though you'll usually see Windows message constants represented in hex). More commonly you'll see this as 0xA1 (or 0x00A1) since that's how the hex number would be represented in C or C++ (the Windows API was originally written for C).
You won't be sending WM_NCLBUTTONDOWN to Windows; it's the other way around. Windows will be sending you WM_NCLBUTTONDOWN.
If you want to know what WM_NCLBUTTONDOWN is for, the documentation is just a Web-search away.

Programmatically find blink cursor position in windows c++?

How to find out blink cursor position in windows, from c++? In many cases I need send button click on the position of the blinking cursor, but I didn't find any important function which will take care of that.
OS win 7(64), c++
It is called "caret", cursor is the mouse pointer. You use GetCaretPos() to get its position. But the returned position is relative to the client area of the window that owns the caret. Which probably means that you need to find that window first, use GetForegroundWindow() for that. And don't send button click messages, they are posted so use PostMessage().
Avoid all of this by just using SendInput().
Note that UIPI (the user interface component of UAC) prevents you from poking stuff into a window owned by an elevated process.
GetGUIThreadInfo() is probably your best bet; pass it with idThread = 0 to get the info from the currently active thread, and then check the rcCaret member of the returned GUITHREADINFO structure. You'll then need to use ClientToScreen() with the hwndCaret value to convert client-relative coordinates to screen coordinates.
Note that this only works for apps that use the Win32 caret functions - specifically SetCaretPos(). If an app draws its own caret without using these, you may not get anything meaningful back. (Some apps, like Word, draw their own caret, but still call SetCaretPos so that accessibility aids that need to track the caret can use this technique.)
The rectangle you get back can sometimes be wider than the actual caret. When a bitmap is used for the caret, as is the case for Right-To-Left or Left-To-Right carets that have a little 'flag' attached to the top, you'll get back a rectangle that's a bit wider than the actual caret area, and may need to adjust or otherwise figure out where within this area the actual caret bar is - it may or may not be in the exact middle. Looks like for Notepad++ you should be fine, though.

how to find type of GDI

i am beginner in win 32 api . i try use win 32 api for create an onscreen keyboard . I can give handle of window and components by click but how to realize type of these and i want set text only on text box and editable components
i try to use GetWindowInfo() and try use atomWindowType of window for realize type of that but this is not use full for this goal because this change on each restart of OS.
(click is handle of window)
WINDOWINFO pwi = new WINDOWINFO(); USER32INST.GetWindowInfo(click, pwi); if (pwi.atomWindowType != -15891) { setLastclick(click); } tnx
You are not going to be able to achieve what you desire, in full generality it is not realistically possible.
A window's type (or class) is essentially determined by its WndProc. You can use GetClassName and its ilk to help you identify some standard window classes, but as you have already discovered, most real-world apps will not use these standard classes.
So, although in theory, you could analyse the code behind the WndProc at runtime, in practice this is not remotely feasible.

API Call for arranging icons on desktop

Are there any calls for arranging icon by name, size, etc or 'Align to grid'?
I have never tried this, but if I had to I would first try sending LVM_ARRANGE message to the desktop window. And LVM_SORTITEMS/LVM_SORTITEMSEX might help with the sorting.
For the auto arrange you could try modify the style and using LVS_AUTOARRANGE style or the extended styles .
So you will need to use something like FindWindow to get the desktop windows and then use SetWindowLong with GWL_STYLE/GWL_EXSTYLE to modify the window style bits.

Resources