I have build a code and I have 2 cpp files. I did include in the header(.h) the functin and I add also add in the main cpp the "header.h", but one error comes with:
||=== Build: Debug in Ex2CppFILES (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `Z7WndProcP6HWND__jjl@16':|
C:\Users\..............\main.cpp|14|undefined reference to `StaticWindow()'|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
this is the code:
The main.cpp
#include <windows.h>
#include "resources.h"
HWND hwnd;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch(msg)
{
case WM_CREATE:
{
StaticWindow();
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProcW(hwnd, msg, wp, lp);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int nCmdShow)
{
WNDCLASSW wc = {0};
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = hInst;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = L"myWindowClass";
if(!RegisterClassW(&wc))
return -1;
hwnd = CreateWindowW(L"myWindowClass", L"Ex2FilesC++", WS_OVERLAPPEDWINDOW,
350, 150, 700, 500, NULL, NULL, NULL, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
MSG msg = {0};
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
the resources.cpp
#include <windows.h>
#include "resources.h"
void StaticWindow(HWND hwnd)
{
CreateWindowW(L"static", L"Static window from resources.cpp", WS_CHILD | WS_VISIBLE,
10, 20, 150, 50, hwnd, NULL, NULL, NULL);
}
resources.h
void StaticWindow();
What I have tried:
I'm using Code::Blocks ver 17.12
and C++ the language..
Please help. Thank you..!