|
This should be the proper sequence after SetItemCount():
GotoDlgCtrl(&MyList_);
MyList_.SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
GotoDlgCtrl(&MyEdit_); // optional - if you want initial focus on the edit control
Then return FALSE from OnInitDialog() (important!).
(make sure you comment out any fake mouse click stuff )
That works for me - I just tested it.
Without setting the focus to the list before setting the selection, it
indeed fails to select the item as you've seen - I confirmed that as well.
AmVal wrote: I don't know if this ancient version I'm using has SetItemCountEx()
That's why I gave you the Win32 equivalent
You can get the Win32 equivalent of anything missing from your ancient MFC
version here: List View Control[^]
AmVal wrote: It would be nice if I could keep the highlight blue all the time
You'd have to use custom draw for that.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hmmm... Everything you say makes sense, but for some reason this is not working for me with the virtual list control (it does work for non-virtual).
This is pretty much what I had been trying, and I had also previously tried calling SetItemState() with one, or the other, or both LVIS_SELECTED and LVIS_FOCUSED, and even with only LVIS_SELECTED it didn't / doesn't work for me.
I'll keep looking to see if I can find something else wrong somewhere...
But I thought functionality was supposed to work the same for CListCtrl whether virtual or not, which makes it seem like it could be a bug in the version I'm using...
|
|
|
|
|
Hmm I'm stumped
I personally would use a message posted at the end of the OnInitDialog
to the dialog itself, then in response to that message do the item select.
I really don't like simulated clicks and /or keystrokes
If I think of something I'll let you know....good luck
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I would prefer not to use the simulated mouse click, that was a last resort. But it appears I may have to, as without it, right now I can't select anything in the list when the user types in the edit control. The mouse click takes care of everything except the initial display. There's gotta be a way to do the same thing on initial display, I just can't figure out where to do it.
If it's not too much trouble, could you give me an example of the code you are suggesting so I can try it?
I'm pretty new to Windows/MFC programming (this is the first time I've even used CListCtrl, much less sent messages, etc. Each step of the way has been a real struggle, looking for examples I can follow, etc. (although I'm learning a TON which is cool!) Even though I don't really like the idea of the simulated mouse click, I was actually kind of impressed that I got it to work
So anyway, a sample of the code you are suggesting would just save me some time trying to figure out how to do it! Thanks a bunch.
|
|
|
|
|
AmVal wrote: right now I can't select anything in the list when the user types in the edit control.
Wow - I thought it was just the original selection...
There's something wrong somewhere....you should be able to change
item states anywhere.
What version of Visual Studio are you using?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
It's Visual Studio 97. (Yikes! I know...)
The one article I referenced from 2000 was by a guy who sounded like a pretty experienced programmer, and he also discovered that programmatically selecting items in a virtual list control didn't seem to work. He never found any solution other than the fake mouse click. It sounded like he did get it to work for the initial selection as well. Unfortunately his code isn't out there any more so I can't see where he did that! (I don't know what version he was using, but his article was from 2000)
If I make the list box non-virtual, I can programmatically select items fine at any time. But as soon as I make it virtual, I can't programmatically select at all.
|
|
|
|
|
AmVal wrote: It's Visual Studio 97. (Yikes! I know...)
I'm worried MFC had its own version of the control then.
I just can't remember
These days (since Windows 98), the control is provided by
the operating system. You may want to not use MFC for the
control and use Win32 APIs directly. The problem seems to be
in MFC, not in the control.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You're right, if I just use:
ListView_SetItemState(MyList_, i, LVIS_SELECTED, LVIS_SELECTED)
It works to select the first item on initial display, as well to select at any other time. So I can avoid the fake mouse clicks! Yeah!
Thanks so much Mark!
|
|
|
|
|
Cool! Thanks for the update
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You can also do this:
//GotoDlgCtrl(&MyList_);
MyList_.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
GotoDlgCtrl(&MyEdit_); // optional - if you want initial focus on the edit control
It seems you can't set LVIS_FOCUSED unless the control has focus.
And if the control doesn't have focus and you try to specify LVIS_SELECTED | LVIS_FOCUSED,
it doesn't set either state
Good to know!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm not expert on exceptions. I need to catch some memory exception and ignore it, but it des not work. It only works in debug release (exception is ignored), but in release mode it crashes like when I don't handle the exception. What is the problem?
Here is code :
try
{
*((char*)0)=1;
}
catch(...)
{
}
It is MFC app in VC6.0.
Thank you.
|
|
|
|
|
This is the difference between C++ typed exceptions and Win32 structured exceptions. What you have is the former. See _set_se_translator() for more.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Thank you. I'm going to check it.
I wonder why debug mode caught the exception. Does debug mode use some default translator?
|
|
|
|
|
rrrado wrote: I wonder why debug mode caught the exception.
I'm really not sure, but it may have to do with the optimizer.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
rrrado wrote: I wonder why debug mode caught the exception
Might be because you set the "Enable C++ Exception=> YES with Structured exception (/EHa)" for debug configuration settings but not for release configuration.
|
|
|
|
|
In C++ - assuming the implementation follows the standard - catch is only allowed to catch exceptions raised using the throw keyword: since this isn't the case in your example the code in the catch block should NOT be executed. MSVC6 got this wrong but the bug has been corrected in later versions. The /EH[^] switch can be used to reinstate the bug.
Steve
|
|
|
|
|
|
Hi all...
I'm using CxImage to load and draw PNG. Either in dialog box or preferably on desktop screen.. Need help how to draw the PNG. So far i did this.
CxImage* newImage = new CxImage();
newImage->LoadResource(FindResource(NULL,MAKEINTRESOURCE(IDR_PNG1),"PNG"),CXIMAGE_FORMAT_PNG);
Thanks.
|
|
|
|
|
For PNG files you can use of CImage class and its easy to use.
|
|
|
|
|
I guess Cimage and CxImage are sort of same thing..
Neverthless how can i do with Cimage Class..
Thanks..
|
|
|
|
|
Surely CxImage must have rendering methods.
Look for methods called Draw()
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark...
After i call this.
newImage->LoadResource(FindResource(NULL,MAKEINTRESOURCE(IDR_PNG1),"PNG"),CXIMAGE_FORMAT_PNG);
How do i call Draw??
Draw has these two declaration..
long Draw(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1, RECT* pClipRect = 0, bool bSmooth = false);
long Draw(HDC hdc, const RECT& rect, RECT* pClipRect=NULL, bool bSmooth = false);
Thanks..
|
|
|
|
|
Till now i've done this with no success.. Trying to draw PNG on desktop.
HBITMAP m_bitmap = NULL;
CxImage image("E:\\My_Prog\\FINAL_PNG\\Res\\eScan.png", CXIMAGE_FORMAT_PNG);
HWND hDesktop = GetDesktopWindow();
HDC hdc = GetDC(hDesktop);
m_bitmap = image.MakeBitmap(hdc);
image.Draw(hdc);
Where am i wrong?
|
|
|
|
|
Edited..
Now i'm doing something like this.. This should disply PNG on picture control..But no success..
case WM_INITDIALOG:
{
HBITMAP m_bitmap = NULL;
CxImage image("E:\\My_Prog\\FINAL_PNG\\Res\\eScan.png", CXIMAGE_FORMAT_PNG);
RECT rect;
HWND hImage = GetDlgItem(hWnd, IDC_DRAW_IMAGE);
GetClientRect(hImage, &rect);
int rectHeight = rect.bottom - rect.top;
int rectWidth = rect.right - rect.left;
int height = image.GetHeight();
int width = image.GetWidth();
int xpos = 0;
int ypos = 0;
if(height > rectHeight || width > rectWidth)
{
double ratiox = (double)rectWidth /(double)width;
double ratioy = (double)rectHeight/(double)height;
double ratio = ratiox > ratioy? ratioy: ratiox;
width = width * ratio;
height = height * ratio;
image.Resample(width, height);
image.Save("E:\\My_Prog\\FINAL_PNG\\Res\\eScan.bmp", CXIMAGE_FORMAT_BMP);
}
xpos = (rectWidth - width)/2;
ypos = (rectHeight - height)/2;
HDC hdc = GetDC(hImage);
image.Draw(hdc, xpos, ypos);
break;
}
|
|
|
|
|
You don't draw on "picture controls". Picture controls keep their own
bitmap and render it themselves.
Try getting your image to render on the window first, then maybe work
on rendering on a child window.
This isn't a CxImage support site, and I've never used the library,
nor am I going to research the documentation, so it's tough to figure
out what's not working.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|