#include <windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
LPSTR lpszClass="ClipText";
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance
,LPSTR lpszCmdParam,int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_hInst=hInstance;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=(WNDPROC)WndProc;
WndClass.lpszClassName=lpszClass;
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass);
hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);
while(GetMessage(&Message,0,0,0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
#define ID_BTN_COPY 100
#define ID_BTN_PASTE 101
HWND Edit1;
char str[]="Clipboard Test String";
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
HGLOBAL hmem;
char *ptr;
switch(iMessage) {
case WM_CREATE:
CreateWindow("button","Copy",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
10,50,100,25,hWnd,(HMENU)ID_BTN_COPY,g_hInst,NULL);
CreateWindow("button","Paste",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
10,90,100,25,hWnd,(HMENU)ID_BTN_PASTE,g_hInst,NULL);
Edit1=CreateWindow("edit","",WS_CHILD | WS_VISIBLE | WS_BORDER |
ES_MULTILINE,
10,130,200,200,hWnd,(HMENU)3,g_hInst,NULL);
return 0;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case ID_BTN_COPY: // Copy
hmem=GlobalAlloc(GHND, strlen(str)+1);
ptr=(char *)GlobalLock(hmem);
memcpy(ptr,str,sizeof(str));
GlobalUnlock(hmem);
if (OpenClipboard(hWnd)) {
EmptyClipboard();
SetClipboardData(CF_TEXT,hmem);
CloseClipboard();
}
break;
case ID_BTN_PASTE: // Paste
if (IsClipboardFormatAvailable(CF_TEXT)) {
OpenClipboard(hWnd);
hmem=GetClipboardData(CF_TEXT);
ptr=(char *)GlobalLock(hmem);
SetWindowText(Edit1, ptr);
GlobalUnlock(hmem);
CloseClipboard();
}
break;
}
return 0;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
TextOut(hdc, 10, 10, str, strlen(str));
EndPaint(hWnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
LPSTR lpszClass="ClipText";
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance
,LPSTR lpszCmdParam,int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_hInst=hInstance;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=(WNDPROC)WndProc;
WndClass.lpszClassName=lpszClass;
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass);
hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);
while(GetMessage(&Message,0,0,0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
#define ID_BTN_COPY 100
#define ID_BTN_PASTE 101
HWND Edit1;
char str[]="Clipboard Test String";
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
HGLOBAL hmem;
char *ptr;
switch(iMessage) {
case WM_CREATE:
CreateWindow("button","Copy",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
10,50,100,25,hWnd,(HMENU)ID_BTN_COPY,g_hInst,NULL);
CreateWindow("button","Paste",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
10,90,100,25,hWnd,(HMENU)ID_BTN_PASTE,g_hInst,NULL);
Edit1=CreateWindow("edit","",WS_CHILD | WS_VISIBLE | WS_BORDER |
ES_MULTILINE,
10,130,200,200,hWnd,(HMENU)3,g_hInst,NULL);
return 0;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case ID_BTN_COPY: // Copy
hmem=GlobalAlloc(GHND, strlen(str)+1);
ptr=(char *)GlobalLock(hmem);
memcpy(ptr,str,sizeof(str));
GlobalUnlock(hmem);
if (OpenClipboard(hWnd)) {
EmptyClipboard();
SetClipboardData(CF_TEXT,hmem);
CloseClipboard();
}
break;
case ID_BTN_PASTE: // Paste
if (IsClipboardFormatAvailable(CF_TEXT)) {
OpenClipboard(hWnd);
hmem=GetClipboardData(CF_TEXT);
ptr=(char *)GlobalLock(hmem);
SetWindowText(Edit1, ptr);
GlobalUnlock(hmem);
CloseClipboard();
}
break;
}
return 0;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
TextOut(hdc, 10, 10, str, strlen(str));
EndPaint(hWnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
'Windows > Windows API' 카테고리의 다른 글
텍스트 인쇄 (print) (0) | 2013.10.01 |
---|---|
MDI (0) | 2013.10.01 |
클립보드 에디트 복사 (Clipboard) (0) | 2013.10.01 |
클립보드 그림 복사 (Clipboard) (0) | 2013.10.01 |
레지스트리 사용 (Registry) (0) | 2013.10.01 |