|
thanks for your reply!
I'm aksing myself whether this is possible:
Currently my app reads a whole file into a variable called "cache"
fread(cache, sizeof(char), buf.st_size, db);
I thought it would be nice to put the database (db) into my exe as a resource, so that I directly could set the buffer like that:
cache = (unsigned char*)rc_dat;
rc_dat is the content of the resource I'v got from the LockResource call.
But I think it doesn't work as expected
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Don't care about it anymore. Everything works fine
modified 12-Sep-18 21:01pm.
|
|
|
|
|
My application makes extensive use of the GDI resources. I use them to draw text in the view using specific font information etc... Anyway, the application terminates due to the fact that it eats up all of the system's available GDI resources. I'm trying to eliminate this issue but have had no luck. Even when using the DeleteObject() function, the GDI resources are never freed. Does anyone know how to free the GDI resources successfully?
|
|
|
|
|
ooooooooooooh...
CPen pen;
pen.CreatePen(PS_SOLID,1,RGB(255,0,0);
dc.SelectObject(&pen);
pen.DeleteObject(&pen);
problem...
SelectObject selects your pen and give you the previous pen. This must be selected back in the dc before pen is deleted.
so...
CPen* pPrevPen dc.SelectObject(&pen);
... do some drawing
dc.SelectObject(pPrevPen)
pen.DeleteObject(&pen);
and this goes for every GDI object you select into the DC, fonts, brush, etc.
Normski. - the next bit of code is self modifying ... jmp 0xCODE
|
|
|
|
|
I'm selecting the old pen back into the DC and deleting the object, but I'm not getting the resources to free up on my system. I've tried using the CAutoPen class that I found on this site to initialize, select, and delete the Pen object from the DC. I've also tried using the CPen class and just creating a pen, selecting it into the DC, using it, selecting the old pen back into the DC, and deleting the object. Neither method has worked. I'm not sure what I'm doing wrong to hold these GDI resources.
|
|
|
|
|
Hi.
I would like to implement a context menu inside a dialog box. I created a "clear" menu (no caption) using Resource Editor. Note that I create an entirely new menu item like IDR_MAINFRAME (mine is IRD_CONTEXTMENU1. Inside the dialog box, I added a message for right-click. Here is what the code looks like.
-----
CPoint mPointCurrent;
::GetCursorPos(&mPointCurrent);
CMenu mPopupMenu;
mPopupMenu.LoadMenu(IRD_CONTEXTMENU1);
// Program crashes at this point.
CMenu *pContextMenu = mPopupMenu.GetSubMenu(0);
pContextMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY,
mPointCurrent.x, mPointCurrent.y, GetActiveWindow(), NULL);
-----
The code above does not work. The program crashes when I right-click inside the dialog box. Is the code above for a view class only? Is there a different and corrent way to implement a context menu inside a dialog box?
Thanks,
Kuphryn
|
|
|
|
|
I thing your problem is that you are passing argument &mPointCurrent in client coordinates. You need to implement function ClientToScreen()and converse it into screen coordinates.
ClientToScreen(&mPointCurrent);//after mPopupMenu.LoadMenu
|
|
|
|
|
No, ::GetCursorPos() returns screen coordinates, and that's what TrackPopupMenu() expects. I do wonder if maybe having both TPM_LEFTBUTTON and TPM_RIGHTBUTTON set could be causing problems though...
---
Shog9
If I could sleep forever, I could forget about everything...
|
|
|
|
|
I don't know.
But, you can rule out a couple of things right off: put in an ASSERT() for pContextMenu , and for GetActiveWindow() . If either one triggers, there's your problem:
CMenu *pContextMenu = mPopupMenu.GetSubMenu(0);
ASSERT(NULL != pContextMenu);
ASSERT(NULL != GetActiveWindow());
---
Shog9
If I could sleep forever, I could forget about everything...
|
|
|
|
|
Okay. Thanks.
I found the problem.
// The menu ID was incorrect
-----
CMenu mPopupMenu;
mPopupMenu.LoadMenu(IRD_CORRECTMENUID);
-----
Kuphryn
|
|
|
|
|
I’m using SetTabStops() function in CListBox class., but I can’t figure out how to set a right alignment for tabs. Is there any way to do it? Please help.
|
|
|
|
|
I've never heard of it being possible, though someone else may have. You may just want to go with CListCtrl though, it's a bit nicer for doing columns (and supports left/center/right alignment).
---
Shog9
If I could sleep forever, I could forget about everything...
|
|
|
|
|
I read that dynamic data exchange (DDE) let's you interface
with ms word. How can I print my output into ms word? Is this possible?
Please, any response any one can give me will be greatly appreciated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
Hello,
Trying to accept a file from a zipped file from Windows Explorer. What information I should set to FORMATETC struct in order to know it's zipped file? Thank you!
|
|
|
|
|
After working in my application for a while, I'm getting an error when I try to create a Pen for drawing in the view. I assume it's some sort of memory issue, but I'm not sure. Is there any way for me to tell, conclusively, if it is a memory issue and is there any way for me to find out what it is that's causing the problem? I figure I'm not freeing something, but I thought that I got all of the memory allocation stuff.
Well, after watching the system monitor while executing my application, I've figured out that it's GDI resources that are the issue. Apparently, I'm not freeing the resources. How can I do that? I've tried inserting DeleteObject() statements but that doesn't seem to do anything for me.
|
|
|
|
|
Remember to always release objects.
<br />
...<br />
CPen* pOldPen = NULL;<br />
CPen* pNewPen = NULL;<br />
pNewPen = new CPen( );<br />
<br />
pOldPen = SelectObject ( pNewPen );<br />
...
<br />
(void) SelectObject ( pOldPen );<br />
...<br />
<br />
delete pNewPen;<br />
<br />
Or other stuff like that ...
Max.
|
|
|
|
|
Get BoundsChecker. It find most of your memory and resource leaks.
Todd Smith
|
|
|
|
|
Hi,
Can anyone help with this thread scenario:
I have a worker thread which calls on the Main Application to display its progress on the UI.
When you go to close the main application, I do a 'WaitForSingleObject' to allow the thread to terminate.
The thing is though, if the worker thread goes to the update the user interface whilst the Main App is in the 'WaitForSingleObject' the application crashes.
Can anyone offer any potential solutions.
Cheers
Rich
|
|
|
|
|
Create a mutex that the worker thread needs to go into when it requests the main thread to display the UI update. When the main thread is waiting on the worker thread it can acquire the mutex. Then when the worker thread is not able to aquire the mutex, it will simply skip the UI update process.
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!
|
|
|
|
|
Like that idea, my only other solution is to use messages to request the UI update process. Just hoping that they are ignored when in the wait state.
Cheers
|
|
|
|
|
Obviously it is best to post messages from the worker thread to the UI thread instead of sending them. If the UI thread is blocked by something, the worker thread can continue its Job and you don't get deadlocks.
In multithreading it is always a good idea to make as few synchronsiation points in your programm execution as possible. Asynchronous message passing using PostMessage() is a good mechanism to achieve this.
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
|
The best solution is to use the MsgWaitForMultipleObjects API.
Also, as someone pointed out, don't use SendMessage in your worker thread when you want to send a message to the main thread, use PostMessage.
It'll look something like this:
HANDLE hThread =
DWORD dwWait;
do{
dwWait = MsgWaitForMultipleObjects(1,
&hThread,
FALSE,
5000,
QS_ALLINPUT);
switch( dwWait )
{
case WAIT_OBJECT_0:
break;
case WAIT_OBJECT_0 + 1:
{
MSG msg;
while( PeekMessage(&msg, NULL, 0,0, PM_REMOVE ) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}break;
case WAIT_TIMEOUT:
{
}break;
default:
{
}break;
}
}while( dwWait != WAIT_OBJECT_0 );
The above code snippet assumes that your worker thread exits when it's finished doing it's thing. If it hangs around in a wait state for future requests, it's best to create an event object which is signalled when the worker thread finishes it's task & then have the above code snippet wait on the event handle instead of the thread handle.
FYI, the thread handle becomes 'signalled' when the thread exits. Signalled means that any of the wait functions will return.
HTH,
Wes
Sonork ID 100.14017 wtheronjones
|
|
|
|
|
I found out that I am scheduled to teach an AP Computer Programming class in Visual C++ this fall.
I'm trilled to find this site that has been a great help already, but I need to order the program and the textbooks. Any suggestions and comments would be appreciated.
Sherry
|
|
|
|
|
Is there already a cirriculum defined for the class? If so what will be the main focus?
Learning to program C++, Learning to program inside of the Visual C++ environment, Learning to program windows programs?
If you give a little bit more detail I think it would be a little easier to recommend some books for you.
As far as Visual C++, you should be able to get a really good acedemic discount on the standard version for your students.
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 a sample, I see that when the _RecordsetPtr objec tis created, its closed after we're done with it. Same for the Connection object.
What about the _CommandPtr object. After we get through, is there close() for it too?
I didnt see anything about it in MSDN or the web....
Thanks,
ns
|
|
|
|