|
I use the following code to create a device context in
a static control being part of a CFormView window in
order to draw inside its clients area. This code is in
the OnDraw() method of a CStatic derived class (an instance
of this class in part of CFormView window and OnDraw() is
called in CFormView window OnPaint()).
CWnd* l_pWnd;<br />
l_pWnd = m_pParentWnd->GetDlgItem(m_dwParentId);<br />
CClientDC l_Dc(l_pWnd);
The problem is the following:
my picture is drawn also if its coordinates
are out of client control area. In this way, if my
input data are out of ranges my code paints also the
parent window area.
How can I avoid this problem ?
I'd like that, if picture coordinates are out of
range, it is not drawn !!!
Thanks a lot!
|
|
|
|
|
If I understad your problem correctly you may have to use clipping functions. If you set clipping regions or rectangles the DC will only paint in those regions/rectangles.
See the documentation of the CDC class for details and have a look on the Clipping Functions section in the documentation of the CDC class.
|
|
|
|
|
Can someone plz have a look at my code and tell me what I am doing wrong. I have an SQL server and trying to connect to it using ADO. Only learning ADO a few days but already it is driving me mad connecting to the SQL server I have.
The error message I get is: "Cannot open database requested in login 'Branch'. Login fails."
Here is my code:
try
{
HRESULT hResult;
if(FAILED(::CoInitialize(NULL)))
return;
_ConnectionPtr pConnection;
hResult = pConnection.CreateInstance(__uuidof(Connection));
hResult = pConnection->Open(_T("Provider=SQLOLEDB.1; Data Source=(local);Initial Catalog=Branch;Trusted_Connection=yes;"),
_T(""),
_T(""),
adOpenUnspecified);
}
catch(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bs = _bstr_t(" Error: ") + _bstr_t(e.Error()) + _bstr_t(" Msg: ")
+ _bstr_t(e.ErrorMessage()) + _bstr_t(" Description: ")
+ _bstr_t(e.Description());
MessageBox(0,bs,bstrSource, MB_OK);
}
I didn't think I needed to login once I used the Trusted Connection=yes. Once I can get the connection, I should be ok.
Branch is the name of my database.
Thanks.
|
|
|
|
|
You need to specify the User that you use to logon and his password if there is any. For example if the user is sa with no password you should add after trusted connection User Id=sa;Password=;
Spiros Prantalos
Miami the place to be!!
|
|
|
|
|
any idea how to create this???
thanx a lot!
|
|
|
|
|
Try CodeJock.com's flashy XFT library. It lets you do Office2003 style toolbars, menus, etc. Very nice looking stuff.
|
|
|
|
|
hy, i already downloaded the trial, but i dont figuered aout, how to do the office2003 style. it is also not documented! i think its in this function:
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
So i would need other styles, but i didnt found styles like Gradient for the TBSTYLE_FLAT,
and it is also not documented
any idea??
andreas
|
|
|
|
|
maby the key is alwo in this function:
(from the customize toolbar sample)
void CMainFrame::OnViewXpmode()
{
xtAfxData.bXPMode = !xtAfxData.bXPMode;
RedrawWindow( NULL, NULL,
RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN );
}
unfortunately there is nothing like a xtAfxData.bOfice2003 flag ...
any ideas?
|
|
|
|
|
Hello,
I have a directory in wich I'll save "archive" files for my application (the format is *.dat, where * is a number). So, when I need to save a new file, I take the last file number and I add 1. So, I have always a file name that doesn't exist in the directory.
How can I do to find the bigger file number in the directory ?
I tried with the CFileFind class but there is a problem with it because if I want to use the GetFileTitle() method, I need to call GetNextFile() before. So if I have just one file in the directory (wich can be different from "0.dat" !!), I will have a problem here!
Any idea?
Thanks!
|
|
|
|
|
That's how CFileFind is meant to work, did you see the example in MSDN?:
<br />
CFileFind finder;<br />
BOOL bWorking = finder.FindFile("*.*");<br />
while (bWorking)<br />
{<br />
bWorking = finder.FindNextFile();<br />
cout << (LPCTSTR) finder.GetFileName() << endl;<br />
}<br />
so you modify the loop to get (untested, but essentially right):
<br />
CFileFind finder;<br />
BOOL bWorking = finder.FindFile("*.dat");<br />
int highest = 0;<br />
int current;<br />
while (bWorking)<br />
{<br />
if(bWorking = finder.FindNextFile())<br />
{<br />
current = atoi((LPCTSTR) finder.GetFileTitle());<br />
highest = highest > current ? highest : current;<br />
}<br />
}<br />
An easier solution is to use a datestamp for the filename instead
--
Ian Darling
|
|
|
|
|
I already tried this but in fact, I made a mistake in my code and so, when I tried with one single file in the directory, I couldn't find it. I corrected the bug and now it works fine!
But I found an easier and faster solution: I keep a file in wich I write this number and some other notitifications infos.
I always look for complicated solutions first !
|
|
|
|
|
The only problem with using the store-number-in-file method is that some *.dat files may get deleted and then your numbering would be off.
|
|
|
|
|
I have a rich-edit where I only want to support *one* font (Tahoma 10pt. etc.) set up at time of constructing of the edit. This works fine when writing in it.
But how do I force a text into this specific font and look when *pasted* in - from some other size and font?
Think it's something about monitoring the clipboard format but I'm not sure?
It makes sense to have a OnPaste() not calling the base impl. and then do the paste-work myself adding my format to it before it goes in - but no such are found anywhere!?
As far as I can see in CWnd I have:
ChangeClipboardChain(...)
SetClipboardViewer(...)
OpenClipboard(...)
GetClipboardOwner(...)
GetOpenClipboardWindow(...)
GetClipboardViewer(...)
and in CRichEdit:
Copy(...)
Cut(...)
Paste(...)
PasteSpecial(...)
CanPaste(...)
I'm a little puzzled here?
Regards,
Michael Mogensen, mm it-consult dk.
><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>
|
|
|
|
|
First, I am sorry, because I adviced yesterday to do so, and I did not answer your second post. :-OThere is actually no OnPaste() routine, do it that way :
Create a class CMyRichEditCtrl derived from CRichEditCtrl .
Create your RichEditCtrl in the resource editor, and assign it a control member : m_MyRichEdt
Go into the automatically generated code, and replace
CRichEditCtrl m_MyRichEdt;
with
CMyRichEditCtrl m_MyRichEdt;
Do not forget to add an #include "MyRichEditCtrl.h" in that same file after
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
Now override PreTranslatemessage like that :
B
OOL CMyRichEditCtrl::PreTranslateMessage(MSG* pMsg)
{
if ((pMsg->message == WM_PASTE))
{
Change font ...
}
else
return CRichEditCtrl::PreTranslateMessage(pMsg);
}
Hope this helps.
~RaGE();
|
|
|
|
|
After few testing (sorry, no time today ), my code snippet lacks one or two things :
First, if (message == WM_PASTE) is not really good, since it can be that several messages are contained in one message. So prefer something like if ((message & WM_PASTE)==0) return ... else paste font;
Secondly, I think you will have to remove the WM_PASTE from the message queue, otherwise, the clipboard contents will be paste (it passes ans passes over again in PreTranslateMessage().
~RaGE();
|
|
|
|
|
OK thanx' - this is a new approch and I understand what you are saying. I'll check it out soon.
Only my feeling now is that this solution seems kind of "emergency exit" and a little primitive as well - there *must* be a better way. Not complaining or anything -
Regards,
Michael Mogensen, mm it-consult dk.
><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>
|
|
|
|
|
Thanx' sharing the ideas!
But I found another way around my CHARFORMAT-problem than using the PreTranslateMessage(...) - here it is.
What I did was that I made the CHARFORMAT-change to the full selection in response to *not* an UPDATE event but a CHANGE ev. As it turned out an update-ev. came over and over again if I did the work on EN_UPDATE - ON_CHANGE was less sensitive. So this is how the final solution looks:
<br />
const void CCalFrameWnd::CCalendar::Note_EditChange()<br />
{<br />
TRACE(_T("Note_EditChange()\n"));<br />
long lChar_Start = 0, <br />
lChar_End = 0;<br />
CHARFORMAT cf_def;<br />
cf_def.cbSize = sizeof(CHARFORMAT);<br />
m_pEdit_Note->GetDefaultCharFormat(cf_def);<br />
m_pEdit_Note->GetSel(lChar_Start, lChar_End);<br />
m_pEdit_Note->HideSelection(TRUE, FALSE);<br />
m_pEdit_Note->SetSel(0, -1);<br />
m_pEdit_Note->SetSelectionCharFormat(cf_def);<br />
m_pEdit_Note->SetSel(lChar_End, lChar_End);<br />
m_pEdit_Note->HideSelection(FALSE, FALSE);<br />
}<br />
So I just force the def-CHARFORMAT on to the entire selection having always set the def-format first. Also I remember to be able to restore to the orig. caret pos.
Btw. Can one make a "ON_EN_REFLECT_CHANGE" for a edit/rich edit - work like this should be held totally inside the class as far as I can se.
Regards,
Michael Mogensen, mm it-consult dk.
><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>
|
|
|
|
|
I have problems with the message handler of a system tray icon. I am writing an SDI application, and it adds the icon with no problems, but my custom message handler does not get the messages sent to the icon.
I have successfully done this in a Dialog App some years ago, and now it does not work in the SDI one. I try to move this functionallity to the App, View, Frame classes - but nothing happens. I use VC++ 6.0 under Windows XP.
Are there any catches here? What do I do wrong???
Really appreciate the help.
"Needless redundancy is the hobgoblin of software engineering." - Peter Darnell
|
|
|
|
|
All you need to do is create your own message MY_MSG (or something like that), then attach this message to the callbackmsg (of the trayicon), then place the message in the message map of your mainframe and implement the function you attached to the message.
|
|
|
|
|
I'v made a well working fct. for this:
inline const bool SetTrayIcon(
CWnd *pWnd,
CONST DWORD dwMessage,
CONST DWORD dwMessage_NIM,
CONST UINT uId_Icon,
LPCTSTR lpszTTT,
CONST UINT uId_Callback)
// In the tray, show specific icon. Return T on succes and F if not.
//
// To add the icon use: NIM_ADD for NIM msg.
// To change the icon use: NIM_MODIFY for NIM msg.
// To remove the icon use: NIM_ADD for NIM msg.
//
{
NOTIFYICONDATA nid;
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = pWnd->GetSafeHwnd();
nid.uID = uId_Callback;
nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
nid.uCallbackMessage = dwMessage;
nid.hIcon = (HICON)::AfxGetApp()->LoadIcon(uId_Icon);
::lstrcpyn(nid.szTip, lpszTTT, sizeof(nid.szTip));
bool bResult = (::Shell_NotifyIcon(dwMessage_NIM, &nid) != 0);
if(nid.hIcon)
::DestroyIcon(nid.hIcon);
return bResult;
}
And then you go:
BEGIN_MESSAGE_MAP(CMyFrameWnd, CFrameWnd)
// Callback handler for tray icon.
ON_MESSAGE(WM_NOTIFYICON, OnTrayIconNotification)
END_MESSAGE_MAP()
And:
LRESULT CCalFrameWnd::OnTrayIconNotification(WPARAM, LPARAM lParam)
// Called back on notifications to the tray icon.
{
switch(lParam)
{
case WM_LBUTTONDBLCLK:
{
// Do stuff.
break;
}
case WM_LBUTTONDOWN:
{
// Do stuff.
break;
}
case WM_RBUTTONDOWN:
{
// Do stuff.
break;
}
// etc.
}
return 0L;
}
Regards,
Michael Mogensen, mm it-consult dk.
><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>
|
|
|
|
|
...I forgot some examples:
// Setup tray icon.
::SetTrayIcon(this, WM_NOTIFYICON, NIM_ADD, m_uId_TrayIconActive, (LPCTSTR)GetBaloonInfo());
// Refresh baloon for tray icon.
::SetTrayIcon(this, WM_NOTIFYICON, NIM_MODIFY, m_uId_TrayIconActive, (LPCTSTR)GetBaloonInfo());
// Remove tray icon.
::SetTrayIcon(this, WM_NOTIFYICON, NIM_DELETE, m_uId_TrayIconActive);
And you have:
inline const bool
SetTrayIcon(
CWnd*,
CONST DWORD,
CONST DWORD,
CONST UINT,
LPCTSTR lpszTTTEx = _T(""),
CONST UINT uId_CallbackEx = 0);
Regards,
Michael Mogensen, mm it-consult dk.
><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>
|
|
|
|
|
Hai...
I need a Grid whcih should work like ExcelSheet..i.e at run time we should be able to add comments to text in a cell,sholud be able to insert a horizontal line in a cell...can anybody help me regarding this???
ThomasKennedyBose
|
|
|
|
|
This Code Project Grid[^] should give you a good starting point.
Michael
'War is at best barbarism...Its glory is all moonshine. It is only those who have neither fired a shot nor heard the shrieks and groans of the wounded who cry aloud for blood, more vengeance, more desolation. War is hell.' - General William Sherman, 1879
|
|
|
|
|
yup.....thnxs...but it doesn't work like a Excel sheet right??(with this v can't add a comment for cell !)plz gimme more useful stuff
ThomasKennedyBose
|
|
|
|
|
Help yourself
It's an extensive, capable grid, and it's free. Don't expect it to be an excelsheet-plug-and-play-replacement.
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|