Comments (1)
Hello,
You just have to define and associate a WndProc for each window.
The following example shows how to create two windows, we associate to each of them a WndProc function.
When you click on a window, a MessageBox appears mentioning which window has received the mouse down message.
Only window 1 closes the application when you click the close button.
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#include <Windows.h>
#include <CommCtrl.h>
HWND window1 = nullptr;
WNDPROC defWndProcWindow1 = nullptr;
HWND window2 = nullptr;
WNDPROC defWndProcWindow2 = nullptr;
LRESULT CALLBACK WndProcWindow1(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
if (message == WM_CLOSE && hwnd == window1) PostQuitMessage(0);
if (message == WM_LBUTTONDOWN) MessageBox(window1, L"Window1 click", L"", MB_OK);
return CallWindowProc(defWndProcWindow1, hwnd, message, wParam, lParam);
}
LRESULT CALLBACK WndProcWindow2(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
if (message == WM_CLOSE && hwnd == window2) CloseWindow(window2);
if (message == WM_LBUTTONDOWN) MessageBox(window2, L"Window2 click", L"", MB_OK);
return CallWindowProc(defWndProcWindow2, hwnd, message, wParam, lParam);
}
int main() {
window1 = CreateWindowEx(0, WC_DIALOG, L"Window1", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, nullptr, nullptr, nullptr, nullptr);
defWndProcWindow1 = (WNDPROC)SetWindowLongPtr(window1, GWLP_WNDPROC, (LONG_PTR)WndProcWindow1);
ShowWindow(window1, SW_SHOW);
window2 = CreateWindowEx(0, WC_DIALOG, L"Window2", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, nullptr, nullptr, nullptr, nullptr);
defWndProcWindow2 = (WNDPROC)SetWindowLongPtr(window2, GWLP_WNDPROC, (LONG_PTR)WndProcWindow2);
ShowWindow(window2, SW_SHOW);
MSG message = { 0 };
while (GetMessage(&message, nullptr, 0, 0))
DispatchMessage(&message);
return (int)message.wParam;
}
But if you want to use a GUI close to the Win32 API, but much easier to use.
I suggest you to look at my xtd project.
Here is the same example with xtd :
#include <xtd/xtd>
using namespace xtd::forms;
int main() {
form form1;
form1.text("form1");
form1.click += [&] {
message_box::show(form1, "form1 click");
};
form form2;
form2.text("form2");
form2.click += [&] {
message_box::show(form2, "form2 click");
};
form2.show();
application::run(form1);
}
Regards,
Gammasoft
from examples_win32.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from examples_win32.