|
when you click button then button has focus,can you use of GetFocus ?
|
|
|
|
|
When you click the button the button will receive a WM_SETFOCUS message.
That message contains the handle of the window that lost focus. You could compare
that handle to the edit control window handles.
An alternative is to have the edit controls track when they get focus.
Remember that the last window with focus when your button is clicked isn't necessarily
going to be one of the edit controls. It may not even be a window in your app.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi all. Im trying to make the same function but with a console instead of a Window app. The code is from this site here: http://www.codeproject.com/system/Hack_Windows_Task_Manager.asp
From what i can see in my version i've done everything right but its not doing the desired task which is to wipe the list in task manager.
Here's what i have.
<br />
#include <iostream><br />
#include <afxcmn.h><br />
using namespace std;<br />
<br />
BOOL CALLBACK EnumChildProcedure(HWND hWnd, LPARAM lParam);<br />
<br />
void main(){<br />
HWND taskmnger = ::FindWindow(NULL,"Windows Task Manager");<br />
if(taskmnger){<br />
cout << "Task Manager window found! " << endl;<br />
EnumChildWindows(taskmnger,EnumChildProcedure,NULL);<br />
}<br />
else{<br />
cout << "Not found! " << endl;<br />
}<br />
}<br />
<br />
BOOL CALLBACK EnumChildProcedure(HWND hWnd,LPARAM lParam)<br />
{<br />
char name[256]; <br />
GetWindowText(hWnd,name,256);<br />
<br />
char ClassName[256];<br />
GetClassName(hWnd,ClassName,256);<br />
<br />
if((strcmp(ClassName,"SysListView32")==0)&&(strcmp(name,"Processes")==0))<br />
{<br />
cout << "Process tab Found! " << endl;<br />
}<br />
if((strcmp(ClassName,"SysListView32")==0)&&(strcmp(name,"Tasks")==0))<br />
{<br />
cout << "Task tab Found! " << endl;<br />
}<br />
if(name==NULL)<br />
return FALSE;<br />
return TRUE;<br />
}<br />
Im thinking my problem lies in the SendMessage function. Everything else seems to work. EnumChildWindows() and the Enum function all detect the lower windows. But when it finds the windows, it doesnt pretty much do anything. So if anyone has any suggestion as to what im missing please let me know. Thanx in advance!
|
|
|
|
|
hi every one
am stuck, this is what i want to do.
i have a Report styled list control with 5 columns and i have a double clicked event handler for the list control; so i want to get the index of a row once i double click on it, which list control function do i interrogate, e.g
if it was a list box , i would do this;
CListBox m_Listbx;
....
...
int nSel = m_ListBox.GetCurSel();
now in CListCtrl what function is analogous to CListBox's GetCurSel() and how is it used..
thanks;
|
|
|
|
|
GetNextItem(-1,LVNI_SELECTED); .
|
|
|
|
|
GetNextItem()
retrun value is an integer.the integer is your need
|
|
|
|
|
About several weeks I tried to learn MFC,but unfortunately failed to do so.
At first I was confident ,but then I got frustrated 、confused and didn't know what to do.
I think I've known C++ well,and know something about computer organization and operating
system .But I just could copy the same codes as described in the books,even cannot change a bit.
I didn't know exactly what the code means,and could nou find the ways.Is it googbye to the MFC world? I wonder....
Hope for help.
|
|
|
|
|
If you can not write your code so you are faint on MFC and need to more work of course codeproject has articles about MFC and its controls but I suggest see codes that has beginner on their titles, do you know c++ very well for example Object Oriented Programming (inheritance,Polymorphism) and Type Casting,Preprocessor directives, Input/Output,Arrays,Pointers Dynamic Memory and other things,but I didnt understand you cant change codes on books?
|
|
|
|
|
Take a look at "Teach Yourself Visual C++ 6 in 21 days" Its great, for the total beginners, and for slightly experienced. It did help me with some stuff too...
//Johannes
|
|
|
|
|
If you really want to learn MFC, then you really need to understand
Windows programming.
Start with the basics. Get the book "Programming Windows" by Charles Petzold
or an equivalent. Make sure you understand Windows Messaging, the basics of
Win32 APIs, etc.
MFC will make a lot more sense if you understand what's going on.
Just my opinion,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
One thing I made when I started with MFC was, after reading some online manuals and articles of codeproject, started a MFC-Win32 application with the wizard of VC++ 6.0. Then, just with the 5 classes created (CMyApp, CMyDoc, CMyView, CMainFrm, CChildFrm), I used the class wizard to call almost all messages in every class. Just putting an AfxMessageBox ("(Funct Nr XX) The function XXXX is being called") and just played with the windows up and down, clicking, opening docs, closing docs, destroying windows, resizing... all what I could do with empty code.
Afterwards, when I more or less knew the order in which functions are called. I put some break points here and there. When the debug stays in a break point, you get a step towards with F10, but if you use F11, the step is towards (but going INTO the called code). I mean.
BOOL CMyApp::InitInstance ( )
{
if (!ProcessShellCommand(cmdInfo))
return FALSE;
pMainFrame->ShowWindow(m_nCmdShow | SW_SHOWMAXIMIZED);
pMainFrame->UpdateWindow();
}
When compile, it stops at the if . If you use F10, it will go to pMainFrame->ShowWindow (...); (next line in the same layer). But if you use F11 insteads, then you will go to the next step in a deeper layer:
BOOL CWinApp::ProcessShellCommand(CCommandLineInfo& rCmdInfo)
{
BOOL bResult = TRUE;
switch (rCmdInfo.m_nShellCommand)
{
case CCommandLineInfo::FileNew:
if (!AfxGetApp()->OnCmdMsg(ID_FILE_NEW, 0, NULL, NULL))
OnFileNew();
if (m_pMainWnd == NULL)
bResult = FALSE;
break;
}
That is part of the hidden code that you don't usually see.
Maybe this is not the best way to learn it correctly, but for me was ok to have a global idea (seeing more or less how the functions are distributed and reading the comments from Microsoft in the code). And after I went deeper in contents as I needed new things.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
You're throwing in the towel only after a couple of weeks of learning MFC? Amazing! I've still not got it all figured after 15 years. Maybe I'm just stubborn.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I have a question in regards to, if there is a built in function in mfc
i can overload that gets called when a dialog is brought back to focus
after a DoModal() operation. I end the modal dialog with OnOK().
the OnPaint() starts to paint again when its brought back to focus,
but is there is a cleaner way to check for this event?
Thanks
|
|
|
|
|
I'm not sure what you're asking...
As soon as DoModal() returns, the modal dialog
has been dismissed. While the modal dialog was displayed,
other windows should still get WM_PAINT messages.
If you've halted painting before calling DoModal(), then just
start painting again when DoModal() returns.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The initial dialog does not paint when there is
a modal dialog in focus, because i run the app in full screen.
But if there are no functions that i can use that deals
with "OnFocus", WM_PAINT works, i just need to be carefull with it.
Thanks
Fredrick
|
|
|
|
|
You could use the WM_ACTIVATE[^] message. Use a handler which looks something like this:
void CDialogAppDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CDialog::OnActivate(nState, pWndOther, bMinimized);
if (nState==WA_ACTIVE || nState==WA_CLICKACTIVE)
{
}
}
Steve
|
|
|
|
|
Perfect, just what i needed.
Thanks!
|
|
|
|
|
Hello everyone,
I think in built-in C/C++ functions, there is no direct function call to trim heading and trailing space characters, right? So, we have to implement it manually by iterating the string to check character one by one.
Support not using MFC.
thanks in advance,
George
|
|
|
|
|
|
Hi Christian,
It is implemented by find_first_not_of and find_last_not_of of STL string,
no built-in functions.
regards,
George
|
|
|
|
|
G'day George,
dBaseIII had a popular function for this purpose, alltrim. In the mid nineties i needed that function in C and wrote the following implementation, plain C code.
<br />
char *alltrim( char *t)<br />
{<br />
unsigned char *t_, *tc_;<br />
int i=0, l;<br />
<br />
l = strlen(t);<br />
tc_ = (unsigned char*) t;<br />
<br />
<br />
while (*(tc_+i) <= ' ' && i < l)<br />
i++;<br />
<br />
if (i==l) <br />
{<br />
*t = (char) 0; <br />
return t;<br />
}<br />
else<br />
t_ = ( unsigned char* ) (t+i); <br />
<br />
<br />
<br />
i=l-1;<br />
while (*(tc_+i) <= ' ')<br />
i--;<br />
i++; <br />
*(t+i) = ( char ) 0; <br />
l = strlen((char*) t_) + 1; <br />
memmove(t, t_, l); <br />
return t;<br />
}<br />
Unfortunatedly the preview of the code looks awfull, like it has been handled by alltrim itself.
Regards,
Henk
21cm: the universal wavelength of neutral hydrogen
|
|
|
|
|
Thanks Henk,
I think you mean there is no built-in function.
regards,
George
|
|
|
|
|
I have written a CString Object into Text file by using :
f.Write (&FileName,FileName.GetLength());//FileName is CString Object
Now I want to Read CString object back How this could be done?I am using code :
LPTSTR p = CurrentLanguageName.GetBuffer(11);
void *g=(void *)p;
f.Read (g,CurrentLanguageFileLen);
CurrentLanguageName.ReleaseBuffer( );
//But this method don't work.
Regards,
priyank
|
|
|
|
|
you better use CStdioFile class which is derived from CFile.
It has a ReadString and a WriteString method.
|
|
|
|
|
Try the following to write:
CString StringToWrite;
StringToWrite="ABC";//e.g.
f.Write (StringToWrite.GetBuffer(20),StringToWrite.GetLength()+1);
Try the following to read:
CString str;
char B;
for(i=0;i<1000;i++){
f.Read(&B,sizeof(B));
str+=B;
if(B=='\0')break;
}
Not the best way to do it, but if it work U R OK!
kostas KEL
|
|
|
|
|