From: Viv on
Hi all,

I have a very basic application which has just a dialog with a listbox
on it. I need to simulate in the listbox the ctrl+a and ctrl+c
behavior. I mean, in the listbox there are some lines (messages sent
by another application) and I would like to do like any windows user
is used: ctrl+a to select the whole content of the listbox, then
ctrl+c to copy everything in the clipboard.

The code I'm having at the moment:

<myfile.rc>

// Microsoft Visual C++ generated resource script.
//
#include "resource."

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32

/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

IDD_PRIMARYFAMILY_DLG DIALOGEX 260, 200, 431, 306
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION
| WS_SYSMENU
CAPTION "!@$@!$#@$%@#$#!@#@!#!*^&$%^#$%@#$@!#!"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
LISTBOX IDC_PRIMARYFAMILY_LB,13,10,404,252,LBS_EXTENDEDSEL
END


#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE
BEGIN
"resource.\0"
END

3 TEXTINCLUDE
BEGIN
"\r\0"
END

2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\0"
END

#endif // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_PRIMARYFAMILY_DLG, DIALOG
BEGIN
RIGHTMARGIN, 297
BOTTOMMARGIN, 244
END
END
#endif // APSTUDIO_INVOKED

#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//

/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

</myfile.rc>

=================================================


<myfile.cpp>

#include <windows.h>
#include <Windowsx.h>
#include "Resource.h"
#include "wchar.h"
#include "strsafe.h"

//---------------------------------------------------------------------------
HWND hWnd;
HINSTANCE hInstGlobal;
LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM
lParam);
//---------------------------------------------------------------------------
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
hInstGlobal = hInstance;
DialogBox(hInstGlobal, MAKEINTRESOURCE(IDD_PRIMARYFAMILY_DLG),
hWnd, reinterpret_cast<DLGPROC>(DlgProc));
return FALSE;
}
//---------------------------------------------------------------------------
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM
lParam)
{
HWND lbxPrimaryFamily;
lbxPrimaryFamily = GetDlgItem(hWndDlg, IDC_PRIMARYFAMILY_LB);
switch(msg)
{
case WM_INITDIALOG: {
LONG style;
style = GetWindowLong(hWndDlg, GWL_STYLE);
//style &= ~(WS_CAPTION);
SetWindowLong(hWndDlg, GWL_STYLE, style);
return TRUE;
}
case WM_COMMAND: {
switch(LOWORD(wParam))
{
case IDC_PRIMARYFAMILY_LB:
{
return TRUE;
}
}
return TRUE;
} break;
case WM_CLOSE: {
PostQuitMessage(WM_QUIT);
} break;
}
return FALSE;
}
//---------------------------------------------------------------------------

</myfile.cpp>


Can smbd point me how could I have the ctrl+a, ctrl+c behaviour
implemented into this listbox?

Thanks in advance,
Viv
From: Friedel Jantzen on
Hi Viv,

you could subclass your listbox to get the ctrl+a, ctrl+c key messages.
Search MSDN for "subclassing". MS changes and removes contents all the
time.

On ctrl+a -> LB_SETSEL with wParam = (WPARAM)TRUE and lParam = (LPARAM)-1.

On ctrl+c -> OpenClipboard, EmptyClipboard, SetClipboardData,
CloseClipboard.

Regards,
Friedel
From: Viv on
Hi Friedel,

Thanks for your tips!
Viv


On Tue, 13 Jul 2010 08:30:37 +0200, Friedel Jantzen
<nospam_plz(a)freenet.de> wrote:

>Hi Viv,
>
>you could subclass your listbox to get the ctrl+a, ctrl+c key messages.
>Search MSDN for "subclassing". MS changes and removes contents all the
>time.
>
>On ctrl+a -> LB_SETSEL with wParam = (WPARAM)TRUE and lParam = (LPARAM)-1.
>
>On ctrl+c -> OpenClipboard, EmptyClipboard, SetClipboardData,
>CloseClipboard.
>
>Regards,
> Friedel