|
How can I make use of CRebar and CToolBar in a dialog-based window? (I dont want to use CRebarCtrl/CToolBarCtrl)
ps: does MS intend to support MFC any further or is it going the way of the dodo?
|
|
|
|
|
Check MFC sample called DLGCBR32.
UGenn wrote:
does MS intend to support MFC any further or is it going the way of the dodo?
New version of MFC is included in VS.NET.
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
My app creates html fire reports when it surprisingly enough detects a fire. I need the enum all the printers and print this html fire report inside a CWebBrowser2 controls on all the connected printers. I do this by setting the default printer, and printing, and then setting the default printer again etc.
I use the SetDefaultPrinter command. This worksd fine. The problem is though that it only works in Win2000+. MSDN says that I should use the following code on < Win2000
GetProfileString(TEXT("Windows"),TEXT("Device"),_T(",,,"),m_szName, COUNTOF(m_szName));
WriteProfileString(TEXT("Windows"),TEXT("Device"),pszPrinterName ));
#if WM_WININICHANGE != WM_SETTINGCHANGE
SendNotifyMessage(HWND_BROADCAST,WM_WININICHANGE,0,(LPARAM)szWindows);
#endif
SendNotifyMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,(LPARAM)szWindows);
I can't seem to get this to work I'm not quite sure what I should set szWindows to....
Can anyone help please? Thanks
Jeremy Davis
http://www.astad.org
|
|
|
|
|
Hello,
Can any one point me to a real time programming tutorial with vc?
tnx
|
|
|
|
|
Windows OSs are not real-time by nature, so your question seems a little unclear to me. Could you please ellaborate some more?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
Can anyone please give me any comment or solution to this situation??
In my program, I've used multithread (many clients) to send message to one thread(Server). However, I realized that only the first client can get access to the server from start to end, other clients are always blocked. Can anyone help me to solve this problem, so that all clients can access the server??
The following is the code of the server:
if ( svrSocket.Accept(socket))
AfxMessageBox("Socket is created Succesfully");
while (...)
flag = socket.Receive(buff,sizeof(buff));
....
Please HELP! Thank you!!
|
|
|
|
|
If you have the server thread processing the requests for one client in a tight loop, it can't accept other connections.
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?
|
|
|
|
|
hkl wrote:
flag = socket.Receive(buff,sizeof(buff));
Execution in this thread blocks until Receive can get (sizeof(buff)) bytes of data. You should probably use CAsyncSocket; it would probably meet your requirements better.
Jon
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
That is because the thread Accept() ing the connection is the same that Receive() s the request on the socket.
You must dispatch the socket returned by Accept() first param to another thread, which will Receive() , preventing the server thread from blocking.
If you have problem understanding this concept, I suggest that you read this:
http://www.codeproject.com/useritems/winsockintro03.asp
Michel
If I am wrong or said something stupid, I apologize in advance
|
|
|
|
|
that's all,
i want to know if it possible pass a array of doubles like parameter by reference to a function and in the case it was possible how.
Thanks in advance.
|
|
|
|
|
You just want to change the array elements in the function?
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
Yes i want, if it's possible i want pass an array where after an operations the result was back in this array.
|
|
|
|
|
Hi,
I need to pass an IPicture through process boundaries, but IPicture cannot be marshaled so I decide to pass it over one Stream created on one HGlobal..., what I did in the server is:
STDMETHOD(SetMetafile)(VARIANT GlobMeta)
{
HGLOBAL hGlob = (HGLOBAL) GlobMeta.lVal;
IStream *pStream = NULL;
HRESULT hr = ::CreateStreamOnHGlobal(hGlob, TRUE, &pStream);
if(!pStream) return S_FALSE;
if(!SetMeta(pStream, &_Pict)) {
return S_FALSE;
}
pStream->Release();
return S_OK;
}
BOOL SetMeta(IStream *pStream, IPicture **Pict)
{
BOOL bResult = FALSE;
CComPtr<IPictureDisp> pic;
LARGE_INTEGER l;
l.QuadPart =0;
pStream->Seek(l, STREAM_SEEK_SET, NULL);
OleLoadPicture(pStream, l.LowPart, FALSE, IID_IPictureDisp, (void **) &pic);
if(pic != NULL) {
pic->QueryInterface(IID_IPicture, (void **) Pict);
if(Pict) {
bResult = TRUE;
}
}
return bResult;
}
Do you see something wrong in the code ( it fails when tries to load the picture (( ).
Thanks in advance, Greetings
Braulio
|
|
|
|
|
Very first thing, I would use an HRESULT and catch the return value from OleLoadPicture. In fact you should be checking the return values of all of your COM function calls especially the ones that cross process boundaries. With COM the functions can fail due to unforeseen problems outside of your program.
after you get the HRESULT, you can test if it is valid with the SUCCEEDED(hResult) macro, or if it failed with the FAILED(hResult) macro. Also if you want to know what the error code is when it fails you can look it up in the tools menu with error lookup.
|
|
|
|
|
Thanks for the tip,
One thing... to install my COM server DLL in another computer, I only need to call
RegSvr32 MyDll.dll
Not more not less ?, or do I need to make more operations ?
Thanks !
Braulio
I
|
|
|
|
|
That should be it, but it has to be called from that computer.
|
|
|
|
|
Hi everyone. I have a dialog with a control toolbar, which I have been able to successfully create. It has 2 combo boxes, both were simple combo boxes, and it worked fine. Then, I made one of the combo boxes a CFontPreviewCombo (which is a combo box which displays all available system fonts, which is a new control added to CodeProject, by Chris Losinger). I did this by changing the type from CComboBox to CFontPreviewCombo, and it compiled and ran fine. It did display the fonts in the combo box, but box itself did not draw properly. I realized it was supposed to be owner drawn variable, so I made it owner drawn variable by using the CBS_OWNERDRAWVARIABLE style.
When I did that, I got a daocore.cpp, line 42. It asserts on the cToolBar.m_cboFont.Create() line, when the combo box is created. It does not assert when not owner drawn, but does when it is.
I have my combo box code below, I am doing this in the OnCreate() of the dialog. I was told this was the right place to put it, but I am not completely sure, I have to admit I am new to manipulating toolbars directly.
<br />
int CDlgReport::OnCreate(LPCREATESTRUCT lpCreateStruct) <br />
{<br />
if (CDialog::OnCreate(lpCreateStruct) == -1)<br />
return -1;<br />
<br />
CRect rect;<br />
<br />
<br />
cToolBar.Create(this);<br />
cToolBar.LoadToolBar(IDR_TBR_REPORT);<br />
<br />
#define SNAP_WIDTH_FONT_SIZE 50 //the width of the combo box<br />
#define SNAP_WIDTH_FONT 150 //the width of the combo box<br />
<br />
<br />
cToolBar.SetButtonInfo(0, ID_TBR_REPORT_CBO_FONT, TBBS_SEPARATOR,<br />
SNAP_WIDTH_FONT);<br />
cToolBar.GetItemRect(0, &rect);<br />
<br />
rect.top+=2;<br />
rect.bottom += 200;<br />
<br />
<br />
<br />
<br />
<br />
<br />
if (!cToolBar.m_cboFont.Create(WS_CHILD|WS_VISIBLE|CBS_AUTOHSCROLL| CBS_OWNERDRAWVARIABLE |<br />
CBS_DROPDOWNLIST|CBS_HASSTRINGS | CBS_SORT,<br />
rect, &cToolBar, IDC_CBO_FONT))<br />
{<br />
TRACE0("Failed to create combo-box\n");<br />
return FALSE;<br />
}<br />
<br />
<br />
<br />
cToolBar.m_cboFont.SetFont(cToolBar.GetFont());<br />
cToolBar.m_cboFont.ShowWindow(SW_SHOW);<br />
<br />
cToolBar.m_cboFont.m_style = CFontPreviewCombo::NAME_GUI_FONT;<br />
cToolBar.m_cboFont.Init();<br />
<br />
<br />
<br />
<br />
cToolBar.SetButtonInfo(1, ID_TBR_REPORT_CBO_FONT_SIZE, TBBS_SEPARATOR,<br />
SNAP_WIDTH_FONT_SIZE);<br />
cToolBar.GetItemRect(1, &rect);<br />
<br />
rect.top+=2;<br />
rect.bottom += 200;<br />
<br />
if (!cToolBar.m_cboFontSize.Create(WS_CHILD|WS_VISIBLE|CBS_AUTOHSCROLL| <br />
CBS_DROPDOWNLIST|CBS_HASSTRINGS,<br />
rect, &cToolBar, IDC_CBO_FONT_SIZE))<br />
{<br />
TRACE0("Failed to create combo-box\n");<br />
return FALSE;<br />
}<br />
cToolBar.m_cboFontSize.SetFont(cToolBar.GetFont());<br />
cToolBar.m_cboFontSize.ShowWindow(SW_SHOW);<br />
<br />
cToolBar.m_cboFontSize.AddString("1");<br />
cToolBar.m_cboFontSize.AddString("2");<br />
cToolBar.m_cboFontSize.AddString("3");<br />
cToolBar.m_cboFontSize.AddString("4");<br />
cToolBar.m_cboFontSize.AddString("5");<br />
cToolBar.m_cboFontSize.AddString("6");<br />
cToolBar.m_cboFontSize.AddString("7");<br />
cToolBar.m_cboFontSize.SetCurSel(0);<br />
<br />
return 0;<br />
}<br />
If I am not specific enough, I can provide more code. I hope I explained this correctly.
Thanks in advance!
|
|
|
|
|
Replace with : CBS_OWNERDRAWFIXED
my part codes:
// Create the Line Style combo box
SetButtonInfo(6,ID_PRTFMTLINESTYLE,TBBS_SEPARATOR,80);
GetItemRect(6, &rect);
rect.top = 2;
rect.bottom = rect.top + 18*8;
if (!m_LineStyleSelect.Create(
CBS_DROPDOWNLIST|CBS_OWNERDRAWFIXED|CBS_SORT
|WS_VISIBLE|WS_TABSTOP,
rect, this, ID_PRTFMTLINESTYLE))
return -1;
|
|
|
|
|
I tried making it own drawn fixed, but it also asserts
|
|
|
|
|
my codes was run normally! if possible, please send your more codes
*.h
----------------------------------------
class AFX_EXT_CLASS CLineStyleComboBox : public CComboBox
{
protected:
virtual void MeasureItem( LPMEASUREITEMSTRUCT lpMIS);
virtual void DrawItem( LPDRAWITEMSTRUCT lpDIS);
virtual int CompareItem(LPCOMPAREITEMSTRUCT lpCIS);
//{{AFX_MSG(CLineStyleComboBox)
afx_msg int OnCreate( LPCREATESTRUCT lpCreateStruct );
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
void AddStyleItem(int Style) { AddString((LPCTSTR)Style);}
int SelectItem(int Style);
};
*.cpp
----------------------------------------
#define LSTYLE_ITEM_HEIGHT 18
BEGIN_MESSAGE_MAP(CLineStyleComboBox, CComboBox)
//{{AFX_MSG_MAP(CLineStyleComboBox)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
int CLineStyleComboBox::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
int nRet = CComboBox::OnCreate(lpCreateStruct);
if( nRet==-1 )
return nRet;
static int styles[] =
{
PS_SOLID,PS_DASH,PS_DOT,PS_DASHDOT,PS_DASHDOTDOT,PS_NULL
};
for(int i=0;i<sizeof(styles) sizeof(styles[0]);i++)
="" addstyleitem(="" styles[i]="" );
="" setcursel(0);
="" return="" nret;
}
void="" clinestylecombobox::measureitem(lpmeasureitemstruct="" lpmis)
{
="" lpmis-="">itemHeight = LSTYLE_ITEM_HEIGHT;
}
void CLineStyleComboBox::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
CDC* pDC = CDC::FromHandle(lpDIS->hDC);
COLORREF Color =
(lpDIS->itemState & ODS_SELECTED)?RGB(0xff,0,0):RGB(0,0,0);
int nPenStyle = int(lpDIS->itemData);
CPen Pen( nPenStyle,1, Color );
CPen * pOldPen = pDC->SelectObject( &Pen );
pDC->SetBkMode(TRANSPARENT);
int y = (lpDIS->rcItem.top+lpDIS->rcItem.bottom)>>1;
pDC->MoveTo( lpDIS->rcItem.left,y );
pDC->LineTo( lpDIS->rcItem.right,y );
pDC->SelectObject( pOldPen );
}
int CLineStyleComboBox::CompareItem(LPCOMPAREITEMSTRUCT lpCIS)
{
return int(lpCIS->itemData1)-int(lpCIS->itemData2);
}
int CLineStyleComboBox::SelectItem(int Style)
{
int n = GetCount();
for(int i=0;i
|
|
|
|
|
I wonder if you understand me when I explain my problem.
I am trying to make an application with Visual C++, my application must contain MFC and ADo connection.
It must me connected to database (which I made in Access).
We must be able to brows tables (2-3 different tables) of the database.
INserting, adding and deleting records of the tables.
I have done the following:
My database is a phonebook, I have made and access database connection to it, and I can brows it, add, delete and updating.
My problem is: How do I add another table in the application? I have tried everything, and made mistakes and over and over again. What I meen is that I must have 2 tables och more working paralell in the application.
How do I do this?
|
|
|
|
|
I've written an MFC DLL, say ClientAPI.dll and ClientAPI.lib. In the DLL, there's a class, say CMyClassA, it's just a class doing some getXXX and setXXX with CString's, and without any memory allocations.
However, in the application using it, i just link with ClientAPI.lib, and create an instance as
CMyClassA *pInsA;
pInsA = new CMyClassA();
delete pInsA;
In delete pInsA, I got an error :
Heap block at 003B7378 modified at 003B7400 past requested size of 80
What's worng with it ?
Thanks
|
|
|
|
|
Probably the reason of heap corruption is that you're allocating memory blocks for CStrings in .DLL and freeing them in .exe.
Did you link with MFC dynamically or statically?
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
Yeah, the CString's are in the classes in the DLL, but I just make it class variable ( should be auto variable ). I didn't allocate memory on my own.
You are right too, I declared the classes in the DLL, and use it in a EXE. In the exe routine, i did
CMyClassA *pInst;
pInst = new CMyClassA;
delete pInst;
I like MFC dynamically in debug mode.
Hiya, Everybody ^^
|
|
|
|
|
Hi!
I making a "funny" application (not serious but good practice). I want to steer a picture with the arrow keys. The problem is that when I holding arrow left to move the picture left and then press up arrow while I holding left arrow down the left arrow functionality seems to stop then... How to make the picture move left and up at the same time? because that must be the problem...
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|