|
How can I calculate the required size of text which can be placed in one column of CListCtrl object and fits in.
when I tried to use the next code, some text did not appear all, I get three dots at the end of the appeared text on the column.
Can you help me please what is wrong with code ?
void CMyDialogDlg::AdjustColSize(int ColNo,CString s)
{
CClientDC dc(this);
CSize sz;
CFont *f = m_ListControl.GetFont();
dc.SelectObject(f);
sz = dc.GetTextExtent(s,_tcslen(s));
sz.cx += GetSystemMetrics(SM_CXBORDER);
if( width[ColNo] < sz.cx )
{
m_ListControl.SetColumnWidth(ColNo,sz.cx);
width[ColNo]=sz.cx;
}
}
Dr Abudawood
|
|
|
|
|
Use LVM_GETSTRINGWIDTH to get the width in pixels of a string. The docs say:If you use the returned string width as the column width in the LVM_SETCOLUMNWIDTH message, the string will be truncated. To retrieve the column width that can contain the string without truncating it, you must add padding to the returned string width. so you have to fudge the return value by a few pixels (I guess the exact number depends on the font, bigger font means more padding).
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
aef392rDFA#@(#*@%@#$Rfa39f3fqwf--=
NO CARRIER
|
|
|
|
|
Tanke you very mush Mr .Michael Dunn for your help. And I'll try to do your advice.
Dr Abudawood
|
|
|
|
|
Now I got the answer. after your help it was very easy as next:
void CTestScrolDlg::AdjustColSize(int ColNo,CString s)
{
//Global variable Array width[ColNo]
int Gab = 15;
int size=m_ListControl.GetStringWidth(s)+Gab;
if( width[ColNo] < size )
{
m_ListControl.SetColumnWidth(ColNo,size);
width[ColNo]=size;
}
};)
Dr Abudawood
|
|
|
|
|
I just realized this, but if you want the column to be wide enough to show all strings in the column, use the LVSCW_AUTOSIZE or LVSCW_AUTOSIZE_USEHEADER value with LVM_SETCOLUMNWIDTH .
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--=
NO CARRIER
|
|
|
|
|
I am attempting to use the parallel port for output control. I thus write a simple code to test the outp() as follow:
#include <conio.h>
void main (void)
{ int i;
i = outp(888,1);
}
VC6.0 returned the followign error msg :
error LNK2001: unresolved external symbol _outpw
Would appreciate any help to solve this. Thanks!!
|
|
|
|
|
You have to link your project with whichever library outpw is in - i think it's LIBC.LIB but i'm not sure
=====
Phlip
Always proofread carefully to see if you any words out
|
|
|
|
|
First, what OS are you planning to run this on? inp and outp do not work on Windows NT based systems (NT, 2000, XP, 2003, etc..)
Second, you need to link to the right lib file.
--
Where are we going? And why am I in this handbasket?
|
|
|
|
|
come on, someone must know this...
How can you send a char that's not on the keyboard using SendInput?
To send '¯', for example, you hold alt and type 0175 on the num pad.
So I guessed this, but it doesn't work
int i;
INPUT input[10];
ZeroMemory(input, sizeof(input));
for (i = 0; i < 10; i++)
input[i].type = INPUT_KEYBOARD;
input[0].ki.wVk = 18;
input[1].ki.wVk = input[2].ki.wVk = 0x60;
input[3].ki.wVk = input[4].ki.wVk = 0x61;
input[5].ki.wVk = input[6].ki.wVk = 0x67;
input[7].ki.wVk = input[8].ki.wVk = 0x65;
input[9].ki.wVk = 18;
input[2].ki.dwFlags = input[4].ki.dwFlags = input[6].ki.dwFlags =
input[8].ki.dwFlags = input[9].ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(10, input, sizeof(INPUT));
using a keyboard logger, i can see that it does exactly what I want, ie press alt, type 0175, release alt, but it doesn't send '¯' to the active app
Any ideas?
thanks in advance
=====
Phlip
Always proofread carefully to see if you any words out
BTW: Why doesn't replying bump messages to the top of the forum?
|
|
|
|
|
Undoubtedly "cin" is one of those quick ways you can use to receive data. But how reliable is it?
I ask the question because I noticed at times I'd get the right amount of data inputted, and at other times, not only would I receive one ot two characters less, but they'd be in the wrong order in which they were entered.
It is NOT a permanent situation I'm talking about for which I'm using "cin", but if it's reliability is in question during development, I'd just as soon not bother using it. (Or is there some way I can improve its reliability? Yes, I do use "cin.clear()" right before I start inputting, and "No", I don't enter more data than the buffer can hold.)
Thanks.
William
Fortes in fide et opere!
|
|
|
|
|
forget that stuff, use C
char input[80];
printf("Enter a string: ");
gets(input);
printf("\nYou Typed: %s\n", input);
puts(""); // line return;
puts("press any key to continue");
getc(stdin);
|
|
|
|
|
Thanks for your answer, but the ONLY reason why I used "cin" was because of the characters it delivered from the "istream" buffer, I could use in test like, "isspace", "isalpha", "ispunct" (etc.) as they were coming in.
Nonetheless, your suggestion does have merit to it. Thanks.
William
Fortes in fide et opere!
|
|
|
|
|
Using gets() is about as unsafe as you can do it. What if the user types more than 80 characters? Buffer overflow. That it what causes crashes. At least use fgets() where you can actually specify the size of the buffer.
There is nothing wrong with using the STL streams. I would choose it every time over gets() .
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Ryan Binns wrote:
types more than 80 characters? Buffer overflow. That it what causes crashes. At least use fgets()
I think that's pretty obvious, you can use fgets() too, although normally for file i/o, but it doesn't really matter as long as you know what your doing.
|
|
|
|
|
|
sure, but if you're writing a quick application that requires inputs like names, it's pretty safe to assume 80 or 100 chars will be ok.
I don't get paranoid about that stuff. You can however use fgets() with stdin as the file handle as you said.
|
|
|
|
|
I don't know who I'm quoting at the moment, but I need to let you know:
"Programming nowdays is a contest of making the best idiot proof program, against the universe making bigger idiots!"
(2 thums up to the one who thought of that sentence )
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
I managed to put together a very cool looking
.chm file using the program FAR. How can I
execute the .chm from my program? I used the
code:
CreateProcess(NULL, "help.chm, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
But it didn't work, even though it works for all the
other .exe files that I have. Is there something
special I need to do to run a .chm file?
Please, please, any response any one can give me
will be greatly appreciated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
ShellExecute(NULL, _T("Open"), _T("help.chm"), NULL, NULL, 0);
|
|
|
|
|
you also had a non-matching parenthesis in your code.
|
|
|
|
|
It worked.
Thank you very much. ;)
|
|
|
|
|
ShellExecute will work, but you need to use the HtmlHelp Api.
This will also help you launch directly a specific topic inside the chm help file.
HtmlHelp(m_hWnd, AfxGetApp()->m_pszHelpFilePath, HH_HELP_CONTEXT,
<topid_id>);
Also, you need to do this to replace the '.hlp' extension to .chm. in your initinstance.
CString strHelpFile = _pszHelpFilePath;
strHelpFile.Replace(_T(".HLP"), _T(".chm"));
free((void*)m_pszHelpFilePath);
m_pszHelpFilePath = tcsdup(strHelpFile);
You can download htmlhelp lib and header files from microsoft's site, if you don't have it already.
Hari Krishnan
|
|
|
|
|
pranavamhari wrote:
HtmlHelp(m_hWnd, AfxGetApp()->m_pszHelpFilePath, HH_HELP_CONTEXT,
);
You have missed 4th parameter of HtmlHelp. Can you tell me what to give here when using HH_HELP_CONTEXT command. I am giving mapid but getting this message
"HH_HELP_CONTEXT called without a [MAP] Section."
Any remedy to this?
Hashim Saleem
|
|
|
|
|
Now instead of using HH_HELP_CONTEXT, I am doing this
<br />
::HtmlHelp(NULL, <br />
"C:\\MyHelpFile.chm::/Welcome.htm>MyWindow",<br />
HH_DISPLAY_TOC,<br />
NULL) ;<br />
I am achieving my purpose. But tell me is it the right way instead of
HH_HELP_CONTEXT.
Hashim Saleem
|
|
|
|
|
I've tried to put background image into CListCtrl, but i completely ran out of ideas how to do this!!!
I cannot use owner drawn control because I need big icons.
I cannot use CListCtrl::SetBkImage() because it cannot stretch bitmap;
Maybe this is done somehow by using custom draw, but I failed. Can somebody give me link to working sample with background image?
Give me any suggestions!
|
|
|
|