TIA
PS: CWnd::ModifyStyle just does...
style = GetWindowLong( whatever.m_hWnd, GWL_STYLE );
style &= ~( LBS_SORT );
SetWindowLong( whatever.m_hWnd, GWL_STYLE, style );
...which I have also tried here.
--
unfo...@my-deja.com
http://www.bmeworld.com/unformat/ -- see my ass!
"Enough love to knock a rhino sideways" - SNUFF
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
Many Windows controls only use the style when the control is created.
Therefore, while you can change the style bits, the control blissfully
ignores them.
The work-around in these situations is to either destroy the original
control and create another in the style you want, or to maintain 2
controls, one of each style, and hide/show the appropriate one.
Dave
----
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.
Send me a mail and I'll forward you the (extremely simple) program I tested
it with.
Scott Tunstall
Get C64 -> PC Boulderdash code @
www.kwikrite.clara.net/bdash/
David Lowndes wrote in message <37718d88...@msnews.microsoft.com>...
Scott,
It doesn't seem to work for me. Are you sure that your list box
doesn't already have the sort style set in the dialog resource?
Rather than post an entire project, just show us the few lines of code
that works for you. Here's what I've tried (and doesn't work for me):
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
....
// TODO: Add extra initialization here
CListBox * pLB = (CListBox*) GetDlgItem( IDC_LIST1 );
pLB->AddString("E(top) String 1");
pLB->AddString("B String 2");
pLB->AddString("G String 3");
pLB->AddString("D String 4");
pLB->AddString("A String 5");
pLB->AddString("E(bottom) String 6");
/* This has no effect */
pLB->ModifyStyle( 0, LBS_SORT );
return TRUE;
CWnd::ModifyStyle is prototyped as:
BOOL ModifyStyle( DWORD dwRemove, DWORD dwAdd, UINT nFlags = 0 );
Here's mine to remove the LBS_SORT style (from another program but it still
uses ModifyStyle):
HWND hWnd = ::GetDlgItem(GetSafeHwnd(), IDC_LIST1);
m_pListBox->Attach(hWnd);
m_pListBox->ModifyStyle(LBS_SORT,0,0);
And I rechecked my resource file, I can assure you the LBS_SORT style IS
there in my dialog, yet is successfully removed at run time (I used Spy++)
Hope this helps.
Scott
You're right Scott, my logic was backwards to the original posters
question, however (for me at least) it doesn't change anything, I
can't get a listbox to change its sorting at run-time.
>And I rechecked my resource file, I can assure you the LBS_SORT style IS
>there in my dialog, yet is successfully removed at run time (I used Spy++)
The style flag does indeed change, I don't dispute that. However, the
control doesn't change its behaviour. The following code attached to a
button on the dialog should illustrate the situation if you care to
try it, I'd be interested in your results.
void CMyDlg::OnButton1()
{
static bSort = false;
CListBox * pLB = (CListBox*) GetDlgItem( IDC_LIST1 );
/* Clear the list, change the style, and re-add the items
* just to be sure sorting doesn't only work on adding.
*/
pLB->ResetContent();
if ( bSort )
{
pLB->ModifyStyle( LBS_SORT, 0 );
}
else
{
pLB->ModifyStyle( 0, LBS_SORT );
}
bSort = !bSort;
pLB->AddString("E(top) String 1");
pLB->AddString("B String 2");
pLB->AddString("G String 3");
pLB->AddString("D String 4");
pLB->AddString("A String 5");
pLB->AddString("E(bottom) String 6");
}
Dave
Can you see what's wrong here?
> if ( bSort )
> {
> pLB->ModifyStyle( LBS_SORT, 0 );
> }
> else
> {
> pLB->ModifyStyle( 0, LBS_SORT );
> }
The code is like so:
IF YOU WANT TO SORT THEN
REMOVE SORT STYLE FROM LISTBOX (The first param of ModifyStyle is
dwRemove!!!)
ELSE IF YOU DON'T WANT SORT THEN
ADD SORT STYLE
Do you see what's wrong? Here's the revised code, and it works on mine (I
can send you the workspace and files if you want).
CListBox * pLB = (CListBox*) GetDlgItem( IDC_LIST1 );
/* Clear the list, change the style, and re-add the items
* just to be sure sorting doesn't only work on adding.
*/
pLB->ResetContent();
if ( bSort )
{
pLB->ModifyStyle( 0, LBS_SORT );
}
else
{
pLB->ModifyStyle( LBS_SORT, 0 );
}
pLB-RedrawWindow();
Shit.
Oh well, it looks like the only way to get round this is (unfortunately) to
destroy the current window and create a new one with the required sort style
in it's place.
Scott
David Lowndes wrote in message <3779bdf9...@msnews.microsoft.com>...
>
>>Your code is *adding* the LBS_SORT style to the listbox. In the original
>>post you wanted to REMOVE the sort style.
>
>You're right Scott, my logic was backwards to the original posters
>question, however (for me at least) it doesn't change anything, I
>can't get a listbox to change its sorting at run-time.
>
>>And I rechecked my resource file, I can assure you the LBS_SORT style IS
>>there in my dialog, yet is successfully removed at run time (I used Spy++)
>
>The style flag does indeed change, I don't dispute that. However, the
>control doesn't change its behaviour. The following code attached to a
>button on the dialog should illustrate the situation if you care to
>try it, I'd be interested in your results.
>
>void CMyDlg::OnButton1()
>{
> static bSort = false;
>
> CListBox * pLB = (CListBox*) GetDlgItem( IDC_LIST1 );
>
> /* Clear the list, change the style, and re-add the items
> * just to be sure sorting doesn't only work on adding.
> */
> pLB->ResetContent();
>
> if ( bSort )
> {
> pLB->ModifyStyle( LBS_SORT, 0 );
> }
> else
> {
> pLB->ModifyStyle( 0, LBS_SORT );
> }
> bSort = !bSort;
>
> pLB->AddString("E(top) String 1");
> pLB->AddString("B String 2");
> pLB->AddString("G String 3");
> pLB->AddString("D String 4");
> pLB->AddString("A String 5");
> pLB->AddString("E(bottom) String 6");
>}
>
Whew, thanks for that confirmation Scott, I was beginning to doubt my
sanity.
I'm surprised at this, you would have thought removing the sort style and
then redrawing the window would have the desired effect?
Aha! Wait a minute, there is a way around this but it is known as "el long
wayo" in Spanish <grin>. You could implement an "owner draw" listbox... but
to my mind this is overkill.
Maybe you could make a million from writing an OCX version? If you do, I
want royalties for the idea :)
I wish you all the best
Scott
David Lowndes wrote in message <37817954...@msnews.microsoft.com>...
I somehow doubt it. There's probably a good helping of them available
already - I usually find I'm never first with a good idea :(.
added to your .h file. Then, instead of the gross GetDlgItem, you can write
c_List1.ModifyStyle(...);
I use a c_ prefix to indicate control variables and m_ is reserved for data
value variables. That way you can use the same name suffix and know what you
are using it for. OTOH, I rarely use data variables to initialize controls,
since it is rare that a simple copy suffices.
joe
Scott Tunstall <tuns...@email.msn.com> wrote in message
news:Oxxx9aaw#GA.309@cpmsnbbsa03...
> David, you have messed up.
>
> Can you see what's wrong here?
>
> > if ( bSort )
> > {
> > pLB->ModifyStyle( LBS_SORT, 0 );
> > }
> > else
> > {
> > pLB->ModifyStyle( 0, LBS_SORT );
> > }
>
> The code is like so:
>
> IF YOU WANT TO SORT THEN
> REMOVE SORT STYLE FROM LISTBOX (The first param of ModifyStyle is
> dwRemove!!!)
> ELSE IF YOU DON'T WANT SORT THEN
> ADD SORT STYLE
>
>
> Do you see what's wrong? Here's the revised code, and it works on mine (I
> can send you the workspace and files if you want).
>
>
>
> CListBox * pLB = (CListBox*) GetDlgItem( IDC_LIST1 );
>
> /* Clear the list, change the style, and re-add the items
> * just to be sure sorting doesn't only work on adding.
> */
> pLB->ResetContent();
>
> if ( bSort )
> {
> pLB->ModifyStyle( 0, LBS_SORT );
> }
> else
> {
> pLB->ModifyStyle( LBS_SORT, 0 );
> }
>
> pLB-RedrawWindow();