#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <tchar.h>
#include "main.h"
//
// Process WM_COMMAND message for window/dialog: hwndDlg
//
void hwndDlg_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
// TODO: Add your message processing code here...
static int count = 0;
char thetext[20];
count++;
wsprintf(thetext,"Clicked %d times",count);
if(id==IDOK)SetDlgItemText(hwnd,IDOK,thetext);
}
//
// Process WM_CLOSE message for window/dialog: hwndDlg
//
void hwndDlg_OnClose(HWND hwnd)
{
// TODO: Add your message processing code here...
ExitProcess(0);
}
static LRESULT CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
HANDLE_MSG (hwndDlg, WM_CLOSE, hwndDlg_OnClose);
HANDLE_MSG (hwndDlg, WM_COMMAND, hwndDlg_OnCommand);
}
return 0;
}
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
/* The user interface is a modal dialog box */
DialogBoxParam(0, MAKEINTRESOURCE(DLG_MAIN), 0, (DLGPROC)MainDlgProc,0);
return 0;
}
Why?
First parameter 0, need to be hInstance for resources ?.
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
/* The user interface is a modal dialog box */
DialogBoxParam(hInstance, MAKEINTRESOURCE(DLG_MAIN), 0, (DLGPROC)MainDlgProc,0);
return 0;
}
No. Either with 0, hInstance or GetModuleHandle(0) the dialog doesn't show up.
It must be something else. Although if I register the window class it does show up.
But I've coded dialog-based programs before and it doesn't need to register the class.
Now, I'm confused.
In MainDlgProc WM_INITDIALOG message should return TRUE ?
If in rc file is CLASS keyword, remove it.
This code works:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <tchar.h>
#include "main.h"
#define NELEMS(a) (sizeof(a) / sizeof((a)[0]))
static HANDLE ghInstance;
void hwndDlg_OnClose(HWND hwnd)
{
ExitProcess(0);
}
void hwndDlg_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
if(id==IDOK) {
HWND textedit = GetDlgItem(hwnd,4001);
HWND listbox = GetDlgItem(hwnd,4002);
char buf[25];
GetDlgItemText(hwnd,4001,buf,20);
SendMessage(listbox,LB_ADDSTRING,0,(LPARAM)buf);
}
}
BOOL CALLBACK MainDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
HANDLE_MSG (hwndDlg, WM_CLOSE, hwndDlg_OnClose);
HANDLE_MSG (hwndDlg, WM_COMMAND, hwndDlg_OnCommand);
default: return FALSE;
}
}
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
WNDCLASSEX wcx;
ghInstance = hInstance;
/* Get system dialog information */
wcx.cbSize = sizeof(wcx);
if (!GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), &wcx))
return 0;
/* Add our own stuff */
wcx.hInstance = hInstance;
wcx.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
wcx.lpszClassName = _T("testClass");
if (!RegisterClassEx(&wcx))
return 0;
/* The user interface is a modal dialog box */
return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)MainDlgProc);
}
I guess I must have that class registration there. Very strange...
Quote from: timovjl on January 03, 2008, 07:01:37 PM
If in rc file is CLASS keyword, remove it.
Thanks for the tip. It worked! ;)