|
When a menu pops up it sends this message
WM_INITMENUPOPUP
<marquee direction="up" height="30" scrolldelay="1" step="1" scrollamount="1" hspace="0" vspace="0">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
Hi..
I'm very new to C++ and have just written 2 methods that are pretty unstable (ie. same input may or may not run correctly). My gut feeling tells me it's because of my poor memory and string management. Could someone kindly review the code and let me know if there's any obvious error? I would seriously very appreciate it.
Method 1
============
char* _LoggedInUserID;
char* _LoggedInUserName;
DWORD CALLBACK streamDisclaimer(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
DWORD read;
CRtfStream *st = reinterpret_cast<CRtfStream *>(dwCookie);
const int MAX_USER_TAG = 10;
char* userTag = (char*) malloc(strlen("<user>")+1);
strncpy(userTag, "<user>", strlen("<user>"));
userTag[strlen("<user>")] = '\0';
size_t displayLen = strlen(_DlgLoggedInUserID);
if(_DlgLoggedInUserName != NULL) displayLen += strlen(_DlgLoggedInUserName) + 3; char* displayStr = (char*) malloc(displayLen+1);
if(_DlgLoggedInUserName != NULL){
sprintf(displayStr, "%s (%s)", _DlgLoggedInUserName, _DlgLoggedInUserID);
}else{
sprintf(displayStr, "%s", _DlgLoggedInUserID);
}
displayStr[displayLen] = '\0';
LPBYTE tmpBuff = new BYTE[cb + (displayLen*MAX_USER_TAG)];
ReadFile(st->fileDisclaimer.get(), tmpBuff, cb, &read, NULL);
string tmBuffStr = (char*) tmpBuff;
size_t iPos = tmBuffStr.find(string(userTag), 0);
if(iPos != tmBuffStr.npos){
int cnt = 0;
while(iPos != tmBuffStr.npos && cnt < MAX_USER_TAG){
tmBuffStr = tmBuffStr.erase(iPos, strlen(userTag));
tmBuffStr.insert(iPos, displayStr);
iPos = tmBuffStr.find(string(userTag), 0);
cnt++;
}
int newLength = read - (strlen(userTag)*cnt) + (displayLen*cnt);
strncpy((char*)pbBuff, tmBuffStr.c_str(), newLength);
pbBuff[newLength] = '\0';
*pcb = newLength;
}else{
strncpy((char*)pbBuff, (char*)tmpBuff, read);
*pcb = read;
}
delete [] userTag;
delete [] displayStr;
userTag = NULL;
displayStr = NULL;
tmpBuff = NULL;
return 0;
}
Method 2
=============
char* _DlgLoggedInUserID;
char* _DlgLoggedInUserName;
void CGina::setLoggedInUserID(PWSTR pszUserName){
delete [] _LoggedInUserID;
delete [] _LoggedInUserName;
_LoggedInUserID = NULL;
_LoggedInUserName = NULL;
if(pszUserName != NULL)
{
int nstrlen = WideCharToMultiByte(CP_ACP, 0, pszUserName, -1, NULL, 0, NULL, NULL);
PSTR UserNameStr = (PSTR)HeapAlloc(GetProcessHeap(),0,nstrlen);
if(UserNameStr!=NULL){
WideCharToMultiByte(CP_ACP, 0, pszUserName, -1, UserNameStr, nstrlen, NULL, NULL);
_LoggedInUserID = (char*)malloc(nstrlen);
strncpy(_LoggedInUserID, (char*)UserNameStr, nstrlen);
for(int i = 0; i < nstrlen; i++){
_LoggedInUserID[i] = toupper(_LoggedInUserID[i]);
}
HeapFree(GetProcessHeap(), 0, UserNameStr);
}
}
try {
DirectoryEntry* directoryEntryUser = new DirectoryEntry(S"LDAP://xxx.com.au/dc=xxx,dc=com,dc=au");
DirectorySearcher* directorySearcherUser = new DirectorySearcher();
directorySearcherUser->Filter = S"(objectClass=user)";
directorySearcherUser->SearchRoot = directoryEntryUser;
char* filterStr = (char*) malloc(strlen("samaccountname=")+strlen(_LoggedInUserID)+1);
sprintf(filterStr, "samaccountname=%s", _LoggedInUserID);
filterStr[strlen("samaccountname=")+strlen(_LoggedInUserID)+1] = '\0';
directorySearcherUser->Filter = filterStr;
SearchResult* searchResultUser = directorySearcherUser->FindOne();
if(searchResultUser->Properties->Contains(S"cn")){
IEnumerator* myEnum = searchResultUser->Properties->Item[S"cn"]->GetEnumerator();
while (myEnum->MoveNext()) {
String* fullNameStrPtr = (String*)myEnum->Current;
char* fullNameChar = (char*)(void*)Marshal::StringToCoTaskMemAnsi(fullNameStrPtr);
_LoggedInUserName = (char*)malloc(strlen(fullNameChar)+1);
strncpy(_LoggedInUserName, (char*)fullNameChar, strlen(fullNameChar));
_LoggedInUserName[strlen(fullNameChar)] = '\0';
delete [] fullNameChar;
fullNameChar = NULL;
fullNameStrPtr = NULL;
break;
}
myEnum = NULL;
}
delete [] filterStr;
filterStr = NULL;
directoryEntryUser = NULL;
directorySearcherUser = NULL;
searchResultUser = NULL;
} catch (Exception* e) {
LDB1(L"<--setLoggedInUserID (%s)", e->Message);
}
}
Thanks guys
-- modified at 0:56 Wednesday 23rd November, 2005
|
|
|
|
|
:-Di need the variuos methods that are used in MSChart, to use in VC++.
in my project i need to show the scale on the x & y axis, of the graph and then label it. but i dont know how to go about it.
please help it with it.
Namrata
|
|
|
|
|
I would like to ask a question on how to create/insert an HTML control (like a checkbox or a radio button group or a text field) in a MDI Window application designed using MFC.
|
|
|
|
|
CWebBrowser2 is an ActiveX html control.
includeh10
|
|
|
|
|
Hello everybody,
I am trying to make multiple language support for my VC++ 6.0 dialog based project. I have all dialogs in one language, which is English. I have made resource only DLLs for all languages which I need to support. Both, the main application and DLL are UNICODE enabled. In the resource only DLL, there is string table which has the tranlation of strings for their respective languages. Now comes my problem. I am facing problem when I am trying to make the string table for Asian languages. I have set the language of String table to Chinese(Taiwan) and I have also installed the Chinese language pack. When I try to paste some Chinese text in the String table of Chinese DLL, the text pasted is some question marks. When I run the application, the same question marks are displayed. But, when I paste "1/2T(c)w" ((c) is for copywrite symbol), which I got from the resource file of dialog application which I made in Chinese language, it displays proper Chinese euivalent for "OK".
In a nutshell, I cannot copy any Chinese text in the Chinese Resource only DLL. If anyone knows the solution please help me!
-- modified at 12:46 Wednesday 23rd November, 2005
|
|
|
|
|
I have a window handle but I can determine that window is a datagrid or not. ::GetClassName(), ::GetClassLong() don't work. Plz help me!
Thanks!
|
|
|
|
|
I have done some looking around on here and on the Internet but might still be missing what I am looking for so here goes: I have been trying to compile galblast 1.6 on VC6 and the only thing I need are a set of input/output calls to the parallel port. I have been working with the inpout32 dll but without much success. I did find a page on the internet(http://cet.ssu.portsmouth.oh.us/~pyost/etec351/pport.html) that helped. I was able to get the inp32 and out32 functions to work. When I bring the code to the galblast C file it has trouble. Is there a way to get inpout32 dll to work with C or compile the C source with the CPP portion containing the inpout32 dll functions?
|
|
|
|
|
Hello. A quick check tells me that the funcs in the dll is written in plain C.
You doesn't provide the error message, but I suspect you get a link error, (missing functions) right?
If that's the case, try this in your source code
extern "C" {
short _stdcall Inp32(short PortAddress);
void _stdcall Out32(short PortAddress, short data);
};
Then the C name mangling is suppressed.
Kakan.
|
|
|
|
|
I did get the missing functions error as you stated. In every example I found involving Inpout32.dll it seems that stdafx.h needs to be loaded. I think that is where the cpp related issues began. I did go through the project settings and set the stdafx.h to create the .pch file and have the c file I am working on to use the .pch file like how the example projects do. The error I have been running into is "fatal error C1853: 'Debug/gblast2.pch' is not a precompiled header file created with this compiler"
Chris
|
|
|
|
|
Hello.
Try a "Rebuild All", first of all. If it doesn't work, turn off the use of precimpiled headers.
You can do it either for the entire project or for a specific source file.
If you want to turn it off for a specific file, do this (VC 6):
In "File View", highligt a file. Right-click, select "Settings...".
In The C/C++-tab, select Category Precompiled Headers. Select "Not using precompiled headers". Click OK.
For the entire project, Select "Project->Settings. Do the same operation as before.
This should help. If it works in Debug build, don't forget to do the same for Release build! (A common mistake of mine.)
Good luck.
Kakan
|
|
|
|
|
Thanks again for your help. I did find some information and successfully ran inpout32.dll by means of GetProcAddress (even though I wanted to call the functions like I could in C++) The address of the example is at: http://www.unixwiz.net/techtips/win32-callconv.html
|
|
|
|
|
How do you copy memory using this function?
Suppose you have
PBYTE source1 = new BYTE[2];
PBYTE source2 = new BYTE[2];
PBYTE source3 = new BYTE[2];
PBYTE source4 = new BYTE[2];
PBYTE source5 = new BYTE[2];
PBYTE source6 = new BYTE[2];
PBYTE source7 = new BYTE[2];
PBYTE source8 = new BYTE[2];
PBYTE destination = new BYTE[16];
how can you copy all of the sources into "destination" ?
memcpy(destination,source1,2); // this would copy the source1 into destination
memcpy(destination,source2,2): // this would not start from where the first one ended !! rather it would over write !
Or is there a better method?
-Cindy
|
|
|
|
|
|
Thats what I thought too,
but that DOES NOT seem to work,
to be more exact
memcpy((char*)destination,(char*)source1,2)
memcpy((char*)destination+2,(char*)source2,2)
memcpy((char*)destination+4,(char*)source3,2)..and so on
is what I had tried, and destination only has source1, I dont think the rest are being copied, why ? how ?
-Cindy
-- modified at 22:02 Tuesday 22nd November, 2005
|
|
|
|
|
What is PBYTE ?
memcpy((char*)destination+2,(char*)source2,2)
is it an order of operations problem ? What if you did
memcpy(((char*)destination)+2,(char*)source2,2) ??
Why do you need the cast at all, if the length of PBYTE[2] is 2 ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
PBYTE is an unsigned char *, right ? Stupid macros.
Anyhow, this works fine for me:
char c1[2] = {'a', 'b'};
char c2[2] = {'c', 'd'};
char c3[2] = {'e', 'f'};
char c4[2] = {'g', 'h'};
char * c = new char[8];
memcpy(c, c1, 2);
memcpy(c + 2, c2, 2);
memcpy(c + 4, c3, 2);
memcpy(c + 6, c4, 2);
memcpy(&c[6], c1, 2);
memcpy(&c[4], c2, 2);
memcpy(&c[2], c3, 2);
memcpy(&c[0], c4, 2);
Note I did it two different ways, both worked.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
HELLO.
i am trying to open two different windows using two buttons in the attached menu of the main window. first window should have similar style (color and size) like the main window, the second window should have different style.
here is what i got until now:
<br />
#include <windows.h><br />
#include "resource.h" <br />
<br />
HWND hwnd = NULL;<br />
HBRUSH g_hbrBackground = NULL;<br />
const char lpClassName[] = "myWindowClass";<br />
<br />
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)<br />
{<br />
switch(msg)<br />
{<br />
case WM_COMMAND:<br />
switch(LOWORD(wParam))<br />
{<br />
case IDM_NewWin1:<br />
break;<br />
<br />
case IDM_NewWin2:<br />
break;<br />
<br />
case IDM_EXIT:<br />
DestroyWindow(hwnd);<br />
break;<br />
}<br />
break; <br />
<br />
case WM_CLOSE:<br />
DestroyWindow(hwnd);<br />
break;<br />
case WM_DESTROY:<br />
PostQuitMessage(0);<br />
break;<br />
default:<br />
return DefWindowProc(hwnd, msg, wParam, lParam);<br />
}<br />
return 0;<br />
}<br />
<br />
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,<br />
LPSTR lpCmdLine, int nCmdShow)<br />
{<br />
WNDCLASSEX wc;<br />
MSG Msg;<br />
<br />
wc.cbSize = sizeof(WNDCLASSEX);<br />
wc.style = 0;<br />
wc.lpfnWndProc = WndProc;<br />
wc.cbClsExtra = 0;<br />
wc.cbWndExtra = 0;<br />
wc.hInstance = hInstance;<br />
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);<br />
wc.hCursor = LoadCursor(NULL, IDC_ARROW);<br />
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+18);<br />
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);;<br />
wc.lpszClassName = lpClassName;<br />
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);<br />
<br />
RegisterClassEx(&wc);<br />
<br />
hwnd = CreateWindowEx(<br />
WS_EX_CLIENTEDGE,<br />
lpClassName,<br />
"My Window",<br />
WS_OVERLAPPEDWINDOW,<br />
0, 0, 480, 240,<br />
NULL, NULL, hInstance, NULL);<br />
<br />
ShowWindow(hwnd, SW_SHOW);<br />
<br />
while(GetMessage(&Msg, NULL, 0, 0) > 0)<br />
{<br />
TranslateMessage(&Msg);<br />
DispatchMessage(&Msg);<br />
}<br />
<br />
return Msg.wParam;<br />
}<br />
THANKS FOR HELP.
STEFAN.
|
|
|
|
|
Using GDI+ to load a PNG 32 bit image with transparency.
I draw the image on a static control and I get this result :
Image
with this code in the WM_PAINT :
case WM_PAINT:
{
if ( this->m_pImage != NULL ) {
PAINTSTRUCT ps;
HDC hdc;
hdc = BeginPaint( this->m_Hwnd, &ps );
RECT rect;
GetClientRect( this->m_Hwnd, &rect );
Graphics grphx( hdc );
grphx.DrawImage( this->m_pImage, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
EndPaint( this->m_Hwnd, &ps );
bParsed = TRUE;
return 0L;
}
}
break;
I'd like to have the transparent part stay grey.
Thanks
David
|
|
|
|
|
Fill the client rect with grey before DrawImage or change your image.
|
|
|
|
|
MFC UPDATE_COMMAND_UI doesn't work for dialog menu.
how to enable and/or disable menu items of a dialog's menu?
includeh10
|
|
|
|
|
Hi,
Check this[^]
Bye
Cool Ju
Dream Ur Destiny
|
|
|
|
|
thx.
currently I use a timer, it looks much simpler than code in your link.
includeh10
|
|
|
|
|
I use a method where the parent of the dialog (e.g. a view) relays its WM_IDLEUPDATECMDUI to its dialogs, mimicking what CFrameWnd does.
The CDialog-derived child in turn handles WM_IDLEUPDATECMDUI and calls UpdateDialogControls, which looks for the UI-functions to be called.
The reference linked in the code snipped desrcibes the process for a status bar, but all commandUIs are equal - it does work for, say, buttons to enable and disable on staus change of another button.
The advantage of how this works is that you work with the MFC, not against it.
ON_MESSAGE(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI)<br />
...<br />
LRESULT CMethodPage::OnIdleUpdateCmdUI(WPARAM, LPARAM)<br />
{<br />
UpdateDialogControls(this, false);
return 0L;<br />
}<br />
ON_MESSAGE(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI)<br />
...<br />
LRESULT CTreeBrowserView::OnIdleUpdateCmdUI(WPARAM wParam, LPARAM lParam)<br />
{<br />
if (m_pEditor == NULL) /no editor open<br />
{<br />
return 0L;<br />
}<br />
else
{<br />
return m_pEditor->SendMessage(WM_IDLEUPDATECMDUI, wParam, lParam);<br />
}<br />
}
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
-- modified at 8:55 Wednesday 23rd November, 2005
|
|
|
|
|
Hello,
I have a basic SDI Windows application that was created with the MFC Application wizard. I want to set the minimum size of the application window so the user can't make it smaller that 640x480. What's the best (easiest) way to do this?
Thanks!
-Ian
|
|
|
|
|