|
There's no such thing as converting ASCII to hexidecimal. One is not like the other. Perhaps you wanted to know how to convert from base 10 to base 16.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
|
Hello Techies,
How can I retrieve the path from where the application is being executed? This path should be retrieved at the initialization process itself.
Thank you,
Bye
Neelesh Jain
|
|
|
|
|
Use GetModuleFileName , passing NULL in for the hModule parameter.
|
|
|
|
|
Thank you Graham, But when I used the above function in the following way
GetModuleFileName(NULL,LPTSTR(path),1000);
It gave me an memory exception mentioning that it cann't read the memory.
path is a type of char pointer.
I had declared path as char* path;
|
|
|
|
|
It sounds as if you haven't allocated the memory - GetModuleFileName won't do that for you.
Try:
char path[1000];<br />
GetModuleFileName(NULL, path, 1000);
This statically allocates 1000 characters for the path variable.
|
|
|
|
|
Hi Graham,
Thank you for ur suggestion, its working, but its retrieving the file name also. I want to know only the path. For eg., If the application is present in C:\my document\Testing, then its displaying as C:\my document\testing\Test.exe
but i want to display only C:\my document\Testing. The application file should be displayed.
Bye
Thank you once again
Regards,
Neelesh
Neelesh Jain.
|
|
|
|
|
The easiest way to do this is to parse the returned string and find the last '\'. If you terminate the string there you will get just the path as you require.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
You should process yourself. Just find the last \ and extract the left before that.
|
|
|
|
|
|
use _tSplitPath api,that may help you in above cause
and for removing '\' use CString::trimRight function
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
I display HTML reports in a CWebbrowser2 control embedded in my dialog based app. I also draw graphs within it using DHTML. They will only print if "Print Background Colours and Imgages" is set within Internet Options in the control panel. Is there a way I can set this for just the webbrowser control and not globally?
TIA
I feel like I'm diagonally parked in a parallel universe
Jerry Davis
http://www.astad.org http://www.jvf.co.uk
|
|
|
|
|
Hi all
I tried to use CursorClip to limit my drawing region on SDI. Any easier way to do that? I need to limit my drawing region to a rectangle (400x400 pixels).
Thanks;)
|
|
|
|
|
RECT rcClip; // new area for ClipCursor
RECT rcOldClip; // previous area for ClipCursor
// Record the area in which the cursor can move.
GetClipCursor(&rcOldClip);
// Get the dimensions of the application's window.
rcClip = your_rectangle(400x400);
// Confine the cursor to the application's window.
ClipCursor(&rcClip);
//
// Process input from the confined cursor.
//
// Restore the cursor to its previous area.
ClipCursor(&rcOldClip);
|
|
|
|
|
THanks for the code. But I am still quite confused.
rcClip = your_rectangle(400x400);
When I use GetClientRect(), it retrieved the coordinates of the top left of the client. However, when I am using SDI, there is menu and toolbar.
Can you write more detailed? I am new to visual C++ but I have programming experience.
Thanks;)
|
|
|
|
|
POINT p;
GetClientRect(hwnd, &rcClip);
p.x = rcClip.left;
p.y = rcClip.top;
ClientToScreen(hwnd, &p);
OffsetRect(&rcClip, p.x, p.y);
ClipCursor(&rcClip);
ShowCursor(TRUE);
//////////////////////////////
// The GetClientRect function retrieves the coordinates of a window's client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner will be (0,0).
// The ClientToScreen function replaces the client coordinates in the POINT structure with the screen coordinates. The screen coordinates are relative to the upper-left corner of the screen.
// The OffsetRect function moves the specified rectangle by the specified offsets.
// The ClipCursor function confines the cursor to a rectangular area on the screen. If a subsequent cursor position (set by the SetCursorPos function or the mouse) lies outside the rectangle, Windows automatically adjusts the position to keep the cursor inside the rectangular area.
|
|
|
|
|
Hi!
I am looking for a control, where i can select the text width. For example in MS Excel if i want to import a textfile with a fixed width.
http://schueler.bulme.at/~vodep_mi/screen.png
(Sorry i only have office on mac)
Does anybody know how i can build such a control with the MFCs?
thx,
regards mike
|
|
|
|
|
I got a button, so i want0 when user moves the arrow on the button it shows a help hint. In the properties i found the menu HelpID, and i can do it true or false - what is it, and how can it help?
|
|
|
|
|
You can use CToolTipCtrl for creating hits. Have a look @ msdn for CToolTipCtrl.
|
|
|
|
|
So i tried to make a CToolTipCtrl;
in the InitDialog()
a call:
m_MyToolTip.Create(this,TTS_ALWAYSTIP);
m_MyToolTip.AddTool(GetDlgItem(IDC_BUTTON1),"Rassul");
But, nothing hapens, a tooltip doesnt appear when i move the cursor over the button.
|
|
|
|
|
Hello!
I ran into a problem, that can be simplified like this, consider the following code:
----8<--------8<--------8<--------8<--------8<----
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
ofstream("myFile.txt") << "Hello" << endl;
return 0;
}
---->8-------->8-------->8-------->8-------->8----
I would expect this to put "Hello" in the file, but it prints the string address there.
I can't see why.
If you write:
ofstream("myFile.txt") << "Hello" << " men" << endl;
then " men" will be printed correctly, while "Hello" will be printed as the address.
Please note that this happens ONLY if you are using a temporary as the destination stream and ONLY with the leftmost object and ONLY if it's a string constant.
All the following versions behave as I would expect:
ofstream("myFile.txt") << (char*) "Hello" << endl;
//
ofstream("myFile.txt") << 123 << "Hello" << endl;
//
ofstream("myFile.txt") << 1.5f << endl;
//
ofstream myFile("myFile.txt");
myFile << "Hello" << endl;
//
I tried this with Visual Studio 2003 under WinXP and with the GNU compilare under Linux: same result, so it seems to be an intended behavior, because I tend not to think that I found any STL implementation issue. However, I found nothing in the STL documentation about this issue (hey... I found nothing, but maybe something is there hidden to my eyes ).
I am pretty much convinced that I forgot something very obvious and I'm being stupid, so if anyone can bring some light, it would be nice.
Thanks everyone.
Note: the original problem was found while creating a class deriving from basic_ostream to handle a custom error console, I also found several code sinppets around using temporary unnamed objects derived from basic_ostream but none of them was ever using a string constant as the leftmost object... -_-
C++U,
FrOYd
|
|
|
|
|
I am trying to create an ActiveX control (mediaplayer9.0 to be more specific) over document/view architecture. I have created the same application on VC++6.0. Its working fine.
But as soon as I port the same application from VC++6.0 to VC.Net and tries to run the application, it gives an error in call to GetParent() function as this function checks for ASSERT(::IsWindow(m_hWnd)). m_hWnd handle is assigned inside CreateControl() call, which is happening perfectly fine with VC++6.0.
I debugged the application in more detail for CreateControl() call in both VC++6.0 and VC.Net and found that in VC.Net:
1. COleControlSite::XOleIPSite::OnInPlaceActivateEx() function is getting called and assigning the (mediaplayer) control to be windowless.
In parallel to this VC++6.0 calls:
1. COleControlSite::XOleIPSite::OnInPlaceActivate(), which is doing nothing but returning "OK".
In addition to above inside CreateControl() VC.Net calls:
1. COleControlSite::AttachWindow(), which actually assigns the handle to “m_hWnd”. This is failing in VC.Net but working perfectly ok with VC++6.0 and that’s the reason why control is working fine with VC6.0 and not with VC.Net.
So my question is can anyone let me know why the behavior (which is leading to error) is changing in VC.Net.
FYI: .Net/VC7/atlmfc/src/mfc/occsite.cpp (This is the path for OnInPlaceActivateEx() and AttachWindow() functions).
Thanks,
Ajit
Amol Chavan
Persistent System Pvt. Ltd.
Member of Technical Staff
Bhageerath,402
Senapati Bapat Road,
Pune 411 016, India.
|
|
|
|
|
I wanna hook a certain window and coded as below but it didn't work!
please check my code.
In control dialog project..
BOOL (*install_hook)(HWND, HWND, DWORD);<br />
m_inst_hooker_dll = LoadLibrary("Hooker_dll.dll");<br />
if(m_inst_hooker_dll == NULL)<br />
{<br />
AfxMessageBox("Hooker_dll.dll was not found!");<br />
PostQuitMessage(0);<br />
return;<br />
}<br />
<br />
install_hook = (BOOL (*)(HWND, HWND, DWORD))GetProcAddress(m_inst_hooker_dll, "install_hook");<br />
<br />
DWORD process_di = 0;<br />
DWORD id = GetWindowThreadProcessId(edit, &process_di);<br />
<br />
if(!install_hook || !(*install_hook)(this->GetSafeHwnd(), edit, id))<br />
{<br />
AfxMessageBox("Fail to intall the Hooker,");<br />
PostQuitMessage(0);<br />
return;<br />
}<br />
'edit',found by FindWindow, the window handle of the external process which will be hooked, has a valide value. I verificated the value by sending a certail message.(It worked!)
In hook_dll project..
<br />
#include "stdafx.h"<br />
#pragma data_seg(".HKT")<br />
HINSTANCE g_module = NULL;<br />
HHOOK g_hook = NULL;<br />
HWND g_msg_destination = NULL;<br />
HWND g_hooked_window = NULL;<br />
#pragma data_seg()<br />
#pragma comment(linker, "/SECTION:.shared, RWS")<br />
<br />
BOOL APIENTRY DllMain( HANDLE hModule, <br />
DWORD ul_reason_for_call, <br />
LPVOID lpReserved<br />
)<br />
{<br />
switch (ul_reason_for_call)<br />
{<br />
case DLL_PROCESS_ATTACH:<br />
g_module = (HINSTANCE)hModule;<br />
break;<br />
<br />
case DLL_PROCESS_DETACH:<br />
UnhookWindowsHookEx(g_hook);<br />
break;<br />
}<br />
return TRUE;<br />
}<br />
<br />
LRESULT CALLBACK proc(int nCode, WPARAM w_param, LPARAM l_param)<br />
{<br />
if(nCode >= 0)<br />
{<br />
static char buf[256];<br />
int n;<br />
<br />
n = ::SendMessage(g_hooked_window, WM_GETTEXT, 256, (LPARAM)buf);<br />
buf[n] = 0;<br />
::SendMessage(g_msg_destination, WM_SETTEXT, 0, (LPARAM)buf);<br />
}<br />
<br />
return ::CallNextHookEx(g_hook, nCode, w_param, l_param);<br />
}<br />
<br />
extern "C" __declspec(dllexport)BOOL install_hook(HWND dest_window, HWND hooked_window, DWORD thread_id)<br />
{<br />
if(!hooked_window) return FALSE;<br />
g_msg_destination = dest_window;<br />
g_hooked_window = hooked_window;<br />
g_hook = ::SetWindowsHookEx(WH_GETMESSAGE, proc, (HINSTANCE)g_module, thread_id);<br />
return TRUE;<br />
}
It seems that my hook-procedure was not inserted to the hook chain. and If I set the thread_id = 0, as global hook, It works well.
Please answer me.
|
|
|
|
|
Code delete all child Values and keys of a particular key
DWORD dwReturn = SHDeleteKey(hKey,sKeyName);
if(dwReturn != ERROR_SUCCESS)
{
return FALSE;
}
else
{
HKEY hChildKey = NULL;
if(RegCreateKey(hKey,sKeyName,&hChildKey) == ERROR_SUCCESS)
{
return TRUE;
}
else
{
return FALSE;
}
}
|
|
|
|
|
Nope. SHDeleteKey will fail on NT where there are sub keys or values. See MSDN
this is how i do it
void
VPropertyRegistryPersister::DeleteRegKey(HKEY parentKey, LPCTSTR path)
{
DWORD index = 0;
DWORD nameBuffSize = MAX_PATH;
TCHAR nameBuff[MAX_PATH];
FILETIME lastWriteTime;
HKEY key = OpenKey(parentKey, path);
long result;
while((result = RegEnumKeyEx(key, index, nameBuff, &nameBuffSize,
NULL, NULL, NULL, &lastWriteTime)) != ERROR_NO_MORE_ITEMS)
{
RegistryException::VerifyAndThrow(result, "RegEnumKeyEx");
result = RegDeleteKey(key, nameBuff);
RegistryException::VerifyAndThrow(result, "RegDeleteKey");
index++;
nameBuffSize = MAX_PATH;
}
RegCloseKey(key);
RegDeleteKey(parentKey, path);
}
|
|
|
|
|