the Focus event on Combo box is generated twice. Win Desktop API - c++

The focus event on the combo box is generated twice.
this is the code for the Action Procedure of the Dialog box.
INT_PTR DialogBox::ActionProc(
HWND hwndDlg,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case COMBOBOX:
{
if (CBN_SETFOCUS == HIWORD(wParam))
{
MessageBox(
hwndDlg,
CString("Test"),
CString("Test"),
(MB_ICONEXCLAMATION | MB_OK));
}
break;
}
default:
break;
}
break;
}
default:
break;
}
return INT_PTR(true);
}
the MessageBox Gets displayed twice(because the focus event is generated twice on the combo box). Is there a way to display it only once.
I have tried focussing to another element such as:
INT_PTR DialogBox::ActionProc(
HWND hwndDlg,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case COMBOBOX:
{
if (CBN_SETFOCUS == HIWORD(wParam))
{
MessageBox(
hwndDlg,
CString("Test"),
CString("Test"),
(MB_ICONEXCLAMATION | MB_OK));
SendDlgItemMessage(
hwndDlg,
ANOTHER_CONTROL,
WM_SETFOCUS,
0,
0);
}
break;
}
default:
break;
}
break;
}
default:
break;
}
return INT_PTR(true);
}
Can some one tell me what i am doing wrong.
This is in Windows Desktop API.

Related

C++ receiving ListBox messages

I want to handle the user's doubleclick over a ListBox, but there's no way to handle the listbox activity because it doesn't send a message to the window. I have this:
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_LISTBOX1:
{
if(HIWORD(wParam) == LBN_DBLCLK)
{
//...
}
//...
}
//...
}
//...
}
//...
}
return 0;
}
How can I handle the listbox messages?

Formview not showing

I've created a formview using the Visual Studio resource editor but I can't get it to show.
The procedure to handle it's messages is this:
BOOL CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case IDC_BUTTONCancel:
EndDialog(hDlg,0);
return TRUE;
}
break;
}
return FALSE;
}
When a button is pressed in the main window I call:
DialogBox(hInst, MAKEINTRESOURCE(IDD_FORMVIEW), hwnd, (DLGPROC)DlgProc);
The main window freezes, but there is no dialog shown.
I'd appreciate some help. Thanks in advance.

ComboBox Subclassing Listbox

I am trying to Subclass the Listbox and the Edit Control of a Combobox for some customasing reasons. Below is the code work . Subclassing for Edit Control is working perfect but Listbox is not getting the messeage of MouseDown.
void Subclass(HWND hComboBox)
{
HWND hEdit=FindWindowEx(hComboBox, NULL, WC_EDIT, NULL);
HWND hCombo=FindWindowEx(hComboBox, NULL, WC_LISTBOX, NULL);
SetProp(hEdit, TEXT("Wprc"), (HANDLE)GetWindowLongPtr(hEdit, GWL_WNDPROC));
SubclassWindow(hEdit, ComboBox_Proc);
SetProp(hCombo, TEXT("Wprc1"), (HANDLE)GetWindowLongPtr(hCombo, GWL_WNDPROC));
SubclassWindow(hCombo, ComboBox_Proc1);
}
static LRESULT CALLBACK ComboBox_Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CHAR:
break;
case WM_KEYDOWN:
break;
case WM_DESTROY:
SetWindowLongPtr(hwnd, GWLP_WNDPROC, (DWORD)GetProp(hwnd, TEXT("Wprc")));
RemoveProp(hwnd, TEXT("Wprc"));
break;
default:
return CallWindowProc((WNDPROC)GetProp(hwnd, TEXT("Wprc")), hwnd, msg, wParam, lParam);
}
return FALSE;
}
static LRESULT CALLBACK ComboBox_Proc1(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_LBUTTONDOWN:
//PROBLEM IS HERE
break;
case WM_DESTROY:
SetWindowLongPtr(hwnd, GWLP_WNDPROC, (DWORD)GetProp(hwnd, TEXT("Wprc1")));
RemoveProp(hwnd, TEXT("Wprc1"));
break;
default:
return CallWindowProc((WNDPROC)GetProp(hwnd, TEXT("Wprc1")), hwnd, msg, wParam, lParam);
}
return FALSE;
}
The ListBox part of a ComboBox is of type COMBOLBOX (with L).
The ComboLBox window is not a child of the ComboBox window.
The only way I found to subclass the COMBOLBOX control is as follows.
Windows sends the WM_CTLCOLORLISTBOX message to the COMBOBOX (no L) before the listbox is drawn. The lParam of this message contains the handle of the listbox.
case WM_CTLCOLORLISTBOX:
{
if ( !hSubclassedListBox )
{
hSubclassedListBox = (HWND)lParam;
SubclassWindow(hSubclassedListBox , MyLBProc);
}
}
Alsoo see this link for more information
For those who are using Visual Studio with WINVER set to 0500 or higher (Windows XP or later), you can use the GetComboBoxInfo function (passing the handle to the ComboBox), which will return (in a COMBOBOXINFO structure) the handles to both the Edit box and the ComboLBox (ListBox). The handles can then be used to get the CWnd-derived objects they represent.

