|
i'm using plain winapi and i'm trying to find out which items are selected
in a multi-selection listview window. i need this for "remove all selected items"
functionality.
(1) i could walk down all items and check if an item is selected.
but that would take very long with big lists (linear time)
(2) i could also track selection changes inside the window procedure but
i guess this would slow down selecting/unselecting items noticebly.
also it would be a lot of extra coding.
isn't there some easy, fast and elegant way to get a list of all selected items?
a listbox provides a message for this - listview does not?
please help!
thanks in advance, sebastian
-------------------------------------------
My website: http://www.hartwork.org
|
|
|
|
|
My first guess would be to use LVM_FINDITEM to find selected items...
Be sure to turn off redrawing during the delete operations to improve performance.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
thanks for your quick reply!
i overlooked LVM_FINDITEM somehow...
DavidCrow suggested LVM_GETNEXTITEM instead:
i compared these two and LVM_FINDITEM seems more
powerful so expect more speed from LVM_GETNEXTITEM .
also thanks for the tip on redrawing!
-------------------------------------------
My website: http://www.hartwork.org
|
|
|
|
|
Sebastian Pipping wrote: i need this for "remove all selected items"
functionality.
Make sure you delete from the bottom-up (e.g., largest item to the smallest item).
Sebastian Pipping wrote: (1) i could walk down all items and check if an item is selected.
but that would take very long with big lists (linear time)
Use the LVM_GETNEXTITEM message for this?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
|
|
|
|
|
thanks for you quick reply!
i am using LVM_GETNEXTITEM now.
i stumbled over the line "The specified item is itself excluded from the search"
on MSDN, and modified my code so it works with top-down deletion:
iWalk = SendMessage( _hView, LVM_GETNEXTITEM, iWalk - 1, LVNI_SELECTED );
-------------------------------------------
My website: http://www.hartwork.org
|
|
|
|
|
Hi ...
I have written a Windows Service using ATL COM (ATL3 / Visual Studio 6.0). The service works fine, I am able to start and stop the service.
I have created a COM Class called CTest with a methof called TestBeep(). I would like to access this object and call the method from the CServiceModule::Run() method.
Below is the CServiceModule::Run() Method.
The code will fail on both attempts to create the ITest* pTest using CoCreateInstance(). The error message are written to the event log
"Error: ITest failed"
"CoCreateInstance failed"
Any help is appreciated,
Thanks,
Chris
void CServiceModule::Run()<br />
{<br />
_Module.dwThreadID = GetCurrentThreadId();<br />
<br />
HRESULT hr = CoInitialize(NULL);<br />
<br />
_ASSERTE(SUCCEEDED(hr));<br />
<br />
CSecurityDescriptor sd;<br />
sd.InitializeFromThreadToken();<br />
hr = CoInitializeSecurity(sd, -1, NULL, NULL,<br />
RPC_C_AUTHN_LEVEL_PKT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);<br />
_ASSERTE(SUCCEEDED(hr));<br />
<br />
hr = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER, REGCLS_MULTIPLEUSE);<br />
_ASSERTE(SUCCEEDED(hr));<br />
<br />
LogEvent(_T("Blue Service started"));<br />
LogEvent(_T("Message 1"));<br />
LogEvent(_T("Message 2"));<br />
<br />
if (m_bService)<br />
SetServiceStatus(SERVICE_RUNNING);<br />
<br />
MSG msg;<br />
while (GetMessage(&msg, 0, 0, 0))<br />
DispatchMessage(&msg);<br />
<br />
_Module.RevokeClassObjects();<br />
<br />
<br />
<br />
char progID[] = "Blue.Test.1";<br />
<br />
CLSID clsid;<br />
wchar_t wide[80]; <br />
mbstowcs(wide, progID, 80);<br />
CLSIDFromProgID(wide, &clsid);<br />
<br />
LogEvent(_T("Attempt to use ITest"));<br />
<br />
ITest* pTest = NULL;<br />
if(SUCCEEDED(CoCreateInstance(clsid, NULL, CLSCTX_ALL, IID_ITest, (void**)&pTest)))<br />
{<br />
pTest->TestBeep(); <br />
}<br />
else<br />
{ <br />
LogEvent(_T("Error: ITest failed"));<br />
} <br />
<br />
<br />
<br />
CComPtr<ITest> pObj;<br />
hr = pObj.CoCreateInstance(OLESTR("Blue.Test.1"));<br />
if( SUCCEEDED(hr) )<br />
{<br />
hr = pObj->TestBeep();<br />
if( SUCCEEDED(hr) )<br />
{ <br />
LogEvent(_T("Call to ITest was successful"));<br />
}<br />
else<br />
{ <br />
LogEvent(_T("Error: ITest failed"));<br />
} <br />
}<br />
<br />
if( FAILED(hr) )<br />
{ <br />
LogEvent(_T("CoCreateInstance failed"));<br />
}<br />
<br />
CoUninitialize();<br />
}<br />
<br />
This is the implementation of the CTest Class and the TestBeep() method
<br />
#ifndef __TEST_H_<br />
#define __TEST_H_<br />
<br />
#include "resource.h"
<br />
class ATL_NO_VTABLE CTest : <br />
public CComObjectRootEx<CComSingleThreadModel>,<br />
public CComCoClass<CTest, &CLSID_Test>,<br />
public IDispatchImpl<ITest, &IID_ITest, &LIBID_BLUELib><br />
{<br />
public:<br />
CTest()<br />
{<br />
}<br />
<br />
DECLARE_REGISTRY_RESOURCEID(IDR_TEST)<br />
<br />
DECLARE_PROTECT_FINAL_CONSTRUCT()<br />
<br />
BEGIN_COM_MAP(CTest)<br />
COM_INTERFACE_ENTRY(ITest)<br />
COM_INTERFACE_ENTRY(IDispatch)<br />
END_COM_MAP()<br />
<br />
public:<br />
STDMETHOD(TestBeep)();<br />
STDMETHOD(GetCount)();<br />
int nCount;<br />
};<br />
<br />
#endif //__TEST_H_<br />
<br />
<br />
<br />
#include "stdafx.h"<br />
#include "Blue.h"<br />
#include "Test.h"<br />
<br />
<br />
<br />
STDMETHODIMP CTest::GetCount()<br />
{<br />
<br />
return S_OK;<br />
}<br />
<br />
STDMETHODIMP CTest::TestBeep()<br />
{<br />
Beep(4000, 200); <br />
Beep(1000, 50); <br />
Beep(4000, 200); <br />
Beep(1000, 50); <br />
return S_OK;<br />
}<br />
<br />
Thanks,
Chris
|
|
|
|
|
I want to take a bunch of unit test files from an LGPL opensource project, include them in my _closed_ project, modify them a bit and use it to test parts of my application. Can I do this?
thanks!
|
|
|
|
|
Chintoo723 wrote: Can I do this?
no[^].
You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.
d)...
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Chris Losinger wrote: copy and distribute such modifications or work under the terms of Section 1 above,
What does distribute here mean? who wants my work? where should I publish it to call it distributed?
Chris Losinger wrote: a) The modified work must itself be a software library.
As I said, it is only test modules which will be in a seperate .dsp project anways. Does this constitute a library in LGPL terms?
Chris Losinger wrote: You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.
Same query as the first one. How should I go about it to make sure I am hiding anything from any third parties that want to use it.
thanks!
|
|
|
|
|
Chintoo723 wrote: What does distribute here mean?
the same thing it means anywhere else: if you give it, sell it or let anyone else use it, you're distributing it.
Chintoo723 wrote: How should I go about it to make sure I am hiding anything from any third parties that want to use it.
please, don't take this as legal advice... i'm not a lawyer
but, i think if anything you distribute (ie. let anyone else use outside your organization use) uses L/GPL code, you need to distribute all the code in that app/library. you can't break it up and put parts of it into closed-source apps or libraries.
the LGPL, as i understand it, lets you link LGPL libs into closed-source apps. but it doesn't let you use the code from those libs in closed-source apps.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
If used only for testing, I believe you can. The key is that you won't be shipping any binaries from code covered by the LGPL.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
|
I have been looking for an answer on this one, but found only references to structures. Basically I have a VB.NET structure containing an member array of onother structure that has to be passed to unmanaged C++. I have been able to pass the structure which has members of type structure, but as soon as I define a member array of that structure I get an error: "An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: The operation completed successfully."
This is how I am doing it:
VB.NET:
Public Structure SndStr2
<marshalas(unmanagedtype.i4)> Public memb1 As Integer
<marshalas(unmanagedtype.lpstr)> Public memb2 As String
<marshalas(unmanagedtype.i4)> Public memb3 As Integer
<marshalas(unmanagedtype.i4)> Public memb4 As Integer
End Structure
Public Structure SndStr1
<marshalas(unmanagedtype.i4)> Public memb1 As Integer
<marshalas(unmanagedtype.lpstr)> Public memb2 As String
<marshalas(unmanagedtype.i4)> Public memb3 As Integer
<marshalas(unmanagedtype.r8)> Public memb4 As Double
Public memb5() As SndStr2
End Structure
Declaration: Private Declare Function RcvFun Lib "...\RcvFun.dll" _
(ByRef SndVar As SndStr1) As String
Unmanaged C++:
struct RcvStr1 {
int memb1;
LPSTR memb2;
int memb3;
int memb4;
};
struct RcvStr2{
int memb1;
LPSTR memb2;
int memb3;
double memb4;
RcvStr1 *memb5;
};
LPSTR __declspec (dllexport) __stdcall RcvFun(RcvStr2 **RcvPtr)
{
RcvStr1 RcvVar1;
RcvVar1 = RcvPtr[0]->memb5[0];
return RcvVar1.memb2;
}
If there is anybody out there that did this before, please help!
-- modified at 12:05 Wednesday 22nd February, 2006
|
|
|
|
|
I have created a Listview box which would display data in the Report mode. When filling in the header columns is it possible to set the width to correctly display the full text string?
Most of the examples I have found on the net either give the width a static value or a percentage of the total. I would prefer it if I could simply find the length in dialog units or pixels of the max string to be displayed and set the width according to that.
So far I have found no function which is able to find the length of a string in this manner? Is there a method to doing this or would it be easier to do something like (chars_in_string * static_size)?
|
|
|
|
|
It's been a while since I did this, so if I don't get it exactly right, I apologize.
There is a member function of CListCtrl::GetStringWidth(), though I seem to recall it doesn't quite work as stated in the documentation. I seem to recall having to pad it slightly, but I may be mistaken.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Following on from Joes comment above. Using the LVM_SETCOLUMNWIDTH[^] message, pass LVSCW_AUTOSIZE as the column width and the ListView will automaticaly resize the column to fit the longest string.
Gavin Taylor
w: http://www.gavspace.com
|
|
|
|
|
funny we are working on the same thing at the same time.
i found a function calculating the width of a string
on MSDN. the column here contains numbers only so my code is
HDC hdc = GetDC( _hView );
SIZE size;
BOOL res = GetTextExtentPoint32( hdc, TEXT( "0" ), 1, &size );
ReleaseDC( _hView, hdc );
const int iWidth = res ? ( size.cx * _iDigits ) : 120;
this function can be still helpfull when you want
to size for the largest string of all, not just the visible
ones (which LVSCW_AUTOSIZE does).
also i found out you can size the last column
to take as much space as possible without adding the
horizontal scrollbar (unlike LVSCW_AUTOSIZE_USEHEADER ):
RECT r;
GetClientRect( _hView, &r );
const int iWidth = ListView_GetColumnWidth( _hView, 0 );
ListView_SetColumnWidth( _hView, 1, r.right - r.left - iWidth );
best regards, sebastian
-------------------------------------------
My website: http://www.hartwork.org
|
|
|
|
|
Thanks for the info. You say that LVSCW_AUTOSIZE only allows for the width of the visible items, I'm not sure I understand cleary.
1. The header items only?
2. Those which are in view due to scroll limits?
I will play around with it when I get home, thanks again.
|
|
|
|
|
i'm not sure if it got you right but i guess
number 2 is what i meant
i'll try again with more details:
my column contains numbers from 1 to 4000.
when the current view is at the very top you can
only see numbers with one or tow digits.
applying LVSCW_AUTOSIZE now sets the
size to two digits not four since the big number
are out of view and ignored.
maybe i should mention my column header
has "#" as title so it is even shorter than
the numbers. i'm not sure what happens if the
header text is longer than all the row text.
i'm using the control in virtual/getdispinfo mode
maybe that's also playing in here!?
btw i had trouble with two-digit numbers shown
as "1..." so the current text width code is
const int iWidth = res ? ( int )( size.cx * ( _iDigits + 0.25f ) ) : 120;
i hope i put it clearly. i'm not a native speaker.
best regards, sebastian
-------------------------------------------
My website: http://www.hartwork.org
|
|
|
|
|
Thanks Sebastian, you have answered my questions clearly and with precission, very much appreciated
|
|
|
|
|
Hi,
I am after a quick fix.
I have dynamically created a CComboBox control.
It works fine, but the drop down part does not seem to draw.
I cannot see any obvious calls to adjust the height of the dropdown
Cheers
|
|
|
|
|
A quick guess - you actually create a combobox with its full dropped down height on
creation. It will self correct the height to one row of text, but remember the original
height.
Iain.
|
|
|
|
|
Cheers Iain just the trick!!
|
|
|
|
|
i have a sdi application and i want to draw a dynamic array that is present in CMainframe. problem is that the onDraw function is present in the view class.
i have tried getting the active view in the cmainframe but if i work with it, application throws exception or something.
please help me, as to how i can draw the variables(contents of the dynamic array) present in the mainframe, on screen.
thankyou
|
|
|
|
|
Why don't you want to draw it on your view ? The view is there for that reason, the mainframe is just the 'window' that will contain your view.
I think you need to review a little bit your program architecture. First, in a SDI application, all data should be contained in your document, not in your mainframe. Then, when the view is painted, it ask for data to the document and it draws this data. Normally, that is the standard way to proceed.
|
|
|
|