void displayPosition(HWND hwnd, UINT msg, POINT focusPnt)
{
// Post: Displays the x,y coordinate where the mouse is in static control
char x[MAX_PATH];
char y[MAX_PATH];
char pnt[MAX_PATH];
itoa(focusPnt.x,x,10);
itoa(focusPnt.y,y,10);
// how can I combine x & y so I can display the result in the static control
SendDlgItemMessage(hwnd,msg,WM_SETTEXT,0,(LPARAM)pnt); // set control text
}
Combine 2 char arrays
Hi
I am trying to figure out how to combine 2 char arrays. I know I could easily combine 2 strings but I'm pretty sure I cant use strings for what I am trying to do.
I am trying to convert 2 integers(x,y) to characters(char arrays) so I can display them in a static control(SetWindowText()). I can convert each x,y value to a char array but I dont know how to combine the 2 char arrays to send them to the static control to display
psuedo code/function:
Quote:Original post by gretty
Hi
I am trying to figure out how to combine 2 char arrays. I know I could easily combine 2 strings but I'm pretty sure I cant use strings for what I am trying to do.
I am trying to convert 2 integers(x,y) to characters(char arrays) so I can display them in a static control(SetWindowText()). I can convert each x,y value to a char array but I dont know how to combine the 2 char arrays to send them to the static control to display
psuedo code/function:
*** Source Snippet Removed ***
Of course you can use strings for this [smile]
// don't forget#include <sstream>void displayPosition(HWND hwnd, UINT msg, POINT focusPnt){ // Post: Displays the x,y coordinate where the mouse is in static control std::stringstream ss; ss << focusPnt.x << ", " << focusPnt.y; // ss now contains something like "4, 2" (no quotes of course) // ss.str() gives us an std::string // calling c_str() on that string gives us a null-terminated C-style string SendDlgItemMessage(hwnd,msg,WM_SETTEXT,0,(LPARAM)ss.str().c_str()); // set control text}
You just have to make sure SendDlgItemMessage() expects a null-terminated C-style string.
(Assuming C)
sprintf
sprintf
void displayPosition(HWND hwnd, UINT msg, POINT focusPnt){ // Post: Displays the x,y coordinate where the mouse is in static control char buf[MAX_PATH]; sprintf( buf, "(%i, %i)", focusPnt.x, focusPnt.y ); SendDlgItemMessage(hwnd,msg,WM_SETTEXT,0,(LPARAM)buf); // set control text}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement