|
I want get a associated icon from a file system (for example c:\test.doc") using SHGetFileInfo function and save it in a file (for ex "C:\myicon.ico").
But GlobalSize and GlobalLock returns 0 (invalid value!!!).
I've read an IconPro example (in vs6example.exe) but I didn't found a good solution!
Please give me a good idea!
Tnk you
/******MY CODE*****/
CString nomefile = "c:\\test.doc";
HICON hGen32Icon;
HIMAGELIST hSysImageList;
SHFILEINFO shfi;
int fh;
UINT uiSize;
DWORD dwSize;
LPVOID lpGMem;
OFSTRUCT of;
hSysImageList = (HIMAGELIST)SHGetFileInfo
(nomefile,
0,
&shfi,
sizeof (SHFILEINFO),
SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
hGen32Icon = ImageList_GetIcon (hSysImageList,
shfi.iIcon,
ILD_NORMAL);
dwSize = GlobalSize(hIcon); /*Don't work*/
lpGMem = GlobalLock(hIcon); /*Don't work*/
fh = OpenFile ("c:\\myicon.ico", &of, OF_WRITE | OF_CREATE);
if (fh == -1) // If NOT opened successfully.
{
MessageBox("Unable to create file", NULL, MB_OK );
}
uiSize = _lwrite(fh, (LPSTR)lpGMem, (UINT)dwSize);
_lclose(fh);
|
|
|
|
|
Enza wrote:
dwSize = GlobalSize(hIcon); /*Don't work*/
lpGMem = GlobalLock(hIcon); /*Don't work*/
What is hIcon ? I assume this is supposed to be hGen32Icon . GlobalSize() is probably failing because hGen32Icon is not a global variable memory object.
|
|
|
|
|
sorry, the HICON is hGen32Icon...
How I can declare a global variable memory object?
tnk
|
|
|
|
|
I have software that "Commits" 2KB with every call to fopen(). I have tried the following with the following results:
<br />
<br />
if (fp = fopen(filename, "cwt"), fp != NULL)<br />
{<br />
}<br />
else<br />
perror( ... );<br />
<br />
<br />
<br />
if (h = _open(filename, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_TEXT), h != -1)<br />
{<br />
}<br />
else<br />
perror( ... );<br />
<br />
Any thoughts? Thanks ...
|
|
|
|
|
jmf314159 wrote:
if (fp = fopen(filename, "cwt"), fp != NULL)
{
What is this??
I'd like to think the majority of people would write:
if ( (fp = fopen(filename, "cwt")) != NULL )
open/fopen etc. will fail if the file is marked r/o and you are trying to write to it or create it. Or if the file is locked by another process, or the path is invalid etc. You can test errno for specific details of the error.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Thanks for telling me what you would like to think.
I thought I had made clear that ...
(a) the anomaly was induced by the addition of the 'c' switch, and
(b) perror(), which maps errno to text, reported "no error" even though fopen() returned NULL.
This suggests that the problem was not file attributes, file locking, and/or file specification, and that further interrogating errno would achieve little. Thanks anyway.
|
|
|
|
|
jmf314159 wrote:
Thanks for telling me what you would like to think.
Its comments like this that realy make me wonder why I spend time trying help my fellow programmers sometimes.
"c" can't be the first character in the mode string. A quick bit of digging showed this.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Neville Franks wrote:
Its comments like this that realy make me wonder why I spend time trying help my fellow programmers sometimes.
... because most of your fellow programmers are good guys, like you... and then there are exceptions
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
|
|
|
|
|
Try using C or C++ and you might have more luck...
|
|
|
|
|
I'd like to add some nice effects in my SDI-Application. But which message do I have to handle or in which function do I have to add my own code?
I tryed to handle the ID_APP_EXIT from the menubar. But when I use my own code for this, the window won't close and I don't know how to close it manually...(and this also doesn't work for the close-shortcut in the upper-right (the x))
Tryed PostMessage((HWND)m_pMainWnd,WM_CLOSE,NULL,NULL); but this doesn't work either
btw. how can I get the code for such compiler-made functions like closing the windows, minimizing and all that?
Basicly my question is, where do I have to put my code that I still have the window shown (to edit the DC) but closing after my code is done.
thanks for help
|
|
|
|
|
Try posting WM_DESTROY message. By the way, this should also be the message windows sends when the X button is pressed (upper right of window title).
You can respond to this message inside of afx_msg void OnDestroy() function.
Hope this helps
Mike Ellertson
|
|
|
|
|
Hi!
I have a problem with Autoscrolling in an CEdit. The Code i written works fine for scrolling but has an ugly graphic-error.
It scrolls the text in the direction where i have the mousecursor. If i scroll up the first visible line is shown 2 times.
When I scroll down it is the last visible line.
Here is the code:
// MyEdit.cpp: Implementierungsdatei
//
#include "stdafx.h"
#include "MyEdit.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// MyEdit
MyEdit::MyEdit()
{
iScrollCount = 0;
iScrollSpeed = 5;
}
MyEdit::~MyEdit()
{
}
BEGIN_MESSAGE_MAP(MyEdit, CEdit)
//{{AFX_MSG_MAP(MyEdit)
ON_WM_SETCURSOR()
ON_WM_NCHITTEST()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Behandlungsroutinen für Nachrichten MyEdit
BOOL MyEdit::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// TODO: Code für die Behandlungsroutine für Nachrichten hier einfügen und/oder Standard aufrufen
HCURSOR g_CursorIcon;
g_CursorIcon=LoadCursor (NULL,IDC_SIZENS);
SetCursor(g_CursorIcon);
//return CEdit::OnSetCursor(pWnd, nHitTest, message);
return 1;
}
UINT MyEdit::OnNcHitTest(CPoint point)
{
// TODO: Code für die Behandlungsroutine für Nachrichten hier einfügen und/oder Standard aufrufen
CRect rect;
GetClientRect( &rect );
ScreenToClient(&point);
if(point.y > (rect.bottom - 60))
{
KillTimer(0);
SetTimer(1,25,0);
}
else if(point.y < 60)
{
KillTimer(1);
SetTimer(0,25,0);
}
else
{
KillTimer(0);
KillTimer(1);
}
return CEdit::OnNcHitTest(point);
}
void MyEdit::SetScrollSpeed(int Speed)
{
iScrollSpeed = Speed;
}
void MyEdit::OnTimer(UINT nIDEvent)
{
// TODO: Code für die Behandlungsroutine für Nachrichten hier einfügen und/oder Standard aufrufen
CPoint point;
GetCursorPos(&point);
ScreenToClient(&point);
CRect rect;
GetClientRect( &rect );
if(point.y > rect.bottom || point.y < 0 || point.y < rect.bottom && point.x < rect.left ||point.y < rect.bottom && point.x > rect.right )
{
}
else
{
if(nIDEvent == 1)
{
if(iScrollCount == iScrollSpeed)
{
LineScroll(1,0);
iScrollCount = 0;
}
else
iScrollCount++;
}
else
{
if(iScrollCount == iScrollSpeed)
{
LineScroll(-1,0);
iScrollCount = 0;
}
else
iScrollCount++;
}
}
CEdit::OnTimer(nIDEvent);
}
#############################################################
Does anyone know what to do for showing the scrolled text correctly?
Patrick
|
|
|
|
|
Hi,
I have to programs, both written in MDI, MFC,
I am able to call the executable of program2 from program1, by using CreateProcess method.
My question is, How can I call the methods of program2, within program1.
or how can I have a pointer to the View class of program2 from program1.
Thanks
Ehsan Behboudi
|
|
|
|
|
They are two processes in different address spaces. You cannot access objeects between address spaces. One solution to sharing data is file-mapping. Another solution is pipe. Another solution is WM_COPYDATA.
Kuphryn
|
|
|
|
|
1) You can use Automatization. You must create type library from View class of program2, and after calling CreateProcess in program1, attach to running Program2's instance. You can provide values, with which you would be able to change variable values in program2, from program1, execute some code in program2(methods), etc. program2 will be server of Automatization and program1 will be client n this case.
yiy
|
|
|
|
|
hi,
can u provide me witha little source code?
Ehsan Behboudi
|
|
|
|
|
Hi all,
How to i write output text on the status bar in visual studio?
i've created a dev studio add-in, and now i need to display some text on the status bar , how do i do that??? also how to i use a progres control on the status bar (same progress as the one that shows the "loading project")
thanks in advanced
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Check CodeProject for a good progress bar class.
As for updating text in the status bar, one solution is SetPaneText().
Kuphryn
|
|
|
|
|
Hi thanks for the reply.
i know how to work with progress bar and status bar...because i am writting a Visual Studio add in , i want to know how do i access (through which object) the status bar????
thanks again
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
I have an edit box. I click properties and removed the border.
When some types something in that edit box, the text starts in
the upper left corner. How can I remove the border, but make
the text start down 1 or 2 pixels and to the right more by
1 or 2 pixels? I like not having a border, but I want the
text to appear vertically centered in the edit box and just
start off the edge.
Please any response any one can give me will be greatly
appreciated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
Hi all
In my MFC dailog i used my itself ActiveX controls.But when its dialog recieved WM_PAINT message it not redraw my controls to the end.Sometimes controls drawing on half or less sometimes almost complete.Whats a problem here???
There are more explicity referience of this trouble
I have 2 thread
First thread its a console application which create second thread .This first thread not call _beginthread function
instead of one use CoInitializeEx() function and create new appartment.In this new appartment created COM object what launch MFC dialog box with 2 controls. Behaviour of this control fine while i dont sinchronized this two thread.
Sinchronizing i implemented this way:
COM object from the secon thread have method IsLock its method returned true while in dialog not pressed any key.
In first thread i maked loop what check this method and continued execution of first thread as soon as IsLock method
became false i.e.
First thread
...
while(cptr->isLock){} //Blocked its thread while isLock true
...
Second thread
CMyObj::get_isLock(VARIANT_BOOL* pVal){
*pVal = lock_fg;
}
...
CMyDlg::OnKey(){
lock_fg = false;
}
...
and after this i see whats my dialog are drawing not properly.
Sorry for complicated explonation and my eanglish.
Thanks.
|
|
|
|
|
I try to load icmp.dll and call three functions from it (by address): IcmpCreateFile, IcmpSendEcho, IcmpCloseHandle.
On WinXP it works without any errors, I recieve right functions' addresses, call this functions without problems, etc.
On Win2000 i recieve correct handle of loaded icmp.dll but:
1) When I call GetProcAddress() for any of this three functions at first time, I recieve positive(!=NULL) value, but when I call function by this address, I recieve following message: ".., Memory could not by written,...".
2) When I call GetProcAddress() for last two functions, I recieve NULL.
yiy
|
|
|
|
|
Sounds like a different version of the dll. I'd double check to make sure. Other than that, I can't say what's wrong.
Joel Lucsy
|
|
|
|
|
I have provide icmp.dll with which I have tested my program with my program, but on the other computers with Win2000 it don't work,
yiy
|
|
|
|
|
Joel, do you know any program, which shows list of exported functions of specified DLL ?
Thank you for advice.
yiy
|
|
|
|