|
Another way of doing it would be for you to learn COM+ wich is the standard that Microsoft uses for Dll's.
I find COM+ the easiest way of doing it. Preferably by using ATL but you can do it with MFC aswell.
Any respectible book about MFC or ATL would do for you. Just make sure that the MFC book contains chapters about COM/Automation/OLE.
/Martin
|
|
|
|
|
I have a list box, and want the user to be able to search by typing, for example "pagescan" and have it match the first instance of "Read_Page_Scan_Enable" or "Write_Page_Scan_Enable". To accomplish this, I specified the LBS_WANTKEYBOARDINPUT style for the list box. In the WinProc for the parent window, I handle WM_VKEYTOITEM to build up a buffer of recent keys (with a timeout) and do a customized comparison (ignore case, ignore underscores, if not present in user-typed text, ignore Set_, Read_, Write_ in the list item text). I find the first match, or if none, consider the item at index 0 to match. I send an LB_SETCURSEL message to select the item, and dutifully return -2 from WinProc. The documentation for WM_VKEYTOITEM states:
"A return value of –2 indicates that the application handled all aspects of selecting the item and requires no further action by the list box."
And yet... If I type "pages" everything functions for p,a,g,e and I see the search narrow to the proper item (none of those letters are present as the first letter of any of the strings for any items in the list) but as soon as I type the S key (there is an item starting with S), the list box jumps to the first string starting with S!!! That is so completely screwed up...I think NT stands for "Not Tested"...does anyone know a workaround for this?
Thanks in advance,
Brian
|
|
|
|
|
I did find a workaround, but it isn't very nice...here it is:
SendMessage( (HWND)m_commands_list, LB_SETCURSEL, matching_index, 0);
m_windows_suck_workaround = true;
Then way back out in WinMain, in the Translate/Dispatch loop:
if(msg.message == WM_CHAR && m_windows_suck_workaround)
{
m_windows_suck_workaround = false;
continue;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
It's actually not quite as indicated because of the objects involved (the m_ prefix betrays the fact that it's a member variable in an MDIChildWindow_t subclass but the above code shows the gist of it.
The question still stands, but I'll rephrase it as does anyone know a more appropriate workaround?
Thanks,
Brian
|
|
|
|
|
ummmmm have u tried trapping the pretranslatemsg() for the dialog and filtering there too to stop the default listbox behaviour?
just a thought
"traffic lights are for people who can't make their own decisions" biz stuff about me
|
|
|
|
|
Is there any way not to save the data at once. I would like to have a Ok and a Cancel button and not save the data till they hit ok.
Is there a way of doing this with a CDataGrid in VC++ 6.0.
thanks
Scott
|
|
|
|
|
can i use WM_TIMER and SetTimer without a Thread?
how must i use it?
can somebody give me an example?
thanks
sunny
|
|
|
|
|
Sunnygirl wrote:
can i use WM_TIMER and SetTimer without a Thread?
No. On the other hand, without a thread you don't have any code running, so that shouldn't be a problem.
Perhaps your question is if you can use SetTimer and handle WM_TIMER messages in the main thread? In that case the answer is an obvious Yes. For examples, please look it up yourself. MSDN, Google, even CodeProject itself contains lots of example code.
|
|
|
|
|
Hello,
I'am doing a mfc dialog based program. In this one, I have a settings dialog box that should allow the user to select somethings through check boxes. The problem is that I've a lot of checkbox in this dialog (18 check box even more later!).
I wanted to do array of controls in my settings dialog box (just like in VB). In order to do that I've short-circuited Class wizard to create an array of CButton member variables but I still have to enumerate each variable for each ID of each control with the DDX_Control(...) macro.
There is also another problem.
If the member variable is defined like this:
CButton m_variable1;
I can use the following statement:
m_variable1.SetCheck();
But if I use the following declaration:
CButton m_variable[18];
m_variable[0].SetCheck();
I'have a assertion failed.
Can somebody give me a smart way to do such array of control?
Thanks a lot.
T. Varidel
|
|
|
|
|
The smart alternative: A list box of checkboxes, via the CCheckListBox class.
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
You can do something like this:
CButton* pButton[] =
{
&m_chk1,
&m_chk2,
&m_chk3,
&m_chk4,
};
pButton[n]->DoSomething();
or
UINT array[] =
{
IDC_CONTROL1,
IDC_CONTROL2,
IDC_CONTROL3,
IDC_CONTROL4,
};
GetDlgItem(array[n)->DoSomething();
or use collection classes or STL;
header file:
vector<cwnd*> m_wnds;
then add your controls
int OInitDialog:
m_wnds.push_back(&m_chk1);
m_wnds.push_back(&m_chk2;
m_wnds.push_back(&m_chk3);
m_wnds.push_back(&m_chk4);
m_wnds.at(i)->DoSomething();
|
|
|
|
|
Redesign your app. 18 checkboxes in one dialog is just too much.
And use a listview, a tree with checkboxes, whatever.
I don't think this is a serious possesion, and the evil most likely comes from your hand. Colin J Davies, The Lounge
|
|
|
|
|
I've created a dialog application in MSVC++ on an NT platform. Within the application I'm making periodic system calls to invoke the execution of a bat file. Every time the system call is made a MS Dos Command prompt window displaying cmd.exe in the title bar appears then disappears(quite annoying). Is there a way of disabling this behavior, or is there another call that can be made to invoke the bat file without the creation of the Dos window.
|
|
|
|
|
CreateProcess with CREATE_NO_WINDOW flag
|
|
|
|
|
One solution is SW_HIDE and CreateProcess().
STARTUPINFO si;
si.wShowWindow = SW_HIDE;
::CreateProcess(...);
Kuphryn
|
|
|
|
|
CreateProcess is the official way, but if you just need a quick alternative,
WinExec("whatever.exe", SW_HIDE);
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
i have made a little wrapper [in C#] for using windows hooks. When i came to test it, I found that it works on local hooks, butnot system wide hooks. i set the threadID to 0 as msdn instructs, but it doesnt work, so I was wondering if there are any special permissions needed to do such a thing. [i am using Windows Xp Pro]
1001111111011101111100111100101011110011110100101110010011010010 Sonork | 100.21142 | TheEclypse
|
|
|
|
|
|
Nishant S wrote:
Global hooks need to be in a DLL.
Well thats a bit stupid if you ask me. is that the SetWindowsHookEx call - or the callback in the dll?
1001111111011101111100111100101011110011110100101110010011010010 Sonork | 100.21142 | TheEclypse
|
|
|
|
|
|
Hy everyone!
I have a problem here...
my CRichEditCtrl, when it haves more than ~250 characteres, it crashes, and loses my CHARFORMAT atributes.
Or, if I try to make CString::GetLength() with the String that is associate with the control, it crashes too...
does anyone have some idea?
thanks!
Ricky
|
|
|
|
|
I need to know how I can detect whether the user currently has an active internet connection. Can anyone help? I've tried InetIsOffline(), but that only determines if the user is in online or offline mode, not if the actual connection is currently active.
|
|
|
|
|
One solution is to simply connect to a server.
Kuphryn
|
|
|
|
|
bool IsConnectedToInternet(void)
{
DEBUGF("IsConnectedToInternet");
WORD wVersionRequested = MAKEWORD(1, 1);
WSADATA wsaData;
TCHAR hostaname[1000];
int hostname_size = sizeof(hostaname);
bool connected = false;
if (WSAStartup(wVersionRequested, &wsaData) != 0)
{
DEBUGF("WSAStartup Failed (%i.%i) %s",
wsaData.wHighVersion, wsaData.wVersion, wsaData.szDescription);
return connected;
}
if (gethostname(hostaname, hostname_size) != SOCKET_ERROR)
{
struct hostent FAR *h = gethostbyname(hostaname);
if (h != NULL)
{
DEBUGF("gethostname %s %s", h->h_name, h->h_addr_list[0]);
if (strncmp(h->h_addr_list[0], "\x7f\x0\x0\0x1", 4)!=0)
{
connected = true;
}
}
}
else
{
DEBUGF("gethostname Failed");
}
WSACleanup();
return connected;
}
Todd Smith
|
|
|
|
|
Is it possible to add a scroll bar to a CStatic control?
I've derived a new base class from CStatic for graph/chart purposes, and I'd like to be able to allow the graph to scroll if it is too big for the available viewing area. I've found many graphing projects on the net, but none seem to have this feature which is of particular importance to me since I have long series of data.
I've tried adding the WS_HSCROLL and WS_VSCROLL styles, I've called EnableScrollBarCtrl(), and I've called ShowScrollBar() but none of these methods have any effect. Anyone know something I don't?
A second question: I've also added the SS_NOTIFY style, but my (base) class isn't receiving the notification. Do I have to override the message notification in every other class I derive from the base class to process the notification?
Thanks for the help,
--Dean
|
|
|
|
|
FWIW, I would have derived the control from CWnd, not CStatic. CStatic has too many restrictions such as the ones you described.
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|