|
There are two possible ways of implementing this (that I know of). Both of them include trapping either one or both of the MOUSEMOVE or SETCURSOR messages.
You can either trap them at level of the main FrameWnd or in the Button (I would personally prefer to subclass the Button and trap it in there so I could reuse that new button in other parts of my code). In the case of trapping it in the FrameWnd (probably trapping MOUSEMOVE after you know the cursor is in the FrameWnd - using SETCURSOR to set some flag) you then need to work out if the mouse is over the button to change to the IBEAM cursor - as well as not over the button to change it back!!).
There are probably other pitfalls to worry about that my simple explanation doesn't cover but they would be the two basic approaches to consider.
Regards,
Gary Menzel
==================
The original message was:
How to change mouse cursor to "IDC_IBEAM" when move mouse pass the button?
<cut>
|
|
|
|
|
I developed a dll with a class exported. In my application, I declare an object of it and call one of its member functions. I got the following link time error:
error LNK2001: unsolved external symbol "__declspec(dllimport) public:void __thiscall testclass::function(char const *)" (__imp_?Export@testclass@@QAEXPBD@Z)
When I look at the dll, I see
...
314 139 00001131 ?function@testclass@@QAEXPBG@Z
Apparently there is a mismatch here. I would like to know the reason of this problem. Any ideas?
|
|
|
|
|
Hi!
You have to declare the class as "__declspec(dllimport)". And you also have to include the *.LIB file for your DLL. You can do this in the Link section of your project settings or by inserting the pragama in the source code. For example:
#pragma comment(lib, "MyClass.lib")
Regards,
Alex Gorev,
Dundas Software.
==================
The original message was:
I developed a dll with a class exported. In my application, I declare an object of it and call one of its member functions. I got the following link time error: error LNK2001: unsolved external symbol "__declspec(dllimport) public:void __thiscall testclass::function(char const *)" (__imp_?Export@testclass@@QAEXPBD@Z)
When I look at the dll, I see
... 314 139 00001131 ?function@testclass@@QAEXPBG@Z
Apparently there is a mismatch here. I would like to know the reason of this problem. Any ideas?
|
|
|
|
|
How could I make status bar to show tool tips for its panes?
Regards,
Stefan
----------
|
|
|
|
|
Stefan,
If the items in your status bar have ID's, then you can add them to a tooltip object like so:
CWnd* pSomeItem = GetDlgItem(IDC_SOMEID);
m_tooltip.Create(this);
m_tooltip.Activate(TRUE);
m_tooltip.AddTool(&pSomeItem, "A tool tip");
Then, in your mainframe do the following:
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
// Let the ToolTip process messages.
m_tooltip.RelayEvent(pMsg);
return CMDIFrameWnd::PreTranslateMessage(pMsg);
}
This might work.
==================
The original message was:
How could I make status bar to show tool tips for its panes?
Regards, Stefan ----------
|
|
|
|
|
Have you tried:
SendMessage
(
hStatusBarWnd,
SB_SETTIPTEXT,
(WPARAM)(INT)iStatusBarPart,
(LPARAM)(LPCTSTR)lpcszTextToDisplayAsTooltip
);
code sequence?
The status bar window must be created (as in the following example) using
g_hStatusBarWnd =
CreateWindowEx
(
0L,
STATUSCLASSNAME,
0,
WS_CHILD | WS_VISIBLE | SBT_TOOLTIPS,
0,
0,
0,
0,
hParentWnd,
(HMENU)ID_STATUSBAR,
g_hInstance,
0
);
For more information, you can check the WindowsNT System Manager, where you can find, among other stuff like this, also something about status bar APIs.
All the best,
Sardaukar
==================
The original message was:
How could I make status bar to show tool tips for its panes?
Regards, Stefan ----------
|
|
|
|
|
Hi,
does anyone know how to to fnd out whether a string matches a wildcard pattern? Something like
int iMatch = wcmatch("??ES*H", "DOESMATCH");
There are lots of functions that use wildcards on filenames or database tables - but I didn' find anything for strings.
Any ideas or sample code welcome!
|
|
|
|
|
Hi
I don't know any existing function which can
do this but it's very easy to write it yourself.
Here is the fully working example:
bool strmatch(char *lpszWildCard, char *lpszString)
{
if(lpszWildCard == NULL || lpszString == NULL) {
return false;
}
while(*lpszWildCard != NULL && *lpszString != NULL) {
if(*lpszWildCard == '?') {
}
else if(*lpszWildCard == '*') {
++ lpszWildCard;
while(*lpszWildCard != *lpszString && *lpszString != NULL) {
++lpszString;
if(*lpszWildCard == NULL || *lpszString == NULL)
break;
}
}
else if(*lpszWildCard != *lpszString) {
return false;
}
++ lpszString;
++ lpszWildCard;
}
if(*lpszString == NULL) {
while(*lpszWildCard == '*') {
++lpszWildCard;
}
}
if(*lpszWildCard == *lpszString) {
return true;
}
return false;
}
Let me know if you have any problems with this code.
Alex Gorev,
Dundas Software.
==================
The original message was:
Hi, does anyone know how to to fnd out whether a string matches a wildcard pattern? Something like int iMatch = wcmatch("??ES*H", "DOESMATCH"); There are lots of functions that use wildcards on filenames or database tables - but I didn' find anything for strings. Any ideas or sample code welcome!
|
|
|
|
|
Hi Alex,
thanks for your code. It is ok for the most cases. But there are many cases in which strmatch() will fail:
strmatch("*?s*", "doesmatch");
doesn't work, because after '*' explicit match to '?' is searched.
strmatch("*to*", "doesmatchtoo");
doesn't work because '*t' finds the first 't' and compares "tchtoo" with "to*" - result: no match.
Due to a bug in the '*' case, the function will return false on all wildcards, that end on '*':
else if(*lpszWildCard == '*')
{
++ lpszWildCard;
while(*lpszWildCard!=*lpszString && *lpszString!=NULL)
{
++lpszString;
// this is WRONG
//if(*lpszWildCard == NULL || *lpszString == NULL)
// break;
// must be like this:
if(*lpszWildCard == NULL)
return TRUE; // rest DOES match to '*'!
if (*lpszString == NULL)
break;
}
}
I suppose, that a 100% solution requires recursion and is NOT so easy to realize!
-- Thomas
==================
The original message was:
Hi
I don't know any existing function which can do this but it's very easy to write it yourself.
Here is the fully working example:
bool strmatch(char *lpszWildCard, char *lpszString) { if(lpszWildCard == NULL || lpszString == NULL) { return false; }
while(*lpszWildCard != NULL && *lpszString != NULL) { if(*lpszWildCard == '?') { } else if(*lpszWildCard == '*') { ++ lpszWildCard; while(*lpszWildCard != *lpszString && *lpszString != NULL) { ++lpszString; if(*lpszWildCard == NULL || *lpszString == NULL) break; } } else if(*lpszWildCard != *lpszString) { return false; }
++ lpszString; ++ lpszWildCard; }
if(*lpszString == NULL) { while(*lpszWildCard == '*') { ++lpszWildCard; } }
if(*lpszWildCard == *lpszString) { return true; }
return false; }
Let me know if you have any problems with this code.
Alex Gorev, Dundas Software.
================== The original message was: Hi, does anyone know how to to fnd out whether a string matches a wildcard pattern? Something like int iMatch = wcmatch("??ES*H", "DOESMATCH"); There are lots of functions that use wildcards on filenames or database tables - but I didn' find anything for strings. Any ideas or sample code welcome!
|
|
|
|
|
Hi Thomas!
Of course my example will not work correctly in many situations,
I've spend about 5 minutes writing it and my main task was to give
an idea how you can do this.
If you really want to make something like this you should spend much
more time coding and testing. You've mention about the recursion but
I don't think it's the right place for it, the only place when you can use
it
is while testing for the '*' but I don't see big advantage comparing to the
usual loop.
So spend some time, add several IFs and WHILEs and it will work great
for you. And don't try to find an existing function, it's always better to
do something small like this yourself, because you can always adjust it
to your own needs.
Don't forget to post the results on the CodeProject and I will also took
part in testing...
Regards,
Alex Gorev,
Dundas Software.
==================
The original message was:
Hi Alex,
thanks for your code. It is ok for the most cases. But there are many cases in which strmatch() will fail:
strmatch("*?s*", "doesmatch"); doesn't work, because after '*' explicit match to '?' is searched.
strmatch("*to*", "doesmatchtoo"); doesn't work because '*t' finds the first 't' and compares "tchtoo" with "to*" - result: no match.
Due to a bug in the '*' case, the function will return false on all wildcards, that end on '*':
else if(*lpszWildCard == '*') { ++ lpszWildCard; while(*lpszWildCard!=*lpszString && *lpszString!=NULL) { ++lpszString; // this is WRONG //if(*lpszWildCard == NULL || *lpszString == NULL) // break; // must be like this: if(*lpszWildCard == NULL) return TRUE; // rest DOES match to '*'! if (*lpszString == NULL) break; } }
I suppose, that a 100% solution requires recursion and is NOT so easy to realize!
-- Thomas ================== The original message was: Hi
I don't know any existing function which can do this but it's very easy to write it yourself.
Here is the fully working example:
bool strmatch(char *lpszWildCard, char *lpszString) { if(lpszWildCard == NULL || lpszString == NULL) { return false; }
while(*lpszWildCard != NULL && *lpszString != NULL) { if(*lpszWildCard == '?') { } else if(*lpszWildCard == '*') { ++ lpszWildCard; while(*lpszWildCard != *lpszString && *lpszString != NULL) { ++lpszString; if(*lpszWildCard == NULL || *lpszString == NULL) break; } } else if(*lpszWildCard != *lpszString) { return false; }
++ lpszString; ++ lpszWildCard; }
if(*lpszString == NULL) { while(*lpszWildCard == '*') { ++lpszWildCard; } }
if(*lpszWildCard == *lpszString) { return true; }
return false; }
Let me know if you have any problems with this code.
Alex Gorev, Dundas Software.
================== The original message was: Hi, does anyone know how to to fnd out whether a string matches a wildcard pattern? Something like int iMatch = wcmatch("??ES*H", "DOESMATCH"); There are lots of functions that use wildcards on filenames or database tables - but I didn' find anything for strings. Any ideas or sample code welcome!
|
|
|
|
|
Hi Thomas,
Try this method, maybe it will work correctly:
bool strmatch(char *lpszWildCard, char *lpszString)
{
if (lpszWildCard == NULL || lpszString == NULL)
return false;
char *p;
if ((p = strpbrk(lpszWildCard, "?*")) == NULL)
return 0 == strcmp(lpszWildCard, lpszString);
if (0 != strncmp(lpszString, lpszWildCard, p - lpszWildCard))
return false;
lpszString += p - lpszWildCard;
if (*p == '?')
return (*lpszString != NULL) && my_strmatch(++p, ++lpszString);
while (true)
{
while (*p == '*') ++p;
if (*p == NULL)
return true;
if (*p != '?') break;
++lpszString;
++p;
}
while (true)
{
if ((lpszString = strchr(lpszString, *p)) == NULL)
return false;
if (*lpszString == NULL)
return false;
if (my_strmatch(p + 1, ++lpszString))
return true;
}
return false;
}
Regards,
Serguei Velikevitch,
Dundas Software.
==================
The original message was:
Hi Alex,
thanks for your code. It is ok for the most cases. But there are many cases in which strmatch() will fail:
strmatch("*?s*", "doesmatch"); doesn't work, because after '*' explicit match to '?' is searched.
strmatch("*to*", "doesmatchtoo"); doesn't work because '*t' finds the first 't' and compares "tchtoo" with "to*" - result: no match.
Due to a bug in the '*' case, the function will return false on all wildcards, that end on '*':
else if(*lpszWildCard == '*') { ++ lpszWildCard; while(*lpszWildCard!=*lpszString && *lpszString!=NULL) { ++lpszString; // this is WRONG //if(*lpszWildCard == NULL || *lpszString == NULL) // break; // must be like this: if(*lpszWildCard == NULL) return TRUE; // rest DOES match to '*'! if (*lpszString == NULL) break; } }
I suppose, that a 100% solution requires recursion and is NOT so easy to realize!
-- Thomas ================== The original message was: Hi
I don't know any existing function which can do this but it's very easy to write it yourself.
Here is the fully working example:
bool strmatch(char *lpszWildCard, char *lpszString) { if(lpszWildCard == NULL || lpszString == NULL) { return false; }
while(*lpszWildCard != NULL && *lpszString != NULL) { if(*lpszWildCard == '?') { } else if(*lpszWildCard == '*') { ++ lpszWildCard; while(*lpszWildCard != *lpszString && *lpszString != NULL) { ++lpszString; if(*lpszWildCard == NULL || *lpszString == NULL) break; } } else if(*lpszWildCard != *lpszString) { return false; }
++ lpszString; ++ lpszWildCard; }
if(*lpszString == NULL) { while(*lpszWildCard == '*') { ++lpszWildCard; } }
if(*lpszWildCard == *lpszString) { return true; }
return false; }
Let me know if you have any problems with this code.
Alex Gorev, Dundas Software.
================== The original message was: Hi, does anyone know how to to fnd out whether a string matches a wildcard pattern? Something like int iMatch = wcmatch("??ES*H", "DOESMATCH"); There are lots of functions that use wildcards on filenames or database tables - but I didn' find anything for strings. Any ideas or sample code welcome!
|
|
|
|
|
Regular expressions will give you what you need (and a lot more). I don't know if this site has already received classes to do that but I know there are some in CodeGuru (http://www.codeguru.com/string/index.shtml).
Good luck!
Alvaro
|
|
|
|
|
Hello everybody and thanks for all tips and code.
After all I wrote my own function that serves my needs.
It is capable to handle ? and * correctly - as I think.
Here it is:
int wcmatch(const char *pPattern, const char *pStr;
const char *mystrstr(const char *pPattern, const char *pStr, int *pLen;
//similiar to strstr() but:
// + the search pattern ends at a '\0' or a '*'.
// + '?' matches to every character != '\0'
// + Return value is pointer to the first char in pStr
// that belongs to the first occurence of pPattern
// or NULL if not found.
//
// Example: mystrstr("a?c*xyz", "123456abcdefg", &len) = "abcdefg"
// len==3.
const char *mystrstr(const char *pPattern, const char *pStr, int *pLen)
{
int iMatch;
const char *pStart=pStr, *pp, *ps;
if (pLen)
*pLen = 0;
if (!pPattern || !pStr)
return FALSE;
for (pStart=pStr; *pStart; pStart++)
{
ps = pStart;
pp = pPattern;
iMatch = TRUE;
while (iMatch)
{
switch (*pp)
{
case '*':
case '\0':
if (pLen)
*pLen = ps - pStart;
return pStart;
break;
case '?':
if (*ps)
{
pp++; ps++;
}
else
iMatch = FALSE;
break;
default:
if (*pp == *ps)
{
pp++; ps++;
}
else
iMatch = FALSE;
break;
}
}
}
return FALSE;
}
int wcmatch(const char *pPattern, const char *pStr)
{
if (!pPattern || !pStr)
return FALSE;
int iWildcardMode = FALSE,
iLen;
const char *pStarMatchStart;
while (*pPattern && *pStr)
{
switch (*pPattern)
{
case '?':
pPattern++; pStr++;
break;
case '*':
// Switch to wildcard-mode. Keep this mode until a
// character diffrent to '?' and '*' is found.
iWildcardMode = TRUE;
pPattern++;
break;
default:
if (iWildcardMode)
{
iWildcardMode = FALSE;
if (pStarMatchStart = mystrstr(pPattern, pStr, &iLen))
{
pPattern += iLen;
pStr = pStarMatchStart + iLen;
}
else
return FALSE;
}
else
{
if (*pPattern != *pStr)
return FALSE;
pPattern++; pStr++;
}
break;
}
}
if (*pPattern == *pStr)
return TRUE;
if (*pPattern == '\0')
{
if (iWildcardMode)
return TRUE; // Last char of pattern was '*'
else
return FALSE; // String has additional non matching chars. No match.
}
if (*pStr=='\0')
{
// This is a match, if only '*'s follow
while (*pPattern == '*')
pPattern++;
if (*pPattern != '\0')
return FALSE; // Pattern has additional non matching chars. No match.
}
return TRUE;
}
==================
The original message was:
Hi, does anyone know how to to fnd out whether a string matches a wildcard pattern? Something like int iMatch = wcmatch("??ES*H", "DOESMATCH"); There are lots of functions that use wildcards on filenames or database tables - but I didn' find anything for strings. Any ideas or sample code welcome!
|
|
|
|
|
Hi,
I want to move my caret in my CEditView window but I can only
show or hide the caret, not being able to move it. Does anyone know
how to move it?
Thanks in advance,
Hung
|
|
|
|
|
|
CRichEditCtrl::SetSel(startPos, endPos);
If you don't want any highlighted text, then make sure that startPos == endPos.
|
|
|
|
|
Hi
I have some problem when run this program (press F5) when I click
Run button then close program in suddenly. When return to VC++
it tells Detect Memory leak !!! and dump object ...
I don't understand how it occur ??? and What is it ???
My program want Stop button that terminate running job not terminate
program.
Thanks
bool stop;
void CPumpMessageView::OnRun() // clicked Run Button
{
stop=false;
for(int i=0; i<100; i++) {
PumpMessage();
if(stop)
break;
else
Sleep(250);
}
}
void CPumpMessageView::PumpMessage()
{
MSG msg ;
while (PeekMessage (&msg, 0, 0, 0, PM_NOREMOVE))
{
if (!(AfxGetApp()->PumpMessage()))
{
// regenerate WM_QUIT for main message loop.
::PostQuitMessage(0);
break;
}
}
// let MFC do its idle processing
LONG lIdle = 0;
while (AfxGetApp()->OnIdle(lIdle++));
}
void CPumpMessageView::OnStop() // clicked Stop Button
{
stop=true;
}
|
|
|
|
|
The problem does not seem to be with this code. If you dynamically created an object of type CPumpMessageView make sure you destroy the object before the application object terminates. If this is not your problem please post the object dump so that I can better understand the problem.
|
|
|
|
|
I'm looking for the network monitor 2.0 SDK Could you tell me where can I get it?
|
|
|
|
|
I have used a DB Grid control and it is working fine but it has got one problem. When I run the application, the select database dialog popups! How can I get rid of this dialog?
|
|
|
|
|
Hi,
The following code snippit, produces an embeded excel object. My question is how do I manipulate it?
#import "C:\Program Files\Microsoft Office\Office\EXCEL9.OLB" rename ("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename ("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces//, raw_native_types
snip.....
WORDLib::_ApplicationPtr pWrd = m_pParentApp;
pWrd->Visible = VARIANT_TRUE;
WORDLib::_DocumentPtr pDoc = pWrd->ActiveDocument;
COleVariant vClassType = "Excel.Sheet";
WORDLib::InlineShapePtr pShp = pDoc->InlineShapes-
>AddOLEObject ( vClassType );
WORDLib::OLEFormatPtr pFmt = pShp->OLEFormat;
_bstr_t bTyp = pFmt->ClassType;
/*
** pFmt->ClassType == "Excel.Sheet.8"
**
** pFmt->Object returns an IDispatch -- but to what ????
*/
Excel::_WorksheetPtr pSheetptr = pFmt->GetObject(); // pFmt-
>Object;
pSheetptr->Range["A1"]->Font->Bold = VARIANT_TRUE; // This fails with Code = 80020003 ( Member not found. )
The functions do exist.
If I do this by creating an excel app ptr, then get active worksheet()
I can then call these functions to manipluate the work sheet.
What I suspect is the GetObject is returning something that can be used to get the app ptr or wrksheet ptr.
Regards
Ian G
/*
Object Property
Returns the object that represents the specified OLE
object's top-level interface.
This property allows you to access the properties and
methods of the application in
which an OLE object was created. Read-only.
Remarks
Use the TypeName function to determine the type of
object this property returns for a
specific OLE object.
Object Property Example
This example displays the type of object contained in
shape one on slide one in the
active presentation. Shape one must contain an OLE
object.
MsgBox TypeName(ActivePresentation.Slides(1) _
.Shapes(1).OLEFormat.Object)
This example displays the name of the application in
which each embedded OLE object
on slide one in the active presentation was created.
For Each s In ActivePresentation.Slides(1).Shapes
If s.Type = msoEmbeddedOLEObject Then
MsgBox
s.OLEFormat.Object.Application.Name
End If
Next
This example adds text to cell A1 on worksheet one in
the Microsoft Excel workbook
contained in shape three on slide one in the active
presentation.
With ActivePresentation.Slides(1).Shapes(3)
.OLEFormat.Object.Worksheets(1).Range
("A1").Value = "New text"
This would indicate that its of type Excel application ?
*/
|
|
|
|
|
Hi
I am displaying information of a simple Cperson class
in a dailog box - which is better practice to pass the
information by parameter to the dailog via DDX or to
pass a pointer to the Cperson object and let the dailog
box extract the data ?
Thanks
|
|
|
|
|
It would definately take less processor time to pass a reference or a pointer, so this would be the best option in that case. However, you can also have a dialog box class that accepts a Cperson class in its constructor, and then is permenantly linked with that Cperson or a copy of it. It is mostly a matter of opinion and depends on what you intend to use the dialog for.
==================
The original message was:
Hi
I am displaying information of a simple Cperson class in a dailog box - which is better practice to pass the information by parameter to the dailog via DDX or to pass a pointer to the Cperson object and let the dailog box extract the data ?
Thanks
|
|
|
|
|
My suggestion would be pass a reference to the object and let the Dialog interrogate the object directly for the data. Why pass n parameters when half the raison d'etre for the object is the encapsulation of this data? Pass a reference.
In fact, there are probably ways to display the data in a dialog in such a way (combined with a bright method or two in the CPerson object) such that you can change the internal data represented in the CPerson without having to modify the Dialog that displays it. One of the stratagems of the experienced programmer is to try to devise ways to insulate himself from changes in data structure within object classes - this tends to happen, and the less impact it has on code scattered across the project, the better.
|
|
|
|
|
Hi,
I would like to know how I exit a program (the way it should) and than run another program.
I'm planning to use this after a user has downloaded an update from within the program and than letting him start the update. For that, the running program has to be closed.
Could anyone give me a suggestion?
|
|
|
|
|