Reputation: 21
I am running the normal win32 API, but all messages are displayed shortly after execution. I was testing the callback of the input keys for my game and nothing happens when I press any button, but after closing the application everything goes back to normal and I have no idea what I'm doing wrong
Window file
#include <stdio.h>
#include <stdlib.h>
#include "./window.h"
Window wind;
LRESULT window_callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
switch (uMsg) {
case WM_DESTROY: {
PostQuitMessage(0);
exit(EXIT_SUCCESS);
} break;
case WM_KEYUP: {
printf("SOME MESSAGE");
} break;
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
void init_window() {
WNDCLASSA window_class = {0};
window_class.style = CS_HREDRAW|CS_VREDRAW;
window_class.lpfnWndProc = window_callback;
window_class.hCursor = LoadCursor(NULL, IDC_ARROW);
window_class.lpszClassName = "GAME_WINDOW_CLASS";
RegisterClassA(&window_class);
wind.ws_window = CreateWindowEx(0,
window_class.lpszClassName,
wind.title,
WS_VISIBLE | WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
wind.width, wind.height,
NULL, NULL, NULL, NULL);
wind.ws_canvas = GetDC(wind.ws_window);
}
void update_window() {
MSG message;
while (GetMessage(&message, NULL, 0, 0)) {
TranslateMessage(&message);
DispatchMessage(&message);
}
}
Window create_window(char * title, int width, int height) {
wind.title = title;
wind.width = width;
wind.height = height;
wind.running = 1;
init_window();
}
Main file
#include <stdio.h>
// #include "core/gui.h"
#include "core/window.h"
void main() {
create_window("Game Window", 600, 600);
while(1) {
// if(key_pressed("A"))
// printf("A was pressed!");
update_window();
}
}
Puting an "\n" at the end of printf solve the problem
Upvotes: 0
Views: 214
Reputation: 29
Win api: use TextOut() or ExTextOut() NOT printf(). You are writing to a HWND not a standard C handle. Also Message Box() instead of printf for debug. Next: WM_PAINT, and it's sequence BeginPaint...EndPaint. This should get you started.
Upvotes: 1