|
Ali Niaz wrote:
how do I change the font of CDC object
SelectObject() will do that for you.
I see several problems with the code you supplied. The most obvious being the severe potential for memory leaks. See http://www.codeproject.com/gdi/drawtechniques.asp[^]. You might also want to make your font a member variable of your static control's parent window.
CDC* pDC = pCtrlWnd->GetDC();
CString text;
pCtrlWnd->GetWindowText(text);
CFont *pOld = pDC->SelectObject(font);
CSize stringsize = pDC->GetTextExtent(text);
pDC->SelectObject(pOld);
...
See also:
http://www.codeproject.com/cpp/nogetdlgitem.asp[^]
http://www.codeproject.com/gdi/csavedc.asp[^]
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
sorry its ERROR_ACCESS_DENIED
|
|
|
|
|
Hai,
I'm opening a serial port COM1 as follows..
static LPTSTR portname = "\\\\.\\COM1\0";
HANDLE hComPort = CreateFile( portname, GENERIC_READ |GENERIC_WRITE, //bidirectional
0, NULL, //no security OPEN_EXISTING, 0, NULL );
if (hComPort == INVALID_HANDLE_VALUE)
{
sprintf(errstr,"Could not open file (error %d)\n", GetLastError());
MsgBox(errstr);
}
But it is giving me ERROR_INVALID_HANDLE..
What did I miss...pls help..
thanks a lot.
|
|
|
|
|
Is COM1 in use by any other processes?
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I don't think so...I have a controller connected to the com1..i'm trying to send data to the controller..
but how can i find whether any other process is using com1??
thanks a lot.
|
|
|
|
|
Try Portmon from sysinternals, freeware
"An expert is a person who has made all the mistakes that can be made in a very narrow field." - Neils Bohr
|
|
|
|
|
changing icon of an exe file by peplacing icon resource inside the exe file.
It is easy if using UpdateResource().
but my users use all OS including win95 and win98.
the program using UpdateResource() will not work on win95/98 because the function is not supportted on 95/98.
do you have idea to implement the task?
thx
includeh10
|
|
|
|
|
Check Erik Kallen's article Updating Resources on Win9x[^], which provides a replacement for UpdateResource and familiy in Win9x systems. I've used this library in the past and it works like a charm.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
thx
I will try it.
includeh10
|
|
|
|
|
I have a database program that I am working on that uses CString for a description of a product, is there anyway to get more than the 256 charecters or do I have to use a diffrent type of string?
|
|
|
|
|
CString has no size limit, other than available memory. Something else is creating the 256-char limit.
--
I'm Michael Dunn and I approve this post.
Vote Trogdor in oh-four!
|
|
|
|
|
Many Databases limit String fields to 256 characters.
They do offer "MEMO" fields with 64K/unlimited length, but typically they cannot be searched, or indexed.
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist Fold With Us! || Agile Programming | doxygen
|
|
|
|
|
I've just started to program Windows Forms apps in VC++ .NET.
I have prior experience in developing WinForms apps in C# .NET, and the confusion that leads to my question is rooted in the jump from C# to C++.
In C#, when I add a button to the form and create an event handler function this function is visible in my code file.
However, in VC++, the designer is the ".h" file and the InitializeComponent function is also in the ".h" file.
The event handler function is also added in the ".h" file.
My question is this:
What code is added in the project's ".cpp" file? By that, I mean to ask, what part of my program should be coded in the .cpp file?
How do I access the components, say btn1 , btn2 etc from the .cpp file.
|
|
|
|
|
Hi Friends,
How to get the items from the listcontrol on scrolling vertically.
I have dialog with listcontrol. I have created seperate class for listcontrol to catch veticall scrollbar. Once uset start scrolling vertically i have to fetch the row from the Listcontrol.
Please suggest me how to do this.
Your help is appreciated.
Please response to purushotham.chandrashekar@orange.co.uk.
Thanks in advance
|
|
|
|
|
I got problem,i have a programm that stops and sends error!!! But when i try to debug my programm it can't show me the place where the mistake must be. In other words i run my programm, and it shows me the message :"Unhandled exception at 0x77f759e4 in NeuralGas.exe: User breakpoint." and jumps on dbgheap.c on 1807 string. I don't know where the problem, but when i push the continue button it shows next:" Debug Assertation Failed!... _CrtIsValidHeapPointer(pUserData)...
And i noticed one thing - i use the recursive function (quick sort algorithm), when i avoid this function my programm works, may be problem in initial stack??? Where can i make it larger?
I can share my project with everyone who can help - just give me your e-mail.
Please help.............
|
|
|
|
|
Maybe you could provide some more info on how you are catching this error? What version of VC are you using? Are you catching this in the debugger? Is this a release or debug build (I am presuming a debug build from your comment about the assert)? _CrtIsValidHeapPointer probably indicates you have overwritten some memory somewhere or are trying to free memory that's already been freed, or perhaps access memory that's already been freed.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
|
Uhhh, is that a "Thank you - it helped" or a "Thank you, and drop dead" ?
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
Hi all,
I'm trying to create a CMDIChildWnd-derived window with a menu, but I'm having problems.
Here's the relevent code from my CMDIChildWnd-derived class's constructor:
<-------------------------SNIP-----------------------------
...
...
Create( NULL, strTitle, WS_CHILD | WS_OVERLAPPEDWINDOW, rectLocation, ((CMDIFrameWnd*)AfxGetMainWnd()), 0 );
VERIFY( m_menu.LoadMenu( IDR_MY_MENU ) );
if( !SetMenu( &m_menu ) )
{
DWORD dwErrorCode = GetLastError(); //returns 1436
ASSERT( FALSE );
}
DrawMenuBar();
...
...
<-------------------------SNIP-----------------------------
The SetMenu(...) call always fails, with GetLastError() returning 1436. According to MSDN this error code is ERROR_CHILD_WINDOW_MENU - "Child windows cannot have menus.".
Does this mean that it's impossible to add a menu to an CMDIChildWnd that's a child of the main window frame?
If so, what are my options to get around this? The two things I can think of are:
A) Draw my own menu window. No Thanks!
B) convert my CMDIChildWnd class to use the MFC Doc/View pattern - AFAIK the frame window of a CView can have menus.
Any other suggestions or advice?
Cheers,
Pete
|
|
|
|
|
Assuming a few things:
You're not using MFC Doc/View
You DO have a properly configured String table entry, accelerator table entry(ies), ICO entry, and MENU entry in your resource .rc file.
The code below uses a class MyMDIChildWnd declared as
class MyMDIChildWnd : public CMDIChildWnd
You can create a new MDI child in you main CWinApp class like so:
MainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
pFrame->CreateNewChild(
RUNTIME_CLASS(MyMDIChildWnd), IDR_MYMDIWNDTYPE, m_hMDIMenu, m_hMDIAccel);
Where:
IDR_MYMDIWNDTYPE is the resource name for the mdi child wnd in the string table, accelerator table, menu entry, and ICO file
m_hMDIMenu is a member in your CWinApp class of type HMENU
m_hMDIAccel is a member in your CWinApp class of type HACCEL
You should initialize m_hMDIMenu and m_hMDIAccel in your InitInstance app function like so:
HINSTANCE hInst = AfxGetResourceHandle();
m_hMDIMenu = ::LoadMenu(hInst, MAKEINTRESOURCE(IDR_MYMDIWNDTYPE));
m_hMDIAccel = ::LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_MYMDIWNDTYPE));
If you create a new MDI app from the MFC App Wizard it will do all of this for you if you DON'T choose Doc/View support.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
Hi Jim,
First of all, thanks for the help!
OK, so I've followed your advice and am now creating my window like so:
<---------------------------------------SNIP---------------------------->
CMDIFrameWnd* pMainFrame = (CMDIFrameWnd *)AfxGetMainWnd();
C2DTrajMainWnd *pWnd = (C2DTrajMainWnd *)pMainFrame->CreateNewChild(
RUNTIME_CLASS(C2DTrajMainWnd), IDR_2D_TRAJ,
hMDIMenu, hMDIAccel );
<---------------------------------------SNIP---------------------------->
However, the IDR_2D_TRAJ menu is still not being displayed.
During the CreateNewChild call, in CMDIChildWnd::LoadFrame(...) MFC TRACE()'s "Warning: no shared menu/acceltable for MDI Child window." Stepping through the execution, it seems that CMDIChildWnd::LoadFrame(...) is being called with a non-NULL CDocTemplate. I don't understand why. My App does have Doc/View support, but I thought that CDocTemplate's were only used when specifically creating Doc/View instances. Am I missing something here?
Thanks again for the help,
Pete
|
|
|
|
|
I think that my solution only work if you are NOT using MFC's Doc/View. If you are then you have to create the child window another way (which I don't recall how at the moment).
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
I'm sorry, I just stepped through the code again and realized some of what I said in my earlier reply was wrong.
When CMDIChildWnd::LoadFrame(...) is called it cannot get a valid CMultiDocTemplate instance from the CreateContext that it's passed, so it says it cannot create the menu/acceltable.
Sorry for the confusion!
|
|
|
|
|
I guess the subject above says it all. I'm trying to find out which message to handle for my CMainFrame being minimized. I had the application where it goes to the system tray when closed if the user has that option checked. But I've recently been informed that it would be better if it only went to the system tray when minimized. Thanks in advance!!
Who are all these people and what are they doing in my house?...Me in 30 years, inside a grocery store
My articles[^]
bdiamond
|
|
|
|
|
Maybe look at WM_SYSCOMMAND and see if the SC_MINIMIZE is set? Another option is to look at WM_SHOWWINDOW or possibly WM_WINDOWPOSCHANGED. Check MSDN docs to be sure (or there's always the tried and true test app to hack around with to test it).
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|