Radio buttons and checkbox repaint - winapi

I have problem with WinAPI radio buttons. Basically I have three of them and when I switch from one to another the old one is still checked until I hover mouse over it or I click again the button I clicked before. I tried with invalidating both - controls and the whole window - with no luck. I have similar issue with checkboxes in the same dialog - I must hover over them to see their actual state.
EDIT:
This is done when each button is selected (note 1011 ... 1013 are radio buttons IDs):
RECT rect;
BringWindowToTop(GetDlgItem(hwnd, 1011));
GetClientRect(GetDlgItem(hwnd, 1011), &rect);
InvalidateRect(GetDlgItem(hwnd, 1011), &rect, TRUE);
RedrawWindow(GetDlgItem(hwnd, 1011), &rect, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
BringWindowToTop(GetDlgItem(hwnd, 1012));
GetClientRect(GetDlgItem(hwnd, 1012), &rect);
InvalidateRect(GetDlgItem(hwnd, 1012), &rect, TRUE);
RedrawWindow(GetDlgItem(hwnd, 1012), &rect, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
BringWindowToTop(GetDlgItem(hwnd, 1013));
GetClientRect(GetDlgItem(hwnd, 1013), &rect);
InvalidateRect(GetDlgItem(hwnd, 1013), &rect, TRUE);
RedrawWindow(GetDlgItem(hwnd, 1013), &rect, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
I also tried sending WM_PAINT message and call UpdateWindow() on both - whole window and each radio button - no effect.

Related

Is it possible to set DateTimePicker to dropdown the monthCalendar by default?

To avoid a duplicate control to CreateWindowEx(0,MONTHCAL_CLASS,...), it is expected to have DateTimePick_Class control showing DropDown Calendar defaultly.
HWND hwndDP = CreateWindowEx(
0,
DATETIMEPICK_CLASS,
TEXT("DateTime"),
WS_BORDER | WS_CHILD | WS_VISIBLE | DTS_SHOWNONE,
50, 20,200,25,
hWnd,
(HMENU)ID_DATETIME_PICKer,
hInst,
NULL);
But it seems that one has to know the control of dropdown arrow button say "ARROW_BTN", like this
SendMessage(hwndDP,WM_NOTIFY,(int)ARROW_BTN,(NMHDR)DTN_DROPDOWN);
or
SendMessage(hwndDP,DTN_DROPDOWN,0,0);
what is the command to retrieve the control ID or some other tricks behind?

TrackPopupMenuEx not seeing keys inside CWinThread

I'm using TrackPopupMenuEx inside a UI CWinThread,
CMonitor is derived from CWinThread
monitor_ = (CMonitor *)AfxBeginThread(RUNTIME_CLASS(CMonitor));
CMonitor::InitInstance containes
m_pMainWnd = new CWnd();
m_pMainWnd->CreateEx(WS_EX_TOOLWINDOW | WS_EX_CONTROLPARENT | WS_EX_WINDOWEDGE | WS_EX_TOPMOST, AfxRegisterWndClass(CS_DBLCLKS),
NULL, WS_POPUP | WS_CLIPSIBLINGS | WS_VISIBLE, 50, 50, 50, 50, NULL, NULL);
Then later I do
SetForegroundWindow(AfxGetMainWnd()->m_hWnd);
auto popup_menu_flags = TPM_RETURNCMD | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON | TPM_VERTICAL;
auto menu_item = TrackPopupMenuEx(menu, popup_menu_flags, point.x, point.y, AfxGetMainWnd()->m_hWnd, NULL);
DestroyMenu(menu);
The PopupMenu display correctly and I can use the mouse to select a menu item. However the arrow keys do not work.
I have used Spy++ and m_pMainWnd get messages for WM_KEYUP, VK_DOWN but nothing happens. WM_KEYDOWN is not seen.
What am I missing?

How to change height of Owner-draw Listbox items whiling resizing Window?

I have Listbox with LBS_OWNERDRAWVARIABLE style, and trying resize items height with WM_MEASUREITEM on WM_SIZE.
I wrote code next in WM_SIZE procedure, referred http://www.codeproject.com/Articles/1401/Changing-Row-Height-in-an-owner-drawn-Control :
WINDOWPOS wp;
ZeroMemory (&wp, sizeof(WINDOWPOS));
wp.hwnd = hwndListbox;
wp.cx = iWidht;
wp.cy = iHeight;
wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
// WM_WINDOWPOSCHANGED for force generate WM_MEASUREITEM:
SendMessage (hwndListbox, WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp);
however, It dosen't work... (dosen't generate WM_MESUREITEM.)
Question: How to force generate WM_MESUREITEM, or Resizing of items height dynamically?
p.s I using C++ with Win32, not MFC.
Use the LB_SETITEMHEIGHT message to change the height of listbox items.

WINAPI LISTBOX scroll down

I'm creating my own program in WINAPI. I've got one problem.
I created a listbox with WS_VSCROLL style.
Everything is ok, but if I fill the listbox with strings the last strings are "invisible".
I must to scroll down list and then I can see the strings.
How do I automatically scroll down the listbox, using the mouse, to show the last string?
You know, I wrote chatBox. Every chatbox, which I know, has got this function:
hListaChatu = CreateWindowEx( WS_EX_DLGMODALFRAME, "LISTBOX", NULL,
WS_CHILD|WS_VISIBLE|WS_BORDER|WS_VSCROLL, rect_okna_glownego.right - 320,
rect_okna_glownego.top, 300, rect_edit_text.top - 25 , hwnd, NULL,
hInstance, NULL );

how to create password field and button in vc++

I am new in vc++ and i need a Password field in my application. I created edit textbox using below code but don't know how to create password field and button control.
CreateWindow(L"EDIT", L"hello", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |
ES_AUTOHSCROLL | ES_WANTRETURN, 350, 500, 130, 20, hwnd, NULL, NULL, NULL);
Any help would be grateful. thanks
Try ES_PASSWORD :
Displays an asterisk (*) for each
character typed into the edit control.
This style is valid only for
single-line edit controls.
Windows XP: If the edit control is
from user32.dll, the default password
character is an asterisk. However, if
the edit control is from comctl32.dll
version 6, the default character is a
black circle.
To change the characters that is
displayed, or set or clear this style,
use the EM_SETPASSWORDCHAR message.
Note Comctl32.dll version 6 is not
redistributable but it is included in
Windows XP or later. To use
Comctl32.dll version 6, specify it in
a manifest. For more information on
manifests, see Enabling Visual Styles.
Source : Edit Control Styles
Edit
You mean creating a button ? Via Using Buttons :
HWND hwndButton = CreateWindow(
L"BUTTON", // Predefined class; Unicode assumed.
L"OK", // Button text.
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
0, // x position.
0, // y position.
50, // Button width.
50, // Button height.
hwnd_parentwindow,
NULL, // No menu.
(HINSTANCE)GetWindowLong(hwnd_parentwindow, GWL_HINSTANCE),
NULL);
You can select the edit box and right click and choose its properties. In that there is an option called password. Just check it.
Also this link will help you.
http://msdn.microsoft.com/en-us/library/d3223ht2.aspx
Or if you want you can directly add
ES_PASSWORD
also along with rest.

Resources