|
Finally, I got it. The code is like this:
RECT rc;
m_cStatic.GetClient(&rc);
m_cStatic.ClientToScreen(&rc);
ScreenToClient(&rc);
pDC->SelectStockObject(BLACK_BRUSH);
pDC->Rectangle(&rc);
But the problem is that: the black rectangle will not be displayed, unless I deselect the visible option of the static control. I tried use pDC->SetBkMode(OPAQUE) or TRANSPARENT, but it doesn't help. It seems to me that the static control hides the black rectangle. Why?
Tim Smith wrote:
Do I feel lucky?
Yeah, sure, I do feel lucky to have such a wonderful forum to go.
|
|
|
|
|
Tim Smith already answered your question; i'm just going to suggest that you use OnCtlColor() to change the background of the static control instead of doing it this way. You will more likely get the results you are looking for.
--------
Sip my mind.
|
|
|
|
|
Yeah, that was in the back of my mind too.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Got it. Overwriting OnCtlColor is cool and easy.
Thank you!
|
|
|
|
|
You are trying to draw this rectangle with the screen coordinates but in OnDraw() member function pDC->Rectangle(&rc) draws with client coordinates...
kozlu
|
|
|
|
|
Is there a way, a user can be prevented from re-sizing or moving a specific window. In this case, the window is a CFrameWnd derived object.
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
|
The easiest way to prevent a window from being sized is to remove the WS_THICKFRAME style from the frame window and replace it with a WS_BORDER style.
The easiest way to prevent a window from being moved is to handle the WM_NCHITTEST message, and convert all HT_CAPTION styles that are returned by DefWindowProc to HT_BORDER. Windows only allows the window to be moved when the cursor is selected over a caption region. The inverse of this, if you make all HT_CLIENT results return a HT_CAPTION instead, the user can move the window whenever they click inside any portion of the window, not jsut the caption.
For finer control in what you do, you can override the WM_ENTERSIZEMOVE message, and filter off any processing for sizing or moving before it even starts. That way a user cannot start dragging the window, you nip it in the bud.
If you were to override the WM_SIZE message, the window would be resized, then it would snap back into place after you handled the message.
Good luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
In the case of SDI MFC project, how could I remove the WS_THICKFRAME style?
|
|
|
|
|
lucy wrote:
In the case of SDI MFC project, how could I remove the WS_THICKFRAME style?
Override PreCreateWindow
Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
|
|
|
|
|
For prevent re-sizing:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style = WS_DLGFRAME ;
return TRUE;
}
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
Oh, yep, this works like a magic. I added one more style
WS_SYSMENU so that on the title bar, I have the small "X" to close the program.
Thank you, all you guys.
|
|
|
|
|
I have a dialog box in which I have a group of two radio buttons and I have an edit box which takes an int as the # of files to open. I also have many other edit boxes with browse buttons to look for a file that should be opened. When I select one of the radio buttons and then put a number in my edit box for integers, the selections don't remain there after I do something else in the dialog box. Such as if I click one of the browse buttons to find the file and then place it in the appropriate other edit box, the radio button gets deselected and the number in the edit box disappears. How can I make the number and the radio button selection remain?
|
|
|
|
|
|
Hello,
I'm writing code to control mechanical syring pump and using the predefined functions written in the .lib file and .dll file provided by the company. I'm new to visual c++ .net and I don't know how to include .lib file into the project. Can anyone help my on this? I try to add it directly in the Resource Folder but it says that the file is invalid and it never shows up as something to add in the first place. Any help would be appreciated. Thanks in advance/
|
|
|
|
|
Project--->proprerties--->Linker---->Additional Dependencies
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
I am trying to create an MFC application that uses a List Control Box in a pop-up dialog box. When a Button is pressed in a pop-up dialog box a List Control Box is supposed to be populated with information from an Access database. However when the Button is pressed the program just hangs and is unresponsive.
But the puzzling thing is that when the exact same code is used on the main dialog (IDD_MAIN_DIALOG) to an identical List Control Box and Button it works perfectly, with no hanging. I have included the code for the Pop-up dialog box.
Any help is greatly appreciated
Aoife
*****************************************************
#include "stdafx.h"
#include "Main.h"
#include "DialogBoxDlg.h"
#include "afxdb.h"
#include "odbcinst.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDialogBoxDlg dialog
CDialogBoxDlg ::CDialogBoxDlg (CWnd* pParent /*=NULL*/)
: CDialog(CDialogBoxDlg ::IDD, pParent)
{
//{{AFX_DATA_INIT(CDialogBoxDlg )
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDialogBoxDlg ::DoDataExchange(CDataExchange*pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDialogBoxDlg )
// NOTE: the ClassWizard will add DDX and DDV calls here
DDX_Control(pDX, IDC_SMS_MYLISTCONTROL,m_SMSMyListControl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDialogBoxDlg , CDialog)
//{{AFX_MSG_MAP(CDialogBoxDlg )
ON_BN_CLICKED(IDC_BUTTON, OnButtonPressed)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialogBoxDlg message handlers
void CDialogBoxDlg ::OnButtonPressed()
{
CDatabase database;
CString SqlString;
CString sNumber, sSender, sDate, sMessage;
CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)";
CString sDsn;
CString sFile = "c:\\THEPROJECT\\Interface\\Project_Databases.mdb";
int iRec =0;
//Build ODBC connection string
sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile);
TRY
{
//Open the Database
database.Open(NULL,false,false,sDsn);
//Allocte the Record set
CRecordset recset (&database);
//Build the SQL statement
SqlString = "SELECT Number, Sender, Date, Message "
"FROM pc_Inbox";
//Execute the query
recset.Open(CRecordset::forwardOnly,SqlString,CRecordset::readOnly);
//Populate the Grids
ListView_SetExtendedListViewStyle(m_SMSMyListControl,LVS_EX_GRIDLINES);
//Column width and heading
m_SMSMyListControl.InsertColumn(0, "SMS No.",LVCFMT_LEFT, -1,0);
m_SMSMyListControl.InsertColumn(1, "Sender",LVCFMT_LEFT, -1,1);
m_SMSMyListControl.InsertColumn(2, "Date",LVCFMT_LEFT, -1,2);
m_SMSMyListControl.InsertColumn(3, "Message",LVCFMT_LEFT, -1,3);
m_SMSMyListControl.SetColumnWidth(0, 100);
m_SMSMyListControl.SetColumnWidth(1, 100);
m_SMSMyListControl.SetColumnWidth(2, 100);
m_SMSMyListControl.SetColumnWidth(3, 200);
//Loop through each record
while (!recset.IsEOF())
{
//Copy each column into a variable
recset.GetFieldValue("Number",sNumber);
recset.GetFieldValue("Sender",sSender);
recset.GetFieldValue("Date",sDate);
recset.GetFieldValue("Message",sMessage);
//Insert values into the list control
iRec = m_SMSMyListControl.InsertItem(0,sNumber,0);
m_SMSMyListControl.SetItemText(0,1,sSender);
m_SMSMyListControl.SetItemText(0,2,sDate);
m_SMSMyListControl.SetItemText(0,3,sMessage);
//Go to the next record
recset.MoveNext();
}
//Close the Database
database.Close();
}
CATCH(CDBException, e)
{
//If a database exception occured, show an error message
AfxMessageBox("Database error: "+e->m_strError);
}
END_CATCH;
}
|
|
|
|
|
Um... have you tried stepping into OnButtonPressed() ? Where does it hang?
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Please be patient with me, I'm a student!
I have tried stepping into it, but...
I decided to step through the Button and List Control box (In the Main Dialog)that works properly so that I could see how that one worked. But while stepping through it pop-up boxes appear requesting that I find the source for certain .C files. I searched my computer for them but couldn't find them. I do have MSDN VC++ libraries installed. If I cancel out of these boxes the debugger starts going through Assembly code.
Why does this happen while debugging, when that part of the application works properly when the application is executed?
So I can't debug the OnButtonPressed() because the same Find Source pop-up boxes appear.
|
|
|
|
|
After a quick lesson in debugging..
I have found that it is hanging on this line,
//Populate the Grids
ListView_SetExtendedListViewStyle(m_SMSMyListControl,LVS_EX_GRIDLINES);
|
|
|
|
|
Perhaps it's dying because you haven't yet inserted the columns? Try setting the LVS_EX_GRIDLINES style after you define the control's columns. Hope this helps!
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Hi there,
I am using the ADO calls to connect to my database and have the following call:
_variant_t varFieldValue;
varFieldValue = m_pRecord->Fields->GetItem((long)nCol)->GetValue();
Now, at some point , I like to convert this varFieldValue to a string, preferably a STL string.
Any tips on how to do this?
thanks
|
|
|
|
|
this should get your variant value into a CString.
CString strTest;
strTest = varFieldValue.bstrVal;
|
|
|
|
|
Nope, that won't work if the variant isn't already a VT_BSTR.
However using static_cast <_bstr_t> (v) will convert the variant to a BSTR and return the string.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
I'm already familiar with the basics of c++ like pointers, multiple inheritance,... but nothing with "windows".
For the last couple of years, I've been programming in java, and I dare to say this, I know it all (almost ).
My question is this: Are there any migration tutorials for java -> c++/vc++?
Bluute tette!
|
|
|
|
|