c++ win32 : adding values to ComboBox

Im sure this question is so easy for all you experts, but I am new to C++ and trying to add a comboBox to a "Option" Dialog in my program, I have done the following, but still can't see any item in Combo box can you please tell me what I am missing here.
in Resourse.h : #define IDD_TRIGGER_MODE 201
in Project.rc : COMBOBOX IDD_TRIGGER_MODE, 64,22,68,14,WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWN
any in the .cpp file I have the folliwng codes :
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_COMMAND:
///Other codes///
case IDM_OPTIONS:
g_hToolbar = CreateDialog(hInst, MAKEINTRESOURCE(IDD_OPTION_BOX), hWnd, ToolDlgProc);
if(g_hToolbar != NULL)
{
ShowWindow(g_hToolbar, SW_SHOW);
}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
///Other codes///
}
the ToolDlgProc function :
INT_PTR CALLBACK ToolDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
HWND fgModes;
switch (message)
{
case WM_INITDIALOG:
fgModes = ::GetDlgItem(hDlg, IDD_TRIGGER_MODE);
fgModes = GetDlgItem(hDlg, IDD_TRIGGER_MODE);
if(fgModes!=NULL){
if(SendMessage(fgModes,CB_ADDSTRING,0, reinterpret_cast<LPARAM (_T("FreeRun")))==NULL){
return (INT_PTR)FALSE ;
}
return (INT_PTR)TRUE;
}
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
I appricate it for any idea to solve this problem, Thank you
thank you so much for your help. but I notice I didnt have problem in my code, simply the size of the ComboBox in .rc file was quite small (because of my lack of experiance in c++ API), so I change it to 42 now I can see my items. here is the edited code :
COMBOBOX IDD_TRIGGER_MODE, 64,22,69,42,WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST
Change:
SendMessage(fgModes,CB_ADDSTRING,0, reinterpret_cast<LPARAM>("FreeRun"));
To:
SendMessage(fgModes,CB_ADDSTRING,0, reinterpret_cast<LPARAM>(_T("FreeRun")));
Also is there a good reason you are mixing CreateWindow/Ex and resources? I am assuming CreateWindow/Ex because I see you are using a WndProc for the first cpp, not a DialogProc.

How to make a dialog movable?

I'm starting out with win32 programming.
I created my first dialog but I can't drag it around with my mouse; it simply stays where it is. Why?
This is its proc function:
static bool CALLBACK ChangeColumnProc(HWND dialog, uint32 message, WPARAM wParam, LPARAM lParam)
{
static ColumnInfo *column = NULL;
switch(message)
{
case WM_INITDIALOG:
column = (ColumnInfo *)lParam;
InitializeDialog(dialog, column);
return true;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
SaveChanges(dialog, column);
break;
case IDCANCEL:
EndDialog(dialog, lParam);
break;
default:
return false;
}
return true;
}
return false;
}
This is how I create it:
if(DialogBoxParam(StartupInfo.Instance, MAKEINTRESOURCE(IDD_CHANGE_COLUMN), StartupInfo.Window, (DLGPROC)ChangeColumnProc, (LPARAM)&column) == IDOK)
What am I doing wrong?
The return type of the dialog procedure is INT_PTR, not bool. Return (INT_PTR)FALSE if you don't handle the message.