|
You could try using the GetClassName() API function, it returns the name of the windows class, then you could check for it in a switch for the names of common controls (check MSDN for them).
Another approach for MFC might be using the IsKindOf() function.
Hope this helps.
|
|
|
|
|
Thanx (especially, because it was quick). I just tried GetClassName; it's beauty is, that I don't have to know the class name; I can get it from a known control and compare it later with the unknown (not as if it would be a problem to remember "Button").
|
|
|
|
|
Glad it worked 4 U
|
|
|
|
|
Hello,
My application needs to retrieve data from the socket, and processes it in real time. It is running OK if I don't use thread.
But when I add thread by calling CreateThread() whenever I receive a data buffer, I got problem.
For each thread I created, I call ProcessMessage(). Within this method, I call another dll ProcessData.dll to do the processing for me. And within this dll, I need to open the database c_database.Open(). That's where I got the error string "Connection in use".
The same code is running OK if I don't use thread..
What's the problem? How to fix it?
Please help!
TQD
|
|
|
|
|
Hi, im trying to learn about setting up system wide windows hooks, ibe
written the .dll where the hookproc resides, and a simple test app.
it actually works, as long as i dont try to call the test application from
inside the hook proc, but if i do try to call it, then its not system wide
any more!.
i put the global variables inside the .dll in a shared section like this:
#pragma data_seg(".HKT")
HHOOK hTheHook=NULL; // the hook handle
HNOTFN pTriggerFn=NULL; // Fn to tell the app the hook has been triggered
LPVOID pUserData=NULL; // app specific pointer passed to the above function
#pragma data_seg();
#pragma comment(linker, "/section:.HKT, rws")
to set the hook, the .dll exports a function like this (there is also
another one to remove it), wich is called by the test app:
BOOL DLL_EXPORT SetTheHook(HNOTFN CalledFn, LPVOID UsrDta)
{
pTriggerFn=CalledFn;
pUserData=UsrDta;
hTheHook=SetWindowsHookEx(WH_KEYBOARD, MyHookProc,
GetModuleHandle("HookLib.dll"), 0);
return (hTheHook!=NULL);
}
CalledFn is typedeféd as this
typedef void (CALLBACK* HNOTFN) (WPARAM, LPARAM, LPVOID);
the test app´s main dialog has a static member function with this signature,
wich is passed when the hook is set, so the .dll can "tell" the app when its
been triggered,
the LPVOID passed is the this pointer of the dialog itself, so the static
function in the dialog can cast it to the dialog type, and call other non
static functions.
my hook proc in the .dll is this:
LRESULT CALLBACK MyHookProc(int Code, WPARAM Wparam, LPARAM Lparam)
{
if(Code >= 0)
{
if(pTriggerFn)
pTriggerFn(Wparam, Lparam, pUserData);
}
return CallNextHookEx(hTheHook, Code, Wparam, Lparam);
}
The Problem:
if i compile / run the above, MyHookProc ONLY gets called when the test app
has the focus, if i press any key with the app minimized(not having focus),
it doesnt get called. (not a system-wide hook)
However, if i just remove the call to pTriggerFn(), and place some other way
of knowing its been called like MessageBox(NULL, "I was Called"), then the
hook works as expected! even if the test app doesnt have the focus!
any idea of what im doing wrong??
thanks for reading!
|
|
|
|
|
The problem could be the way you use the user-defined
function as a "callback". Where in your program is
this function defined? Statically, it seems on first analysis.
In order for it to work correctly this function *must* be
inside the hook DLL, otherwise when your hook DLL is
loaded into another process's address space,
the hook procedure will try to call a function that does not
exist in that address space, and "strange things" will happen.
You have to devise some kind of inter-process communication
to get this to work between processes. windows-messages,
events, rpc etc are all valid options.
Just a guess
James
http://www.catch22.uk.net
|
|
|
|
|
Thanks for your answer James, ibe just read Mr J. Newcomer´s article on hooks, and for what i understood, the whole "dll calls back the app by a function pointer" idea wont work, so i went for PostMessage() instead, the app passes its HWND to the dll in the call to set the hook, wich is stored in the dll´s shared section, and in the hook proc, the dll Posts a custom message to the app using this HWND.
Worked like a charm!
Thanks for reading
|
|
|
|
|
Newbie Question.
Ok, I need to write and then latter read multiple lines to a file.
I figured out how to write one line to a file, and I think I am close for multiple lines, but I am just doin something wrong.
char test1;<br />
char test2;<br />
<br />
test1 = 1;<br />
test2 = 2;<br />
<br />
FILE *fp=fopen("Test.startup","w");<br />
if(fp){<br />
fprintf(fp,"%d",test1 test2);<br />
fclose(fp);<br />
}<br />
Well, obviously that isn't working. Latter it is going to be for like 5 vars. So I am going to need to know how to write five vars, and read five vars to and from a file.
I think for reading it will be something like this.
FILE *fp=fopen("Test.startup","r");<br />
if(fp){<br />
int SomeVar;<br />
if(fscanf(fp,"%d",&SomeVar)==1){<br />
}<br />
fclose(fp);<br />
}
Please help.
Thanks,
Josh
|
|
|
|
|
char test1;<br />
char test2;<br />
<br />
test1 = 1;<br />
test2 = 2;<br />
<br />
FILE *fp=fopen("Test.startup","w");<br />
if(fp){<br />
fprintf(fp,"%d",test1 | test2);<br />
fclose(fp);<br />
}<br />
Well that didn't work, the file ended up being "3"
darn.
LOSTTWARE.com
|
|
|
|
|
Why dont you try with fstream instead? i find them to be a lot easier to use.
if you need help using fstreams, take a look in here http://www.cpp-home.com/FileIO_tutorial.php its a good tutorial on them.
hope this helps
|
|
|
|
|
Ok, I am getting closer, still getting errors, but so far I have this,
ifstream OpenFile("VARS.startup");<br />
char line[6];<br />
<br />
while(!OpenFile.eof())<br />
<br />
{<br />
OpenFile.getline(line,6); <br />
<br />
var_toolbar1 << line;<br />
var_toolbar2 << line;<br />
var_toolbar3 << line;<br />
var_toolbar4 << line;<br />
var_LCLWindow << line;<br />
var_OUTWindow << line;<br />
<br />
}<br />
OpenFile.close();
I declared the vars as intergers in the header file, and each line contains a 0 or a 1. The file has 6 lines for now. I need to get each line into it's respectful Var.
LOSTTWARE.com
|
|
|
|
|
1) fprintf(fp,"%d",test1 test2);
How did this compile?
If the line was "fprintf(fp,"%d",test1, test2);" then it would make since.
OH by the way: fopen("Test.startup","w") and fopen("Test.startup","r") assumes that you are loading binary data not text data. Use fopen("Test.startup","wt") and fopen("Test.startup","rt") when working with text file.
If you want to store characters '1' and '2' to a file:
char test1 = '1';
char test2 = '2';
FILE *fp = fopen("Test.startup","wt");
if(fp)
{
fprintf(fp,"%c%c",test1, test2);
fclose(fp);
}
If you want to load characters '1' and '2' from a file:
char test1;
char test2;
FILE *fp=fopen("Test.startup","rt");
if(fp)
{
if( fscanf(fp,"%c%c", &test1, &test2) )
{
}
fclose(fp);
}
From what I have seen, all you need to do is study the documentation for file I/O. I know peaple ar going to throw iostream a you as a suposably better solution. But 90% of the time it is just a wrapper for for what you are doing.
Writing chacaters to a file using fprintf() is ok, but reading them with fsprintf() has (almost always) been a joke.
Before you use iostream you must understand reading a file at the system level (a.k.a. C level).
INTP
|
|
|
|
|
John R. Shaw wrote:
Writing chacaters to a file using fprintf() is ok, but reading them with fsprintf() has (almost always) been a joke.
Someone has actually suggested that reading from a file can be done via fsprintf() ?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Doh!
I was not thinking clearly. I just made some modifications to the sample code that was given. Besides it should not have been fsprintf (does this exist), it should have been fscanf.
INTP
|
|
|
|
|
i have a lot of questions about compliers
would U plz help me
in my case, it's tcc compiler, and i have to program an auto-grader for C language using C++.
and here are my Q.:
Can i convert a .exe compiler (tcc) to a .dll? How?
How can i get the output file from the (tcc) compiler
Where can i find the error codes or ID, so i can change the error messegs?
Thanx,
|
|
|
|
|
Hi,
What's exactly tcc compiler, I think you're using Turbo C++ ( or Borland C++ 3.1 or older ).
Well, There isn't anyway to use of that compiler to create your Dll.
TCC compilers are 16-bit and they have been made for Ms-Dos OS.
So, The short answer is NO.
But there's MANY ways to create your dll from your code.
Make new project in Visual C++ (Win32 Dynamic-Link Library project or MFC AppWizard Dll project) and then use of your old code !
hmm, perhaps you'll have to change some part of your code because of Dll structures, but you really don't need to change the main code.
Regards,
|
|
|
|
|
Hi,
Yeah i mean Turbo C++
do U know how to get the output files from it?
|
|
|
|
|
Hi there everyone. I am new to MFC application programming. I was just wondering how do i gray a submenu during runtime? For instance like Microsoft Visual C++, you'll need to open up a workspace before the File>Close Workspace will be active. Otherwise it will still stay grayed.
|
|
|
|
|
Try using the method EnableMenuItem() with nEnable set to MF_GRAYED.
From the docs:
=============================
CMenu::EnableMenuItem
UINT EnableMenuItem( UINT nIDEnableItem, UINT nEnable );
MF_GRAYED Disables the menu item so that it cannot be selected and dims it.
=============================
For this to work, you'll need to use CMenu classes for your menus and not just resource menus.
If you don't want to use CMenu, then you can gray menus by using the SDK call EnableMenuItem:
=============================
The EnableMenuItem function enables, disables, or grays the specified menu item.
BOOL EnableMenuItem(
HMENU hMenu, // handle to menu
UINT uIDEnableItem, // menu item to enable, disable, or gray
UINT uEnable // menu item flags
);
=============================
|
|
|
|
|
|
This is an unusual question, because MFC atomaticaly grays submenus until the use specifies a handler or explicitly says not to gray it. The question why is the menue item grayed is far more commond (a good thing). One of the great things about using MFC class wizard it that you do not need to know the details (although you should). When you bring up the class wizard it gives you a chance to specify a handler to use when you select an item (menu/button/etc..) as well as wheather it is enable or not.
INTP
|
|
|
|
|
What i try to say is that how do i gray a particular submenu when i press a button for instance. I know that in the properties, you could gray the submenu. But what i need is to gray the submenu during runtime.
|
|
|
|
|
The normal MFC way of enabling/disabling menu items during runtime is to implement the UPDATE_COMMAND_UI handler for the item.
To do this, use the class wizard to add an UPDATE_COMMAND_UI message handler for the particular menu item that you want to handle:
- On the "Message Maps" page, select the object id of the menu item that you want to control
- select the UPDATE_COMMAND_UI in the Messages window.
- Click on the "Add Function" button to add a handler for it.
- Click on the "Edit Code" button to goto the code for the newly added handler.
In the handler code, you can control whether the menu item is enabled or disabled as follows:
- To enable the menu item, call pCmdUI->Enable( TRUE );
- To disable the menu item, call pCmdUI->Enable( FALSE );
|
|
|
|
|
how could i draw an irregular dialog,for example, like the interface of winamp, according to an image basing on SDI, MDI or Dialog?
could anyone show me a detail step or some articles?
thanks
|
|
|
|
|
Check out,custom drawn button in the CP, i dont know exactly where it is,
There is one article that shows how to draw custom shape button depending upon the button image.
Dont be surprised that i asking you to look into button article, button is a window so it ur dialog, , you can get some inspiration from that article.
Prakash.
The World is getting smaller and so are the people.
|
|
|
|
|