|
I use the GetFilePath() function to find the path of a file in CFileFind class.
The result it returns i store it in a CString class object
e.g. i get c:\temp\mypic.bmp
i need to input this name to a CxImage class object but for that it needs to have "\\" instead of "\"
but when i use the CString function replace it wont work
i have tried
name.replace("\","\\");
name.replace(CString("\"),CString("\\"));
name.replace('\','\\');
Help needed
|
|
|
|
|
This question indicates you don't understand escaping and the role of backslashes in C string literals - when you enter a string in C/C++ source, the '\' character means 'step over the \ and treat the next character specially'
For instance, if you see \" in a C string literal, it means 'insert a double quote character' - as the double quote character is the string delimiter, this is the only way you can enter a double quote charcter.
This use of '\' means that you need to do something special to insert a '\' character in a string - that something special is '\\'.
So if you see this in some C/C++ code:
const char* path = "c:\\temp\\mypic.bmp";
what this means is that path will be assigned the address of the string c:\temp\mypic.bmp - note that the double backslash characters have been transformed to single backslashes.
So - your path doesn't need to be changed once it's in a CString - you can either assign the string literal version I showed above, or read the version with single backslashes using some form of user input, like this:
std::string path;
std::cin >> path;
I can enter c:\temp\mypic.bmp at the console window and that is what'll be assigned to path - no transformation of backslashes will happen from the command line.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Muhammad Hassan Haider wrote: name.replace("\","\\");
Stuart's answer is likely what you need, but in case not, have you tried:
name.replace("\\", "\\\\");
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Thanks
Now i got the joke why after a single space after \ the code worked. Sorry but me new to visual C++.
This site is indeed very helpful.
regards
HASSAN
|
|
|
|
|
offcourse it's quite good site.... welcome abroad dude
|
|
|
|
|
Hello gentlemen,
I am drawing text directly onto the desktop-I am using hooks.
I am capturing these messages from desktop - WM_ERASEBKGND and WM_PAINT
and this is the drawing function:
DrawText(hdc, pszText, strlen(pszText), &rcWindow, DT_RIGHT);
Everythink is working fine - I see text on the desktop. But if I move with a window(which is currently open/active) the text will get bold. Even if I click on the desktop the text on the desktop will get bold.
But if I hit F5 and the desktop is active - the text is normal.
Can you give me a hind, what I am doing wrong?
Thank you.
|
|
|
|
|
daavena wrote: But if I move with a window(which is currently open/active) the text will get bold. Even if I click on the desktop the text on the desktop will get bold.
But if I hit F5 and the desktop is active - the text is normal.
Can you give me a hind, what I am doing wrong?
This happens if you have a wrong font selected into your dc (the one used for hdc). Also make sure the font object has a valid life time.
|
|
|
|
|
Hi there,
I have not looked at C++ code for 7 years and so need a bit of help with this. I basically need to have a dll installed on a client machine. This dll will be called from another program. The dll will need to open a customed browser (basically I need to change it so that it looks more like an application than a browser), the dll will tell the browser the link to connect to. This will call a PHP script on a server which will then display as a normal site. I need to be able to control the focus of the browser window, so if the user presses the close button, it will hide the window, etc.
I have seen that you can achieve most of this using CHTMLView - my question here is how do you incorporate this into a dll? I am using Microsoft Visual studio to set up my projects.
Also is MFC the correct approach when this will be installed on a client machine, or does this even matter?
I have also looked at using IWebBrowser2, but I'm finding it hard to get clear examples!
As you can see I am in need of direction!
Thanks
|
|
|
|
|
Create an MFC DLL project.
Create a dialog template as a resource in the DLL.
Add the web browser control in the dialog.
Create and export a function in the DLL that will show the dialog and call member functions of the browser control like Navigate2 to execute the PHP script.
Now you can load the DLL from an application and call the exported function to display the dialog or customized web browser as you call it.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
hi all,
i am sorry i dont know weather i could ask this question ornot coz, these r the
thinks always run in my mind.
since we call sizeof as operator but y does we use it as sizeof(type) as a function...
plese if any buddy finds it silly forgive me i even tried with google i didnt find it out..
|
|
|
|
|
well ... technically speaking ... every operator IS a function.
So what's the difference ?
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
emilio_grv wrote: well ... technically speaking ... every operator IS a function
In a language like Haskell, yes. In C or C++, not so much - for example, can you show me how to get the address of +, so I can use it as a functor in an STL algorithm?
To elaborate on the Haskell reference - any operator can be used where a function could be used by surrounding it in parentheses. Similarly, any function can be used as an operator by enclosing it in backticks.
For example:
-- Define an addition function
add x y = x + y
-- Define two functions that add integer lists. The first uses the + operator
-- as a function, the second uses add. They are equivalent.
addLists1 :: [Int] -> [Int] -> [Int]
addLists1 l1 l2 = zipWith (+) l1 l2
addLists2 :: [Int] -> [Int] -> [Int]
addLists2 l1 l2 = zipWith add l1 l2
-- The 4 lines of main are equivalent - they all add 3 and 4 with
-- different combination of operator/function and operator/function syntax.
main = do
print (add 3 4)
print ((+) 3 4)
print (3 `add` 4)
print (3 + 4)
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: can you show me how to get the address of +, so I can use it as a functor in an STL algorithm?
Good point! And that's probably the difference that makes the standard deployers to use different therms.
In theory it shold be &operator+ , but that's ambiguous because of its overloading ...
Thanks for pointing this out.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Mmm - thinking about it, you *can* use something like that for class/struct types:
struct XX
{
};
XX operator+( XX const&, XX const& ) {}
struct YY
{
};
YY operator+( YY const&, YY const& ) {}
int main()
{
&static_cast<XX( & )( XX const&,XX const& )>(operator+);
&static_cast<YY( & )( YY const&,YY const& )>(operator+);
}
The static_cast effectively specifies which operator+ you want.
But you can't use that for built-in types.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
hawk23reddy wrote: y does we use it as sizeof(type) as a function...
Because that's what the C and C++ Standard's define. To quote the C++ Standard:
The sizeof operator yields the number of bytes in the object representation of its operand. The operand is either an expression, which is not evaluated, or a parenthesized typeid.
And you're better off using parentheses with expressions, as sizeof has higher precedence than most arithmetic operators. Consider this code:
#include <stdio.h>
int main(int argc, char** argv)
{
printf("%d\n", (int)(sizeof 3+4));
printf("%d\n", (int)(sizeof (3+4)));
}
Because sizeof has higher precedence than +, sizeof 3+4 == (sizeof 3) + 4.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
The parenthesis are required if you are requesting the size of a type (e.g., int ). Otherwise, the parenthesis are optional.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
hi thankx for answer
but y for int (or types) the parenthesis is required is there
any conceret reason
|
|
|
|
|
As I said in this reply[^] - because the standard says so...
But it's probably to simplify parsing - lord knows C++ (and to a degree, C) parsers need all the help they can get.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
sizeof is not a function. It is an operator.
Just because parenthesis is used does mean that it is a function.
In that case if , switch , while , return etc. can be called functions.
This is a excerpt from MSDN -
The operand to sizeof can be one of the following:
A type name. To use sizeof with a type name, the name must be enclosed in parentheses.
An expression. When used with an expression, sizeof can be specified with or without the parentheses. The expression is not evaluated.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hi,
I am working in an application with docking window like Visual Studio 2005 interface. I do it with Visual Studio 2008 and MFC.
The left pane is a CTreeCtrl. I put items in it. When I click on an item, I want to display a form in the view portion of the application.
To do that, I have a member function called void CViewTree::OnTvnSelchanged(NMHDR *pNMHDR, LRESULT *pResult) to catch the event.
To display the form associated with the item clicked, I have to access the view class and after that the document class.
I access the view like that from the CViewTree::OnTvnSelchanged function:
CFrameWnd *pFrameWnd = (CFrameWnd*)AfxGetApp()->m_pMainWnd;
CCDSView* pView;
pView = (CCDSView*)pFrameWnd->GetActiveView();
I get memory leaks, but the program run anyway.
What I can't understand is that the program run under Vista 64 Home premium at home, but not run on an XP computer at office.
I compile it with Net Framework 2.0.
Does it has another way to access the view or document that does not crash my application ?
Thanks,
Claude
|
|
|
|
|
I am working with win32 application. I wanted to copy text using TextOut( ) in to temp DC (not original DC). then after BitBlt( ) copy temp DC in to original DC.
Here is my code please correct it.
case WM_PAINT:
{
HDC hdc;
hdc= CreateCompatibleDC(NULL);
TextOut( hdc,0,0, "Check Text", strlen( "Check Text" ) );
BitBlt(GetDC(hWnd), m_rect.left, m_rect.top, m_rect.right - m_rect.left, m_rect.bottom-m_rect.top,hdc, m_rect.left, m_rect.top, SRCCOPY);
}
|
|
|
|
|
From documentation [^]:
Remarks
A memory DC exists only in memory. When the memory DC is created, its display surface is exactly one monochrome pixel wide and one monochrome pixel high. Before an application can use a memory DC for drawing operations, it must select a bitmap of the correct width and height into the DC. To select a bitmap into a DC, use the CreateCompatibleBitmap function, specifying the height, width, and color organization required.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Modified code:
case WM_PAINT:
{
HDC hdc;
hdc= CreateCompatibleDC(NULL);
HBITMAP hBit = CreateCompatibleBitmap( hdc,m_rect.right- m_rect.left, m_rect.bottom -
m_rect.top );
SelectObject( hdc, hBit );
TextOut( hdc,0,0, "Check Text", strlen( "Check Text" ) );
BitBlt(GetDC(hWnd), m_rect.left, m_rect.top, m_rect.right - m_rect.left, m_rect.bottom-m_rect.top,hdc, m_rect.left, m_rect.top, SRCCOPY);
}
Still the code is not working. Thank You
|
|
|
|
|
zakkas2483 wrote: HBITMAP hBit = CreateCompatibleBitmap( hdc,m_rect.right- m_rect.left, m_rect.bottom -
m_rect.top );
I would use (see, for instance, ... documentation [^] ):
HDC hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
HBITMAP hBit = CreateCompatibleBitmap( hdcScreen,m_rect.right- m_rect.left, m_rect.bottom -
m_rect.top );
CreateCompatibleBitmap( hdcScreen, m_rect.right- m_rect.left, m_rect.bottom -
m_rect.top );
(I don't know if the
CreateCompatibleBitmap( NULL, m_rect.right- m_rect.left, m_rect.bottom -
m_rect.top );
'shortcut' would work).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I have inserted a combo-box control in my project.
In that control vertical scroll bar is present.
I want horizontal scroll bar also.
how to attach horizontal scroll bar to control
thanks
|
|
|
|
|