WINAPI LISTBOX scroll down - winapi

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 );

Related

How do I create a search bar in win32 API

I am working on one project in win32 API. Here, I want the user to type a text in a search bar and the first corresponding words should pop-up. When the user is done with the typing or selects the word, clicking on the 'Process' button should display another message box. I want the search bar should look as this:
I want each word to display a different message box when the user clicks on the 'Process' button. Implying that, the application must be able to store data such that it can be retrieved. So far, I have this code which can store data and be retrieved.
HWND hWndComboBox = CreateWindow (TEXT("COMBOBOX"), TEXT (""),
CBS_DROPDOWN| CBS_HASSTRINGS | WS_VSCROLL| WS_VISIBLE |WS_CHILD ,
100, 20, 200, 70,
hwnd ,(HMENU) NULL, NULL, NULL);
CreateWindow (TEXT("BUTTON"), TEXT ("Process "),
WS_VISIBLE | WS_CHILD ,
200, 100, 70, 20,
hwnd,(HMENU) NULL, NULL, NULL);
SendMessage (
hWndComboBox ,
(UINT) CB_ADDSTRING,
(WPARAM) 0, (LPARAM) TEXT ("Apple"));
SendMessage (
hWndComboBox ,
(UINT) CB_ADDSTRING,
(WPARAM) 0, (LPARAM) TEXT ("Apple juice"));
SendMessage (hWndComboBox , CB_GETCURSEL , (WPARAM) 0, (LPARAM) 0);
Here, what I cannot do is that there is no default word like "Search Fruits" which clears when the user begins to type. Moreover, when the user selects 'Apple' and clicks on the 'Process' button, no dialog box is displayed. I do not know how to call the message box to respond depending on the user inputs. And also, the small search icon on the right of the search box.
Please what should I do? I am using win32 API Code:Blocks. Any further question for clarification is welcome. Any link or answer is most welcome. Thank you all.

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.

How to get rect of the item in Listbox using winapi

I am using VC6.0. I am trying programming to show contextmenu when I right click on the item of the ListBox. But now the popmenu can show anywhere in the rect of ListBox, since I only can get the rect of the ListBox, and I dont know how to get the rect of the item. I know that there is a macro ListView_GetSubItemRect which seems to get the rect of item of ListView. Is there similar way for ListBox, or is there a way to get the width and the height of item of ListBox, so I can caculate the rect? I didnt find some useful information on msdn and google? Can anyone give me some ideas? Thanks.
My current Code:
void My_OnContextMenu(HWND hwnd, HWND hwndContext, UINT xPos, UINT yPos)
{
HWND hList = GetDlgItem(hwnd,IDC_LIST_RESTYPE);
if (hList == hwndContext)
{
if(-1!=indexLB)
{
RECT rect;
POINT pt;
GetClientRect(hwndContext, &rect);
ScreenToClient(hwndContext, &pt);
if(PtInRect(&rect, pt))
{
HMENU hroot = LoadMenu((HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), MAKEINTRESOURCE(IDR_MENU_DELTYPE));
if(hroot)
{
HMENU hpop = GetSubMenu(hroot,0);
ClientToScreen(hwndContext, &pt);
TrackPopupMenu(hpop, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwndContext, NULL);
DestroyMenu(hroot);
}
}
}
}
}
Edit
Current:
First, I left click an item to selected、 an item. And Second I right click the selected item to show popmenu. It shows normally. But in the second step if I click the blank area of ListBox, it shows menu either. That is not what I expected.
What I expected is:
The menu only shows when I click an item and the position only over the item. When I right click other area, it wont be showed.
You are looking for the ListBox_GetItemRect macro.
However, I do feel that the user will find it odd to click in one place and see the menu appear somewhere else.
The proper solution to this problem is to popup the context menu at the mouse position. Clicking in one place and popping it up somewhere else would be very bad.
To get the mouse position use GetCursorPos().
http://msdn.microsoft.com/en-us/library/windows/desktop/ms648390%28v=vs.85%29.aspx
To be clear, first use ListBox_GetItemRect to work out which item is clicked on, and ignore it if none. Then use GetCursorPos so the menu appears exactly where the mouse is -- inside the list item -- and not somewhere a few pixels away. The Windows UI standards are that the context menu appears at the cursor position.
I'm not sure Why you wrote your own OnContextMenu - you should use the class wizard to map WM_CONTEXTMENU with the standard handler where the existing function ends up in your code like this:
//Wizard Added this the message map block
ON_WM_CONTEXTMENU()
//Declares the function with the proper parameters
void MyDlg::OnContextMenu(CWnd* pWnd, CPoint point);
//in the body of OnContextMenu use the system supplied parameters and the
//menu will appear next to the mouse position wherever it is clicked in the control
CMenu popupmenu;
popupmenu.LoadMenu(IDR_RMOUSEPOPUP);
int Command = (int)popupmenu.GetSubMenu(0)->TrackPopupMenu(
TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY,
point.x, point.y, pWnd);

Added column stays invisible after adding it to Listview

In WM_CREATE message of my main window procedure I create a listview with the next code:
hMyList = CreateWindowA( WC_LISTVIEW,TEXT(""), WS_CHILD | WS_VISIBLE |
LVS_LIST | LVS_TYPEMASK , XPOS(450), YPOS(20), NWIDTH(200),
NHEIGHT(200),hWnd,(HMENU) 9876, hInst, NULL);
Then I insert code to add a column to that listview:
LVCOLUMN column;
column.mask = LVCF_TEXT;
column.pszText = "Name";
SendMessage(hMyList, LVM_INSERTCOLUMN, NULL, (LPARAM)&column );
//returns 0; so everything is fine
But column doesn't appear in the listview.
What can be the source of the problem?
Columns are visible only in report/details view of the listview. To switch it in that mode you should post LVM_SETVIEW message to it, or use LVS_REPORT style instead of LVS_LIST in the CreateWindowA.

How to add a custom button to windows' minimize/maximize/close (x)

I was wondering if there is a way to add (programatically, of course) an icon/button/whatever besides plain text to a window (Microsoft Windows window...)'s title bar or next to where the minimize/maximize/close buttons are. I could draw it myself and create an illusion it is a part of the window, but I wonder if in the user32 api there is such a method.
So far, I found a way to disable the minimize/maximize/close buttons but not a way to add a custom one to them. It seems strange to me.
Here is what I am trying to achieve:
I have been wondering how it is done here, since drawing a button for every window using gdi/gdi+ and then detecting if it is overlapped by another window and then displaying only the non-overlapped part seems to me like an unlikely solution. Probably the button has been registered in the window class so that every window has this button. Any pointers what to do?
In addition, how do I create a button at all, assuming I DON'T have Unicode enabled. Then in the following piece of code:
HWND hwndCommandLink = CreateWindow(
L"BUTTON", // Class; Unicode assumed.
L"", // Text will be defined later.
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_COMMANDLINK, // Styles.
10, // x position.
10, // y position.
100, // Button width.
100, // Button height.
hDlg, // Parent window.
NULL, // No menu.
(HINSTANCE)GetWindowLong(hDlg, GWL_HINSTANCE),
NULL); // Pointer not needed.
SendMessage(clHwnd, WM_SETTEXT, 0, (LPARAM)L"Command link");
SendMessage(clHwnd, BCM_SETNOTE, 0, (LPARAM)L"with note");
I have to substitute all the nice Windows constants with their long equivalent....However, when I search for them, all i get is this:
http://msdn.microsoft.com/en-us/library/bb775951(v=VS.85).aspx
Any pointers?

Resources