|
I have a list ctrl and want to sort it when user click the column. In my sort function, i only can get the item's lparam, but i need get the item's index then could use GetItemText function to compare two strings. I find i could use the FindItem to get the item index from the item's lparam, but it seems slow(if items more than 3000, the sort time is too long). So could any one teach me which function or which way I could use to get the item index effectively?
Thank you very much for your help!
|
|
|
|
|
|
Mike, Thank you very much! You really help me!
|
|
|
|
|
Are you calling the list control's SortItems() method? If so, the callback function will receive two LPARAM variables, lParam1 and lParam2 . Those are pointers and need to be cast to the same type of object that was used with SetItemData() . For example:
struct myStruct
{
int i;
char name[32];
};
...
int nIndex = InsertItem(...);
myStruct *p = new myStruct;
SetItemData(nIndex, (DWORD) p);
...
SortItems(CompareFunc, 0);
...
int CALLBACK CompareFunc( LPARAM lParam1, LPARAM lParam2, LPARAM )
{
int nReturn = 0;
myStruct *p1,
*p2;
p1 = (myStruct*) lParam1;
p2 = (myStruct*) lParam2;
...
} Make sense?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hello
How do I send a specific key to a winow?
I tryed using the SendMessage function like this:
SendMessage(hwnd,WM_KEYDOWN,'A',0x2701);
I think it doesn't work because of the 4th parameter and I don't understand that parameter very well.Can anyone explain it to me, it is supposed to be some kind of a value that identifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table. But I don't understand this.
I also tryed sending a hotkey message to the window as I think that the letter I send is actually a hotkey because it is underlined. I tryed doing that like this:
SendMessage(hwnd,WM_HOTKEY,IDHOT_SNAPWINDOW,'A');
But it didn't work. Why?
Is there some other way that I can press a button on this window programaticly? The buttons on this window keep changing every time you run it and they have no names just handles so that would be pretty hard.
|
|
|
|
|
The WM_KEYDOWN message is sent to a window when the window has focus and a non-system keyboard key goes down and remains pressed. After the keyboard repeat delay, multiple WM_KEYDOWN messages are simultaneously generated. A non-system keyboard key is any key excluding F10 and keys pressed together with ALT. To simulate an ALT + key combination, use WM_SYSKEYDOWN message.
In order to simulate a keypress to a window, use WM_CHAR message. WM_CHAR messages are not translated anymore, so the keycode you issue for it will proceed directly as-is to the receiving window. WM_KEYDOWN messages have virtual key-codes that are translated to character codes. WM_CHAR messages have character-code (ASCII) values with them.
To precisely simulate a keypress (such as CTRL/SHIFT + key), you must generate virtual keypress events. This is much more complicated than just sending a single message. Check SendInput in MSDN. In here, you will generate sequentical keyboard events for each and every event of the key combination. Remember that pressing CTRL + SHIFT + F, for example, consists of first setting CTRL, SHIFT and F keys to pressed state, in order, and then releasing them, in inverse order. Note that to target the keypress combination, you must set the target window active by using SetFocus .
Also, if your program is running on a seperate thread than the target program, you must first attach the input streams by using AttachThreadInput , and detach them after you've synthesized the keystrokes.
-Antti Keskinen
----------------------------------------------
"If we wrote a report stating we saw a jet fighter with a howitzer, who's going to believe us ?"
-- R.A.F. pilot quote on seeing a Me 262 armed with a 50mm Mauser cannon.
|
|
|
|
|
Hi-
I have a value 0xfffffff3 that is defined as:
exponent = 0xfffffff3 & 0xff000000 = 0xff
mantissa = 0xfffffff3 & 0x00ffffff = 0xfffff3
value = (mantissa) * (10^exponent)
This works find for positive numbers, but isnt for negative numbers. The true value is -1.3. But I keep getting 16777203 which is the 0xfffff3 in decimal, but should be -13 which becomes -1.3 once I do the multiplication.
Is there a way to convert this 2s complement value into the correct signed integer value?
I tried shifting left then right (0xfffff3 << 2) >> 2, but it doesnt seem to fill in the most significant bits w/ the correct sign.
Thanks.
-C
|
|
|
|
|
Integer values are 2s complement values. All you lack is the sign extension.
if (mantissa & 0x800000) mantissa |= 0xff000000;
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
...that shows the corresponding text from the String Table when you hover the mouse over a String Resource ID in code?
That would be great!
Thanks,
Ian
|
|
|
|
|
The grandaddy[^] of VS addins.
Provides what you need and so much more
It is a commercial app, so you will have to pay for the privilege
I Dream of Absolute Zero
|
|
|
|
|
Hi,
I am beginner in vc++, in my current project, I have one issue, I want some help from you.
I am creating, server socket & am listening for the clients. Once we have client, I am creating a seperate thread for that client.
Everything is done & working fine with this.
But, now the issue is, suppose Client socket is broken some how, & at that time if server sends the client the reply message, & if on client machine any firewall is installed, it treats the reply from the server under NMAP XMAS.scan.
to avoid this, before responding to the client, server should check wether client is alive or not, suggest me how can I do this?
|
|
|
|
|
You can't in the general case. Get a copy of TCP/IP illistrated by Richard Stevens to understand why (all volumns). (He died a few years ago, but the book is still worth reading, even if slightly dated)
The short of it is, the only way you know a client is alive is if you send data and it responds, and then you only know it was alive at the time it responded, which is always some time before you got the result. (normaly less than a second, but in the case of space craft can be hours!)
There are TCP/IP keep alives, but the time out is far too long to be useful for most purposes.
|
|
|
|
|
Hi !! All
i m facing Fixup linker error in my module. i have searched on internet and found that this problem arises when the memory model is not suitable for the application. to overcome this problem we must have the large memory model. i m using TC V3.0 and set the memory model to large , the program runs but when the function containing the bulitin function of c execute error occurs and programm exits from the dos shell. plz help me in fixing this error ? should i change some thing in my program?? i m using low level system programming in the code likes using the mouse interrupts and video interrupts? plz suggest some solution ASAP.
Best Regards
Thanks
Naina Khawaja
|
|
|
|
|
I considered replying with "This is the VC++ forum, not the Turbo C forum" but that would be so cliché. The only reason I mention it is that you may not get any help at all unless there happens to be a Turbo C user in the house. For me, it's been over 11 years since I've used that compiler.
I do not know an exact answer to your problem but with 16-bit code, being aware of the program's memory model was always very important. Crossing over into another program's address space was always a possibility and oh-so-easy to do with the segment:offset addressing scheme.
nainakhawaja wrote:
...the program runs but when the function containing the bulitin function of c execute error occurs...
How about showing us a code snippet and the error message? There are no guarantees but at least that would be a start.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Should I even bother using DrawDragRect or just write my own by using SetROP2?
DrawDragRect wouldn't draw off the window size so when I scroll up/down it won't follow along.
Someone mentioned in earlier post about using translate function for DragDractRect but I can't seem to find the function. With translation would it be possible drag a rectangle while scrolling down?
|
|
|
|
|
Anonymous wrote:
Someone mentioned in earlier post about using translate function for DragDractRect but I can't seem to find the function.
It's a member of the CDC class.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I have look through but I can't find the function that does the translation
|
|
|
|
|
Hmm! I have never used DrawDragRect(), but your question implies that you have a scrolling problem and not a drawing problem. This sounds like you want the window to scroll, much like the window scrolls when you are trying to select more text (w/mouse) than you can actualy see (automatic scrolling). You have to issue the scroll command your self when the edge of the rectangle reaches the edge of the window you want it to scroll. The best way to do this, that I have used, is to start a timer and check the edge position in the timer function and have it issue the scroll commands (based on the edge position). The reason you would use a timer is because, if you do not, it would scroll way to fast.
You might look for articles on simple text editors to see how they are handling the scrolling when a user is dragging a mouse.
Good Luck!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
I've already found quite some "niceties" regarding VC6 and function templates (template parameter must occur as argument, and template over type rather than typename isn't resolved correctly).
I found new one, that boils down to:
<br />
template <typename CHAR, typename STRLEN> void Foo(CHAR const * p, STRLEN lenFunc, size_t charsize)<br />
{ ... };<br />
<br />
Foo("Hello", strlen, 1);<br />
Foo(L"Hello", wcslen, sizeof(wchar_t);<br />
I haven't reproduced this in minimum code yet, but it's pretty obvious that the compiler (sometimes) uses just the wchar_t overload for both branches.
Q:
- is this valid code under the piercing eyes of the C++ standard?
- Is this a known problem for VC6?
- Is something known about VC7 / other compilers?
we are here to help each other get through this thing, whatever it is Vonnegut jr. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
Are you sure that the problem is not caused by the fact that Windows headers define CHAR according if Unicode or MBCS is set ?
Try changing the typename in the template to something that is not so "reserved" as CHAR is. Like 'TYPE_CHAR' and 'TYPE_STRLEN', for example. If the compiler still produces wchar_t overloads, then it might be a bug.
As for the questions.
- Like stated, overloading the CHAR typedef can be a bad mistake. Most compilers have in-built definitions for CHAR. Many of them resolve to 8-bit integer values, but some specific compilers (such as mobile device/mobile platform ones) might produce a different result. In eyes of the C++ standard, the code is correct, though, as 'CHAR' is not a base type, but 'char' is.
- Unknown. You could try posting this as a bug suggestion to Microsoft and see what they reply. Most possibly the reply is a suggestion to move into a newer programming environment.
- Unknown. Visual Studio compilers are aimed at producing Windows and Windows Embedded code. Because ANSI/ISO Standard doesn't support stuff like multithreading, many of these compilers are not entirely standard compliant. Make no mistake, this is due to the lacking standard, not due to Microsoft's ineptness in following the standard.
-Antti Keskinen
----------------------------------------------
"If we wrote a report stating we saw a jet fighter with a howitzer, who's going to believe us ?"
-- R.A.F. pilot quote on seeing a Me 262 armed with a 50mm Mauser cannon.
|
|
|
|
|
OK, I'll try renaming them (although CHAR works fine for other templates).
I'll see if I can reproduce that in VC6 in an minimum environment, and if if so, try VC7.
we are here to help each other get through this thing, whatever it is Vonnegut jr. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
Hi everybody,
I've got a strange behavior with my code.
I have a dialog-based program, which opens another dialog (modal) when the user click on the right menu item.
There, OnInitDialog() is called before the new dialog is displayed, and it it there where I initialize my dialog depending on how the dialog was created.
I do a set of LoadString() to display the texts of the dialog in the correct language. but after loading the strings, SetWindowText() crashes.
here is the code :
Call of the new dialog :
<font color=#0000FF>void</font> CFactEditorDlg::OnFileOpen() {
COpenFilesDlg dlg(m_strDBFile, m_strDestFile);
<font color=#0000FF>if</font> (dlg.DoModal() == IDOK) {
<font color=#008000>
}
}
New dialog's initialisation :
BOOL COpenFilesDlg::OnInitDialog() {
CDialog::OnInitDialog();
<font color=#008000>//...</font>
CString strWindowText;
strWindowText.LoadString(IDS_OFD_FACT_RECSTAT); m_psrFact->SetWindowText(strWindowText);
strWindowText.LoadString(IDS_OFD_DB_RECSTAT); m_psrDataBase->SetWindowText(strWindowText);
strWindowText.LoadString(IDS_OFD_PROMPT); m_psFactPrompt->SetWindowText(strWindowText);
m_psDBPrompt->SetWindowText(strWindowText);
<font color=#FF0000>-></font> strWindowText.LoadString(IDS_OFD_PREVIEW_BTN); m_pbPreviewFact->SetWindowText(strWindowText);
<font color=#008000>//...</font>
}
The real place having problem :
<font color=#0000FF>void</font> CWnd::SetWindowText(LPCTSTR lpszString) {
<font color=#FF0000>-></font> ASSERT(::IsWindow(m_hWnd));
<font color=#0000FF>if</font> (m_pCtrlSite == NULL)
::SetWindowText(m_hWnd, lpszString);
<font color=#0000FF>else</font>
m_pCtrlSite->SetWindowText(lpszString);
}
what does it mean ???
few day ago, this code was working well, and today, when i was updating another class of the program (which have no relation of any order with this one), it stops me there now...
can anyone help of any kind please ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Is m_pbPreviewFact mapped to a valid control? In other words, you've probably got a DoDataExchange() method that looks similar to:
void COpenFilesDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, SOME_ID_HERE, m_pbPreviewFact);
} Look to make sure that SOME_ID_HERE is in the project's resource.h file with a unique number, and that it is also in the dialog's template in the project's .rc file.
toxcct wrote:
few day ago, this code was working well, and today, when i was updating another class of the program (which have no relation of any order with this one), it stops me there now...
What happens if you remove this class? Does the SetWindowText() call start working again?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
yes it does.
i put comments in the code sample, but before i do this into OnInitDialog() , I do :
pbPreviewFact = (CButton*)GetDlgItem(IDC_PREVIEW_BTN); i don't understand... the assert failure is like pbPreviewFact is not a window, but it actually is... !
the worst is that i didn't even modify this class !!!
I was only working on another new dialog, with no relationship with this one...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
i have another strange fact :
if i move the line (in my code) that is giving me an error, i still have an error at the same line !!!, that means on another code line ! any idea ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|