Windows 통신 메커니즘 과 DLL 메커니즘
<1>event.h
#include<windows.h>
#include<math.h>
#ifndef LIB_H
#define LIB_H
extern "C" void _declspec(dllexport)setCalculate(HWND hwnd,HWND hwnd1,HWND hwnd2,HWND hwnd3,HWND hwnd4);
extern "C" void _declspec(dllexport)setClearAll(HWND hwnd1,HWND hwnd2,HWND hwnd3,HWND hwnd4);
#endif
<2>event.cpp
#include"event.h"
char Money[] = "";
char Rate[] = "";
char Year[] = "";
char Total[] = "";
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ +
+ * :Check +
+ * : +
+ * : a[] +
+ * : TRUE FALSE +
+ +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
BOOL Check(char a[])
{
int i;
int len = strlen(a);
for(i=0;i<len;i++)
{
if(a[i]>'9'||a[i]<'0')
{
return FALSE;
}
}
return TRUE;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ +
+ * :setCalculate +
+ * : CalculateButton +
+ , , +
+ * : hwnd +
+ hwnd1 +
+ hwnd2 +
+ hwnd3 +
+ hwnd4 +
+ * : +
+ +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void setCalculate(HWND hwnd,HWND hwnd1,HWND hwnd2,HWND hwnd3,HWND hwnd4)
{
GetWindowText(hwnd1,Money,20);
GetWindowText(hwnd2,Rate,20);
GetWindowText(hwnd3,Year,20);
double totalMoney;
if(Check(Money)&&Check(Rate)&&Check(Year))
{
totalMoney = atof(Money)*pow(1/atof(Rate)+1,atoi(Year));
gcvt(totalMoney,10,Total);
SetWindowText(hwnd4,Total);
}
else
{
MessageBox(hwnd,TEXT(" , "),TEXT(" "),MB_OK);
SetWindowText(hwnd1,"");
SetWindowText(hwnd2,"");
SetWindowText(hwnd3,"");
SetWindowText(hwnd4,"");
}
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ +
+ * :setClearAll +
+ * : ClearButton +
+ +
+ * : hwnd1 +
+ hwnd2 +
+ hwnd3 +
+ hwnd4 +
+ * : +
+ +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void setClearAll(HWND hwnd1,HWND hwnd2,HWND hwnd3,HWND hwnd4)
{
SetWindowText(hwnd1,"");
SetWindowText(hwnd2,"");
SetWindowText(hwnd3,"");
SetWindowText(hwnd4,"");
}
window
<1>window.h
//windows
#include<windows.h>
extern char szTitle[]; //
extern char szWindowClass[]; //
extern char szMenuName[] ;
extern int ID,ID_1;
//
ATOM InitApplication(HINSTANCE); //
BOOL InitInstance(HINSTANCE , int); //
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM); //
int APIENTRY WinMain( HINSTANCE , HINSTANCE , LPSTR , int); //
BOOL CreateControl(HINSTANCE,HWND, LPSTR); //
<2>window.cpp
#include "window.h"
#include<math.h>
//
char szTitle[] = "Windows DLL "; //
char szWindowClass[] = "w32"; //
char szMenuName[] = "NULL"; //
typedef void (*lpsetCalculateFun)(HWND ,HWND ,HWND ,HWND ,HWND);
typedef void (*lpsetClearAllFun)(HWND ,HWND ,HWND ,HWND);
HWND hwnd1,hwnd2,hwnd3,hwnd4,calculateButton,clearButton;
HWND hwnd;
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ +
+ * :WinMain +
+ * : , , +
+ * : hInstance +
+ hPrevInstance +
+ lpCmdLine +
+ nCmdShow +
+ * :msg.wParam +
+ +
++++++++++++++++++++++++++++++++++++++++++++++++*+++++++++++++++++++++++++++++++*/
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance , LPSTR lpCmdLine , int nCmdShow )
{
MSG msg; //
InitApplication( hInstance); //
if( !InitInstance( hInstance, nCmdShow ) ) //
{
return FALSE;
}
while ( GetMessage(&msg, (HWND) NULL, 0, 0) ) //
{
TranslateMessage(&msg); //
DispatchMessage(&msg); //
}
return msg.wParam; // PostQuitMesage
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ +
+ * :InitApplication +
+ * : +
+ * : hInstance +
+ * : , , , 0 +
+ +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
ATOM InitApplication(HINSTANCE hInstance)
{
WNDCLASS wc; //
//
wc.style = CS_HREDRAW | CS_VREDRAW; //
wc.lpfnWndProc = WndProc; //
wc.cbClsExtra = 0; //
wc.cbWndExtra = 0; //
wc.hInstance = hInstance; //
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); //
wc.hCursor = LoadCursor(NULL, IDC_ARROW); //
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); //
wc.lpszClassName = szWindowClass; //
wc.lpszMenuName = szMenuName; //
return RegisterClass(&wc); //
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ +
+ * :InitInstance +
+ * : +
+ * : hInstance +
+ nCmdShow +
+ * : , , , 0 +
+ +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{ //
hwnd = CreateWindow(
szWindowClass, // ,
szTitle, // ,
WS_OVERLAPPEDWINDOW |WS_VSCROLL|WS_HSCROLL, //
CW_USEDEFAULT, // x
CW_USEDEFAULT, // y
400, //
300, //
NULL, //
NULL, //
hInstance, //
NULL //
);
if(!hwnd) //
{
return FALSE;
}
CreateControl( hInstance, hwnd, NULL);
ShowWindow(hwnd, nCmdShow); //
UpdateWindow(hwnd); // WM_PAINT
return TRUE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ +
+ * :CreateControl +
+ * : +
+ * : hwndp +
+ szTitle +
+ * : +
+ +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
BOOL CreateControl(HINSTANCE hInstance, HWND hwndp, LPSTR szTitle)
{
hwnd1 = CreateWindow( "edit",NULL, WS_CHILD |WS_VISIBLE|WS_BORDER,
50, 40,100, 20,
hwndp, NULL,hInstance, NULL);
calculateButton = CreateWindow( "BUTTON"," ", WS_CHILD |WS_VISIBLE|WS_BORDER,
180, 40,60, 20,
hwndp, NULL,hInstance, NULL);
clearButton = CreateWindow( "BUTTON"," ", WS_CHILD |WS_VISIBLE|WS_BORDER,
180, 70,60, 20,
hwndp, NULL,hInstance, NULL);
hwnd2 = CreateWindow( "edit",NULL, WS_CHILD |WS_VISIBLE|WS_BORDER,
50, 70,100, 20,
hwndp, NULL,hInstance, NULL);
hwnd3 = CreateWindow( "edit",NULL, WS_CHILD |WS_VISIBLE|WS_BORDER,
50, 100,100, 20,
hwndp, NULL,hInstance, NULL);
hwnd4 = CreateWindow( "EDIT",NULL, WS_CHILD |WS_VISIBLE|WS_VSCROLL|WS_BORDER|ES_LEFT|ES_MULTILINE|ES_AUTOVSCROLL,
50, 130,300, 100,
hwndp, NULL,hInstance, NULL);
ShowWindow(hwnd1, SW_SHOW);
ShowWindow(calculateButton, SW_SHOW);
ShowWindow(clearButton, SW_SHOW);
ShowWindow(hwnd2, SW_SHOW);
ShowWindow(hwnd3, SW_SHOW);
ShowWindow(hwnd4, SW_SHOW);
return TRUE;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ +
+ * :WndProc +
+ * : +
+ * : hwnd +
+ message +
+ wParam MSG +
+ lParam MSG +
+ * :0 +
+ +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
LRESULT CALLBACK WndProc(HWND hwnd , UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch(message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
TextOut(hdc, 150 , 10, " ", strlen(" "));
TextOut(hdc, 10 , 40, " :", strlen(" :"));
TextOut(hdc, 10 , 70, " :", strlen(" :"));
TextOut(hdc, 10 , 100, " :", strlen(" :"));
EndPaint(hwnd,&ps);
break;
case WM_COMMAND:
HINSTANCE hDll;
lpsetCalculateFun setCalculateFun;
lpsetClearAllFun setClearAllFun;
hDll = LoadLibrary("..\\DLL\\Debug\\DLL.dll"); // DLL
if(hDll!=NULL)
{
setCalculateFun = (lpsetCalculateFun)GetProcAddress(hDll,"setCalculate");//
setClearAllFun = (lpsetClearAllFun)GetProcAddress(hDll,"setClearAll"); //
if(setCalculateFun!=NULL)
{
if(LOWORD(lParam)==LOWORD(calculateButton))
{
setCalculateFun(hwnd,hwnd1,hwnd2,hwnd3,hwnd4);
}
}
if(setClearAllFun!=NULL)
{
if(LOWORD(lParam)==LOWORD(clearButton))
{
setClearAllFun(hwnd1,hwnd2,hwnd3,hwnd4);
}
}
FreeLibrary(hDll);
}
else
{
MessageBox(hwnd,TEXT("hDll "),TEXT(" "),MB_OK);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
제한된 크기의 디렉토리를 만드는 방법오늘 저는 장치에 공간이 없을 때 백업 중에 응용 프로그램이 어떻게 작동하는지 테스트(및 수정)하는 작업이 있습니다. 결과적으로 "남은 공간 없음"오류로 백업이 실패하면 새 파일이 없어야 합니다. 지금까지 문제를 재...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.