|
sawerr wrote: I think DrawItem MEthod is not only for "items". We can paint/make entire control. Right?
You are limited in DrawItem function. The point is that it's just a helper function. The master of these functions is OnPaint or WM_PAINT message.
sawerr wrote: For example we can make elliptic buttons in ownerdraw():
CRect rect = lpDrawItemStruct->rcItem;
dc.Ellipse(rect);
You are not free to draw anything anytime in DrawItem functions. There is a rule. You draw based on the flag's that's passed in. So if the flag tells you draw entire client area (ODA_DRAWENTIRE)then go around splashing colors, else if it's just to paint a focus rect (ODA_FOCUS) then you can't do that.
Now you may ask how to know if have to draw a focus rect or remove a focus rect, that's why we have the state flag ODS_FOCUS.
Do the same in OnPaint in and you will what I meant.
sawerr wrote: IS that a right scenario to see that when we need onpaint and can't be done such a thing with DrawItem Method? We can draw entire button with ownerdraw method, but we can't draw Listbox or combobox with ownerdraw, only it is items?
Can you rephrase this question? My brain just fell apart!
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
OK.
DRAWITEMSTRUCT has got a hDC member which identifies a device context. Is that Device Context for drawing shapes or etc. things to the surface of the control or redraw control itself. For example:
void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rect;
GetClientRect(&rect);
rect.DeflateRect(20,50);
pDC->Ellipse(rect);
}
That code draws an ellipse to the surface of the button, not elliptic button. Because when i clicked out of ellipse buttonclicked handler invoked.
I tried same thing for OnPaint() -->> CPaintDC dc(this);
It gave me same result.
1-) Is there a way to get DC for drawing control itself, not its surface?
2-)If yes, how can i understand which DC is for surface of control and which DC is for draw a control?
Thanks for all helps...
|
|
|
|
|
sawerr wrote: 1-) Is there a way to get DC for drawing control itself, not its surface?
So you want to change the shape of the control itself! For that you've got to call SetWindowRgn . You can use functions in CRgn class to create a region your window.
To create an elliptical dialog you just have to call SetWindowRgn with a region parameter from OnInitDialog .
Read this for more information.[^]
sawerr wrote: 2-)If yes, how can i understand which DC is for surface of control and which DC is for draw a control?
There is nothing like surface and a control dc. It's just one control dc which is just used for painting on top of a control.
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Hi
FONT this are Decimal NCRs ....How to get ASCII Character from this values....
|
|
|
|
|
int i = 0x32;
char c = i;
|
|
|
|
|
VB experiences, I suppose.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Since you mention FONT, I wonder If you are talking about getting ASCII values from printed/scanned material, you will need something that can do OCR on the scanned image that can recognize the characters.
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Hello,
I have a property sheet with pages in it in my WinCE application devleoped in eVC++4.
The sheet has page as members & are added to sheet. Sheet is a modal & is called directly on menu click. It doesn't have any parent. I have couple of factors to look at :
1) On the device I don't see the Ok, Cancel, Apply buttons. To close it, I have to press Esc.
2) I have OnCommand() in each page, with SetModified(true), which updates the variables of the page. I want to update the changes in a object present in sheet class. How do I achieve that?
Any help is highly appreciated.
Thanks
Terry
|
|
|
|
|
Could someone please explain to me how to use getaddrinfo in its most simple form. The example given by MSDN is beyond my understand as well as every site i've found so far.
All i want is to get my internal ip address and store it in a variable.
Thank you.
|
|
|
|
|
smedowns77 wrote: All i want is to get my internal ip address and store it in a variable.
Do you have the name of your machine? If so, you can use
ADDRINFO hints = {0},
*sa;
hints.ai_family = AF_INET;
hints.ai_flags = AI_CANONNAME;
int nResult = getaddrinfo("machine_name", NULL, &hints, &sa);
char *addr = inet_ntoa(((LPSOCKADDR_IN) sa->ai_addr)->sin_addr); An easier way would be to use gethostbyname() .
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
For getting your ip address, call GetAdaptersInfo() and the IP_ADAPTER_INFO.CurrentIpAddress will give you the current ip address of that adapter.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
A given host can have more than one address.
Here's a simple IP v4 example:
char hostname[256];
if (0 == ::gethostname(hostname, sizeof(hostname)))
{
addrinfo aihints;
addrinfo *ailist = NULL;
memset(&aihints, 0, sizeof(aihints));
aihints.ai_family = AF_INET;
aihints.ai_socktype = SOCK_STREAM;
aihints.ai_protocol = IPPROTO_TCP;
if (::getaddrinfo(hostname, NULL, &aihints, &ailist) == 0)
{
addrinfo *paddrinfo = ailist;
while (paddrinfo)
{
sockaddr_in *paddr_in = (sockaddr_in *)paddrinfo->ai_addr;
char *pipstring = inet_ntoa(paddr_in->sin_addr);
paddrinfo = paddrinfo->ai_next;
}
::freeaddrinfo(ailist);
}
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Try to understand this. I have a main application and a dll. main application has its mfc view window, say window 1 and there's a button on main window(window 1) which calls a function inside a dll to open a new window, say window 2. Both view windows handles WM_KEYDOWN message and pop up a message box.
Now, when only window 1 is opened, all keyboard messages are properly received by it.
When I open a window 2 and then press key, no keyboard message is received by either of the windows.
Even if I minimize window 1 by clicking on minimize button at top right, no keyboard message is received by either of the windows.
Imagine this -> both windows are open side by side and if I directly click on window 2, then it will bring window 2 to forefront and now window 2 will receive all keyboard messages.
I know window 2 is child of window 1 but somehow not able to route messages to window 2 properly. Does anyone have any idea why this problem in setting focus to window 2 is occuring. when I minimize window 1, why cant window 2 receive keyboard messages???
the fruits of your success will be in direct ratio to the honesty and sincerity of your own efforts in keeping your own records, doing your own thinking and, reaching your own conclusions.
..surviving in autumn..in love with spring..
|
|
|
|
|
Hello People,
i have a code written in C++ for DDE ... my task is to read data from a EXCEL sheet at a regular interval ... i am able to do it with the following code ... but the problem is when i say A16,B67,Z63 etc.. my application gives me request fail and type some of my code to excel sheet i don't know how ... but yes when i say A1, B9, V2 etc i.e alphabet with a single digit it gives me correct answer .. but also when i hard-code A16 as "R16C1" it gives me correct answer ... the hard-coded string is the form in which excel understands .... so i have a function to convert C16,A1 to R16C3, R1C1 ...
please help me with it ... and also how to read data from different sheets from a single EXCEL ...
hoping for a positive and immediate reply ... !!
Thank you in advance
Code Build: VC++ 6.0
File Name: DDE_ExcelApplication.
Code:-
// cppDdeApplication.cpp : Defines the entry point for the console application.
//
# include "stdafx.h"
# include "windows.h"
# include "ddeml.h"
# include "stdio.h"
# include "string.h"
# include "conio.h"
HDDEDATA CALLBACK DdeCallback
(
UINT uType, // Transaction type.
UINT uFmt, // Clipboard data format.
HCONV hconv, // Handle to the conversation.
HSZ hsz1, // Handle to a string.
HSZ hsz2, // Handle to a string.
HDDEDATA hdata, // Handle to a global memory object.
DWORD dwData1, // Transaction-specific data.
DWORD dwData2) // Transaction-specific data.
{/* This function is called in DdeInitialize() */
return 0;
}
void DDEExecute(DWORD idInst, HCONV hConv, char* szCommand)
{
//HDDEDATA hData = DdeCreateDataHandle(DWORD(idInst), (LPBYTE)szCommand,DWORD(szCommand)+1, 0, NULL, CF_TEXT, 0);
HDDEDATA hData = DdeCreateDataHandle(DWORD(idInst), (LPBYTE)szCommand,1, 0, NULL, CF_TEXT, 0);
if (hData==NULL)
{
printf("Command failed: %s\n", szCommand);
}
else
{
DdeClientTransaction((LPBYTE)hData, 0xFFFFFFFF, hConv, 0L, 0,XTYP_EXECUTE, TIMEOUT_ASYNC, NULL);
}
}
void DDERequest(DWORD idInst, HCONV hConv, char* szItem, char* sDesc)
{
HSZ hszItem = DdeCreateStringHandle(idInst,LPCTSTR(szItem), 0);
HDDEDATA hData = DdeClientTransaction(NULL,0,hConv,hszItem,CF_TEXT,XTYP_REQUEST,5000 , NULL);
if (hData==NULL)
{
printf("Request failed: %s\n", szItem);
}
else
{
char szResult[255];
DdeGetData(hData, (unsigned char *)szResult, 255, 0);
sDesc = "";
printf("%s%s\n", sDesc, szResult);
}
}
char* cellString(char szItem[])
{
char firstCh = szItem[0];
char strRow[2] = "";
char strCol[3] = "";
int i,j = 0;
int strLength = (int)(strlen(szItem));
for(i=1;i<strLength;)
{
strRow[j] = szItem[i];
i++;
j++;
}
strRow[j] = '\0';
switch(toupper(firstCh))
{
case 'A':strcpy(strCol,"C1");break;
case 'B':strcpy(strCol,"C2");break;
case 'C':strcpy(strCol,"C3");break;
case 'D':strcpy(strCol,"C4");break;
case 'E':strcpy(strCol,"C5");break;
case 'F':strcpy(strCol,"C6");break;
case 'G':strcpy(strCol,"C7");break;
case 'H':strcpy(strCol,"C8");break;
case 'I':strcpy(strCol,"C9");break;
case 'J':strcpy(strCol,"C10");break;
case 'K':strcpy(strCol,"C11");break;
case 'L':strcpy(strCol,"C12");break;
case 'M':strcpy(strCol,"C13");break;
case 'N':strcpy(strCol,"C14");break;
case 'O':strcpy(strCol,"C15");break;
case 'P':strcpy(strCol,"C16");break;
case 'Q':strcpy(strCol,"C17");break;
case 'R':strcpy(strCol,"C18");break;
case 'S':strcpy(strCol,"C19");break;
case 'T':strcpy(strCol,"C20");break;
case 'U':strcpy(strCol,"C21");break;
case 'V':strcpy(strCol,"C22");break;
case 'W':strcpy(strCol,"C23");break;
case 'X':strcpy(strCol,"C24");break;
case 'Y':strcpy(strCol,"C25");break;
case 'Z':strcpy(strCol,"C26");break;
}
szItem = strcpy(szItem,"R");
szItem = strcat(szItem,strRow);
szItem = strcat(szItem,strCol);
return szItem;
}
int DDECall(char szApp[],char szTopic[],char szCmd[],char szInItem[])
{
char szDesc[] = "Requested Cell Value Contains: ";
char* szItem = cellString(szInItem);
//strcpy(szItem,"R13C4");
FILE *fp;
DWORD idInst=0;
UINT iReturn;
iReturn = DdeInitialize((LPDWORD)&idInst, (PFNCALLBACK)DdeCallback,APPCMD_CLIENTONLY, 0L );
/*DdeInitialize() :-
The DdeInitialize function registers an application with the Dynamic Data Exchange Management Library (DDEML).
An application must call this function before calling any other Dynamic Data Exchange Management Library (DDEML)
function.*/
if (iReturn!=DMLERR_NO_ERROR)
{
/*If Error occurs while initialiing DDE then the error code is written to the Log.*/
printf("DDE Initialization Failed: 0x%04x\n", iReturn);
fp = fopen("DdeErrorLog.txt","w+");
fprintf(fp,"\nError Code : DMLERR_DLL_USAGE | DMLERR_INVALIDPARAMETER | DMLERR_SYS_ERROR");
fprintf(fp,"\n\n This Error occurs if Dynamic Data Exchange fails to Initialize ");
fclose(fp);
Sleep(1500);
return 0;
}
HSZ hszApp;
hszApp = DdeCreateStringHandle(DWORD(idInst),LPCTSTR("EXCEL"),CP_WINANSI);
/* DdeCreateStringHandle() :-
The DdeCreateStringHandle function creates a handle that identifies the specified string.
a Dynamic Data Exchange (DDE) client or server application can pass the string handle as
a parameter to other Dynamic Data Exchange Management Library (DDEML) functions.*/
//Start DDE Server and wait for it to become idle.
HINSTANCE hRet = ShellExecute(NULL , "open", "C:\\Test.xls", NULL,NULL, SW_NORMAL);
if ((int)hRet < 33)
{
printf("Unable to Start DDE Server: 0x%04x\n", hRet);
Sleep(1500);
DdeUninitialize(idInst);
return 0;
}
Sleep(1000);
//DDE Connect to Server using given AppName and topic.
HSZ hszTopic;
HCONV hConv;
hszApp = DdeCreateStringHandleA(idInst,LPCTSTR("EXCEL"),CP_WINANSI);
hszTopic = DdeCreateStringHandleA(idInst,LPCTSTR(szTopic), 0);
hConv = DdeConnect(idInst, hszApp, hszTopic, NULL);
DdeFreeStringHandle(idInst, hszApp);
DdeFreeStringHandle(idInst, hszTopic);
if (hConv == NULL)
{
printf("DDE Connection Failed.\n");
Sleep(1500);
DdeUninitialize(idInst);
/*The DdeUninitialize function frees all Dynamic Data Exchange Management Library
(DDEML) resources associated with the calling application.*/
return 0;
}
DDEExecute(DWORD(idInst), hConv, szCmd);
/*Sends a command to another application, using dynamic data exchange (DDE).*/
DDERequest(idInst, hConv, szItem, szDesc);
//DDE Disconnect and Uninitialize.
DdeDisconnect(hConv);
DdeUninitialize(idInst);
Sleep(3000000);
return 1;
}
int main()
{
char szApp[] = "EXCEL";
char szTopic[] = "C:\\Test.xls";
char szCmd[] = "[APP.MINIMIZE()]";
char szItem[] = "A1";
DDECall(szApp,szTopic,szCmd,szItem);
getch();
return 0;
}
Thanks & Regards
Vishrant Shah
|
|
|
|
|
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Your problem is in this line: char strCol[3] = "";
It can only hold TWO chars, counting the null terminator. So when you do: case 'J':strcpy(strCol,"C10");break;, you're overwriting the null terminator plus whatever follows strCol in memory.
|
|
|
|
|
How to dial a phone number ???
or in other words, i want to make a call from a PC connected to the phone line via some modem, then send some string.
plz help me ...
|
|
|
|
|
|
can RasDial be used without batch files, i mean through the VC++ program itself ???
|
|
|
|
|
tina- wrote: can RasDial be used without batch files,
see here[^] and here[^].
|
|
|
|
|
You are confusing rasdial.exe with RasDial() .
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
can i use the RasDial command with the system function ?
|
|
|
|
|
tina- wrote: or in other words, i want to make a call from a PC connected to the phone line via some modem, then send some string.
What do you mean by send some strings to the phone ?
|
|
|
|
|
i want to connect to the telephone the same way the dial-up internet connection works.
in my project, the server is to dial the telephone number of the client, at client side, the phone will check the caller's number, if its server's, then i want the server to communicate with the client thro the telephone line.
|
|
|
|
|
OK - that's the entire assignment. We need to know what have you accomplished in the assignment by far and what exactly do you need help with, at the moment.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|