|
Set a timer for 100 msec.
HPS HwndSpy - GUI developer's aid to visually
locate and inspect windows. For the month of August
only, use coupon code CP-81239 for 30% off.
|
|
|
|
|
I want to restart my MFC dialog application at run time - i.e. to close the dialog box and create it immediately after that. Any suggestions how to this? Thanks.
|
|
|
|
|
You can call CreateProcess in your CMyApp::ExitInstance
But why do you want this?
Arjan.
|
|
|
|
|
Hi, how I can response the system message, when my program is in a loop?
(for instance in a 'for' loop). I want to not use Timer & Thread programing.
DoEvent is a function of Visual Basic.
Thank;)
|
|
|
|
|
when you get a system message, you'll get it as WM_SYSCOMMMAND message on your window!
for a window, you normally have a main loop, which calls GetMessage, TranslateMessage and DispatchMessage!
this loop calls you window procedure!
that means, when you're out of your for loop, the window's message queue will be processed, also the syscommand!
Don't try it, just do it!
|
|
|
|
|
|
GDI+ initialization wrecks up DDE file opening in my MDI application (i.e. when you click on the document file in the Explorer). When I call GdiPlusStartup(...) before CMDIFrameWnd::LoadFrame in CMyApp::InitInstance , it says "Windows cannot find the file: ..." at first, the application shows no window, but it stays running and loads document properly at second attempt. When I initialize GDI+ after CMDIFrameWnd::LoadFrame , the document loads properly but the whole frame goes background.
It seems that nasty GDI+ hidden window demolishes DDE window order or something alike. I tried it on the pure AppWizard-generated MDI sample and it's exactly the same phenomenon. I may send the sample if you have any ideas.
Regards,
BB
|
|
|
|
|
i have created a custom tree control and created a group box to contain its location within in my dialog
here is the code
GetDlgItem(IDC_ZONETREE_FRAME)->GetWindowRect(frameRect);
zone_tree.Create(WS_VISIBLE|TVS_HASLINES|TVS_LINESATROOT|TVS_SHOWSELALWAYS|TVS_HASBUTTONS , frameRect, this, IDC_ZONETREE);
however when i run the program the tree control is like an inch below the group box is there something wrong with my code or whats the deal here ?
|
|
|
|
|
Try this:
GetDlgItem(IDC_ZONETREE_FRAME)->GetWindowRect(frameRect);
ScreenToClient(&frameRect);
zone_tree.Create(WS_VISIBLE|TVS_HASLINES|TVS_LINESATROOT|TVS_SHOWSELALWAYS|TVS_HASBUTTONS,
frameRect, this, IDC_ZONETREE);
HPS HwndSpy - GUI developer's aid to visually
locate and inspect windows. For the month of August
only, use coupon code CP-81239 for 30% off.
|
|
|
|
|
The previous answer is right, but the reason you need the ScreenToClient() call is that GetWindowRect() returns the coords relative to the screen, but Create() takes coords relative to the dialog's client area.
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--=
NO CARRIER
|
|
|
|
|
would like to have your point of view about a really weird behaviour with my popup menu on XP (Desktop properties => Menu Fade effect). I only use CMenu to create the popup menu.
I coded a very simple MFC program to display a popup memu when the left mouse button is pressed.
So I back and forth between my App (Left button) and the desktop (right button)and after a while the menu doesn't display fine.
(http://home.comcast.net/~llaissus/MFCMenu.jpg)
(http://home.comcast.net/~llaissus/MFCMenu2.jpg).
I just get the shading for the whole menu sytem on XP.
I have to click again in my app to get a good display. If I didn't do that I have to reboot my PC to fix that. (It seems like when you put break point in WM_DRAWITEM).
Note It works fine with Menu Scroll effect or no menu effect.
I think it's a problem of timing but I don't know why
I did that and it works better
LRESULT CALLBACK NewMenuHook(int code, WPARAM wParam, LPARAM lParam)<br />
{<br />
return CallNextHookEx(HookOldMenuCbtFilter, code,wParam, lParam);<br />
}<br />
<br />
<br />
BOOL CMFCMenuApp::InitInstance()<br />
{<br />
<br />
HookOldMenuCbtFilter = ::SetWindowsHookEx(WH_CALLWNDPROC, NewMenuHook, NULL, ::GetCurrentThreadId());<br />
<br />
.../...<br />
}
Code .NET:
http://home.comcast.net/~llaissus/MFCMenu.zip
Has anyone any idea ?
Is it a XP bug ?
Regards
|
|
|
|
|
Am replying according to the snapshots you sent, cuz I encountered such weird effect before and it mya be the same problem.
I have encountered this problem when I was making an owner draw menu, which I guess you are making one as well. According to the MSDN you shall save the DC state that is passed to you in the DRAWITEMSTRUCT struct and restore it back.
I found that this is simply calling SaveDC and RestoreDC. Follwing is the code i used:
void CMainFrame::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if(nIDCtl == 0)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
dc.SaveDC();
.
.
.
dc.RestoreDC(-1);
dc.Detach();
}
}
When added this lines it did solve the problem and menus didnt show this effect anymore, so I hope this solves your problem.
|
|
|
|
|
Dear all
I have made an application in MFC using VC++ version 6.0 for Windows
2000 which uses Shell_NotifyIcon to show icon on the status bar. I have
made this application as a NT Service. (ie. the code of service is in
the MFC application only).
Purpose of application:
........................
The purpose of application is that when we run it as a service, an icon
appears in system tray and currently the window corresponding to it is
hidden. When we double click the tray icon the window corresponding to
it is shown. (ie I call ShowWindow(SW_RESTORE) to show the window .)
Problem
........
The program works fine across reboots but gives problem during log
off/log on. When we logg off the system and then login, the icon in the
system tray is shown . But this icon is not responding at all. ie. if
we click double click on it then no event is called and the window is
not shown.
I think we have to refresh the system tray task bar after logon OR may
be there some problem in the service.
Can anybody please suggest a way out. Thanks in advance.
|
|
|
|
|
Hi im creating a popup menu but i only want it to show up when the user right clicks on a tree ctrl in a dialog i mapped the tree controls onrightclick but i dont know how to get the mouse coordinates what is the best way to handle a popup menu for a tree control within a dialog
|
|
|
|
|
It would be better to use WM_CONTEXTMENU instead of the right-click. The reason for this is that OnContextMenu() also catches Shift+F10, which is the Windows standard shortcut key for context menus (try it in the Explorer). But to catch right-clicks with OnContextMenu(), you also have to have a handler for ON_WM_RBUTTONDOWN - otherwise, the tree control will think you are starting a drag operation. One final thing: if OnContextMenu gets called because of Shift+F10, the point will always be -1, -1. Therefore, always use GetCursorPos() to get the actual point.
Here is an example (it assumes you have derived a minimal CMyTreeCtrl from CTreeCtrl):
void CMyTreeCtrl::OnRButtonDown(UINT nFlags, CPoint point)
{
}
void CMyTreeCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
{
CPoint pos;
GetCursorPos(&pos);
ScreenToClient(&pos);
UINT flags = 0;
HTREEITEM hItem = HitTest(pos, &flags);
SetFocus();
if (hItem != NULL)
{
SelectItem(hItem);
CMenu menu;
menu.CreatePopupMenu();
VERIFY(menu.AppendMenu(MF_STRING, ID_MYID, "My Selection"));
GetCursorPos(&pos);
VERIFY(menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, pos.x, pos.y, this));
}
else
{
TRACE("not on item\n");
}
}
HPS HwndSpy - GUI developer's aid to visually
locate and inspect windows. For the month of August
only, use coupon code CP-81239 for 30% off.
|
|
|
|
|
I readed this topic and I tested it. HitTest() and SelectItem() dosen't exist when i try to complie it. Do I have to include header files or something?
|
|
|
|
|
void CTestView::OnContextMenu(CWnd* pWnd, CPoint point)
{
CMenu *pMenu,oMenu;
oMenu.LoadMenu(IDR_TESTMFTYPE);
pMenu = oMenu.GetSubMenu(0);
pMenu->EnableMenuItem(ID_FILE_NEW,MF_DISABLED | MF_GRAYED);
pMenu->TrackPopupMenu(0,point.x,point.y,this);
}
|
|
|
|
|
Hi,
I writing a small program what read a file, say has 600000000 ip addresses, and output to different smaller files (each contains 2000 ip addresses)as such file1.txt, file2.txt, file3.txt.,, so on. I am stuck at the part of how to name the output files.
Can anyone help me?
Thank you very much.
|
|
|
|
|
for ( int i = 1; i <= 2000; i++ )
{
ostringstream strmName;
strmName << "file" << i << ".txt" << ends;
ofstream outfile ( strmName.str().c_str() );
}
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--=
NO CARRIER
|
|
|
|
|
Micheal, Thank you very much.
Tomss.
|
|
|
|
|
I have used the following code, but feel uncomfortable about it, if you could make any suggestions as to how to better it, I would appreciate it.
char* pTmpBuf = new char[filename.GetLength()+1];
ZeroMemory(pTmpBuf, filename.GetLength()+1);
CopyMemory(pTmpBuf, filename, filename.GetLength());
GetParent()->SendMessage(LVN_ADDFILE, filename.GetLength(), (LONG)pTmpBuf);
delete[] pTmpBuf;
Thats the code that send the message obviously
void MyDialog::MyFunc(WPARAM wParam, LPARAM lParam)
{
CString buff="";
CopyMemory(buff.GetBuffer(wParam), (void*)lParam, wParam);
AfxMessageBox(buff);
}
The main question I have...is it safe to delete the temp buffer after the message has been sent? Or should I leave deletion of the pointer to the client programmer inside MyFunc
I'm drinking triples, seeing double and acting single
|
|
|
|
|
As long as you are using SendMessage, which is Synchronous, you are fine to delete pTmpBuf after the call to SendMessage. SendMessage won't return until the message is completely processed.
If on the other hand, you were using PostMessage, which is Asynchronous, you would have to delete pTmpBuf inside your MyDialog::MyFunc instead, because PostMessage will almost certainly return before your message is processed.
Chris Richardson Terrain Software
|
|
|
|
|
Chris Richardson wrote:
As long as you are using SendMessage, which is Synchronous, you are fine to delete pTmpBuf after the call to SendMessage. SendMessage won't return until the message is completely processed.
Thats all I wanted to know...
Thanks a bunch
I'm drinking triples, seeing double and acting single
|
|
|
|
|
Unless I'm missing something, you're making it way too complicated. The SendMessage can be:
GetParent()->SendMessage(LVN_ADDFILE, (WPARAM)(LPCTSTR) filename); Then the message handler can do:
void MyDialog::MyFunc(WPARAM wParam, LPARAM lParam)
{
AfxMessageBox ( (LPCTSTR) wParam);
}
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--=
NO CARRIER
|
|
|
|
|
Hi, I want to find a file that could be in any directory in any of the local disks. CFileFind find relies on specific directories. Is there an easy way to do this, or do I need to hack something up? If I need to hack something, does anybody know how to get a list of the drives?
Cheers
|
|
|
|