|
Your question is not clear. Do you want to get the path of the source module you have open in Visual Studio? Then GetModuleFileName() won't do it. That will get you the full path of the running executable.
|
|
|
|
|
overloaded Name wrote: hello guys... I need to get the file path of the current document that im using.
Check out CDocument::GetPathName() .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
OK, here is a func i wrote for stripping new lines:
wchar_t * StripNL(IN wchar_t *buff)
{
int len = wcslen(buff);
wchar_t *temp = (wchar_t *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(wchar_t *) * len + 1);
int x = 0;
for (int i = 0; i < len; i++)
{
if(buff[i] != '\n' && buff[i] != '\r\n')
{
temp[x] = buff[i];
x++;
}
}
temp = (wchar_t *)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
temp, sizeof(wchar_t *) * wcslen(temp) + 1);
return temp;
}
Here is some dirty array constructor function, it returns array where strings including new lines:
wchar_t **sss(int &lll)
{
wchar_t *Arr[] = {L"\r\ntest test\n\n", L"test\r\n\r\n so be it\n\n"};
for (int i = 0; i < (sizeof(Arr) / sizeof(wchar_t *)); i++)
{
lll++;
}
return Arr;
}
Now i am trying to strip new lines from array's strings like that:
int elems = 0;
wchar_t **Arr = sss(elems);
for (int i = 0; i < elems; i++)
{
wprintf(L"elems: %s, len = %d\r\n", StripNL(Arr[i]), wcslen(Arr[i]));
}
Now this behaves completely crazy. WHile it should output:
elems: test test, len = some len
elems: test so be it, len = some len
it prints this:
test test, len = some len
so be it, len = some len
And then app crashes. So it strips something that is shouldnt. It looks like memory gets overwritten somewhere, but i cannot see where exactly?
Thanks
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
|
C++ is not the way.
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Ah, i was so pathetically lame - cant stand myself. Shame on me!
if(buff[i] != '\n' && buff[i] != '\r')
{
temp[x] = buff[i];
x++;
}
Works perfectly. That was '\r' char unparsed which messed up everything.
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
I'd expect a compiler error on the original code; single quotes mean a character is between them and \r\n is two characters.
If you still want to check for \r\n rather than for any occurence of \r separately, you could use something like this:
for (int i = 0; i < len; i++)
{
if(!(buff[i] == '\n' || (buff[i] == '\r' && i+1 < len && buff[i+1] == '\n')))
{
temp[x] = buff[i];
x++;
}
}
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Nope, there was no error. That was silly mistake
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
I suppose you do a HeapFree call somewhere, however
temp = (wchar_t *)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
temp, sizeof(wchar_t *) * wcslen(temp) + 1);
is a bit dangerous. HeapReAlloc might return NULL, in which case you have no chance of freeing the memory since you're overwriting the only access you have to it.
You should always use a temporary pointer for the return value.
wchar_t* temp2 = (wchar_t *)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
temp, sizeof(wchar_t *) * wcslen(temp) + 1);
if (temp2 != NULL)
temp = temp2;
else
Error handling and HeapFree temp pointer
|
|
|
|
|
Everything is under control :P There are memory checks outside of the function i posted here, and, it is not complete here (code was meant to just present en error situation). However, thank you for suggestions about HeapRealloc
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
I want to capture the desktop image behind my main window.I used
HDC hDesktopDC = GetDC(NULL);
RECT rect;
GetWindowRect(&rect);
......
BitBlt(hMemDC, 0,0, nWidth, nHeight, hDesktopDC, rect->left, rect->top, SRCCOPY);
hBitmap = (HBITMAP)SelectObject(hMemDC, hOldBitmap);
but, the image I got was my window,not Its background.
what's the matter?
How could I get the image behind my main window?
Thanks guys!
|
|
|
|
|
Hide your window first by calling ShowWindow(hwnd, SW_HIDE) .
|
|
|
|
|
thanks hans.
that would be fine,but there is always a flash.not perfect.
|
|
|
|
|
You can minimize your application window first and then get the hWnd to the desktop window using the GetDesktopWindow.[^]Then you can maximize your application back again.
I am a HUMAN. I have that keyword in my name........
_AnsHUMAN_
|
|
|
|
|
You could manipulate the clipping region for the desktop window before having it paint itself.
|
|
|
|
|
Dear All,
I have a main modeless dialogbox created by CreateDialog and have another child model dialog box created by DialogBox and on this child window I have many button but when I am clicking on any button WM_COMMAND is not getting fired in winproc of child dialog.
I will be very thankful for your support.
With regards
RYK
|
|
|
|
|
There is only a few reasons I can think of why this is happening:
1. Make sure you are looking in the right place for the message. I know it seems trivial, but it happens to everyone.
2. Make sure you set the right MsgProc for the child dialog.
3. Make sure something else isn't replacing the MsgProc for the child dialog (such as MFC)
Spy++ is distributed with Visual Studio, and can be found under the tools menu. Follow these steps to debug using Spy++.
Run your program and open the child dialog where the problems are
Start Spy++ from the Tools menu
Find your child dialog window, either in the list or using the find window toolbar icon
Right click on your child dialog window in the list and select Messages
Click some buttons in your program to see if they show up in the list
You can also check things like check the memory address of the MsgProc and window styles by selecting properties from the right click menu.
|
|
|
|
|
Hi
I'm working on an application that makes use of the MessageBox API. I've written the MessageBox API as:
MessageBox(NULL, sMsg, sTitle, MB_OK|MB_ICONEXCLAMATION|MB_TASKMODAL);
The issue I face is that sometimes when this message box comes on view, it disappears to the background shortly after it displays even though I've specified MB_TASKMODAL.
I replaced MessageBox with AfxMessageBox and the issue seems to be fixed. I no longer have the message box hiding behind other dialogs. I am planning to use AfxMessageBox for the project I am working on.
Could some let me know why this issue occurs and what difference between MessageBox and AfxMessageBox may have fixed the issue?
Thanks
Jens
|
|
|
|
|
MessageBox(NULL, sMsg, sTitle, MB_OK|MB_ICONEXCLAMATION|MB_TASKMODAL);
The first parameter means: "A handle to the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window". For AfxMessageBox you don't need to pass the windows handle.
So this, might be the cause but I might be wrong.
I am a HUMAN. I have that keyword in my name........
_AnsHUMAN_
|
|
|
|
|
AfxMessageBox is a modal dialog of the calling CWnd; MessageBox with a NULL hwnd is a modal dialog of the desktop. Hence, AfxMessageBox will always stay on top of your app, but MessageBox can be hidden by other windows. You can force MessageBox to have the same behavior by using m_hWnd for the first parameter.
|
|
|
|
|
Hans
From what I understand I can still continue using MessageBox by using m_hWnd as the first parameter. What should I declare m_hWnd as? Should it be just an HWnd? If so, what should it be initialized to?
|
|
|
|
|
In MFC, anytime you have any window (such as dialog, view, etc.), that window has a hwnd, which is accessible by the variable m_hWnd , which is declared to be HWND (which is what MessageBox wants).
|
|
|
|
|
A common value for a MFC application is AfxGetMainWnd()->m_hWnd .
AfxGetMainWnd() returns the value you set for m_pMainWnd in the YourApp::InitInstance() function. As the name suggests, it is the main application window.
If you are using it from inside a dialog, you may want to use the dialog HWND instead, although it is not necessary.
|
|
|
|
|
i have a Dialog and ListBox
i created a class to manipulate Controls: CControl
my class have function:
BOOL CControl::GetAllProcess(CListCtrl list1, int *arrProcId)
and in Dialog's function:
CControl ctr;
ctr.GetAllProcess(IDC_LIST1,arrProcId);
but can't convert int to CListBox
don't same CSharp
plz Help me...
very clearly if you have a example for me...thanks very much
sorry if my english isn't good
|
|
|
|
|
You have defined the function this way:
BOOL CControl::GetAllProcess(CListCtrl list1, int *arrProcId) but you are calling it this way:
ctr.GetAllProcess(IDC_LIST1,arrProcId); .
You can't convert from IDC_LIST1 to a CListCtrl; one is a numeric id, the other is a class. Look at the examples here on Codeproject about how to use the CListCtrl class. Basically, you need to use the resource editor to create a CListCtrl variable; a DDX statement will attach the CListCtrl variable to IDC_LIST1.
And you probably want to write the function like this:
BOOL CControl::GetAllProcess(CListCtrl& list1, int *arrProcId)
|
|
|
|