|
Yes.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
|
So could this be an example for method overloading?
int foo(int number);
int foo(intnumber1, int number);
Moujan
|
|
|
|
|
Yes, but be careful with default argument. The following does NOT work:
int foo(int number);
int foo(int number1, int number = 0);
Basically, any ambiguity the compiler cannot resolve will not work.
Best,
Jun
|
|
|
|
|
Hi guys,
I am trying to use openprocess however I am running into a few problems. Specifically for the last parameter of the function OpenProcess , I am wondering how would I retreive the process id using hwnd retrieved from FindWindow ? I have tried GetProcessId however that doesnt seem to work. I get a compiler error saying that its an undeclared identifier. However I have included windows.h so there should not be any problems. Would anyone know how to get the process id of a window handle?
Thanks,
Robbie
|
|
|
|
|
First note that GetProcessId requires at least Windows XP or Windows Server 2003.
Call GetWindowThreadProcessId and OpenProcess:
DWORD dwProcessID = 0;
::GetWindowThreadProcessId(hWnd, &dwProcessID);
HANDLE hProcess = ::OpenProcess(PROCESS_QUERY_INFORMATION,
FALSE,
dwProcessID);
if(NULL != hProcess)
{
::CloseHandle(hProcess);
}
else
{
DWORD dwError = ::GetLastError();
}
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
lol I just saw and used that from the MSDN and it worked. Thanks for confirming thats the right one to use!
|
|
|
|
|
You are welcome!
BTW. Is MSDN really so funny to "lol", or just my answer ?
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
I've skewed the meaning of "lol" so much that I end up including it in almost every post even if I have a straight face, but if I had to literally have a chuckle at your answer then it would have to be corniest joke I would have ever laughed at
|
|
|
|
|
Hi,
I have a login dialog on which there is a logo. In the OnPaint() function I have added some code to make the logo transparent.
But everytime I minimize the login dialog box and then maximise it again, I get Debug assersion failure. But if I do not minimize it, then the rest of the program works fine.
I am not able to figure out what I must do to correct this. If I block out the code in the OnPaint() function, this problem dosen't occure.
void CLogin::OnPaint()
{
CPaintDC dc(this);
CRect rect;
GetDlgItem(IDC_STATIC_MJ)->GetWindowRect(&rect);
ScreenToClient(&rect);
COLORREF clrDlg = GetSysColor(COLOR_BTNFACE);
m_bitmap.LoadBitmap ( IDB_MJ_SOFTWARE ) ;
CBrush mybrush, *oldbrush ;
mybrush.CreateSolidBrush ( clrDlg ) ;
oldbrush = dc.SelectObject ( &mybrush ) ;
Display ( &dc, rect.left , rect.top , RGB ( 255, 255, 255 ) ) ;
mybrush.DeleteObject( ) ;
dc.SelectObject ( oldbrush ) ;
}
Please can you tell me what I am doing wrong here.
Thanks,
Tara
Fortitudine Vincimus!
-- modified at 7:20 Sunday 2nd July, 2006
|
|
|
|
|
Aside note: in your code it's not even necessary to call mybrush.DeleteObject() because anyhow it is deleted when out-of-scope.
Ovidiu Cucu
Microsoft MVP - Visual C++
-- modified at 3:23 Monday 3rd July, 2006
|
|
|
|
|
Thanks a lot.
Its working now.
I used GetSafeHdc() but it was still giving error. But I understood that before loding a bitmap to m_bitmap , I must free it. So I used m_bitmap.DeleteObject(); and, of course the second point that you stated.
Thanks once again.
Fortitudine Vincimus!
|
|
|
|
|
Oups, I made a mistake in my previous answer.
I just have corrected it.
Also as long as we have not a CBitmap pointer, you can directly test m_hObject member instead of call GetSafeHandle, like WhiteSky already suggested.
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
SO, the reason that the assersion failure occurs is that when the dialog is minimised and then maximised, and the onPaint() function is called, the bitmap object tries to load an already loaded object. Is that correct?
Therefore, one must either delete the object before calling Load or check whether it is NULL, and call Load only if it is.
Fortitudine Vincimus!
|
|
|
|
|
You can use
if (m_bitmap.m_hObject==NULL) <br />
m_bitmap.LoadBitmap ( IDB_MJ_SOFTWARE ) ;
whitesky
|
|
|
|
|
Hi all,
I am having trouble to calculate precisly how many visible lines (according to the font currently selected) i have in my CRichEditCtrl derived class.
here is the code snippet:
// this event is EN_CHANGE
void CMyRichEditCtrl::OnEdtChange()
{
CDC* pDC = GetDC();
int nTxtLen = GetWindowTextLength();
SetSel(nTxtLen,nTxtLen);
CHARFORMAT2 cf;
GetSelectionCharFormat(cf);
int nFontSize = cf.yHeight / 20;
int nFontHeight = -MulDiv(nFontSize, GetDeviceCaps(pDC->m_hDC, LOGPIXELSY), 72);
nFontHeight *= -1;
ReleaseDC(pDC);
CRect rc;
GetRect ( rc );
int nVisibleLines = rc.Height() / nFontHeight;
nVisibleLines -= 3;
int nTotalLines = GetLineCount();
int nDelta = nTotalLines - nVisibleLines;
}
trouble is , the calculation i get is incorrect, especially when i change the font size.....
can any1 help?
thanks in advanced
Rami
|
|
|
|
|
Hi,
I'm looking for function which works reverse of QueryDosDevice. I've got a "\\Device\\HarddiskVolume1" and I want to translate it to drive letter.
-----------
Mila
|
|
|
|
|
<br />
TCHAR GetDriveLetter(LPCTSTR lpDevicePath)<br />
{<br />
TCHAR d = _T('A');<br />
while(d < = _T('Z'))<br />
{<br />
TCHAR szDeviceName[3] = {d,_T(':'),_T('\0')};<br />
TCHAR szTarget[512] = {0};<br />
if(QueryDosDevice(szDeviceName, szTarget, 511) != 0)<br />
if(_tcscmp(lpDevicePath, szTarget) == 0)<br />
return d;<br />
d++;<br />
}<br />
return NULL;<br />
}<br />
|
|
|
|
|
im trying to make a scrolling text im using scrollwindow and it moves back and forth but when it goes from left to right if the text is say "hello" it looks like hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhello how can i get it to look right and not repeat the first letter?
|
|
|
|
|
To avoid such nasty hhhhhhhhhhhhhhhhhhhhheadaches, you can take a look at THIS FAQ[^]
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
CMyDialog::PreTranslateMessage()
{
if(pMsg->message == WM_KEYDOWN)
{
if(pMsg->wParam == VK_UP)
{
m_bUp = TRUE;
pMsg->wParam = VK_TAB;//tranlate into TAB
keybd_event(VK_SHIFT, 0, 0, 0); //press down the shift
}
else if(pMsg->wParam == VK_DOWN)
{
m_bUp = FALSE;
pMsg->wParam = VK_TAB;//tranlate into TAB
}
else
m_bUp = FALSE;
if(IsDialogMessage(pMsg))
return TRUE;
}
else if(m_bUp)
{
keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);//Release SHIFT
m_bUp = FALSE;
}
return CDialog::PreTranslateMessage(pMsg);
}
|
|
|
|
|
Could someone tell me what open mode I can use to write data only to the end of my already created (existing) file? should I use iso::trunc?
~Moujan
-- modified at 1:59 Sunday 2nd July, 2006
|
|
|
|
|
ios::app
0 bottles of beer on the wall, 0 bottles of beer, you take 1 down, pass it around, 4294967295 bottles of beer on the wall.
Awasu 2.2.2 [^]: A free RSS/Atom feed reader with support for Code Project.
|
|
|
|
|
|
Could some one tell me how I can prevent duplicate definitions in my program. I mean should I use something like #definemyClass or should I use provate keyword.
Thanks, Moujan
|
|
|
|